-
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-46519: Support for new affinities abstraction for slave templates #243
Conversation
9c9c7ac
to
99d82cd
Compare
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.
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) { |
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.
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(); |
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.
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) |
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.
maybe this can't be added if affinity is not set ?
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 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.
c6a53f9
to
3c4a218
Compare
2bcff37
to
80ee0ae
Compare
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 |
75a5e14
to
3e89d44
Compare
@carlossg I added the corresponding tests for this feature. Unfortunately, it is failing one of the other tests, 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 |
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
3e89d44
to
f6273f8
Compare
testingNamespace = namespaceWithBranch; | ||
} | ||
} catch (KubernetesClientException e) { | ||
// nothing to do |
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.
@alorlea Hi. Just curious but shouldn't you just fail-fast in this case, rather than suppressing a KubernetseClientException like this?
@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); |
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.
why the sleeps? what is the condition that must be met ?
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.
@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.
3e6c8b6
to
cbfa3e4
Compare
@mumoshu Yes, it is consistent the failure with the |
The update of kubernetes-client is breaking the test, see #271 |
I will close this PR this corresponding functionality is now available with the new YAML abstraction |
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.