Skip to content

Commit

Permalink
OCM-11840 | ci: Centralize environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
radtriste committed Oct 14, 2024
1 parent 05691b4 commit 96f27c1
Show file tree
Hide file tree
Showing 21 changed files with 397 additions and 359 deletions.
8 changes: 4 additions & 4 deletions tests/e2e/account_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler"

"github.com/terraform-redhat/terraform-provider-rhcs/tests/ci"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec"

. "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/log"
Expand Down Expand Up @@ -164,15 +164,15 @@ var _ = Describe("Create Account roles with shared vpc role", ci.Exclude, func()
vpcArgs := &exec.VPCArgs{
NamePrefix: helper.StringPointer(clusterName),
AWSRegion: helper.StringPointer(profileHandler.Profile().GetRegion()),
VPCCIDR: helper.StringPointer(constants.DefaultVPCCIDR),
AWSSharedCredentialsFiles: helper.StringSlicePointer([]string{constants.SharedVpcAWSSharedCredentialsFileENV}),
VPCCIDR: helper.StringPointer(profilehandler.DefaultVPCCIDR),
AWSSharedCredentialsFiles: helper.StringSlicePointer([]string{config.GetSharedVpcAWSSharedCredentialsFile()}),
}
_, err = vpcService.Apply(vpcArgs)
Expect(err).ToNot(HaveOccurred())
vpcOutput, err := vpcService.Output()
Expect(err).ToNot(HaveOccurred())
sharedVPCArgs := &exec.SharedVpcPolicyAndHostedZoneArgs{
SharedVpcAWSSharedCredentialsFiles: helper.StringSlicePointer([]string{constants.SharedVpcAWSSharedCredentialsFileENV}),
SharedVpcAWSSharedCredentialsFiles: helper.StringSlicePointer([]string{config.GetSharedVpcAWSSharedCredentialsFile()}),
Region: helper.StringPointer(profileHandler.Profile().GetRegion()),
ClusterName: helper.StringPointer(clusterName),
DnsDomainId: helper.StringPointer(dnsDomainOutput.DnsDomainId),
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/cluster_creation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/terraform-redhat/terraform-provider-rhcs/tests/ci"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/cms"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper"
Expand All @@ -27,7 +28,7 @@ var _ = Describe("Create cluster", func() {
Expect(err).ToNot(HaveOccurred())
Expect(clusterID).ToNot(BeEmpty())
//TODO: implement waiter for the private cluster once bastion is implemented
if constants.GetEnvWithDefault(constants.WaitOperators, "false") == "true" && !profileHandler.Profile().IsPrivate() {
if config.IsWaitForOperators() && !profileHandler.Profile().IsPrivate() {
// WaitClusterOperatorsToReadyStatus will wait for cluster operators ready
timeout := 60
err = openshift.WaitForOperatorsToBeReady(cms.RHCSConnection, clusterID, timeout)
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/cluster_destroy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/ci"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler"
)

var _ = Describe("Delete cluster", func() {
It("DestroyClusterByProfile", ci.Destroy,
func() {
// Destroy kubeconfig folder
if _, err := os.Stat(constants.RHCS.KubeConfigDir); err == nil {
os.RemoveAll(constants.RHCS.KubeConfigDir)
if _, err := os.Stat(config.GetKubeConfigDir()); err == nil {
os.RemoveAll(config.GetKubeConfigDir())
}

// Generate/build cluster by profile selected
Expand Down
3 changes: 1 addition & 2 deletions tests/e2e/cluster_misc_day2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
. "github.com/onsi/gomega"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/ci"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/cms"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler"
Expand Down Expand Up @@ -59,7 +58,7 @@ var _ = Describe("Cluster miscellaneous", func() {
}

By("Adding additional custom property to the existing cluster")
updatedCustomProperties := constants.CustomProperties
updatedCustomProperties := profilehandler.CustomProperties
updatedCustomProperties["second_custom_property"] = "test2"

// Apply updated custom properties to the cluster
Expand Down
9 changes: 5 additions & 4 deletions tests/e2e/cluster_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
. "github.com/onsi/gomega"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/ci"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/cms"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper"
Expand Down Expand Up @@ -102,7 +103,7 @@ var _ = Describe("Upgrade", func() {
Expect(string(clusterResp.Body().State())).To(Equal(constants.Ready))
Expect(string(clusterResp.Body().Version().RawID())).To(Equal(targetV))

if constants.GetEnvWithDefault(constants.WaitOperators, "false") == "true" && !profile.IsPrivate() {
if config.IsWaitForOperators() && !profile.IsPrivate() {
// WaitClusterOperatorsToReadyStatus will wait for cluster operators ready
timeout := 60
err = openshift.WaitForOperatorsToBeReady(cms.RHCSConnection, clusterID, timeout)
Expand Down Expand Up @@ -171,7 +172,7 @@ var _ = Describe("Upgrade", func() {
Expect(string(clusterResp.Body().State())).To(Equal(constants.Ready))
Expect(string(clusterResp.Body().Version().RawID())).To(Equal(targetV))

if constants.GetEnvWithDefault(constants.WaitOperators, "false") == "true" && !profile.IsPrivate() {
if config.IsWaitForOperators() && !profile.IsPrivate() {
// WaitClusterOperatorsToReadyStatus will wait for cluster operators ready
timeout := 60
err = openshift.WaitForOperatorsToBeReady(cms.RHCSConnection, clusterID, timeout)
Expand Down Expand Up @@ -218,7 +219,7 @@ var _ = Describe("Upgrade", func() {
Expect(string(clusterResp.Body().State())).To(Equal(constants.Ready))
Expect(string(clusterResp.Body().Version().RawID())).To(Equal(targetV))

if constants.GetEnvWithDefault(constants.WaitOperators, "false") == "true" && !profile.IsPrivate() {
if config.IsWaitForOperators() && !profile.IsPrivate() {
// WaitClusterOperatorsToReadyStatus will wait for cluster operators ready
timeout := 60
err = openshift.WaitForOperatorsToBeReady(cms.RHCSConnection, clusterID, timeout)
Expand Down Expand Up @@ -266,7 +267,7 @@ var _ = Describe("Upgrade", func() {
Expect(string(clusterResp.Body().State())).To(Equal(constants.Ready))
Expect(string(clusterResp.Body().Version().RawID())).To(Equal(targetV))

if constants.GetEnvWithDefault(constants.WaitOperators, "false") == "true" && !profile.IsPrivate() {
if config.IsWaitForOperators() && !profile.IsPrivate() {
// WaitClusterOperatorsToReadyStatus will wait for cluster operators ready
timeout := 60
err = openshift.WaitForOperatorsToBeReady(cms.RHCSConnection, clusterID, timeout)
Expand Down
8 changes: 3 additions & 5 deletions tests/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package e2e

import (
"context"
"os"
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler"
)
Expand All @@ -23,10 +21,10 @@ func TestRHCSProvider(t *testing.T) {
}

var _ = BeforeSuite(func() {
token = os.Getenv(constants.TokenENVName)
token = config.GetRHCSOCMToken()
var err error

err = helper.AlignRHCSSourceVersion(manifests.ManifestsConfigurationDir)
err = helper.AlignRHCSSourceVersion(config.GetManifestsDir())
Expect(err).ToNot(HaveOccurred())

profileHandler, err := profilehandler.NewProfileHandlerFromYamlFile()
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/hcp_machine_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() {
MachineType: helper.StringPointer(machineType),
AutoRepair: helper.BoolPointer(true),
TuningConfigs: helper.StringSlicePointer(tuningconfigs),
Tags: helper.StringMapPointer(constants.Tags),
Tags: helper.StringMapPointer(profilehandler.Tags),
}
_, err = mpService.Apply(mpArgs)
Expect(err).ToNot(HaveOccurred())
Expand Down
57 changes: 29 additions & 28 deletions tests/e2e/idps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
. "github.com/openshift-online/ocm-sdk-go/testing"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/ci"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/cms"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec"
"github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper"
Expand Down Expand Up @@ -65,7 +66,7 @@ func getDefaultLDAPArgs(idpName string) *exec.IDPArgs {
ClusterID: helper.StringPointer(clusterID),
Name: helper.StringPointer(idpName),
CA: helper.EmptyStringPointer,
URL: helper.StringPointer(constants.LdapURL),
URL: helper.StringPointer(profilehandler.LdapURL),
LDAPAttributes: &exec.LDAPAttributes{},
Insecure: helper.BoolPointer(true),
}
Expand All @@ -76,7 +77,7 @@ func getDefaultGitHubArgs(idpName string) *exec.IDPArgs {
Name: helper.StringPointer(idpName),
ClientID: helper.StringPointer(defaultGithubIDPClientId),
ClientSecret: helper.StringPointer(defaultGithubIDPClientSecret),
Organizations: helper.StringSlicePointer(constants.Organizations),
Organizations: helper.StringSlicePointer(profilehandler.Organizations),
}
}
func getDefaultGitlabArgs(idpName string) *exec.IDPArgs {
Expand All @@ -85,7 +86,7 @@ func getDefaultGitlabArgs(idpName string) *exec.IDPArgs {
Name: helper.StringPointer(idpName),
ClientID: helper.StringPointer(defaultGitlabIDPClientId),
ClientSecret: helper.StringPointer(defaultGitlabIDPClientSecret),
URL: helper.StringPointer(constants.GitLabURL),
URL: helper.StringPointer(profilehandler.GitLabURL),
}
}
func getDefaultGoogleArgs(idpName string) *exec.IDPArgs {
Expand All @@ -94,7 +95,7 @@ func getDefaultGoogleArgs(idpName string) *exec.IDPArgs {
Name: helper.StringPointer(idpName),
ClientID: helper.StringPointer(defaultGoogleIDPClientId),
ClientSecret: helper.StringPointer(defaultGoogleIDPClientSecret),
HostedDomain: helper.StringPointer(constants.HostedDomain),
HostedDomain: helper.StringPointer(profilehandler.HostedDomain),
}
}

Expand Down Expand Up @@ -179,9 +180,9 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
Username: defaultHTPUsername,
Password: defaultHTPPassword,
ClusterID: clusterID,
AdditioanlFlags: []string{
AdditionalFlags: []string{
"--insecure-skip-tls-verify",
fmt.Sprintf("--kubeconfig %s", path.Join(constants.RHCS.KubeConfigDir, fmt.Sprintf("%s.%s", clusterID, defaultHTPUsername))),
fmt.Sprintf("--kubeconfig %s", path.Join(config.GetKubeConfigDir(), fmt.Sprintf("%s.%s", clusterID, defaultHTPUsername))),
},
Timeout: 7,
}
Expand Down Expand Up @@ -286,7 +287,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
ClusterID: helper.StringPointer(clusterID),
Name: helper.StringPointer("OCP-63332-ldap-idp-test"),
CA: helper.EmptyStringPointer,
URL: helper.StringPointer(constants.LdapURL),
URL: helper.StringPointer(profilehandler.LdapURL),
LDAPAttributes: &exec.LDAPAttributes{},
Insecure: helper.BoolPointer(true),
}
Expand All @@ -306,9 +307,9 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
Username: defaultLDAPUsername,
Password: defaultLDAPPassword,
ClusterID: clusterID,
AdditioanlFlags: []string{
AdditionalFlags: []string{
"--insecure-skip-tls-verify",
fmt.Sprintf("--kubeconfig %s", path.Join(constants.RHCS.KubeConfigDir, fmt.Sprintf("%s.%s", clusterID, defaultLDAPUsername))),
fmt.Sprintf("--kubeconfig %s", path.Join(config.GetKubeConfigDir(), fmt.Sprintf("%s.%s", clusterID, defaultLDAPUsername))),
},
Timeout: 7,
}
Expand All @@ -334,7 +335,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
Name: helper.StringPointer("OCP-64028-gitlab-idp-test"),
ClientID: helper.StringPointer(defaultGitlabIDPClientId),
ClientSecret: helper.StringPointer(defaultGitlabIDPClientSecret),
URL: helper.StringPointer(constants.GitLabURL),
URL: helper.StringPointer(profilehandler.GitLabURL),
}
_, err := idpServices.gitlab.Apply(idpParam)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -363,7 +364,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
Name: helper.StringPointer("OCP-64027-github-idp-test"),
ClientID: helper.StringPointer(defaultGithubIDPClientId),
ClientSecret: helper.StringPointer(defaultGithubIDPClientSecret),
Organizations: helper.StringSlicePointer(constants.Organizations),
Organizations: helper.StringSlicePointer(profilehandler.Organizations),
}
_, err := idpServices.github.Apply(idpParam)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -392,7 +393,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
Name: helper.StringPointer("OCP-64029-google-idp-test"),
ClientID: helper.StringPointer(defaultGoogleIDPClientId),
ClientSecret: helper.StringPointer(defaultGoogleIDPClientSecret),
HostedDomain: helper.StringPointer(constants.HostedDomain),
HostedDomain: helper.StringPointer(profilehandler.HostedDomain),
}
_, err := idpServices.google.Apply(idpParam)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -427,9 +428,9 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
Name: helper.StringPointer("OCP-64030"),
ClientID: helper.StringPointer(defaultGoogleIDPClientId),
ClientSecret: helper.StringPointer(defaultGoogleIDPClientSecret),
HostedDomain: helper.StringPointer(constants.HostedDomain),
HostedDomain: helper.StringPointer(profilehandler.HostedDomain),
CA: helper.EmptyStringPointer,
URL: helper.StringPointer(constants.LdapURL),
URL: helper.StringPointer(profilehandler.LdapURL),
LDAPAttributes: &exec.LDAPAttributes{},
Insecure: helper.BoolPointer(true),
}
Expand All @@ -449,9 +450,9 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
Username: defaultLDAPUsername,
Password: defaultLDAPPassword,
ClusterID: clusterID,
AdditioanlFlags: []string{
AdditionalFlags: []string{
"--insecure-skip-tls-verify",
fmt.Sprintf("--kubeconfig %s", path.Join(constants.RHCS.KubeConfigDir, fmt.Sprintf("%s.%s", clusterID, defaultLDAPUsername))),
fmt.Sprintf("--kubeconfig %s", path.Join(config.GetKubeConfigDir(), fmt.Sprintf("%s.%s", clusterID, defaultLDAPUsername))),
},
Timeout: 7,
}
Expand All @@ -463,7 +464,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
}

// login to the cluster using cluster-admin creds
username := constants.ClusterAdminUser
username := profilehandler.ClusterAdminUser
password, _ := helper.GetClusterAdminPassword()
Expect(password).ToNot(BeEmpty())

Expand All @@ -472,9 +473,9 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
Username: username,
Password: password,
ClusterID: clusterID,
AdditioanlFlags: []string{
AdditionalFlags: []string{
"--insecure-skip-tls-verify",
fmt.Sprintf("--kubeconfig %s", path.Join(constants.RHCS.KubeConfigDir, fmt.Sprintf("%s.%s", clusterID, username))),
fmt.Sprintf("--kubeconfig %s", path.Join(config.GetKubeConfigDir(), fmt.Sprintf("%s.%s", clusterID, username))),
},
Timeout: 10,
}
Expand Down Expand Up @@ -513,9 +514,9 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
Username: defaultHTPUsername,
Password: defaultHTPPassword,
ClusterID: clusterID,
AdditioanlFlags: []string{
AdditionalFlags: []string{
"--insecure-skip-tls-verify",
fmt.Sprintf("--kubeconfig %s", path.Join(constants.RHCS.KubeConfigDir, fmt.Sprintf("%s.%s", clusterID, defaultHTPUsername))),
fmt.Sprintf("--kubeconfig %s", path.Join(config.GetKubeConfigDir(), fmt.Sprintf("%s.%s", clusterID, defaultHTPUsername))),
},
Timeout: 10,
}
Expand Down Expand Up @@ -544,9 +545,9 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
Username: defaultHTPUsername,
Password: defaultHTPPassword,
ClusterID: clusterID,
AdditioanlFlags: []string{
AdditionalFlags: []string{
"--insecure-skip-tls-verify",
fmt.Sprintf("--kubeconfig %s", path.Join(constants.RHCS.KubeConfigDir, fmt.Sprintf("%s.%s", clusterID, defaultHTPUsername))),
fmt.Sprintf("--kubeconfig %s", path.Join(config.GetKubeConfigDir(), fmt.Sprintf("%s.%s", clusterID, defaultHTPUsername))),
},
Timeout: 10,
}
Expand Down Expand Up @@ -774,7 +775,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
output, err := importService.ShowState(importParam.Resource)
Expect(err).ToNot(HaveOccurred())
Expect(output).To(ContainSubstring(defaultGoogleIDPClientId))
Expect(output).To(ContainSubstring(constants.HostedDomain))
Expect(output).To(ContainSubstring(profilehandler.HostedDomain))

By("Validate terraform import with no idp object name returns error")
var unknownIdpName = "unknown_idp_name"
Expand Down Expand Up @@ -833,9 +834,9 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
Username: defaultLDAPUsername,
Password: defaultLDAPPassword,
ClusterID: clusterID,
AdditioanlFlags: []string{
AdditionalFlags: []string{
"--insecure-skip-tls-verify",
fmt.Sprintf("--kubeconfig %s", path.Join(constants.RHCS.KubeConfigDir, fmt.Sprintf("%s.%s", clusterID, defaultLDAPUsername))),
fmt.Sprintf("--kubeconfig %s", path.Join(config.GetKubeConfigDir(), fmt.Sprintf("%s.%s", clusterID, defaultLDAPUsername))),
},
Timeout: 7,
}
Expand Down Expand Up @@ -888,7 +889,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
Gitlab(cmsv1.NewGitlabIdentityProvider().
ClientID(defaultGitlabIDPClientId).
ClientSecret(defaultGitlabIDPClientSecret).
URL(constants.GitLabURL)).
URL(profilehandler.GitLabURL)).
MappingMethod("claim").
Build()
res, err := cms.CreateClusterIDP(cms.RHCSConnection, clusterID, requestBody)
Expand Down Expand Up @@ -936,7 +937,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
Gitlab(cmsv1.NewGitlabIdentityProvider().
ClientID(defaultGitlabIDPClientSecret).
ClientSecret(newClientSecret).
URL(constants.GitLabURL)).
URL(profilehandler.GitLabURL)).
MappingMethod("claim").
Build()

Expand Down
Loading

0 comments on commit 96f27c1

Please sign in to comment.