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

Refactor labels and make docker label auto-generated instead of default. #37

Merged
merged 2 commits into from Apr 12, 2023

Conversation

nuclearsandwich
Copy link
Member

@nuclearsandwich nuclearsandwich commented Mar 17, 2023

This change is prompted by the addition of recipes for macOS agents coming in a further PR.
Due to the way chef attributes are interleaved, the default docker label will be applied to any node which does not use an override level attribute to remove it (see attribute precedence docs).

Instead, I've made the docker label unconditionally applied when auto-generated labels are enabled since the default recipe is currently for Linux agents and all current linux agents are docker agents. Changes to that assumption in the future would require additional significant changes to the recipes so I'm not too worried about that.

Since the docker label is being applied by default where applicable, I removed it from the default attributes and updated the recipe to handle a lack of default labels.

I also set it up so that labels which are defined in node attributes won't get added if they're already listed. Ruby has a Set class in the standard library which we could use but I don't think there's a justification over these little logic snippets.

In order to allow re-use across different platforms, the docker label
shouldn't be the default. Since there is no default, let's leave it off.
This means we need to handle its absence in the recipe.

We also add the docker label (if it is not already present)
automatically for all hosts since all Linux hosts are docker agents
currently.
Also fixes an indention inconsistency.
Comment on lines +49 to +53
node_labels = if node['osrfbuild']['agent']['labels']
node['osrfbuild']['agent']['labels'].dup
else
Array.new
end
Copy link
Member Author

Choose a reason for hiding this comment

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

There's a way to do this in one line with Ruby's safe navigation operator but I hesitate to do so given that it's not a very common or at-a-glance readable expression. Open to other preferences though.

Suggested change
node_labels = if node['osrfbuild']['agent']['labels']
node['osrfbuild']['agent']['labels'].dup
else
Array.new
end
node_labels = node['osrfbuild']['agent']['labels']&.dup || Array.new

Copy link
Contributor

Choose a reason for hiding this comment

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

new syntax is really great but I have no previous idea about the safe navigation operator. I'm inclined to leave as it is in the PR.

Comment on lines +49 to +53
node_labels = if node['osrfbuild']['agent']['labels']
node['osrfbuild']['agent']['labels'].dup
else
Array.new
end
Copy link
Contributor

Choose a reason for hiding this comment

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

new syntax is really great but I have no previous idea about the safe navigation operator. I'm inclined to leave as it is in the PR.

@nuclearsandwich nuclearsandwich merged commit 5005ba6 into latest Apr 12, 2023
7 checks passed
@nuclearsandwich nuclearsandwich deleted the nuclearsandwich/labels-refactoring branch April 12, 2023 18:03
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.

None yet

2 participants