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

Create a Groovy script to apply singleton labels. #917

Merged
merged 10 commits into from
May 6, 2023

Conversation

nuclearsandwich
Copy link
Contributor

I think this script will need to be run as a system groovy script rather than with the sandbox. I have successfully tested it using the Jenkins script console.

I have not yet created the DSL job for it. I was hoping for some advice on how best to proceed there since storing the script in a standalone file isn't compatible with the system groovy script approach directly. I think what I'll need to do is read the file out of the release-tools git checkout from the Groovy DSL and supply the contents as a string to the system groovy field on the job.

I think this script will need to be run as a system groovy script rather
than with the sandbox. I have successfully tested it using the Jenkins
script console.
Comment on lines 12 to 44
if (label_nodes.size() == 1) {
println(tup[0] + " is currently applied to " + label_nodes[0].name)
continue
}

if (label_nodes.size() > 1) {
println("WARNING: Too many nodes with the label " + tup[0])
for (node in label_nodes) {
println(" " + node.name)
}
continue
}

if (label_nodes.size() < 1) {
println("No host currently has the label " + tup[0])
println("Appointing a node from the configured pool matching '" + tup[1] + "'")
node_set = Label.get(tup[1]).getNodes()
if (node_set.size() <= 0) {
println("WARNING: Pool of '" + tup[1] + "' machines for " + tup[0] + " is empty!")
}
node_pool = []
for (node in node_set) {
node_pool.add(node)
}
Collections.shuffle(node_pool)
appointed_node = node_pool[0]
new_label_string = appointed_node.getAssignedLabels().join(" ")
new_label_string = tup[0] + " " + new_label_string
appointed_node.setLabelString(new_label_string)
appointed_node.save()
println("Added label to " + appointed_node.name)
continue
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ended up using if and continue since Groovy has no internal elseif and I find the compound flow control spacing hard to read. However, if (hehe) there is a preference for if (...) {...} else if (...) {...} I am open to changing it.

nuclearsandwich and others added 6 commits May 1, 2023 16:57
I'd like to make this a struct/class but I'm not quite sure yet.
I was bending around the immutable set in order to use shuffle. But this
is much shorter and makes me happier.
Signed-off-by: Jose Luis Rivero <[email protected]>
Signed-off-by: Jose Luis Rivero <[email protected]>
@j-rivero
Copy link
Contributor

j-rivero commented May 4, 2023

Some changes to the PR:

  • I've implemented the DSL job inside core.dsl. The job load at generation time the groovy script and inject that into the systemGroovy step c0f4f57
  • Modified the groovy file to filter only the online nodes since most of the times we can find labels in swarm agents destroyed by the autoscaling for some reason and they are not really interesting to our logic: 73b12b6
  • Added a global comment to the top of groovy file 4fa302f

Still need to push some changes and run the testing. Move to draft by now. Hope to finish it by the end of today.

@j-rivero
Copy link
Contributor

j-rivero commented May 5, 2023

Final changes:

  • cron scheduling to go together with nightly generation 8bb1bbb
  • Mark build unstable if the labels were not found 2e522fc
  • Handle problems with standalone and jenkins paths using the readFromWorkspace. 7f22754

DSL tested: Build Status

Script tested: Build Status

@nuclearsandwich
Copy link
Contributor Author

Thanks for the assistance @j-rivero! Those changes are all very welcome!

@nuclearsandwich nuclearsandwich merged commit 7676225 into master May 6, 2023
@nuclearsandwich nuclearsandwich deleted the label-assignment-backstop branch May 6, 2023 00:07
j-rivero added a commit that referenced this pull request May 11, 2023
* Create a Groovy script to apply singleton labels.

I think this script will need to be run as a system groovy script rather
than with the sandbox. I have successfully tested it using the Jenkins
script console.

* Add a comment describing the form.

I'd like to make this a struct/class but I'm not quite sure yet.

* Replace shuffle with an in-place pick of a random number.

I was bending around the immutable set in order to use shuffle. But this
is much shorter and makes me happier.

* Add a global coment in the file

Signed-off-by: Jose Luis Rivero <[email protected]>

* Add the _nightly_node_labeler DSL job

Signed-off-by: Jose Luis Rivero <[email protected]>

* Filter nodes to only online nodes

Signed-off-by: Jose Luis Rivero <[email protected]>

* Mark build as unstable if labels were not set correctly

Signed-off-by: Jose Luis Rivero <[email protected]>

* Support for cron operations on nightly preparation

Signed-off-by: Jose Luis Rivero <[email protected]>

* Mark build unstable for non expected scenarios

Signed-off-by: Jose Luis Rivero <[email protected]>

* Fix path expected by Jenkins

Signed-off-by: Jose Luis Rivero <[email protected]>

---------

Signed-off-by: Jose Luis Rivero <[email protected]>
Co-authored-by: Jose Luis Rivero <[email protected]>
j-rivero added a commit that referenced this pull request Jun 28, 2023
* Create a Groovy script to apply singleton labels.

I think this script will need to be run as a system groovy script rather
than with the sandbox. I have successfully tested it using the Jenkins
script console.

* Add a comment describing the form.

I'd like to make this a struct/class but I'm not quite sure yet.

* Replace shuffle with an in-place pick of a random number.

I was bending around the immutable set in order to use shuffle. But this
is much shorter and makes me happier.

* Add a global coment in the file

Signed-off-by: Jose Luis Rivero <[email protected]>

* Add the _nightly_node_labeler DSL job

Signed-off-by: Jose Luis Rivero <[email protected]>

* Filter nodes to only online nodes

Signed-off-by: Jose Luis Rivero <[email protected]>

* Mark build as unstable if labels were not set correctly

Signed-off-by: Jose Luis Rivero <[email protected]>

* Support for cron operations on nightly preparation

Signed-off-by: Jose Luis Rivero <[email protected]>

* Mark build unstable for non expected scenarios

Signed-off-by: Jose Luis Rivero <[email protected]>

* Fix path expected by Jenkins

Signed-off-by: Jose Luis Rivero <[email protected]>

---------

Signed-off-by: Jose Luis Rivero <[email protected]>
Co-authored-by: Jose Luis Rivero <[email protected]>
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.

2 participants