-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: e2e test for trusted-ca-bundle #1346
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,14 @@ import ( | |
"fmt" | ||
"log" | ||
"reflect" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
operatorv1 "github.com/openshift/api/operator/v1" | ||
"github.com/stretchr/testify/require" | ||
autoscalingv1 "k8s.io/api/autoscaling/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
k8serr "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
|
@@ -99,6 +101,10 @@ func creationTestSuite(t *testing.T) { | |
err = testCtx.testDefaultModelRegistryCertAvailable() | ||
require.NoError(t, err, "error getting default cert secret for ModelRegistry") | ||
}) | ||
t.Run("Validate trusted CA bundle", func(t *testing.T) { | ||
err = testCtx.testTrustedCABundle() | ||
require.NoError(t, err, "error validating trusted CA bundle") | ||
}) | ||
t.Run("Validate model registry servicemeshmember available", func(t *testing.T) { | ||
err = testCtx.testMRServiceMeshMember() | ||
require.NoError(t, err, "error getting servicemeshmember for Model Registry") | ||
|
@@ -444,6 +450,46 @@ func (tc *testContext) testDefaultCertsAvailable() error { | |
return nil | ||
} | ||
|
||
func (tc *testContext) testTrustedCABundle() error { | ||
CAConfigMapName := "odh-trusted-ca-bundle" | ||
CADataFieldName := "odh-ca-bundle.crt" | ||
|
||
if tc.testDSCI.Spec.TrustedCABundle.ManagementState == operatorv1.Managed { | ||
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) | ||
} | ||
|
||
checkNewline := strings.HasSuffix(foundConfigMap.Data[CADataFieldName], "\n") | ||
|
||
if checkNewline == false { | ||
fmt.Print("Newline not found at the end of configmap") | ||
} | ||
Comment on lines
+470
to
+472
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are both cases acceptable here (newline or not), or should this assert one of the cases? Also, the check looks like it will pass if a newline character is found anywhere in the string, not just at the end. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @grdryn yea true, i have modified the check here |
||
|
||
if strings.TrimSpace(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 k8serr.IsNotFound(err) { | ||
fmt.Printf("Config map not found in the namespace") | ||
} else { | ||
return fmt.Errorf("failed to validate trusted CA bundle %w", err) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should return other errors here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @VaishnaviHire this is done |
||
} | ||
return nil | ||
} | ||
|
||
func (tc *testContext) testDefaultModelRegistryCertAvailable() error { | ||
// return if MR is not set to Managed | ||
if tc.testDsc.Spec.Components.ModelRegistry.ManagementState != operatorv1.Managed { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure i understand the logic here:
if we are making e2e test (not unit-test) , what we should test is:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, seems confusion for the above comments:
set managementStateChangeTrustedCA := true
is not meant to be set in the testcase, this is only to illustrate the case when set to
Managed
VSRemoved
what need to be done is
tc.testDSCI.Spec.TrustedCABundle.ManagementState: Managed