-
Notifications
You must be signed in to change notification settings - Fork 46
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
AUTH-413: ps syncer: only sync labels if noone else is managing them #127
AUTH-413: ps syncer: only sync labels if noone else is managing them #127
Conversation
0ea5307
to
145b9af
Compare
nsCopy.Labels[psapi.EnforceVersionLabel] = currentPSaVersion | ||
managedNamespaces, err := extractNSFieldsPerManager(ns) | ||
if err != nil { | ||
if err != nil { |
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.
Duplicate if
statement.
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.
Huh, that must have happened somewhere through rebasing. Good thing you noticed
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.
This probably trickled through some commit somewhere as it's still here :)
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.
wat
/lgtm holding for @deads2k to review |
// conditionally removes the label from all those unstructured fields and shoves them back in the proper place | ||
// in the object managedFields is tedious, ugly and super error-prone. | ||
// | ||
// Just remove the fields as the previous owner and quickly readd them as the new one. |
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.
Rather than do this, could we simply do an Apply with the force
option set to true?
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.
That's not possible. The field is owned by "cluster-policy-controller + Update". You cannot set the label to an empty value (fails validation). That means that the only action you can do with it is to remove it. But I don't think there is a way to set up a NamespaceApplyConfiguration
that would express that intention.
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.
huh
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.
That's not possible. The field is owned by "cluster-policy-controller + Update". You cannot set the label to an empty value (fails validation). That means that the only action you can do with it is to remove it. But I don't think there is a way to set up a
NamespaceApplyConfiguration
that would express that intention
Can't you set it to the current value with a force?
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.
If you set it to the current value, the "force" does not seem to matter at all. You will always get double ownership, which will still result in a conflict when you're trying to change it. Some fun corner cases I tested:
cluster-policy-controller
+ apply to the same value
a. the labels is now managed bycluster-policy-controller + update
andcluster-policy-controller + apply
b. you get the applyconfig and remove the ownership in an apply as the cluster-policy-controller
c. the field is now again owned only bycluster-policy-controller + update
this-controller
+ apply the same value
a. the label is now managed bycluster-policy-controller + update
andthis-controller + apply
b. try to change the label value as this-controller - you get a conflict
if changed { | ||
_, err := c.namespaceClient.Update(ctx, nsCopy, metav1.UpdateOptions{}) | ||
if len(nsApplyConfig.Labels) > 0 { | ||
_, err := c.namespaceClient.Apply(ctx, nsApplyConfig, metav1.ApplyOptions{FieldManager: controllerName}) | ||
if err != nil { |
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.
reduce nesting with
if is conflict
log
return nil
if err != nil
return err
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.
I'd like to keep the block that contains error cases like this, unless we decide to handle more errors and introduce a switch here
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.
I'd like to keep the block that contains error cases like this, unless we decide to handle more errors and introduce a switch here
Non-standard with both golang and kube. Sort of like using == ""
versus len(foo) == 0
.
worthy of an e2e test once merged. |
3d0cd0b
to
4f24f35
Compare
nsCopy.Labels[psapi.EnforceVersionLabel] = currentPSaVersion | ||
managedNamespaces, err := extractNSFieldsPerManager(ns) | ||
if err != nil { | ||
if err != nil { |
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.
This probably trickled through some commit somewhere as it's still here :)
52c0faf
to
202b52b
Compare
202b52b
to
f5ce53d
Compare
@stlaz: all tests passed! Full PR test history. Your PR dashboard. 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. I understand the commands that are listed here. |
/hold cancel |
@stlaz: This pull request references AUTH-413 which is a valid jira issue. In response to this: 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. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: liouk, stlaz 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 |
|
||
var changed bool | ||
// we must extract the NS in case only some of the labels we're setting need | ||
// updating to avoid hotlo |
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.
@stlaz just realized that this comment got somehow truncated, just FYI
/cc @deads2k
/cc @ibihim