Skip to content

OCPBUGS-17157: *: label k8s objects we own#3020

Merged
openshift-merge-robot merged 1 commit intooperator-framework:masterfrom
stevekuznetsov:skuznets/controller-adding-labels
Sep 5, 2023
Merged

OCPBUGS-17157: *: label k8s objects we own#3020
openshift-merge-robot merged 1 commit intooperator-framework:masterfrom
stevekuznetsov:skuznets/controller-adding-labels

Conversation

@stevekuznetsov
Copy link
Copy Markdown
Contributor

No description provided.

@openshift-ci-robot openshift-ci-robot added jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. labels Aug 25, 2023
@openshift-ci-robot
Copy link
Copy Markdown
Collaborator

@stevekuznetsov: This pull request references Jira Issue OCPBUGS-17157, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.14.0) matches configured target version for branch (4.14.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @jianzhangbjz

The bug has been updated to refer to the pull request using the external bug tracker.

Details

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.

@stevekuznetsov
Copy link
Copy Markdown
Contributor Author

Need to think about the best way to test this, but code is ready for review.

@stevekuznetsov stevekuznetsov force-pushed the skuznets/controller-adding-labels branch from 12f4b12 to 8685123 Compare August 25, 2023 16:29
@stevekuznetsov
Copy link
Copy Markdown
Contributor Author

I think I will test this once I add logic to startup that ensures we reach a steady-state where we can filter down the WATCH streams. Will be best to test on upgrade.

Comment thread pkg/controller/operators/catalog/operator.go Outdated
Comment thread pkg/controller/operators/catalog/operator.go Outdated
Comment thread pkg/controller/operators/catalog/operator.go Outdated
Comment thread pkg/controller/operators/catalog/operator.go Outdated
Comment thread pkg/controller/operators/labeller/labels.go Outdated
Comment thread pkg/controller/operators/labeller/labels.go Outdated
Comment thread pkg/controller/operators/labeller/labels.go Outdated
Comment thread pkg/controller/operators/labeller/labels.go
Comment thread pkg/controller/operators/labeller/labels.go
Comment thread pkg/controller/operators/labeller/labels.go
Comment thread pkg/controller/operators/labeller/labels.go Outdated
@stevekuznetsov stevekuznetsov force-pushed the skuznets/controller-adding-labels branch 2 times, most recently from 5effa46 to d15be27 Compare August 31, 2023 13:55
Comment thread pkg/controller/operators/catalog/operator.go Outdated
Comment thread pkg/controller/operators/catalog/operator.go Outdated
@joelanford
Copy link
Copy Markdown
Member

@stevekuznetsov can you add a high level description of what's happening here? It seems like we're setting up some new informers with an ObjectLabeller syncer, and those syncs are just ensuring a "olm.managed": "true" label exists on the watched objects?

And this is where I'm confused: Why do we need informers and syncers for this? Shouldn't the thing(s) that create/sync these objects in the first place be where the labels are applied?

@stevekuznetsov
Copy link
Copy Markdown
Contributor Author

And this is where I'm confused: Why do we need informers and syncers for this? Shouldn't the thing(s) that create/sync these objects in the first place be where the labels are applied?

We need both - #3017 went in to label new resources we create, but we need this PR to label resources created by older versions of OLM that upgrade to this one.

@stevekuznetsov stevekuznetsov force-pushed the skuznets/controller-adding-labels branch from d15be27 to 267e59c Compare September 5, 2023 15:23
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
@stevekuznetsov stevekuznetsov force-pushed the skuznets/controller-adding-labels branch from 267e59c to 00c4845 Compare September 5, 2023 15:24
Copy link
Copy Markdown
Member

@awgreene awgreene left a comment

Choose a reason for hiding this comment

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

/approve

Comment on lines +145 to +150
hasOLMOwnerLabels := true
for _, label := range []string{ownerutil.OwnerKey, ownerutil.OwnerNamespaceKey, ownerutil.OwnerKind} {
_, exists := object.GetLabels()[label]
hasOLMOwnerLabels = hasOLMOwnerLabels && exists
}
return hasOLMOwnerLabels
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: Is there a reason you chose not to exit early if the label is missing?

Suggested change
hasOLMOwnerLabels := true
for _, label := range []string{ownerutil.OwnerKey, ownerutil.OwnerNamespaceKey, ownerutil.OwnerKind} {
_, exists := object.GetLabels()[label]
hasOLMOwnerLabels = hasOLMOwnerLabels && exists
}
return hasOLMOwnerLabels
for _, label := range []string{ownerutil.OwnerKey, ownerutil.OwnerNamespaceKey, ownerutil.OwnerKind} {
if _, exists := object.GetLabels()[label]; !exists {
return false
}
}
return true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since N=3 I don't know that it makes any meaningful difference


if err := labelObjects(rbacv1.SchemeGroupVersion.WithResource("clusterroles"), clusterRoleInformer.Informer(), labeller.ObjectLabeler[*rbacv1.ClusterRole, *rbacv1applyconfigurations.ClusterRoleApplyConfiguration](
ctx, op.logger, labeller.HasOLMOwnerRef,
func(name, _ string) *rbacv1applyconfigurations.ClusterRoleApplyConfiguration {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cool, I haven't seen _ string used before.

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Sep 5, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: awgreene, stevekuznetsov

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

The pull request process is described here

Details 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 Sep 5, 2023
@awgreene
Copy link
Copy Markdown
Member

awgreene commented Sep 5, 2023

Nice work @stevekuznetsov, thanks for the PR.

@kevinrizza
Copy link
Copy Markdown
Member

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Sep 5, 2023
@openshift-merge-robot openshift-merge-robot merged commit c55c24d into operator-framework:master Sep 5, 2023
@openshift-ci-robot
Copy link
Copy Markdown
Collaborator

@stevekuznetsov: Jira Issue OCPBUGS-17157: Some pull requests linked via external trackers have merged:

The following pull requests linked via external trackers have not merged:

These pull request must merge or be unlinked from the Jira bug in order for it to move to the next state. Once unlinked, request a bug refresh with /jira refresh.

Jira Issue OCPBUGS-17157 has not been moved to the MODIFIED state.

Details

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.

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-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. 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.

8 participants