diff --git a/tests/e2e/creation_test.go b/tests/e2e/creation_test.go index 5336d6ae1d0..8b8c4325ec3 100644 --- a/tests/e2e/creation_test.go +++ b/tests/e2e/creation_test.go @@ -6,10 +6,10 @@ import ( "fmt" "log" "reflect" + "strings" "testing" "time" - "github.com/go-logr/logr" operatorv1 "github.com/openshift/api/operator/v1" "github.com/stretchr/testify/require" autoscalingv1 "k8s.io/api/autoscaling/v1" @@ -452,43 +452,41 @@ 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" { + checkConfig := trustedcabundle.CreateOdhTrustedCABundleConfigMap(tc.ctx, tc.customClient, tc.testDSCI.Spec.ServiceMesh.ControlPlane.Namespace, CADataFieldName) + fmt.Print(checkConfig) + 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("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) - } - - 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 := trustedcabundle.RemoveCABundleCMInAllNamespaces(tc.ctx, tc.customClient); err != nil { - return fmt.Errorf("error deleting configmap %s from all namespaces %w", CAConfigMapName, err) - } + if err != nil { + return fmt.Errorf("Config map not found, %w", err) + } - foundConfigMap := &corev1.ConfigMap{} - err = tc.customClient.Get(tc.ctx, client.ObjectKey{ - Name: CAConfigMapName, - Namespace: tc.testDSCI.Spec.ApplicationsNamespace, - }, foundConfigMap) + checkNewline := strings.Contains(foundConfigMap.Data[CADataFieldName], "/n") - if err != nil { - return errors.New("Config map not found") - } + if checkNewline == true { + fmt.Print("Newline present at the end of configmap") + } + fmt.Print("test", foundConfigMap.Data[CADataFieldName], tc.testDSCI.Spec.TrustedCABundle.CustomCABundle) + 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 k8serr.IsNotFound(err) { + fmt.Printf("Config map not found in the namespace") + } } return nil } diff --git a/tests/e2e/helper_test.go b/tests/e2e/helper_test.go index 64140cc8111..7441b615ff8 100644 --- a/tests/e2e/helper_test.go +++ b/tests/e2e/helper_test.go @@ -94,7 +94,7 @@ func setupDSCICR(name string) *dsciv1.DSCInitialization { }, TrustedCABundle: &dsciv1.TrustedCABundleSpec{ ManagementState: "Managed", - CustomCABundle: "-----Begin....", + CustomCABundle: "-----Begin...." + "\n", }, ServiceMesh: &infrav1.ServiceMeshSpec{ ControlPlane: infrav1.ControlPlaneSpec{