diff --git a/go.mod b/go.mod index 07514226..e4e61bf8 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/ec2 v1.239.0 github.com/aws/aws-sdk-go-v2/service/sts v1.35.1 github.com/onsi/gomega v1.38.0 + github.com/openshift-online/ocm-common v0.0.30 github.com/openshift-online/ocm-sdk-go v0.1.473 github.com/openshift/api v0.0.0-20250731182533-c7fbd085e10c github.com/openshift/aws-account-operator/api v0.0.0-20250729145742-005e36e69583 diff --git a/go.sum b/go.sum index f08e6e63..b08bec34 100644 --- a/go.sum +++ b/go.sum @@ -440,6 +440,8 @@ github.com/openshift-online/ocm-api-model/model v0.0.426 h1:aZZ0PuknD9V+RUFsP692 github.com/openshift-online/ocm-api-model/model v0.0.426/go.mod h1:PQIoq6P8Vlb7goOdRMLK8nJY+B7HH0RTqYAa4kyidTE= github.com/openshift-online/ocm-cli v1.0.6 h1:48VzgYR9JxscLfup7w1nUfMHCIGp/a8AAHrw9cxjMcw= github.com/openshift-online/ocm-cli v1.0.6/go.mod h1:6BPWRw7d5E3FKRqSxO8YaYJ0g8Am9NxVqKAnFdDp7Lk= +github.com/openshift-online/ocm-common v0.0.30 h1:+JO/WyPGcU99PJlHZNX/pkR5wlIoKHQutTihAiUwfQE= +github.com/openshift-online/ocm-common v0.0.30/go.mod h1:VEkuZp9aqbXtetZ5ycND6QpvhykvTuBF3oPsVM1X3vI= github.com/openshift-online/ocm-sdk-go v0.1.473 h1:m/NWIBCzhC/8PototMQ7x8MQXCeSLjW7q0qR7bPGXKk= github.com/openshift-online/ocm-sdk-go v0.1.473/go.mod h1:5Gw/YZE+c5FAPaBtO1w/asd9qbs2ljQwg7fpVq51UW4= github.com/openshift/api v0.0.0-20250731182533-c7fbd085e10c h1:mY2wQ+0z9CzOn4vdQ+IaP2pnaQxgOx4ei5Qd9sVGr6k= diff --git a/test/e2e/README.md b/test/e2e/README.md index f6ddc260..3c6efeeb 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -2,13 +2,34 @@ When updating your operator it's beneficial to add e2e tests for new functionality AND ensure existing functionality is not breaking using e2e tests. To do this, following steps are recommended -1. Run "make e2e-binary-build" to make sure e2e tests build -2. Deploy your new version of operator in a test cluster -3. Run "go install github.com/onsi/ginkgo/ginkgo@latest" +1. Run "make e2e-binary-build" to make sure e2e tests build + +2. Run "go install github.com/onsi/ginkgo/ginkgo@latest" + +3. Create a ROSA Cluster which would be used for E2E testing using the below command: + + rosa create cluster --cluster-name= --profile + 4. Get kubeadmin credentials from your cluster using ocm get /api/clusters_mgmt/v1/clusters/(cluster-id)/credentials | jq -r .kubeconfig > /(path-to)/kubeconfig -5. Run test suite using +5. AWS Credentials +These are needed for interacting with the cluster. You can find them in the ~/.aws/credentials file. +Check for the access key and the secret key from the used for creating the cluster. +export AWS_ACCESS_KEY_ID= +export AWS_SECRET_ACCESS_KEY= + +6. PAGERDUTY ROUTING KEY + +This is required for the PagerDuty alerts that are being sent as part of the testing: + +https://redhat.pagerduty.com/service-directory/P4BLYHK/integrations + +The value can be picked up from the Integration Key in the above link + +export CAD_PAGERDUTY_ROUTING_KEY= + +7. Run test suite using DISABLE_JUNIT_REPORT=true KUBECONFIG=/(path-to)/kubeconfig ./(path-to)/bin/ginkgo --tags=osde2e -v test/e2e diff --git a/test/e2e/configuration_anomaly_detection_tests.go b/test/e2e/configuration_anomaly_detection_tests.go index c2006632..0d28b974 100644 --- a/test/e2e/configuration_anomaly_detection_tests.go +++ b/test/e2e/configuration_anomaly_detection_tests.go @@ -18,6 +18,8 @@ import ( "github.com/onsi/ginkgo/v2" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + ocmConfig "github.com/openshift-online/ocm-common/pkg/ocm/config" + ocmConnBuilder "github.com/openshift-online/ocm-common/pkg/ocm/connection-builder" v1beta1 "github.com/openshift/api/machine/v1beta1" awsinternal "github.com/openshift/configuration-anomaly-detection/pkg/aws" machineutil "github.com/openshift/configuration-anomaly-detection/pkg/investigations/utils/machine" @@ -47,14 +49,26 @@ var _ = Describe("Configuration Anomaly Detection", Ordered, func() { logger.SetLogger(ginkgo.GinkgoLogr) var err error ocmEnv := ocme2e.Stage - clientID := os.Getenv("OCM_CLIENT_ID") - clientSecret := os.Getenv("OCM_CLIENT_SECRET") clusterID = os.Getenv("OCM_CLUSTER_ID") Expect(clusterID).NotTo(BeEmpty(), "CLUSTER_ID must be set") - ocme2eCli, err = ocme2e.New(ctx, "", clientID, clientSecret, ocmEnv) - Expect(err).ShouldNot(HaveOccurred(), "Unable to setup E2E OCM Client") + cfg, err := ocmConfig.Load() + if err != nil { + // Fall back to environment variables + clientID := os.Getenv("OCM_CLIENT_ID") + clientSecret := os.Getenv("OCM_CLIENT_SECRET") + Expect(clientID).NotTo(BeEmpty(), "OCM_CLIENT_ID must be set") + Expect(clientSecret).NotTo(BeEmpty(), "OCM_CLIENT_SECRET must be set") + + ocme2eCli, err = ocme2e.New(ctx, "", clientID, clientSecret, ocmEnv) + Expect(err).ShouldNot(HaveOccurred(), "Unable to setup E2E OCM Client") + } else { + // Build connection based on local config + connection, err := ocmConnBuilder.NewConnection().Config(cfg).AsAgent("cad-local-e2e-tests").Build() + Expect(err).ShouldNot(HaveOccurred(), "Unable to build OCM connection") + ocme2eCli = &ocme2e.Client{Connection: connection} + } k8s, err = openshift.New(ginkgo.GinkgoLogr) Expect(err).ShouldNot(HaveOccurred(), "Unable to setup k8s client")