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
Conversation
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.
node_labels = if node['osrfbuild']['agent']['labels'] | ||
node['osrfbuild']['agent']['labels'].dup | ||
else | ||
Array.new | ||
end |
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.
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.
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 |
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.
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.
node_labels = if node['osrfbuild']['agent']['labels'] | ||
node['osrfbuild']['agent']['labels'].dup | ||
else | ||
Array.new | ||
end |
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.
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.
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 anoverride
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.