-
Notifications
You must be signed in to change notification settings - Fork 29
✨ Include metadata in WorkApplier cache to detect external changes #224
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import ( | |
| "io" | ||
| "sync" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/klog/v2" | ||
|
|
||
| workapiv1 "open-cluster-management.io/api/work/v1" | ||
|
|
@@ -20,6 +21,7 @@ type workKey struct { | |
| type cachedResource struct { | ||
| resourceHash string | ||
| generation int64 | ||
| metadataHash string | ||
| } | ||
|
|
||
| type workCache struct { | ||
|
|
@@ -48,6 +50,7 @@ func (w *workCache) updateCache(required, existing *workapiv1.ManifestWork) { | |
| value := cachedResource{ | ||
| resourceHash: hashOfResourceStruct(required), | ||
| generation: existing.Generation, | ||
| metadataHash: hashOfMetadata(required), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think resourceHash has included metadata section already. Are you trying to detect if label/annotation of the exisiting mw is changed? If so, I would consider an annotatil/label merge when apply rather than replace.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the quick review! You're right that Re merge vs replace, that's a good point and worth discussing separately. |
||
| } | ||
|
|
||
| w.cache[key] = value | ||
|
|
@@ -79,12 +82,11 @@ func (w *workCache) safeToSkipApply(required, existing *workapiv1.ManifestWork) | |
| generation := existing.Generation | ||
| w.mutex.RLock() | ||
| defer w.mutex.RUnlock() | ||
| var generationMatch, hashMatch bool | ||
| metadataHash := hashOfMetadata(existing) | ||
|
|
||
| if cached, exists := w.cache[cacheKey]; exists { | ||
| generationMatch = cached.generation == generation | ||
| hashMatch = cached.resourceHash == resourceHash | ||
| if generationMatch && hashMatch { | ||
| klog.V(4).Infof("found matching generation & manifest hash") | ||
| if cached.generation == generation && cached.resourceHash == resourceHash && cached.metadataHash == metadataHash { | ||
| klog.V(4).Infof("found matching generation, manifest hash & metadata hash") | ||
| return true | ||
| } | ||
| } | ||
|
|
@@ -101,3 +103,16 @@ func hashOfResourceStruct(o interface{}) string { | |
| rval := fmt.Sprintf("%x", h.Sum(nil)) | ||
| return rval | ||
| } | ||
|
|
||
| func hashOfMetadata(work *workapiv1.ManifestWork) string { | ||
| meta := struct { | ||
| Labels map[string]string | ||
| Annotations map[string]string | ||
| OwnerReferences []metav1.OwnerReference | ||
| }{ | ||
| Labels: work.Labels, | ||
| Annotations: work.Annotations, | ||
| OwnerReferences: work.OwnerReferences, | ||
| } | ||
| return hashOfResourceStruct(meta) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.