-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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-44285] Tool Location overwrites are not preserved #318
Changes from 4 commits
d0f75c1
6d27033
ddec66f
960c0f4
8d95d98
7c25271
9acb62c
c6f1df5
aa0a515
cb87010
0d18be8
a89692d
e9fbcb9
6b09e00
0c0e489
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
@@ -12,6 +13,7 @@ | |
|
||
import javax.annotation.Nonnull; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.csanchez.jenkins.plugins.kubernetes.model.TemplateEnvVar; | ||
import org.csanchez.jenkins.plugins.kubernetes.volumes.PodVolume; | ||
|
@@ -110,7 +112,8 @@ public class PodTemplate extends AbstractDescribableImpl<PodTemplate> implements | |
|
||
private List<PodImagePullSecret> imagePullSecrets = new ArrayList<PodImagePullSecret>(); | ||
|
||
private transient List<ToolLocationNodeProperty> nodeProperties; | ||
@SuppressFBWarnings(value = "SE_BAD_FIELD") | ||
private List<ToolLocationNodeProperty> nodeProperties = new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on upgrade this will be null because the xml does not have the option |
||
|
||
private String yaml; | ||
|
||
|
@@ -135,6 +138,7 @@ public PodTemplate(PodTemplate from) { | |
this.setVolumes(from.getVolumes()); | ||
this.setWorkspaceVolume(from.getWorkspaceVolume()); | ||
this.setYaml(from.getYaml()); | ||
this.setNodeProperties(from.getNodeProperties()); | ||
} | ||
|
||
@Deprecated | ||
|
@@ -476,7 +480,14 @@ public void setImagePullSecrets(List<PodImagePullSecret> imagePullSecrets) { | |
|
||
@DataBoundSetter | ||
public void setNodeProperties(List<ToolLocationNodeProperty> nodeProperties){ | ||
this.nodeProperties = nodeProperties; | ||
if( nodeProperties != null){ | ||
this.nodeProperties.clear(); | ||
this.addNodeProperties(nodeProperties); | ||
} | ||
} | ||
|
||
public void addNodeProperties(List<ToolLocationNodeProperty> nodeProperties){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need this method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be inlined. |
||
this.nodeProperties.addAll(nodeProperties); | ||
} | ||
|
||
@Nonnull | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,11 @@ | |
<f:textbox/> | ||
</f:entry> | ||
|
||
<f:descriptorList title="${%Node Properties}" descriptors="${h.getNodePropertyDescriptors(descriptor.clazz)}" field="nodeProperties" /> | ||
<!-- descriptorList is not working somehow, repeatableProperty has same functionality, just ui changes a little --> | ||
<f:entry title="${%Tool Locations}"> | ||
<f:repeatableProperty field="nodeProperties" noAddButton="false" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Vlatombe any suggestions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd better stick to the existing one. |
||
</f:entry> | ||
|
||
<f:block> | ||
<table> | ||
<f:optionalBlock title="${%Use custom workspace volume}" field="customWorkspaceVolumeEnabled" inline="true"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,11 +30,13 @@ | |
import static org.hamcrest.Matchers.*; | ||
import static org.junit.Assert.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import hudson.tools.ToolLocationNodeProperty; | ||
import org.csanchez.jenkins.plugins.kubernetes.model.KeyValueEnvVar; | ||
import org.csanchez.jenkins.plugins.kubernetes.model.SecretEnvVar; | ||
import org.csanchez.jenkins.plugins.kubernetes.volumes.HostPathVolume; | ||
|
@@ -473,4 +475,22 @@ public void shouldSubstituteMultipleEnvVarsAndNotUseDefaultsForMissing() { | |
properties.put("key2", "value2"); | ||
assertEquals("value1 or value2 or ${key3}", substitute("${key1} or ${key2} or ${key3}", properties, "defaultValue")); | ||
} | ||
|
||
@Test | ||
public void shouldCompineAllToolLocations() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
{ | ||
PodTemplate podTemplate1 = new PodTemplate(); | ||
List<ToolLocationNodeProperty> nodeProperties1 = new ArrayList<>(); | ||
nodeProperties1.add(new ToolLocationNodeProperty(new ToolLocationNodeProperty.ToolLocation("toolKey1@Test","toolHome1"))); | ||
podTemplate1.setNodeProperties(nodeProperties1); | ||
|
||
PodTemplate podTemplate2 = new PodTemplate(); | ||
List<ToolLocationNodeProperty> nodeProperties2 = new ArrayList<>(); | ||
nodeProperties2.add(new ToolLocationNodeProperty(new ToolLocationNodeProperty.ToolLocation("toolKey2@Test","toolHome2"))); | ||
podTemplate2.setNodeProperties(nodeProperties2); | ||
|
||
PodTemplate result = combine(podTemplate1,podTemplate2); | ||
|
||
assertThat(result.getNodeProperties(), hasItems(nodeProperties1.get(0),nodeProperties2.get(0))); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson> | ||
<disabledAdministrativeMonitors/> | ||
<version>2.7.4</version> | ||
<numExecutors>2</numExecutors> | ||
<mode>NORMAL</mode> | ||
<useSecurity>true</useSecurity> | ||
<authorizationStrategy class="hudson.security.AuthorizationStrategy$Unsecured"/> | ||
<securityRealm class="hudson.security.SecurityRealm$None"/> | ||
<disableRememberMe>false</disableRememberMe> | ||
<projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/> | ||
<workspaceDir>${JENKINS_HOME}/workspace/${ITEM_FULLNAME}</workspaceDir> | ||
<buildsDir>${ITEM_ROOTDIR}/builds</buildsDir> | ||
<jdks/> | ||
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/> | ||
<myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/> | ||
<clouds> | ||
<org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud plugin="kubernetes@0.10"> | ||
<name>kubernetes</name> | ||
<templates> | ||
<org.csanchez.jenkins.plugins.kubernetes.PodTemplate> | ||
<inheritFrom></inheritFrom> | ||
<name>maven</name> | ||
<instanceCap>2147483647</instanceCap> | ||
<idleMinutes>0</idleMinutes> | ||
<label>maven</label> | ||
<nodeSelector></nodeSelector> | ||
<volumes/> | ||
<containers> | ||
<org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate> | ||
<name>maven</name> | ||
<image>maven:alpine</image> | ||
<privileged>false</privileged> | ||
<alwaysPullImage>false</alwaysPullImage> | ||
<workingDir>/home/jenkins</workingDir> | ||
<command>/bin/sh -c</command> | ||
<args>cat</args> | ||
<ttyEnabled>true</ttyEnabled> | ||
<resourceRequestCpu></resourceRequestCpu> | ||
<resourceRequestMemory></resourceRequestMemory> | ||
<resourceLimitCpu></resourceLimitCpu> | ||
<resourceLimitMemory></resourceLimitMemory> | ||
<envVars/> | ||
</org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate> | ||
</containers> | ||
<envVars/> | ||
<annotations/> | ||
<imagePullSecrets/> | ||
<nodeProperties> | ||
<hudson.tools.ToolLocationNodeProperty> | ||
<locations> | ||
<hudson.tools.ToolLocationNodeProperty_-ToolLocation> | ||
<type>hudson.plugins.git.GitTool$DescriptorImpl</type> | ||
<name>Default</name> | ||
<home>/custom/path</home> | ||
</hudson.tools.ToolLocationNodeProperty_-ToolLocation> | ||
</locations> | ||
</hudson.tools.ToolLocationNodeProperty> | ||
</nodeProperties> | ||
</org.csanchez.jenkins.plugins.kubernetes.PodTemplate> | ||
</templates> | ||
<serverUrl>http://example.com</serverUrl> | ||
<skipTlsVerify>false</skipTlsVerify> | ||
<namespace>default</namespace> | ||
<jenkinsUrl></jenkinsUrl> | ||
<containerCap>10</containerCap> | ||
<retentionTimeout>5</retentionTimeout> | ||
<connectTimeout>0</connectTimeout> | ||
<readTimeout>0</readTimeout> | ||
</org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud> | ||
</clouds> | ||
<quietPeriod>5</quietPeriod> | ||
<scmCheckoutRetryCount>0</scmCheckoutRetryCount> | ||
<views> | ||
<hudson.model.AllView> | ||
<owner class="hudson" reference="../../.."/> | ||
<name>All</name> | ||
<filterExecutors>false</filterExecutors> | ||
<filterQueue>false</filterQueue> | ||
<properties class="hudson.model.View$PropertyList"/> | ||
</hudson.model.AllView> | ||
</views> | ||
<primaryView>All</primaryView> | ||
<slaveAgentPort>-1</slaveAgentPort> | ||
<label></label> | ||
<crumbIssuer class="hudson.security.csrf.DefaultCrumbIssuer"> | ||
<excludeClientIPFromCrumb>false</excludeClientIPFromCrumb> | ||
</crumbIssuer> | ||
<nodeProperties/> | ||
<globalNodeProperties/> | ||
</hudson> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this actually needed ? doesn't fail without it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I indeed get a FindBugs. However ignoring it feels like hack.
In Jenkins core, this is handled using a
DescribableList
(see here). I would recommend sticking to the same pattern.