Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-72854] UX improvement: make pod templates readonly from UI for NonConfigurableKubernetesCloud #1566

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import hudson.model.Descriptor;
import hudson.model.DescriptorVisibilityFilter;
import hudson.slaves.Cloud;
import java.util.List;
import java.util.stream.Collectors;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
Expand All @@ -28,6 +30,14 @@ public Cloud reconfigure(@NonNull StaplerRequest req, JSONObject form) throws De
return DescriptorImpl.class.cast(getDescriptor()).newInstance(req, form);
}

@NonNull
@Override
public List<PodTemplate> getTemplates() {
return super.getTemplates().stream()
.peek(podTemplate -> podTemplate.setReadonlyFromUi(true))
.collect(Collectors.toList());
}

@Extension
public static class FilterImpl extends DescriptorVisibilityFilter {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ protected static MessageDigest getLabelDigestFunction() {
*/
private transient List<String> yamls;

private transient boolean readonlyFromUi;

@NonNull
public String getId() {
return id;
Expand Down Expand Up @@ -1049,6 +1051,14 @@ private void optionalField(StringBuilder builder, String label, String value) {
@Override
public void save() {}

public boolean isReadonlyFromUi() {
return readonlyFromUi;
}

public void setReadonlyFromUi(boolean readonlyFromUi) {
this.readonlyFromUi = readonlyFromUi;
}

@Extension
public static class DescriptorImpl extends Descriptor<PodTemplate> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ THE SOFTWARE.
<f:form method="post" action="configSubmit" name="config" class="jenkins-form">
<j:set var="instance" value="${it}"/>
<j:set var="descriptor" value="${instance.descriptor}"/>
<j:set var="readOnlyMode" value="${instance.readonlyFromUi}"/>
<j:if test="${instance.readonlyFromUi}">
<f:description>This Pod template is associated with a <strong>non-configurable</strong> cloud setup.</f:description>
</j:if>

<!-- main body of the configuration -->
<st:include it="${instance}" page="config.jelly"/>

<l:hasAdministerOrManage>
<f:bottomButtonBar>
<f:submit value="${%Save}"/>
</f:bottomButtonBar>
<j:if test="${!instance.readonlyFromUi}">
<f:bottomButtonBar>
<f:submit value="${%Save}"/>
</f:bottomButtonBar>
</j:if>
</l:hasAdministerOrManage>
</f:form>
<l:hasAdministerOrManage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ THE SOFTWARE.
<l:tasks>
<l:task href="" icon="symbol-settings"
title="${app.hasPermission(app.MANAGE) ? '%Configure' : '%View Configuration'}"/>
<l:delete permission="${app.MANAGE}" title="${%Delete Pod Template}" message="${%delete.template(it.name)}"/>
<j:if test="${!it.readonlyFromUi}">
<l:delete permission="${app.MANAGE}" title="${%Delete Pod Template}" message="${%delete.template(it.name)}"/>
</j:if>
<t:actions />
</l:tasks>
</l:side-panel>
Expand Down