-
Notifications
You must be signed in to change notification settings - Fork 94
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
✨ sync the labels from klusterlet to agent #475
Conversation
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
254b853
to
d415cad
Compare
/assign @qiujian16 |
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.
let's add an integration test.
pkg/operator/helpers/helpers.go
Outdated
@@ -821,3 +822,18 @@ func GetOperatorNamespace() string { | |||
} | |||
return operatorNamespace | |||
} | |||
|
|||
func MergeLabels(destination map[string]string, source map[string]string) map[string]string { |
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.
can we just use MergeMap in library-go?
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.
done
pkg/operator/helpers/helpers.go
Outdated
} | ||
|
||
func KlusterletAgentDefaultLabels() map[string]string { | ||
return map[string]string{"createdBy": "klusterlet"} |
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.
could be just a var rather than a func?
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.
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()) { |
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 think you can just use deepEqual?
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.
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 |
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.
considering there might be multiple klusterlet in hosted mode, should we put the klusterlet as the real klusterlet name?
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.
the label createdBy: klusterlet
is used to filter in deployment informer, I added another label klusterletName to set the real klusterlet name.
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.
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.
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.
how about to change the label to createdByKlusterlet: <klusterlet name>
, in deployment informer, change to check if the key createdByKlusterlet
exists?
068faaf
to
d7ff3fc
Compare
/hold |
/approve |
[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 |
@zhiweiyin318 can we merge this? |
/unhold |
Signed-off-by: Zhiwei Yin <zyin@redhat.com>
/lgtm |
7fd7330
into
open-cluster-management-io:main
…gement-io#475) Signed-off-by: Zhiwei Yin <zyin@redhat.com>
* 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>
Summary
sync the labels from klusterlet to all agent resouces, the default labels
createdBy: klusterlet
Related issue(s)
#467