Skip to content

Commit

Permalink
Merge pull request #1424 from KubeKyrie/fix-secret-owner-reference
Browse files Browse the repository at this point in the history
fix set secret OwnerReferences
  • Loading branch information
ErikJiang authored Dec 5, 2024
2 parents f4ade18 + 5e93ee2 commit a9d754f
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions pkg/util/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,15 @@ func UpdateOwnReference(client kubernetes.Interface, configMapList []*apis.Confi
}
return err // not ignore
}
if len(cm.OwnerReferences) != 0 {
continue // do nothing
hasSet := false
for _, ownerRef := range cm.OwnerReferences {
if ownerRef.UID == belongToReference.UID {
hasSet = true
break
}
}
if hasSet {
continue
}
// cm belongs to `Cluster`
cm.OwnerReferences = append(cm.OwnerReferences, belongToReference)
Expand All @@ -104,8 +111,15 @@ func UpdateOwnReference(client kubernetes.Interface, configMapList []*apis.Confi
}
return err // not ignore
}
if len(secret.OwnerReferences) != 0 {
continue // do nothing
hasSet := false
for _, ownerRef := range secret.OwnerReferences {
if ownerRef.UID == belongToReference.UID {
hasSet = true
break
}
}
if hasSet {
continue
}
secret.OwnerReferences = append(secret.OwnerReferences, belongToReference)
if _, err := client.CoreV1().Secrets(ref.NameSpace).Update(context.Background(), secret, metav1.UpdateOptions{}); err != nil {
Expand Down

0 comments on commit a9d754f

Please sign in to comment.