From e55f441712ba3a71fdd44bbf0b0a04f8419deeec Mon Sep 17 00:00:00 2001 From: Xue Li Date: Wed, 30 Oct 2024 19:19:40 +0800 Subject: [PATCH] OCM-11675 | ci: Expose some of the cluster configurations for profile override --- tests/ci/config/config.go | 27 +++++++++- tests/utils/helper/string.go | 14 +++++ tests/utils/profilehandler/profile_handler.go | 54 +++++++++++++++++-- 3 files changed, 89 insertions(+), 6 deletions(-) diff --git a/tests/ci/config/config.go b/tests/ci/config/config.go index 87972af3f7..2addc689f9 100644 --- a/tests/ci/config/config.go +++ b/tests/ci/config/config.go @@ -43,6 +43,7 @@ type TestConfig struct { ProxySSHPemFile string ProxyCABundleFile string GlobalENV *GlobalENVVariables + ClusterENV *ClusterENVVariables } type GlobalENVVariables struct { ChannelGroup string `env:"CHANNEL_GROUP" default:""` @@ -53,9 +54,20 @@ type GlobalENVVariables struct { ClusterWaitingTime int `env:"CLUSTER_TIMEOUT" default:"60"` WaitSetupClusterReady bool `env:"WAIT_SETUP_CLUSTER_READY" default:"true"` SVPC_CREDENTIALS_FILE string `env:"SHARED_VPC_AWS_SHARED_CREDENTIALS_FILE" default:""` - ComputeMachineType string `env:"COMPUTE_MACHINE_TYPE" default:""` OCM_LOGIN_ENV string `env:"OCM_LOGIN_ENV" default:""` } +type ClusterENVVariables struct { + ComputeMachineType string `env:"COMPUTE_MACHINE_TYPE" default:""` + BYOVPC string `env:"BYOVPC" default:""` + Private string `env:"PRIVATE" default:""` + Autoscale string `env:"AUTOSCALE" default:""` + ProxyEnabled string `env:"PROXY_ENABLED" default:""` + FipsEnabled string `env:"FIPS_ENABLED" default:""` + VolumeSize string `env:"VOLUME_SIZE" default:""` + Replicas string `env:"REPLICAS" default:""` + MultiAZ string `env:"MULTI_AZ" default:""` + AllowRegistries string `env:"ALLOW_REGISTRIES" default:""` +} func init() { Test = new(TestConfig) @@ -109,10 +121,21 @@ func init() { ProvisionShard: os.Getenv("PROVISION_SHARD"), NamePrefix: os.Getenv("NAME_PREFIX"), SVPC_CREDENTIALS_FILE: os.Getenv("SHARED_VPC_AWS_SHARED_CREDENTIALS_FILE"), - ComputeMachineType: os.Getenv("COMPUTE_MACHINE_TYPE"), OCM_LOGIN_ENV: os.Getenv("OCM_LOGIN_ENV"), ClusterWaitingTime: waitingTime, WaitSetupClusterReady: waitSetupClusterReady, } + Test.ClusterENV = &ClusterENVVariables{ + ComputeMachineType: os.Getenv("COMPUTE_MACHINE_TYPE"), + BYOVPC: os.Getenv("BYOVPC"), + Private: os.Getenv("PRIVATE"), + Autoscale: os.Getenv("AUTOSCALE"), + ProxyEnabled: os.Getenv("PROXY_ENABLED"), + FipsEnabled: os.Getenv("FIPS_ENABLED"), + VolumeSize: os.Getenv("VOLUME_SIZE"), + Replicas: os.Getenv("REPLICAS"), + MultiAZ: os.Getenv("MULTI_AZ"), + AllowRegistries: os.Getenv("ALLOW_REGISTRIES"), + } } diff --git a/tests/utils/helper/string.go b/tests/utils/helper/string.go index e76f03b708..8f15d5963c 100644 --- a/tests/utils/helper/string.go +++ b/tests/utils/helper/string.go @@ -10,6 +10,20 @@ import ( "strings" ) +func ParseBool(value string) bool { + parsedValue, err := strconv.ParseBool(value) + if err != nil { + panic(err.Error()) + } + return parsedValue +} +func ParseInt(value string) int { + parsedValue, err := strconv.Atoi(value) + if err != nil { + panic(err.Error()) + } + return parsedValue +} func ParseLabels(labels string) []string { return ParseCommaSeparatedStrings(labels) } diff --git a/tests/utils/profilehandler/profile_handler.go b/tests/utils/profilehandler/profile_handler.go index ea5fdedb1a..3061654746 100644 --- a/tests/utils/profilehandler/profile_handler.go +++ b/tests/utils/profilehandler/profile_handler.go @@ -65,10 +65,56 @@ func LoadProfileYamlFileByENV() *Profile { profile.NamePrefix = config.Test.GlobalENV.NamePrefix } - if config.Test.GlobalENV.ComputeMachineType != "" { - log.Logger.Infof("Got global env settings for INSTANCE_TYPE, overwritten the profile setting with value %s", - config.Test.GlobalENV.ComputeMachineType) - profile.ClusterConfig.InstanceType = config.Test.GlobalENV.ComputeMachineType + if config.Test.ClusterENV.ComputeMachineType != "" { + log.Logger.Infof("Got global env settings for COMPUTE_MACHINE_TYPE, overwritten the profile setting with value %s", + config.Test.ClusterENV.ComputeMachineType) + profile.ClusterConfig.InstanceType = config.Test.ClusterENV.ComputeMachineType + } + if config.Test.ClusterENV.BYOVPC != "" { + log.Logger.Infof("Got global env settings for BYOVPC, overwritten the profile setting with value %s", + config.Test.ClusterENV.BYOVPC) + + profile.ClusterConfig.BYOVPC = helper.ParseBool(config.Test.ClusterENV.BYOVPC) + } + if config.Test.ClusterENV.Private != "" { + log.Logger.Infof("Got global env settings for PRIVATE, overwritten the profile setting with value %s", + config.Test.ClusterENV.Private) + profile.ClusterConfig.Private = helper.ParseBool(config.Test.ClusterENV.Private) + } + if config.Test.ClusterENV.Autoscale != "" { + log.Logger.Infof("Got global env settings for AUTOSCALE, overwritten the profile setting with value %s", + config.Test.ClusterENV.Autoscale) + profile.ClusterConfig.Autoscale = helper.ParseBool(config.Test.ClusterENV.Autoscale) + } + if config.Test.ClusterENV.ProxyEnabled != "" { + log.Logger.Infof("Got global env settings for PROXY_ENABLED, overwritten the profile setting with value %s", + config.Test.ClusterENV.ProxyEnabled) + profile.ClusterConfig.ProxyEnabled = helper.ParseBool(config.Test.ClusterENV.ProxyEnabled) + } + if config.Test.ClusterENV.FipsEnabled != "" { + log.Logger.Infof("Got global env settings for FIPS_ENABLED, overwritten the profile setting with value %s", + config.Test.ClusterENV.FipsEnabled) + profile.ClusterConfig.FIPS = helper.ParseBool(config.Test.ClusterENV.FipsEnabled) + } + if config.Test.ClusterENV.MultiAZ != "" { + log.Logger.Infof("Got global env settings for MULTI_AZ, overwritten the profile setting with value %s", + config.Test.ClusterENV.MultiAZ) + profile.ClusterConfig.MultiAZ = helper.ParseBool(config.Test.ClusterENV.MultiAZ) + } + if config.Test.ClusterENV.VolumeSize != "" { + log.Logger.Infof("Got global env settings for VOLUME_SIZE, overwritten the profile setting with value %s", + config.Test.ClusterENV.VolumeSize) + profile.ClusterConfig.VolumeSize = helper.ParseInt(config.Test.ClusterENV.VolumeSize) + } + if config.Test.ClusterENV.Replicas != "" { + log.Logger.Infof("Got global env settings for REPLICAS, overwritten the profile setting with value %s", + config.Test.ClusterENV.Replicas) + profile.ClusterConfig.WorkerPoolReplicas = helper.ParseInt(config.Test.ClusterENV.Replicas) + } + if config.Test.ClusterENV.AllowRegistries != "" { + log.Logger.Infof("Got global env settings for ALLOW_REGISTRIES, overwritten the profile setting with value %s", + config.Test.ClusterENV.AllowRegistries) + profile.ClusterConfig.AllowedRegistries = helper.ParseBool(config.Test.ClusterENV.AllowRegistries) } return profile