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

WINC-650: [wmco] Apply worker role to BYOH Nodes #541

Merged
merged 4 commits into from
Jul 28, 2021

Conversation

sebsoto
Copy link
Contributor

@sebsoto sebsoto commented Jul 26, 2021

The goal of this PR is to ensure that BYOH Nodes have the worker role label.
In order to achieve this changes had to be made to the patch generation functions,
refactoring that makes up the bulk of the commits in the PR.

Moves everything that was present in the annotations package into the
metadata package. This is being done as we will need to use the
functions present in the annotations package for labels as well, and it
makes more sense to generalize the functions considering the
similarities between annotations and labels.
@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jul 26, 2021
@openshift-ci openshift-ci bot requested a review from aravindhp July 26, 2021 16:12
Refactors the patch creation in order to enable better unit testing.
Specifically, this commit makes it so that metadata.generatePatch
no longer returns the marshalled patches, but instead returns the slice
of patches it generated, allowing those to be marshalled at the call
sites, metadata.GenerateAddPatch() and metadata.GenerateRemovePatch().

This commit is important for two reasons. Firstly, using
assert.elementsMatch to test that a byte slice is correct does not seem
like the right thing to do. This seems as if it just tests that the
chars are all the same, so the patchdata could be made out of order and
this unit test would not catch that. Secondly this allows for more
complex testing, which will be required in a future commit where
generatePatch() handles both annotations and labels.

Additionally, since the tests had to be changed, I changed one case to
exercise the escaping functionality, something that was being missed by
the tests.
@sebsoto sebsoto changed the title WIP: [wmco] Apply worker role to BYOH Nodes WINC-650: [wmco] Apply worker role to BYOH Nodes Jul 26, 2021
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 26, 2021
@sebsoto
Copy link
Contributor Author

sebsoto commented Jul 26, 2021

/approve cancel

@openshift-ci openshift-ci bot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 26, 2021
Copy link
Member

@mansikulkarni96 mansikulkarni96 left a comment

Choose a reason for hiding this comment

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

Overall the implementation looks good, I think commit 2 &3 could have been combined together. Changes to the same functions in different commits, seems a little confusing to review.

// GenerateRemovePatch creates a comma-separated list of operations to remove all given labels and annotations from an
// object. A "remove" patch fails transactionally if any of the annotations do not exist.
func GenerateRemovePatch(labels, annotations []string) ([]byte, error) {
labelMap := make(map[string]string)
Copy link
Member

Choose a reason for hiding this comment

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

can be renamed, as to not give away the data structure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what I'd rename it to considering there is already a labels

Copy link
Contributor

@aravindhp aravindhp left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, @sebsoto

/approve

// generatePatch creates a patch applying the given operation onto each given annotation key and value
func generatePatch(op string, labels, annotations map[string]string) ([]*patch.JSONPatch, error) {
if len(labels) == 0 && len(annotations) == 0 {
return nil, errors.New("cannot have both label and annotation maps empty")
Copy link
Contributor

Choose a reason for hiding this comment

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

labels and annotations empty will suffice.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 28, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aravindhp

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 28, 2021
Extends the annotation patch creation functions to allow for labels as
well.
The machine-api-controller does this for Nodes associated with
Machines, this needed to be done for BYOH Nodes as well.
@mansikulkarni96
Copy link
Member

Thanks for working on this @sebsoto
/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 28, 2021
@sebsoto
Copy link
Contributor Author

sebsoto commented Jul 28, 2021

/hold cancel

@openshift-merge-robot openshift-merge-robot merged commit f973070 into openshift:master Jul 28, 2021
@sebsoto
Copy link
Contributor Author

sebsoto commented Aug 3, 2021

/cherry-pick community-4.8

@openshift-cherrypick-robot

@sebsoto: new pull request created: #557

In response to this:

/cherry-pick community-4.8

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@mansikulkarni96
Copy link
Member

/cherry-pick release-4.8

@openshift-cherrypick-robot

@mansikulkarni96: new pull request created: #597

In response to this:

/cherry-pick release-4.8

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants