Skip to content

Commit

Permalink
OCM-11675 | ci: Expose some of the cluster configurations for profile…
Browse files Browse the repository at this point in the history
… override
  • Loading branch information
xueli181114 committed Oct 31, 2024
1 parent cc32dc1 commit e55f441
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 6 deletions.
27 changes: 25 additions & 2 deletions tests/ci/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type TestConfig struct {
ProxySSHPemFile string
ProxyCABundleFile string
GlobalENV *GlobalENVVariables
ClusterENV *ClusterENVVariables
}
type GlobalENVVariables struct {
ChannelGroup string `env:"CHANNEL_GROUP" default:""`
Expand All @@ -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)
Expand Down Expand Up @@ -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"),
}

}
14 changes: 14 additions & 0 deletions tests/utils/helper/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
54 changes: 50 additions & 4 deletions tests/utils/profilehandler/profile_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e55f441

Please sign in to comment.