Skip to content

Commit

Permalink
Fix finalizers test to not only rely on namespaced name
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi authored and k8s-infra-cherrypick-robot committed Jan 15, 2024
1 parent ea140ce commit 469f102
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions test/framework/finalizers_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func getObjectsWithFinalizers(ctx context.Context, proxy ClusterProxy, namespace
setFinalizers := obj.GetFinalizers()

if len(setFinalizers) > 0 {
objsWithFinalizers[client.ObjectKey{Namespace: node.Object.Namespace, Name: node.Object.Name}.String()] = obj
objsWithFinalizers[fmt.Sprintf("%s/%s/%s", node.Object.Kind, node.Object.Namespace, node.Object.Name)] = obj
}
}

Expand All @@ -124,11 +124,11 @@ func assertFinalizersExist(ctx context.Context, proxy ClusterProxy, namespace st
var allErrs []error
finalObjsWithFinalizers := getObjectsWithFinalizers(ctx, proxy, namespace)

for objNamespacedName, obj := range initialObjsWithFinalizers {
for objKindNamespacedName, obj := range initialObjsWithFinalizers {
// verify if finalizers for this resource were set on reconcile
if _, valid := finalObjsWithFinalizers[objNamespacedName]; !valid {
allErrs = append(allErrs, fmt.Errorf("no finalizers set for %s/%s",
obj.GetKind(), objNamespacedName))
if _, valid := finalObjsWithFinalizers[objKindNamespacedName]; !valid {
allErrs = append(allErrs, fmt.Errorf("no finalizers set for %s",
objKindNamespacedName))
continue
}

Expand All @@ -138,10 +138,10 @@ func assertFinalizersExist(ctx context.Context, proxy ClusterProxy, namespace st
continue
}

setFinalizers := finalObjsWithFinalizers[objNamespacedName].GetFinalizers()
setFinalizers := finalObjsWithFinalizers[objKindNamespacedName].GetFinalizers()
if !reflect.DeepEqual(expectedFinalizers, setFinalizers) {
allErrs = append(allErrs, fmt.Errorf("expected finalizers do not exist for %s/%s: expected: %v, found: %v",
obj.GetKind(), objNamespacedName, expectedFinalizers, setFinalizers))
allErrs = append(allErrs, fmt.Errorf("expected finalizers do not exist for %s: expected: %v, found: %v",
objKindNamespacedName, expectedFinalizers, setFinalizers))
}
}

Expand Down

0 comments on commit 469f102

Please sign in to comment.