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

✨ sync the labels from klusterlet to agent #475

Conversation

zhiweiyin318
Copy link
Member

@zhiweiyin318 zhiweiyin318 commented May 22, 2024

Summary

sync the labels from klusterlet to all agent resouces, the default labels createdBy: klusterlet

Related issue(s)

#467

@openshift-ci openshift-ci bot requested review from xuezhaojun and zhujian7 May 22, 2024 14:59
@zhiweiyin318 zhiweiyin318 changed the title ✨ wip: sync the labels from klusterlet to agent ✨ WIP: sync the labels from klusterlet to agent May 23, 2024
@zhiweiyin318 zhiweiyin318 changed the title ✨ WIP: sync the labels from klusterlet to agent WIP: ✨ sync the labels from klusterlet to agent May 23, 2024
Copy link

codecov bot commented May 27, 2024

Codecov Report

Attention: Patch coverage is 58.62069% with 12 lines in your changes missing coverage. Please review.

Project coverage is 62.72%. Comparing base (b530125) to head (ea0dd73).

Files Patch % Lines
pkg/operator/helpers/helpers.go 15.38% 11 Missing ⚠️
...stermanagercontroller/clustermanager_controller.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #475   +/-   ##
=======================================
  Coverage   62.72%   62.72%           
=======================================
  Files         136      136           
  Lines       11593    11615   +22     
=======================================
+ Hits         7272     7286   +14     
- Misses       3552     3562   +10     
+ Partials      769      767    -2     
Flag Coverage Δ
unit 62.72% <58.62%> (+<0.01%) ⬆️

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.

@zhiweiyin318 zhiweiyin318 force-pushed the sync-labels branch 3 times, most recently from 254b853 to d415cad Compare May 28, 2024 01:06
@zhiweiyin318 zhiweiyin318 changed the title WIP: ✨ sync the labels from klusterlet to agent ✨ sync the labels from klusterlet to agent May 28, 2024
@zhiweiyin318
Copy link
Member Author

/assign @qiujian16

Copy link
Member

@qiujian16 qiujian16 left a comment

Choose a reason for hiding this comment

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

let's add an integration test.

@@ -821,3 +822,18 @@ func GetOperatorNamespace() string {
}
return operatorNamespace
}

func MergeLabels(destination map[string]string, source map[string]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.

can we just use MergeMap in library-go?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

}

func KlusterletAgentDefaultLabels() map[string]string {
return map[string]string{"createdBy": "klusterlet"}
Copy link
Member

Choose a reason for hiding this comment

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

could be just a var rather than a func?

Copy link
Member Author

Choose a reason for hiding this comment

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

change this func to this:

func GetKlusterletAgentLabels(klusterlet *operatorapiv1.Klusterlet) map[string]string {
	labels := klusterlet.GetLabels()
	if labels == nil {
		labels = map[string]string{}
	}
	labels["klusterletName"] = klusterlet.Name
	// This label is used to filter in deployment informer
	labels["createdBy"] = "klusterlet"

	return labels
}

@@ -463,6 +463,11 @@ func ensureObject(t *testing.T, object runtime.Object, klusterlet *operatorapiv1
return
}

if !mapCompare(helpers.MergeLabels(helpers.KlusterletAgentDefaultLabels(), klusterlet.GetLabels()), access.GetLabels()) {
Copy link
Member

Choose a reason for hiding this comment

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

I think you can just use deepEqual?

Copy link
Member Author

Choose a reason for hiding this comment

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

the synced klusterlet labels is a part of the exiting labels, for example the deployments have label app=klusterlet-registration-agent, namespace has the label workload.openshift.io/allowed=management

@@ -7,6 +7,13 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: open-cluster-management:{{ .KlusterletName }}-registration:addon-management
labels:
createdBy: klusterlet
Copy link
Member

Choose a reason for hiding this comment

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

considering there might be multiple klusterlet in hosted mode, should we put the klusterlet as the real klusterlet name?

Copy link
Member Author

Choose a reason for hiding this comment

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

the label createdBy: klusterlet is used to filter in deployment informer, I added another label klusterletName to set the real klusterlet name.

Copy link
Member

Choose a reason for hiding this comment

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

TBH maybe not necessary to create both label right now...why do we still need createdBy: klusterlet if we have klusterletName label? We can change the filter in deployment informer.

Copy link
Member Author

@zhiweiyin318 zhiweiyin318 May 30, 2024

Choose a reason for hiding this comment

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

how about to change the label to createdByKlusterlet: <klusterlet name> , in deployment informer, change to check if the key createdByKlusterlet exists?

@zhiweiyin318 zhiweiyin318 force-pushed the sync-labels branch 8 times, most recently from 068faaf to d7ff3fc Compare May 30, 2024 16:02
@zhiweiyin318
Copy link
Member Author

/hold

@qiujian16
Copy link
Member

/approve
/lgtm

@openshift-ci openshift-ci bot added the lgtm label May 31, 2024
Copy link
Contributor

openshift-ci bot commented May 31, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qiujian16, zhiweiyin318

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

@qiujian16
Copy link
Member

@zhiweiyin318 can we merge this?

@zhiweiyin318
Copy link
Member Author

/unhold

Signed-off-by: Zhiwei Yin <zyin@redhat.com>
@qiujian16
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Jun 4, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 7fd7330 into open-cluster-management-io:main Jun 4, 2024
14 checks passed
@zhiweiyin318 zhiweiyin318 deleted the sync-labels branch June 4, 2024 06:50
zhiweiyin318 added a commit to zhiweiyin318/ocm that referenced this pull request Jun 13, 2024
openshift-merge-bot bot pushed a commit that referenced this pull request Jun 13, 2024
* sync labels from klusterlet to all agent resources (#475)

Signed-off-by: Zhiwei Yin <zyin@redhat.com>

* add enable-sync-labels flag to klusterlet operator (#505)

Signed-off-by: Zhiwei Yin <zyin@redhat.com>

* fix issue that pull secret and ns are synced labels when enable-sync-labels is disabled (#511)

Signed-off-by: Zhiwei Yin <zyin@redhat.com>

---------

Signed-off-by: Zhiwei Yin <zyin@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants