Skip to content

Commit

Permalink
OCM-5884 | test: [TF HCP] Day1: setup rosa-hcp-ad profile
Browse files Browse the repository at this point in the history
- Allow to manage many files for profiles
- Added `NonClassicCluster`/`NonHCPCluster` labels
- setup `rosa-hcp-ad` cluster creation
  • Loading branch information
radtriste authored and openshift-merge-bot[bot] committed Mar 7, 2024
1 parent 90f0a9d commit 4a917d7
Show file tree
Hide file tree
Showing 70 changed files with 1,552 additions and 294 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ terraform.tfstate*
/tests/rhcs_output
terraform-provider-rhcs
.vscode/**/*
**/ginkgo.report
**/ginkgo.report
/temp
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ fmt_go:
fmt_tf:
terraform fmt -recursive examples

.PHONY: fmt_tests
fmt_tests:
terraform fmt -recursive tests

.PHONY: fmt
fmt: fmt_go fmt_tf
fmt: fmt_go fmt_tf fmt_tests

.PHONY: clean
clean:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ output "oidc_endpoint_url" {
}

output "cluster_admin_username" {
value = rhcs_cluster_rosa_classic.rosa_sts_cluster.admin_credentials == null? null:rhcs_cluster_rosa_classic.rosa_sts_cluster.admin_credentials.username
value = rhcs_cluster_rosa_classic.rosa_sts_cluster.admin_credentials == null ? null : rhcs_cluster_rosa_classic.rosa_sts_cluster.admin_credentials.username
}

