add FindFieldsOwners util function

to be used by kubectl to determine csa manager name used

findowners

Kubernetes-commit: 26a6e1234869b5c546195aaf416f3424cd3c3dc8
This commit is contained in:
Alexander Zielenski
2022-11-03 12:01:34 -07:00
committed by Kubernetes Publisher
parent 4f63b629b5
commit 898b7a3cbd
2 changed files with 283 additions and 0 deletions

View File

@@ -30,7 +30,33 @@ import (
"sigs.k8s.io/structured-merge-diff/v4/fieldpath"
)
// Finds all managed fields owners of the given operation type which owns all of
// the fields in the given set
//
// If there is an error decoding one of the fieldsets for any reason, it is ignored
// and assumed not to match the query.
func FindFieldsOwners(
managedFields []metav1.ManagedFieldsEntry,
operation metav1.ManagedFieldsOperationType,
fields *fieldpath.Set,
) []metav1.ManagedFieldsEntry {
var result []metav1.ManagedFieldsEntry
for _, entry := range managedFields {
if entry.Operation != operation {
continue
}
fieldSet, err := decodeManagedFieldsEntrySet(entry)
if err != nil {
continue
}
if fields.Difference(&fieldSet).Empty() {
result = append(result, entry)
}
}
return result
}
// Upgrades the Manager information for fields managed with client-side-apply (CSA)
// Prepares fields owned by `csaManager` for 'Update' operations for use now