-
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 13 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package org.csanchez.jenkins.plugins.kubernetes; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
|
@@ -9,9 +10,14 @@ | |
import java.util.Set; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import hudson.model.*; | ||
import hudson.slaves.NodeProperty; | ||
import hudson.slaves.NodePropertyDescriptor; | ||
import hudson.util.DescribableList; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.csanchez.jenkins.plugins.kubernetes.model.TemplateEnvVar; | ||
import org.csanchez.jenkins.plugins.kubernetes.volumes.PodVolume; | ||
|
@@ -21,19 +27,11 @@ | |
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
|
||
import com.google.common.base.Strings; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
import hudson.Extension; | ||
import hudson.Util; | ||
import hudson.model.AbstractDescribableImpl; | ||
import hudson.model.Descriptor; | ||
import hudson.model.DescriptorVisibilityFilter; | ||
import hudson.model.Label; | ||
import hudson.model.Node; | ||
import hudson.model.labels.LabelAtom; | ||
import hudson.tools.ToolLocationNodeProperty; | ||
import io.fabric8.kubernetes.api.model.Pod; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import jenkins.model.Jenkins; | ||
|
@@ -43,7 +41,7 @@ | |
* | ||
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a> | ||
*/ | ||
public class PodTemplate extends AbstractDescribableImpl<PodTemplate> implements Serializable { | ||
public class PodTemplate extends AbstractDescribableImpl<PodTemplate> implements Serializable, Saveable { | ||
|
||
private static final long serialVersionUID = 3285310269140845583L; | ||
|
||
|
@@ -112,15 +110,15 @@ public class PodTemplate extends AbstractDescribableImpl<PodTemplate> implements | |
|
||
private List<PodImagePullSecret> imagePullSecrets = new ArrayList<PodImagePullSecret>(); | ||
|
||
private transient List<ToolLocationNodeProperty> nodeProperties; | ||
private PodTemplateToolLocation nodeProperties; | ||
|
||
private String yaml; | ||
|
||
@DataBoundConstructor | ||
public PodTemplate() { | ||
} | ||
|
||
public PodTemplate(PodTemplate from) { | ||
public PodTemplate(PodTemplate from) throws IOException { | ||
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 not throw IOException |
||
this.setAnnotations(from.getAnnotations()); | ||
this.setContainers(from.getContainers()); | ||
this.setImagePullSecrets(from.getImagePullSecrets()); | ||
|
@@ -137,6 +135,7 @@ public PodTemplate(PodTemplate from) { | |
this.setVolumes(from.getVolumes()); | ||
this.setWorkspaceVolume(from.getWorkspaceVolume()); | ||
this.setYaml(from.getYaml()); | ||
this.setNodeProperties(from.getNodeProperties()); | ||
} | ||
|
||
@Deprecated | ||
|
@@ -486,18 +485,19 @@ public void setImagePullSecrets(List<PodImagePullSecret> imagePullSecrets) { | |
} | ||
|
||
@DataBoundSetter | ||
public void setNodeProperties(List<ToolLocationNodeProperty> nodeProperties){ | ||
this.nodeProperties = nodeProperties; | ||
public void setNodeProperties(List<? extends NodeProperty<?>> properties) { | ||
this.getNodeProperties().clear(); | ||
this.getNodeProperties().addAll(properties); | ||
} | ||
|
||
@Nonnull | ||
public List<ToolLocationNodeProperty> getNodeProperties(){ | ||
if (nodeProperties == null) { | ||
return Collections.emptyList(); | ||
} | ||
@NonNull | ||
public PodTemplateToolLocation getNodeProperties(){ | ||
if( this.nodeProperties == null) | ||
this.nodeProperties = new PodTemplateToolLocation(this); | ||
return nodeProperties; | ||
} | ||
|
||
|
||
@Deprecated | ||
public String getResourceRequestMemory() { | ||
return getFirstContainer().map(ContainerTemplate::getResourceRequestMemory).orElse(null); | ||
|
@@ -671,6 +671,12 @@ private void optionalField(StringBuilder builder, String label, String value) { | |
} | ||
} | ||
|
||
/** | ||
* Empty implementation of Saveable interface. This interface is used for DescribableList implementation | ||
*/ | ||
@Override | ||
public void save() { } | ||
|
||
@Extension | ||
public static class DescriptorImpl extends Descriptor<PodTemplate> { | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.csanchez.jenkins.plugins.kubernetes; | ||
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. can you add the MIT license header please |
||
|
||
import hudson.model.Saveable; | ||
import hudson.slaves.NodeProperty; | ||
import hudson.slaves.NodePropertyDescriptor; | ||
import hudson.util.DescribableList; | ||
|
||
import java.io.Serializable; | ||
import java.util.Collection; | ||
|
||
/** | ||
* Pod Template Tool Location | ||
* This class extends Jenkins DescribableList as implemented in Slave Class. Also implements Serializable interface | ||
* for PodTemplate Class. | ||
* Using DescribableList is not possible directly in PodTemplate because DescribableList is not Serializable. | ||
* | ||
* @author <a href="mailto:aytuncbeken.ab@gmail.com">Aytunc BEKEN</a> | ||
*/ | ||
public class PodTemplateToolLocation extends DescribableList<NodeProperty<?>,NodePropertyDescriptor> implements Serializable { | ||
|
||
public PodTemplateToolLocation() {} | ||
|
||
|
||
public PodTemplateToolLocation(DescribableList.Owner owner) { | ||
super(owner); | ||
} | ||
|
||
public PodTemplateToolLocation(Saveable owner) { | ||
super(owner); | ||
} | ||
|
||
public PodTemplateToolLocation(Saveable owner, Collection<? extends NodeProperty<?>> initialList) { | ||
super(owner,initialList); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,10 +30,14 @@ | |
import static org.hamcrest.Matchers.*; | ||
import static org.junit.Assert.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import hudson.model.Node; | ||
import hudson.slaves.NodeProperty; | ||
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; | ||
|
@@ -215,7 +219,7 @@ public void shouldUnwrapParent() { | |
} | ||
|
||
@Test | ||
public void shouldDropNoDataWhenIdentical() { | ||
public void shouldDropNoDataWhenIdentical() { | ||
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. extra whitespaces |
||
PodTemplate podTemplate = new PodTemplate(); | ||
podTemplate.setName("Name"); | ||
podTemplate.setNamespace("NameSpace"); | ||
|
@@ -253,7 +257,7 @@ public void shouldDropNoDataWhenIdentical() { | |
} | ||
|
||
@Test | ||
public void shouldUnwrapMultipleParents() { | ||
public void shouldUnwrapMultipleParents() { | ||
PodTemplate parent = new PodTemplate(); | ||
parent.setName("parent"); | ||
parent.setLabel("parent"); | ||
|
@@ -293,7 +297,7 @@ public void shouldUnwrapMultipleParents() { | |
} | ||
|
||
@Test | ||
public void shouldCombineAllPodKeyValueEnvVars() { | ||
public void shouldCombineAllPodKeyValueEnvVars() { | ||
PodTemplate template1 = new PodTemplate(); | ||
KeyValueEnvVar podEnvVar1 = new KeyValueEnvVar("key-1", "value-1"); | ||
template1.setEnvVars(singletonList(podEnvVar1)); | ||
|
@@ -309,7 +313,7 @@ public void shouldCombineAllPodKeyValueEnvVars() { | |
} | ||
|
||
@Test | ||
public void shouldFilterOutNullOrEmptyPodKeyValueEnvVars() { | ||
public void shouldFilterOutNullOrEmptyPodKeyValueEnvVars() { | ||
PodTemplate template1 = new PodTemplate(); | ||
KeyValueEnvVar podEnvVar1 = new KeyValueEnvVar("", "value-1"); | ||
template1.setEnvVars(singletonList(podEnvVar1)); | ||
|
@@ -340,7 +344,7 @@ public void shouldCombineAllPodSecretEnvVars() { | |
} | ||
|
||
@Test | ||
public void shouldFilterOutNullOrEmptyPodSecretEnvVars() { | ||
public void shouldFilterOutNullOrEmptyPodSecretEnvVars() { | ||
PodTemplate template1 = new PodTemplate(); | ||
SecretEnvVar podSecretEnvVar1 = new SecretEnvVar("", "secret-1", "secret-key-1"); | ||
template1.setEnvVars(singletonList(podSecretEnvVar1)); | ||
|
@@ -438,7 +442,7 @@ public void shouldFilterOutEnvFromSourcesWithNullOrEmptyKey() { | |
} | ||
|
||
@Test | ||
public void shouldCombineAllMounts() { | ||
public void shouldCombineAllMounts() { | ||
PodTemplate template1 = new PodTemplate(); | ||
HostPathVolume hostPathVolume1 = new HostPathVolume("/host/mnt1", "/container/mnt1"); | ||
HostPathVolume hostPathVolume2 = new HostPathVolume("/host/mnt2", "/container/mnt2"); | ||
|
@@ -614,4 +618,23 @@ public void testValidateLabelTooLong() { | |
assertFalse(validateLabel("1234567890123456789012345678901234567890123456789012345678901234")); | ||
assertFalse(validateLabel("abcdefghijklmnopqrstuwxyzabcdefghijklmnopqrstuwxyzabcdefghijklmn")); | ||
} | ||
|
||
@Test | ||
public void shouldCombineAllToolLocations() { | ||
|
||
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))); | ||
|
||
} | ||
} |
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.
should not throw IOException