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

AUTH-413: ps syncer: only sync labels if noone else is managing them #127

Merged
merged 6 commits into from
Aug 16, 2023

Conversation

stlaz
Copy link
Contributor

@stlaz stlaz commented Aug 1, 2023

/cc @deads2k
/cc @ibihim

@openshift-ci openshift-ci bot requested review from deads2k and ibihim August 1, 2023 14:07
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 1, 2023
@stlaz stlaz force-pushed the psa_managed_fields branch 10 times, most recently from 0ea5307 to 145b9af Compare August 8, 2023 14:00
nsCopy.Labels[psapi.EnforceVersionLabel] = currentPSaVersion
managedNamespaces, err := extractNSFieldsPerManager(ns)
if err != nil {
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Duplicate if statement.

Copy link
Contributor Author

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

Copy link
Member

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 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wat

pkg/psalabelsyncer/podsecurity_label_sync_controller.go Outdated Show resolved Hide resolved
@liouk
Copy link
Member

liouk commented Aug 14, 2023

/lgtm
/hold

holding for @deads2k to review

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 14, 2023
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 14, 2023
// 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.
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

huh

Copy link
Contributor

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?

Copy link
Contributor Author

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:

  1. cluster-policy-controller + apply to the same value
    a. the labels is now managed by cluster-policy-controller + update and cluster-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 by cluster-policy-controller + update
  2. this-controller + apply the same value
    a. the label is now managed by cluster-policy-controller + update and this-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 {
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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.

@deads2k
Copy link
Contributor

deads2k commented Aug 14, 2023

worthy of an e2e test once merged.

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 15, 2023
nsCopy.Labels[psapi.EnforceVersionLabel] = currentPSaVersion
managedNamespaces, err := extractNSFieldsPerManager(ns)
if err != nil {
if err != nil {
Copy link
Member

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 :)

@stlaz stlaz force-pushed the psa_managed_fields branch 2 times, most recently from 52c0faf to 202b52b Compare August 15, 2023 14:58
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 15, 2023

@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.

@stlaz
Copy link
Contributor Author

stlaz commented Aug 16, 2023

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 16, 2023
@stlaz stlaz changed the title ps syncer: only sync labels if noone else is managing them AUTH-413: ps syncer: only sync labels if noone else is managing them Aug 16, 2023
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Aug 16, 2023

@stlaz: This pull request references AUTH-413 which is a valid jira issue.

In response to this:

/cc @deads2k
/cc @ibihim

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.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Aug 16, 2023
@liouk
Copy link
Member

liouk commented Aug 16, 2023

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 16, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 16, 2023

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit f31cb0b into openshift:master Aug 16, 2023
7 checks passed

var changed bool
// we must extract the NS in case only some of the labels we're setting need
// updating to avoid hotlo
Copy link
Member

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

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. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. 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