Skip to content

✨ Enable sync labels for clustermanager operator and registration controller #1021

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

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

jeffw17
Copy link
Contributor

@jeffw17 jeffw17 commented Jun 2, 2025

Summary

Previously, there was a feature implemented where the klusterlet resources have labels passed down to resources created indirectly by the controllers. This feature was not implemented in the clustermanager side. For example, the operator goes ahead and create the various deployments on the open-cluster-management-hub namespace and those deployments will now have the same labels as the operator. As such, the changes in this PR implements this feature. The feature in this PR however only applies to the cluster-manager operator and the registration-controller. In a future date, we will implement the same feature for the other controllers (i.e. placement-controller, work-controller, etc.). To enable this feature, in the helm charts, you can set enableSyncLabels to true or, in clusteradm commands, you can add the --enable-sync-labels=true flag.

Related issue(s)

#957

Fixes # 957

@openshift-ci openshift-ci bot requested review from haowells and ldpliu June 2, 2025 21:23
Copy link
Contributor

openshift-ci bot commented Jun 2, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jeffw17
Once this PR has been reviewed and has the lgtm label, please assign jnpacker for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

Copy link

codecov bot commented Jun 2, 2025

Codecov Report

Attention: Patch coverage is 44.94382% with 49 lines in your changes missing coverage. Please review.

Project coverage is 64.02%. Comparing base (8c49474) to head (aa86a23).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pkg/operator/helpers/helpers.go 40.00% 20 Missing and 4 partials ⚠️
pkg/registration/hub/manager.go 27.27% 7 Missing and 1 partial ⚠️
...stermanagercontroller/clustermanager_controller.go 0.00% 4 Missing and 1 partial ⚠️
...rmanagercontroller/clustermanager_crd_reconcile.go 40.00% 2 Missing and 1 partial ⚠️
pkg/registration/helpers/helpers.go 0.00% 3 Missing ⚠️
pkg/cmd/hub/operator.go 0.00% 2 Missing ⚠️
pkg/registration/hub/clusterrole/controller.go 66.66% 2 Missing ⚠️
pkg/registration/hub/managedcluster/controller.go 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1021      +/-   ##
==========================================
- Coverage   64.25%   64.02%   -0.24%     
==========================================
  Files         195      196       +1     
  Lines       19118    19362     +244     
==========================================
+ Hits        12285    12397     +112     
- Misses       5823     5933     +110     
- Partials     1010     1032      +22     
Flag Coverage Δ
unit 64.02% <44.94%> (-0.24%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -176,3 +179,21 @@ func IsCSRSupported(nativeClient kubernetes.Interface) (bool, bool, error) {
}
return v1CSRSupported, v1beta1CSRSupported, nil
}

func ParseLabels(labels string) 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.

Copy link
Member

Choose a reason for hiding this comment

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

do we still need this func?

Copy link
Contributor

Choose a reason for hiding this comment

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

Removed it

@@ -136,6 +136,11 @@ func (c *runtimeReconcile) reconcile(ctx context.Context, cm *operatorapiv1.Clus
}
}

if cm.Labels != nil {
Copy link
Member

Choose a reason for hiding this comment

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

why do we need this again, I think config has been set on the controller already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want to sync the labels continuously. In case the labels are changed on the clustermanager, the new labels should be reflected.

Copy link
Member

Choose a reason for hiding this comment

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

hrm I do not think it will happen in reconcile, the cm is passed from the controller and it has been updated already, this will not be changed in the reconcile loop.

@@ -89,6 +90,8 @@ func (m *HubManagerOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringSliceVar(&m.AutoApprovedARNPatterns, "auto-approved-arn-patterns", m.AutoApprovedARNPatterns,
"A list of AWS EKS ARN patterns such that an EKS cluster will be auto approved if its ARN matches with any of the patterns")
fs.StringSliceVar(&m.AwsResourceTags, "aws-resource-tags", m.AwsResourceTags, "A list of tags to apply to AWS resources created through the OCM controllers")
fs.StringVar(&m.Labels, "labels", m.Labels,
Copy link
Member

Choose a reason for hiding this comment

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

It is better to set it as fs.StringSliceVar, and convert it to map in complete.

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 we use StringSliceVar which returns m.Labels as a []string then we won't be able to leverage generate.ParseLabels() as it expects a string to convert to map.

amrcoder and others added 23 commits June 3, 2025 17:39
…ble and also add labels to rbac manifests if present.
Signed-off-by: Jeffrey Wong <[email protected]>
Signed-off-by: Jeffrey Wong <[email protected]>
Signed-off-by: Jeffrey Wong <[email protected]>
@suvaanshkumar suvaanshkumar force-pushed the test-labels-sync-e2e branch from 857d79d to 5efb103 Compare June 3, 2025 21:39
go.mod Outdated
k8s.io/client-go v0.32.4
k8s.io/component-base v0.32.4
k8s.io/client-go v0.33.1
k8s.io/component-base v0.33.1
Copy link
Member

Choose a reason for hiding this comment

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

please do not upgrade the library

@jeffw17 jeffw17 force-pushed the test-labels-sync-e2e branch 2 times, most recently from b802ec7 to ce7b700 Compare June 5, 2025 01:01
Signed-off-by: Jeffrey Wong <[email protected]>
@jeffw17 jeffw17 force-pushed the test-labels-sync-e2e branch from ce7b700 to a5c33be Compare June 5, 2025 01:23
eventuallyInterval = 1 // seconds
eventuallyTimeout = 30 // seconds
eventuallyInterval = 1 // seconds
testCustomLabel = "custom-label"
Copy link
Member

Choose a reason for hiding this comment

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

this should not be set as global variable. It will be really hard to maintain. You should consider stop the existing hub, customize the option and restart the hub in the specific test. Example like this https://github.com/open-cluster-management-io/ocm/blob/main/test/integration/registration/spokecluster_aws_joining_test.go#L32-L47

@@ -129,6 +129,11 @@ var _ = ginkgo.BeforeSuite(func() {
_, err = operatorClient.OperatorV1().ClusterManagers().Create(context.Background(), &operatorapiv1.ClusterManager{
ObjectMeta: metav1.ObjectMeta{
Name: clusterManagerName,
Labels: map[string]string{
"app": "clustermanager",
Copy link
Member

Choose a reason for hiding this comment

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

same here, consider a test that update the clustermanager, and check that the label is updated on the resource instead of setting it globally.

@suvaanshkumar suvaanshkumar force-pushed the test-labels-sync-e2e branch from 41a2367 to 74e01d5 Compare June 5, 2025 21:27
@suvaanshkumar suvaanshkumar force-pushed the test-labels-sync-e2e branch from 74e01d5 to aa86a23 Compare June 5, 2025 21:28
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.

6 participants