From 96ec2c284466dd48828302fc927a5e0a8bd0425e Mon Sep 17 00:00:00 2001 From: Saravana Date: Thu, 14 Nov 2024 01:04:30 +0530 Subject: [PATCH] test trustedCABundle ManagementState conditions --- tests/e2e/creation_test.go | 58 +++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/tests/e2e/creation_test.go b/tests/e2e/creation_test.go index 5336d6ae1d0..e348564bc41 100644 --- a/tests/e2e/creation_test.go +++ b/tests/e2e/creation_test.go @@ -452,43 +452,49 @@ func (tc *testContext) testDefaultCertsAvailable() error { } func (tc *testContext) testTrustedCABundle() error { - managementStateChangeTrustedCA := false CAConfigMapName := "odh-trusted-ca-bundle" CADataFieldName := "odh-ca-bundle.crt" - err := trustedcabundle.ConfigureTrustedCABundle(tc.ctx, tc.customClient, logr.Logger{}, tc.testDSCI, managementStateChangeTrustedCA) + if tc.testDSCI.Spec.TrustedCABundle.ManagementState == "Managed" { + istrustedCABundleUpdated, err := trustedcabundle.IsTrustedCABundleUpdated(tc.ctx, tc.customClient, tc.testDSCI) - if err != nil { - return fmt.Errorf("Error while configuring trusted-ca-bundle: %w", err) - } - istrustedCABundleUpdated, err := trustedcabundle.IsTrustedCABundleUpdated(tc.ctx, tc.customClient, tc.testDSCI) + if istrustedCABundleUpdated == true { + return fmt.Errorf("odh-trusted-ca-bundle in config map does not match with DSCI's TrustedCABundle.CustomCABundle, needs update: %w", err) + } - if istrustedCABundleUpdated == true { - return fmt.Errorf("odh-trusted-ca-bundle in config map does not match with DSCI's TrustedCABundle.CustomCABundle, needs update: %w", err) - } + err = trustedcabundle.AddCABundleCMInAllNamespaces(tc.ctx, tc.customClient, logr.Logger{}, tc.testDSCI) - err = trustedcabundle.AddCABundleCMInAllNamespaces(tc.ctx, tc.customClient, logr.Logger{}, tc.testDSCI) + if err != nil { + return fmt.Errorf("failed adding configmap %s to all namespaces: %w", CAConfigMapName, err) + } - if err != nil { - return fmt.Errorf("failed adding configmap %s to all namespaces: %w", CAConfigMapName, err) - } + if err := trustedcabundle.RemoveCABundleCMInAllNamespaces(tc.ctx, tc.customClient); err != nil { + return fmt.Errorf("error deleting configmap %s from all namespaces %w", CAConfigMapName, err) + } - if err := trustedcabundle.RemoveCABundleCMInAllNamespaces(tc.ctx, tc.customClient); err != nil { - return fmt.Errorf("error deleting configmap %s from all namespaces %w", CAConfigMapName, err) - } + foundConfigMap := &corev1.ConfigMap{} + err = tc.customClient.Get(tc.ctx, client.ObjectKey{ + Name: CAConfigMapName, + Namespace: tc.testDSCI.Spec.ApplicationsNamespace, + }, foundConfigMap) - foundConfigMap := &corev1.ConfigMap{} - err = tc.customClient.Get(tc.ctx, client.ObjectKey{ - Name: CAConfigMapName, - Namespace: tc.testDSCI.Spec.ApplicationsNamespace, - }, foundConfigMap) + if err != nil { + return fmt.Errorf("Config map not found, %w", err) + } - if err != nil { - return errors.New("Config map not found") - } + if foundConfigMap.Data[CADataFieldName] != tc.testDSCI.Spec.TrustedCABundle.CustomCABundle { + return fmt.Errorf("odh-trusted-ca-bundle in config map does not match with DSCI's TrustedCABundle.CustomCABundle, needs update: %w", err) + } + } else { + foundConfigMap := &corev1.ConfigMap{} + err := tc.customClient.Get(tc.ctx, client.ObjectKey{ + Name: CAConfigMapName, + Namespace: tc.testDSCI.Spec.ApplicationsNamespace, + }, foundConfigMap) - if foundConfigMap.Data[CADataFieldName] != tc.testDSCI.Spec.TrustedCABundle.CustomCABundle { - return fmt.Errorf("odh-trusted-ca-bundle in config map does not match with DSCI's TrustedCABundle.CustomCABundle, needs update: %w", err) + if err != nil { + return fmt.Errorf("Config map not found, %w", err) + } } return nil }