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-46519: Support for new affinities abstraction for slave templates #243

Closed
wants to merge 10 commits into from

Conversation

alorlea
Copy link

@alorlea alorlea commented Oct 31, 2017

With this feature we should be able to run the slaves on nodes based on different affinity options for a pod.

One use case, for us for example is we want to run the slaves in different kubernetes slaves without getting colocated on the kube slave where jenkins master is running.

So far I tried it out with the new NodeAffinity in a jenkins slave pod in our staging setup and it was able to attach the affinity onto the slave upon loading the template.

@alorlea alorlea force-pushed the JENKINS-46519 branch 3 times, most recently from 9c9c7ac to 99d82cd Compare November 3, 2017 09:12
Copy link
Contributor

@carlossg carlossg left a comment

Choose a reason for hiding this comment

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

Added some comments after a quick look.
Tests are currently failing and this would need some new tests

@@ -584,6 +588,22 @@ protected Object readResolve() {
return this;
}

@Nonnull
public List<Affinity> getAffinities() {
if(affinities == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you fix the formatting generally to match the rest of the code?
default eclipse java format

kubernetesPodAffinity.setNodeAffinity(nodeAffinity.buildAffinity());
LOGGER.log(Level.INFO, "Loading node affinity for slave!");
} catch (IOException e) {
e.printStackTrace();
Copy link
Contributor

Choose a reason for hiding this comment

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

needs to do something or log to logger

@@ -293,6 +312,7 @@ private Pod getPodTemplate(KubernetesSlave slave, PodTemplate template) {
.withContainers(containers.values().toArray(new Container[containers.size()]))
.withNodeSelector(getNodeSelectorMap(template.getNodeSelector()))
.withRestartPolicy("Never")
.withAffinity(kubernetesPodAffinity)
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe this can't be added if affinity is not set ?

Copy link
Author

Choose a reason for hiding this comment

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

I went over the code, and initially, if there is no node affinity, pod affinity or pod antiaffinity, we give an Affinity without setting anything. This is how the underying object behaviour of the Affinity object in the kubernetes fabric8 model.

@alorlea alorlea changed the title [WIP] Jenkins-46519: Support for new affinities abstraction for slave templates Jenkins-46519: Support for new affinities abstraction for slave templates Nov 28, 2017
@alorlea
Copy link
Author

alorlea commented Nov 29, 2017

I have been struggling this last couple of weeks to get a grasp on bringing tests in place. I have already some groovy templates in place for the test cases but I am getting issues to figure out the best way to fix the test. Any recommendations on how to debug this locally? I am using minikube & have access to a k8s cluster @carlossg

@alorlea alorlea force-pushed the JENKINS-46519 branch 4 times, most recently from 75a5e14 to 3e89d44 Compare December 5, 2017 14:34
@alorlea
Copy link
Author

alorlea commented Dec 5, 2017

@carlossg I added the corresponding tests for this feature.

Unfortunately, it is failing one of the other tests, ContainerExecDecoratorTest.testCommandExecution with a timeout.

I am not sure why this test is failing, as the other tests in that test suite are passing. I hope it is not an incompatibility issue with me updating the kubernetesclient dependency.

Martin Sander and others added 7 commits December 13, 2017 10:39
adding possibility to select an affinity from the dropdownlist

defining structure for affinities

adding directory structure for the UI

first working sample for node affinity with a JSON blob!

starting to add pod affinity and anti affinity in the kubernetes launcher class

Pod affinity and anti affinity support for JSON deserialization

minor fixes and updating UI code
* adding warning log traces when failing to add affinities
* fix code formatting

Reverting build volume upgrade based on the Kubernetes client.
It was missing the medium string.
one test at time

Node Affinity test loads correct template

fixed node & pod affinities tests

fix race condition on tests

fix broken asserts for mixed affinities test
testingNamespace = namespaceWithBranch;
}
} catch (KubernetesClientException e) {
// nothing to do
Copy link

Choose a reason for hiding this comment

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

@alorlea Hi. Just curious but shouldn't you just fail-fast in this case, rather than suppressing a KubernetseClientException like this?

@mumoshu
Copy link

mumoshu commented Dec 26, 2017

@alorlea Hi, thanks for your efforts on this! Really hope this gets merged someday.

Btw, does the failure persist across runs? Just confirming but I could find nothing suspicious other than https://github.com/jenkinsci/kubernetes-plugin/pull/243/files#diff-6fac64c3dbf99f73936f276f23b4386cR81, which doesn't seem to related with the failure.

Also, is the updated kubernetes-client necessary? Hopefully you can extract the kubernetes-client bump to an another PR to isolate the cause.

WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);

Thread.sleep(1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

why the sleeps? what is the condition that must be met ?

Copy link
Author

@alorlea alorlea Jan 2, 2018

Choose a reason for hiding this comment

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

@carlossg I had to add the sleep, because it seemed that the template seems to take time to load. This made the test fail as it would not find it on the list of templates.

@alorlea alorlea force-pushed the JENKINS-46519 branch 2 times, most recently from 3e6c8b6 to cbfa3e4 Compare January 2, 2018 11:20
@alorlea
Copy link
Author

alorlea commented Jan 3, 2018

@mumoshu Yes, it is consistent the failure with the ContainerExecDecoratorTest.testCommandExecution tests. The bump of the library as I understand is needed, due to the newer versions of Kubernetes, they added the new affinities API as part of their model. https://github.com/fabric8io/kubernetes-client#compatibility

@carlossg
Copy link
Contributor

carlossg commented Jan 9, 2018

The update of kubernetes-client is breaking the test, see #271

@carlossg
Copy link
Contributor

I have created #275 that will supersede this one, allowing any Pod configuration to be passed on. Otherwise adding all possible options (and options as complicated as this one) will be a maintenance nightmare.

Probably #271 will need to be fixed too

@alorlea
Copy link
Author

alorlea commented Mar 25, 2018

Hi @carlossg what is the current status with the migration to use YAML kubernetes file? Is there anything we can help with #275.

@alorlea
Copy link
Author

alorlea commented May 21, 2018

I will close this PR this corresponding functionality is now available with the new YAML abstraction

@alorlea alorlea closed this May 21, 2018
@alorlea alorlea deleted the JENKINS-46519 branch May 21, 2018 12:41
@alorlea alorlea restored the JENKINS-46519 branch May 21, 2018 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants