diff --git a/pkg/apply/apply.go b/pkg/apply/apply.go index c08bd6a..60fc504 100644 --- a/pkg/apply/apply.go +++ b/pkg/apply/apply.go @@ -3,6 +3,7 @@ package apply import ( "context" "fmt" + "sync" "k8s.io/apimachinery/pkg/runtime/schema" kclient "sigs.k8s.io/controller-runtime/pkg/client" @@ -17,11 +18,11 @@ var ( // values that are allowed to change. The key is in the format of // "oldValue => newValue" // subcontext and the value is the old subcontext name. - validOwnerChange = map[string]bool{} + validOwnerChange = sync.Map{} ) func AddValidOwnerChange(oldSubcontext, newSubContext string) { - validOwnerChange[fmt.Sprintf("%s => %s", oldSubcontext, newSubContext)] = true + validOwnerChange.Store(fmt.Sprintf("%s => %s", oldSubcontext, newSubContext), struct{}{}) } type Apply interface { diff --git a/pkg/apply/desiredset_process.go b/pkg/apply/desiredset_process.go index 0bc6c55..80625d0 100644 --- a/pkg/apply/desiredset_process.go +++ b/pkg/apply/desiredset_process.go @@ -277,12 +277,14 @@ func (a *apply) process(debugID string, set labels.Selector, gvk schema.GroupVer func isAllowOwnerTransition(existingObj, newObj kclient.Object) bool { existingAnno := existingObj.GetAnnotations() newAnno := newObj.GetAnnotations() - return newAnno[LabelSubContext] != "" && - (existingAnno[LabelGVK] == "" || existingAnno[LabelGVK] == newAnno[LabelGVK]) && - (existingAnno[LabelNamespace] == "" || existingAnno[LabelNamespace] == newAnno[LabelNamespace]) && - (existingAnno[LabelName] == "" || existingAnno[LabelName] == newAnno[LabelName]) && - validOwnerChange[fmt.Sprintf("%s => %s", existingAnno[LabelSubContext], newAnno[LabelSubContext])] - + if newAnno[LabelSubContext] == "" || + (existingAnno[LabelGVK] != "" && existingAnno[LabelGVK] != newAnno[LabelGVK]) || + (existingAnno[LabelNamespace] != "" && existingAnno[LabelNamespace] != newAnno[LabelNamespace]) || + (existingAnno[LabelName] != "" && existingAnno[LabelName] != newAnno[LabelName]) { + return false + } + _, ok := validOwnerChange.Load(fmt.Sprintf("%s => %s", existingAnno[LabelSubContext], newAnno[LabelSubContext])) + return ok } // isAssigningSubContext is checking to see if an existing managed object