Skip to content

Conversation

@thatmattlong
Copy link
Collaborator

Reason for Change:
Adds SetOwnerRef to nnc client which sets the NNC ownership to the given object

Requirements:

_ = v1alpha.AddToScheme(Scheme)
}

type OwnerExistsError struct{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we flip this around to ErrOwnerExists? seems more canonical (https://go.dev/src/os/error.go) even though k/k likes to do "ThingError"

Copy link
Collaborator

Choose a reason for hiding this comment

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

if we still need it instead of using ctrlutil's similar defined error

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed, caller can rely on ctrlutil's error with errors.Is/As since we just wrap it


// SetOwnerRef sets the owner of the NodeNetworkConfig to the given object, using HTTP Patch
func (c *Client) SetOwnerRef(ctx context.Context, nnc *v1alpha.NodeNetworkConfig, owner metav1.Object) error {
newNNC := nnc.DeepCopy()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should either return the newNNC or mutate the passed nnc, since the patch call will write the resultant object to the ref it gets passed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good point, I'll change that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

decided to return instead of mutate since the nnccli.Patch() could fail and we don't want to mutate the caller if we dn't actually make a successful change

Comment on lines 152 to 155
// SetControllerReference returns an error if the object already has a different owner or
// if there are issues with the scheme. Since we control the scheme in this package, we can safely
// assume than any error is caused by an owner already existing
return &OwnerExistsError{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not lean on ctrlutil's AlreadyOwnedError?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

because I didn't read the docs and didn't know it existed 😆

Copy link
Collaborator

@rbtr rbtr left a comment

Choose a reason for hiding this comment

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

lgtm

@thatmattlong
Copy link
Collaborator Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rbtr rbtr merged commit 0c3efef into Azure:master Nov 30, 2021
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