diff --git a/tests/release/pipelines/rh_advisories.go b/tests/release/pipelines/rh_advisories.go index 32a2c6d6e..f550b091a 100644 --- a/tests/release/pipelines/rh_advisories.go +++ b/tests/release/pipelines/rh_advisories.go @@ -1,10 +1,8 @@ package pipelines import ( - "encoding/base64" "encoding/json" "fmt" - "os" "regexp" "time" @@ -15,15 +13,12 @@ import ( releaseapi "github.com/konflux-ci/release-service/api/v1alpha1" tektonutils "github.com/konflux-ci/release-service/tekton/utils" tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/devfile/library/v2/pkg/util" "github.com/konflux-ci/e2e-tests/pkg/constants" "github.com/konflux-ci/e2e-tests/pkg/framework" "github.com/konflux-ci/e2e-tests/pkg/utils" "github.com/konflux-ci/e2e-tests/pkg/utils/tekton" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "knative.dev/pkg/apis" @@ -73,13 +68,13 @@ var _ = framework.ReleasePipelinesSuiteDescribe("e2e tests for rh-advisories pip "key": constants.PYXIS_STAGE_KEY_ENV, "cert": constants.PYXIS_STAGE_CERT_ENV, } - createSecretFromEnv(managedFw, managedNamespace, "pyxis", pyxisFieldEnvMap) + releasecommon.CreateOpaqueSecret(managedFw, managedNamespace, "pyxis", pyxisFieldEnvMap) atlasFieldEnvMap := map[string]string{ "sso_account": constants.ATLAS_STAGE_ACCOUNT_ENV, "sso_token": constants.ATLAS_STAGE_TOKEN_ENV, } - createSecretFromEnv(managedFw, managedNamespace, "atlas", atlasFieldEnvMap) + releasecommon.CreateOpaqueSecret(managedFw, managedNamespace, "atlas", atlasFieldEnvMap) err = managedFw.AsKubeAdmin.CommonController.LinkSecretToServiceAccount(managedNamespace, releasecommon.RedhatAppstudioUserSecret, constants.DefaultPipelineServiceAccount, true) Expect(err).ToNot(HaveOccurred()) @@ -264,45 +259,3 @@ func createADVSReleasePlanAdmission(advsRPAName string, managedFw framework.Fram }) Expect(err).NotTo(HaveOccurred()) } - -// createSecretfromEnv creates a k8s Secret in the managed workspace if it -// doesn't exist. It populates the Secret data fields based on the mapping of -// fields to environment variables containing the base64 encoded field data. -func createSecretFromEnv( - managedFw *framework.Framework, - managedNamespace, secretName string, - fieldEnvMap map[string]string, -) { - secretData := make(map[string][]byte) - - for field, envVar := range fieldEnvMap { - envValue := os.Getenv(envVar) - Expect(envValue).ToNot(BeEmpty()) - - decodedValue, err := base64.StdEncoding.DecodeString(envValue) - Expect(err).ToNot(HaveOccurred()) - - secretData[field] = decodedValue - } - - secret, err := managedFw.AsKubeAdmin.CommonController.GetSecret( - managedNamespace, - secretName, - ) - if secret == nil || errors.IsNotFound(err) { - secret := &corev1.Secret{ - ObjectMeta: metav1.ObjectMeta{ - Name: secretName, - Namespace: managedNamespace, - }, - Type: corev1.SecretTypeOpaque, - Data: secretData, - } - - _, err = managedFw.AsKubeAdmin.CommonController.CreateSecret( - managedNamespace, - secret, - ) - Expect(err).ToNot(HaveOccurred()) - } -} diff --git a/tests/release/releaseLib.go b/tests/release/releaseLib.go index 213a918a6..c99a83305 100644 --- a/tests/release/releaseLib.go +++ b/tests/release/releaseLib.go @@ -4,13 +4,17 @@ import ( "fmt" "os" "time" + "encoding/base64" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" appservice "github.com/konflux-ci/application-api/api/v1alpha1" appstudioApi "github.com/konflux-ci/application-api/api/v1alpha1" "github.com/devfile/library/v2/pkg/util" "github.com/konflux-ci/e2e-tests/pkg/constants" "github.com/konflux-ci/e2e-tests/pkg/framework" "github.com/konflux-ci/e2e-tests/pkg/utils" + "k8s.io/apimachinery/pkg/api/errors" releaseApi "github.com/konflux-ci/release-service/api/v1alpha1" . "github.com/onsi/ginkgo/v2" @@ -136,4 +140,44 @@ func CheckReleaseStatus(releaseCR *releaseApi.Release) (error) { return nil } +// CreateOpaqueSecret creates a k8s Secret in the managed workspace if it +// doesn't exist. It populates the Secret data fields based on the mapping of +// fields to environment variables containing the base64 encoded field data. +func CreateOpaqueSecret( + fw *framework.Framework, + namespace, secretName string, + fieldEnvMap map[string]string, +) { + secretData := make(map[string][]byte) + for field, envVar := range fieldEnvMap { + envValue := os.Getenv(envVar) + Expect(envValue).ToNot(BeEmpty()) + + decodedValue, err := base64.StdEncoding.DecodeString(envValue) + Expect(err).ToNot(HaveOccurred()) + + secretData[field] = decodedValue + } + + secret, err := fw.AsKubeAdmin.CommonController.GetSecret( + namespace, + secretName, + ) + if secret == nil || errors.IsNotFound(err) { + secret := &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: secretName, + Namespace: namespace, + }, + Type: corev1.SecretTypeOpaque, + Data: secretData, + } + + _, err = fw.AsKubeAdmin.CommonController.CreateSecret( + namespace, + secret, + ) + Expect(err).ToNot(HaveOccurred()) + } +}