output "cluster_admin_password" {
value = rhcs_cluster_rosa_classic.rosa_sts_cluster.admin_credentials == null? null:rhcs_cluster_rosa_classic.rosa_sts_cluster.admin_credentials.password
value = rhcs_cluster_rosa_classic.rosa_sts_cluster.admin_credentials == null ? null : rhcs_cluster_rosa_classic.rosa_sts_cluster.admin_credentials.password
sensitive = true
}
7 changes: 2 additions & 5 deletions tests/ci/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ci
import (
"encoding/json"
"fmt"
"path"
"sort"
"strings"

Expand All @@ -16,10 +15,8 @@ import (
// The cfg will be used to define the testing environment
var cfg = CON.RHCS

func GetYAMLProfileFile(fileName string) (filename string) {
fPath := cfg.YAMLProfilesDir
filename = path.Join(fPath, fileName)
return
func GetYAMLProfilesDir() string {
return cfg.YAMLProfilesDir
}

// ConvertToStringArray will convert the []interface to []string
Expand Down
5 changes: 4 additions & 1 deletion tests/ci/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var Day1Negative = Label("day1-negative")
var Day1Post = Label("day1-post")
var Day2 = Label("day2")
var Upgrade = Label("upgrade")
var Update = Label("update")

// day3 : the test cases will destroy default resource
var Day3 = Label("day3")
Expand All @@ -32,3 +31,7 @@ var Low = Label("Low")

// exclude
var Exclude = Label("Exclude")

// Cluster Type
var NonClassicCluster = Label("NonClassicCluster")
var NonHCPCluster = Label("NonHCPCluster")
65 changes: 31 additions & 34 deletions tests/ci/profile_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
type Profile struct {
Name string `ini:"name,omitempty" json:"name,omitempty"`
ClusterName string `ini:"cluster_name,omitempty" json:"cluster_name,omitempty"`
ClusterType string `ini:"cluster_type,omitempty" json:"cluster_type,omitempty"`
ProductID string `ini:"product_id,omitempty" json:"product_id,omitempty"`
MajorVersion string `ini:"major_version,omitempty" json:"major_version,omitempty"`
Version string `ini:"version,omitempty" json:"version,omitempty"` //Specific OCP version to be specified
Expand All @@ -47,7 +48,6 @@ type Profile struct {
KMSKey bool `ini:"kms_key_arn,omitempty" json:"kms_key_arn,omitempty"`
NetWorkingSet bool `ini:"networking_set,omitempty" json:"networking_set,omitempty"`
Proxy bool `ini:"proxy,omitempty" json:"proxy,omitempty"`
Hypershift bool `ini:"hypershift,omitempty" json:"hypershift,omitempty"`
OIDCConfig string `ini:"oidc_config,omitempty" json:"oidc_config,omitempty"`
ProvisionShard string `ini:"provisionShard,omitempty" json:"provisionShard,omitempty"`
Ec2MetadataHttpTokens string `ini:"imdsv2,omitempty" json:"imdsv2,omitempty"`
Expand All @@ -57,17 +57,16 @@ type Profile struct {
ManagedPolicies bool `ini:"managed_policies,omitempty" json:"managed_policies,omitempty"`
WorkerDiskSize int `ini:"worker_disk_size,omitempty" json:"worker_disk_size,omitempty"`
AdditionalSGNumber int `ini:"additional_sg_number,omitempty" json:"additional_sg_number,omitempty"`
ManifestsDIR string `ini:"manifests_dir,omitempty" json:"manifests_dir,omitempty"`
UnifiedAccRolesPath string `ini:"unified_acc_role_path,omitempty" json:"unified_acc_role_path,omitempty"`
}

func PrepareVPC(region string, privateLink bool, multiZone bool, azIDs []string, name ...string) (*EXE.VPCOutput, error) {

func PrepareVPC(region string, privateLink bool, multiZone bool, azIDs []string, clusterType CON.ClusterType, name ...string) (*EXE.VPCOutput, error) {
vpcService := EXE.NewVPCService()
vpcArgs := &EXE.VPCArgs{
AWSRegion: region,
MultiAZ: multiZone,
VPCCIDR: CON.DefaultVPCCIDR,
HCP: clusterType.HCP,
}

if len(azIDs) != 0 {
Expand Down Expand Up @@ -120,9 +119,9 @@ func PrepareAdditionalSecurityGroups(region string, vpcID string, sgNumbers int)
return output.SGIDs, err
}

func PrepareAccountRoles(token string, accountRolePrefix string, accountRolesPath string, awsRegion string, openshiftVersion string, channelGroup string, manifestDir string) (
func PrepareAccountRoles(token string, accountRolePrefix string, accountRolesPath string, awsRegion string, openshiftVersion string, channelGroup string, clusterType CON.ClusterType) (
*EXE.AccountRolesOutput, error) {
accService, err := EXE.NewAccountRoleService(manifestDir)
accService, err := EXE.NewAccountRoleService(CON.GetAccountRoleDefaultManifestDir(clusterType))
if err != nil {
return nil, err
}
Expand All @@ -139,9 +138,9 @@ func PrepareAccountRoles(token string, accountRolePrefix string, accountRolesPat
return accRoleOutput, err
}

func PrepareOIDCProviderAndOperatorRoles(token string, oidcConfigType string, operatorRolePrefix string, accountRolePrefix string, accountRolesPath string, awsRegion string) (
func PrepareOIDCProviderAndOperatorRoles(token string, oidcConfigType string, operatorRolePrefix string, accountRolePrefix string, accountRolesPath string, clusterType CON.ClusterType, awsRegion string) (
*EXE.OIDCProviderOperatorRolesOutput, error) {
oidcOpService, err := EXE.NewOIDCProviderOperatorRolesService()
oidcOpService, err := EXE.NewOIDCProviderOperatorRolesService(CON.GetOIDCProviderOperatorRolesDefaultManifestDir(clusterType))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -222,7 +221,7 @@ func PrepareProxy(region string, VPCID string, subnetPublicID string) (*EXE.Prox
return &proxyOutput, err
}

func PrepareKMSKey(profile *Profile, kmsName string, accountRolePrefix string, accountRolePath string) (string, error) {
func PrepareKMSKey(profile *Profile, kmsName string, accountRolePrefix string, accountRolePath string, clusterType CON.ClusterType) (string, error) {
kmsService, err := EXE.NewKMSService()
if err != nil {
return "", err
Expand All @@ -235,6 +234,7 @@ func PrepareKMSKey(profile *Profile, kmsName string, accountRolePrefix string, a
TagKey: "Purpose",
TagValue: "RHCS automation test",
TagDescription: "BYOK Test Key for API automation",
HCP: clusterType.HCP,
}

err = kmsService.Apply(kmsArgs, true)
Expand All @@ -249,7 +249,7 @@ func PrepareKMSKey(profile *Profile, kmsName string, accountRolePrefix string, a

func PrepareRoute53() {}

func GenerateClusterCreationArgsByProfile(token string, profile *Profile) (clusterArgs *EXE.ClusterCreationArgs, manifestsDir string, err error) {
func GenerateClusterCreationArgsByProfile(token string, profile *Profile) (clusterArgs *EXE.ClusterCreationArgs, err error) {
profile.Version = PrepareVersion(RHCSConnection, profile.VersionPattern, profile.ChannelGroup, profile)

clusterArgs = &EXE.ClusterCreationArgs{
Expand Down Expand Up @@ -290,10 +290,6 @@ func GenerateClusterCreationArgsByProfile(token string, profile *Profile) (clust
profile.Region = CON.DefaultAWSRegion
}

if profile.ManifestsDIR == "" {
profile.ManifestsDIR = CON.ROSAClassic
}

if profile.Labeling {
clusterArgs.DefaultMPLabels = CON.DefaultMPLabels
}
Expand Down Expand Up @@ -335,7 +331,7 @@ func GenerateClusterCreationArgsByProfile(token string, profile *Profile) (clust

if profile.STS {
majorVersion := GetMajorVersion(profile.Version)
accountRolesOutput, err := PrepareAccountRoles(token, clusterArgs.ClusterName, profile.UnifiedAccRolesPath, clusterArgs.AWSRegion, majorVersion, profile.ChannelGroup, CON.AccountRolesDir)
accountRolesOutput, err := PrepareAccountRoles(token, clusterArgs.ClusterName, profile.UnifiedAccRolesPath, clusterArgs.AWSRegion, majorVersion, profile.ChannelGroup, profile.GetClusterType())
Expect(err).ToNot(HaveOccurred())
clusterArgs.AccountRolePrefix = accountRolesOutput.AccountRolePrefix
clusterArgs.UnifiedAccRolesPath = profile.UnifiedAccRolesPath
Expand All @@ -344,7 +340,7 @@ func GenerateClusterCreationArgsByProfile(token string, profile *Profile) (clust
Logger.Infof("Sleep for 10 sec to let aws account role async creation finished")
time.Sleep(10 * time.Second)

oidcOutput, err := PrepareOIDCProviderAndOperatorRoles(token, profile.OIDCConfig, clusterArgs.ClusterName, accountRolesOutput.AccountRolePrefix, profile.UnifiedAccRolesPath, clusterArgs.AWSRegion)
oidcOutput, err := PrepareOIDCProviderAndOperatorRoles(token, profile.OIDCConfig, clusterArgs.ClusterName, accountRolesOutput.AccountRolePrefix, profile.UnifiedAccRolesPath, profile.GetClusterType(), clusterArgs.AWSRegion)
Expect(err).ToNot(HaveOccurred())
clusterArgs.OIDCConfigID = oidcOutput.OIDCConfigID
clusterArgs.OperatorRolePrefix = oidcOutput.OperatorRolePrefix
Expand All @@ -368,7 +364,7 @@ func GenerateClusterCreationArgsByProfile(token string, profile *Profile) (clust
zones = strings.Split(profile.Zones, ",")
}

vpcOutput, err = PrepareVPC(profile.Region, profile.PrivateLink, profile.MultiAZ, zones, clusterArgs.ClusterName)
vpcOutput, err = PrepareVPC(profile.Region, profile.PrivateLink, profile.MultiAZ, zones, profile.GetClusterType(), clusterArgs.ClusterName)
if err != nil {
return
}
Expand Down Expand Up @@ -418,7 +414,7 @@ func GenerateClusterCreationArgsByProfile(token string, profile *Profile) (clust

if profile.KMSKey {
var kmskey string
kmskey, err = PrepareKMSKey(profile, clusterArgs.ClusterName, clusterArgs.AccountRolePrefix, profile.UnifiedAccRolesPath)
kmskey, err = PrepareKMSKey(profile, clusterArgs.ClusterName, clusterArgs.AccountRolePrefix, profile.UnifiedAccRolesPath, profile.GetClusterType())
if err != nil {
return
}
Expand All @@ -432,20 +428,16 @@ func GenerateClusterCreationArgsByProfile(token string, profile *Profile) (clust
clusterArgs.UnifiedAccRolesPath = profile.UnifiedAccRolesPath
clusterArgs.CustomProperties = CON.CustomProperties

return clusterArgs, profile.ManifestsDIR, err
return clusterArgs, err
}

func LoadProfileYamlFile(profileName string) *Profile {
filename := GetYAMLProfileFile(CON.TFYAMLProfile)
p := HELPER.GetProfile(profileName, filename)
p := HELPER.GetProfile(profileName, GetYAMLProfilesDir())
Logger.Infof("Loaded cluster profile configuration from profile %s : %v", profileName, p.Cluster)
profile := Profile{
Name: profileName,
}
err := HELPER.MapStructure(p.Cluster, &profile)
if profile.ManifestsDIR == "" {
profile.ManifestsDIR = CON.ROSAClassic
}
Expect(err).ToNot(HaveOccurred())
return &profile
}
Expand Down Expand Up @@ -474,12 +466,12 @@ func LoadProfileYamlFileByENV() *Profile {
}

func CreateRHCSClusterByProfile(token string, profile *Profile) (string, error) {
creationArgs, _, err := GenerateClusterCreationArgsByProfile(token, profile)
creationArgs, err := GenerateClusterCreationArgsByProfile(token, profile)
if err != nil {
defer DestroyRHCSClusterByProfile(token, profile)
}
Expect(err).ToNot(HaveOccurred())
clusterService, err := EXE.NewClusterService(profile.ManifestsDIR)
clusterService, err := EXE.NewClusterService(profile.GetClusterManifestsDir())
if err != nil {
defer DestroyRHCSClusterByProfile(token, profile)
}
Expand All @@ -496,9 +488,8 @@ func CreateRHCSClusterByProfile(token string, profile *Profile) (string, error)
}

func DestroyRHCSClusterByProfile(token string, profile *Profile) error {

// Destroy cluster
clusterService, err := EXE.NewClusterService(profile.ManifestsDIR)
clusterService, err := EXE.NewClusterService(profile.GetClusterManifestsDir())
Expect(err).ToNot(HaveOccurred())

clusterArgs := &EXE.ClusterCreationArgs{
Expand Down Expand Up @@ -552,7 +543,7 @@ func DestroyRHCSClusterByProfile(token string, profile *Profile) error {
}
if profile.STS {
// Destroy oidc and operator roles
oidcOpService, err := EXE.NewOIDCProviderOperatorRolesService()
oidcOpService, err := EXE.NewOIDCProviderOperatorRolesService(CON.GetOIDCProviderOperatorRolesDefaultManifestDir(profile.GetClusterType()))
if err != nil {
return err
}
Expand All @@ -566,7 +557,7 @@ func DestroyRHCSClusterByProfile(token string, profile *Profile) error {
}

// Destroy Account roles
accService, err := EXE.NewAccountRoleService()
accService, err := EXE.NewAccountRoleService(CON.GetAccountRoleDefaultManifestDir(profile.GetClusterType()))
if err != nil {
return err
}
Expand Down Expand Up @@ -609,14 +600,20 @@ func PrepareRHCSClusterByProfileENV() (string, error) {
return "", nil
}
profile := LoadProfileYamlFileByENV()
if profile.ManifestsDIR == "" {
profile.ManifestsDIR = CON.ROSAClassic
}
clusterService, err := EXE.NewClusterService(profile.ManifestsDIR)
clusterService, err := EXE.NewClusterService(profile.GetClusterManifestsDir())
if err != nil {
return "", err
}
clusterOutput, err := clusterService.Output()
clusterID := clusterOutput.ClusterID
return clusterID, err
}

func (profile *Profile) GetClusterType() CON.ClusterType {
return CON.FindClusterType(profile.ClusterType)
}

func (profile *Profile) GetClusterManifestsDir() string {
manifestsDir := CON.GetClusterManifestsDir(profile.GetClusterType())
return manifestsDir
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ profiles:
# rosa-sts-pl :: creating a managed oidc config cluster
- as: rosa-sts-pl
cluster:
cluster_type: rosa-classic
multi_az: false
product_id: "rosa"
hypershift: false
cloud_provider: "aws"
region: "us-east-1"
ccs: true
Expand Down Expand Up @@ -33,9 +33,9 @@ profiles:
# rosa-sts-ad :: creating unmanaged oidc config cluster
- as: rosa-sts-ad
cluster:
cluster_type: rosa-classic
multi_az: true
product_id: "rosa"
hypershift: false
cloud_provider: "aws"
region: "ap-northeast-1"
ccs: true
Expand Down Expand Up @@ -66,9 +66,9 @@ profiles:
# rosa-up-y :: creating a cluster for y-stream upgrade purpose
- as: rosa-up-y
cluster:
cluster_type: rosa-classic
multi_az: false
product_id: "rosa"
hypershift: false
cloud_provider: "aws"
region: "ap-northeast-1"
ccs: true
Expand Down Expand Up @@ -97,9 +97,9 @@ profiles:
# rosa-up-z :: creating a cluster for z-stream upgrade purpose
- as: rosa-up-z
cluster:
cluster_type: rosa-classic
multi_az: true
product_id: "rosa"
hypershift: false
cloud_provider: "aws"
region: "ap-northeast-1"
ccs: true
Expand Down
Loading

0 comments on commit 4a917d7

Please sign in to comment.