Skip to content

Commit d09ba2e

Browse files
author
Amarthya Valija
committed
Fix endpoint admission test namespace creation for ROSA
Avoid attempting to create existing namespaces like kube-system which triggers managed-cluster-validating-webhooks in ROSA. Check if namespace exists before creation to prevent unnecessary webhook calls while maintaining same test behavior. Fixes: OCPBUGS-60654
1 parent 4c1d2ce commit d09ba2e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

test/extended/networking/endpoint_admission.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,16 @@ func testOneEndpointSlice(oc *exutil.CLI, client kubernetes.Interface, addrType,
186186
}
187187

188188
func getClientForServiceAccount(adminClient kubernetes.Interface, clientConfig *rest.Config, namespace, name string) (*kubernetes.Clientset, *rest.Config, error) {
189-
_, err := adminClient.CoreV1().Namespaces().Create(context.Background(), &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}, metav1.CreateOptions{})
190-
if err != nil && !errors.IsAlreadyExists(err) {
191-
return nil, nil, err
189+
_, err := adminClient.CoreV1().Namespaces().Get(context.Background(), namespace, metav1.GetOptions{})
190+
if err != nil {
191+
if errors.IsNotFound(err) {
192+
_, err = adminClient.CoreV1().Namespaces().Create(context.Background(), &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}, metav1.CreateOptions{})
193+
if err != nil {
194+
return nil, nil, err
195+
}
196+
} else {
197+
return nil, nil, err
198+
}
192199
}
193200

194201
_, err = adminClient.CoreV1().ServiceAccounts(namespace).Create(context.Background(), &corev1.ServiceAccount{ObjectMeta: metav1.ObjectMeta{Name: name}}, metav1.CreateOptions{})
@@ -210,4 +217,4 @@ func getClientForServiceAccount(adminClient kubernetes.Interface, clientConfig *
210217
}
211218

212219
return kubeClientset, saClientConfig, nil
213-
}
220+
}

0 commit comments

Comments
 (0)