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

Step namespace should have priority over anything else. #161

Merged
merged 1 commit into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public PodTemplate(PodTemplate from) {
this.setInstanceCap(from.getInstanceCap());
this.setLabel(from.getLabel());
this.setName(from.getName());
this.setNamespace(from.getNamespace());
this.setInheritFrom(from.getInheritFrom());
this.setNodeSelector(from.getNodeSelector());
this.setServiceAccount(from.getServiceAccount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ public void stop(Throwable cause) throws Exception {

private String checkNamespace(KubernetesCloud kubernetesCloud, NamespaceAction namespaceAction) {
String namespace = null;
if (!Strings.isNullOrEmpty(namespaceAction.getNamespace())) {
namespace = namespaceAction.getNamespace();
} else if (!Strings.isNullOrEmpty(step.getNamespace())) {
if (!Strings.isNullOrEmpty(step.getNamespace())) {
namespace = step.getNamespace();
} else if (!Strings.isNullOrEmpty(namespaceAction.getNamespace())) {
namespace = namespaceAction.getNamespace();
} else if (!Strings.isNullOrEmpty(kubernetesCloud.getNamespace())) {
namespace = kubernetesCloud.getNamespace();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,28 @@ public void runWithOverriddenNamespace() throws Exception {
r.assertLogContains(overriddenNamespace, b);
}

@Test
public void runWithOverriddenNamespace2() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this just be the only runWithOverriddenNamespace test ?
I'm not sure what the other one was testing because the namespace was not in the pipeline

Copy link
Contributor Author

@iocanel iocanel May 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runWithOverriddenNamespace is meant to verify that if a namespace is not explicitly specified it will be picked up from the NamespaceAction.

runWithOverriddenNamespace2 is meant to verify that if a namepsace IS explictly specified its the one that will be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carlossg: ^^^

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense?

configureCloud(r);
String overriddenNamespace = "kubernetes-plugin-overridden-namespace";
KubernetesClient client = cloud.connect();
// Run in our own testing namespace
client.namespaces().createOrReplace(
new NamespaceBuilder().withNewMetadata().withName("testns2").endMetadata()
.build());

WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "job with dir");
p.setDefinition(new CpsFlowDefinition(loadPipelineScript("runWithOverriddenNamespace2.groovy"), true));

WorkflowRun b = p.scheduleBuild2(0).waitForStart();
NamespaceAction namespaceAction = new NamespaceAction(b);
namespaceAction.push(overriddenNamespace);

assertNotNull(b);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("testns2", b);
}

// @Test
public void runInPodWithRestart() throws Exception {
story.addStep(new Statement() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
podTemplate(cloud: 'minikube', namespace: 'testns2', label: 'mypod', volumes: [emptyDirVolume(mountPath: '/my-mount')], containers: [
containerTemplate(name: 'jnlp', image: 'jenkinsci/jnlp-slave:2.62-alpine', args: '${computer.jnlpmac} ${computer.name}')
]) {

node ('mypod') {
container(name: 'jnlp') {
sh "cat /var/run/secrets/kubernetes.io/serviceaccount/namespace"
}
}
}