-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the profiles Update the external yaml Finish the profile parser Finish the env setup for testing Create a data folder to contains yaml files Fix comment Apply the struct with latest profile change
- Loading branch information
1 parent
1ba8c13
commit 2ad0ae1
Showing
9 changed files
with
209 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ docs/ | |
/rosa-linux-arm64 | ||
/rosa-linux-arm64.sha256 | ||
/*policy.json | ||
/tests/output | ||
.envrc | ||
.env | ||
cover.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"strings" | ||
|
||
"github.com/openshift/rosa/tests/utils/common" | ||
. "github.com/openshift/rosa/tests/utils/log" | ||
) | ||
|
||
var Test *TestConfig | ||
|
||
// TestConfig contains platforms info for the rosacli testing | ||
type TestConfig struct { | ||
// Env is the OpenShift Cluster Management environment used to provision clusters. | ||
ENV string `env:"OCM_LOGIN_ENV" default:""` | ||
TestProfile string `env:"TEST_PROFILE" default:""` | ||
OutputDir string `env:"OUTPUT_DIR" default:""` | ||
YAMLProfilesDir string `env:"TEST_PROFILE_DIR" default:""` | ||
RootDir string `env:"WORKSPACE" default:""` | ||
} | ||
|
||
func init() { | ||
Test = new(TestConfig) | ||
currentDir, _ := os.Getwd() | ||
project := "rosa" | ||
|
||
Test.TestProfile = common.ReadENVWithDefaultValue("TEST_PROFILE", "") | ||
Test.RootDir = common.ReadENVWithDefaultValue("WORKSPACE", strings.SplitAfter(currentDir, project)[0]) | ||
Test.YAMLProfilesDir = common.ReadENVWithDefaultValue("TEST_PROFILE_DIR", path.Join(Test.RootDir, "tests", "ci", "data", "profiles")) | ||
Test.OutputDir = common.ReadENVWithDefaultValue("SHARED_DIR", path.Join(Test.RootDir, "tests", "output", Test.TestProfile)) | ||
err := os.MkdirAll(Test.OutputDir, 0777) | ||
if err != nil { | ||
Logger.Errorf("Meet error %s when create output dirs", err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,4 @@ profiles: | |
additional_sg_number: 3 | ||
account-role: | ||
path: "" | ||
permission_boundary: "" | ||
permission_boundary: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package common | ||
|
||
import "os" | ||
|
||
func ReadENVWithDefaultValue(envName string, fallback string) string { | ||
if os.Getenv(envName) != "" { | ||
return os.Getenv(envName) | ||
} | ||
return fallback | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package profilehandler | ||
|
||
type Profile struct { | ||
Name string `yaml:"as,omitempty"` | ||
Version string `yaml:"version,omitempty"` | ||
ChannelGroup string `yaml:"channel_group,omitempty"` | ||
Region string `yaml:"region,omitempty"` | ||
ClusterConfig *ClusterConfig `yaml:"cluster,omitempty"` | ||
AccountRoleConfig *AccountRoleConfig `yaml:"account-role,omitempty"` | ||
} | ||
type AccountRoleConfig struct { | ||
Path string `yaml:"path,omitempty"` | ||
PermissionBoundary string `yaml:"permission_boundary,omitempty"` | ||
} | ||
type ClusterConfig struct { | ||
InstanceType string `yaml:"instance_type,omitempty" json:"instance_type,omitempty"` | ||
Zones string `yaml:"zones,omitempty" json:"zones,omitempty"` | ||
TagEnabled bool `yaml:"tag_enabled,omitempty" json:"tag_enabled,omitempty"` | ||
LabelEnabled bool `yaml:"label_enabled,omitempty" json:"label_enabled,omitempty"` | ||
EtcdEncryption bool `yaml:"etcd_encryption,omitempty" json:"etcd_encryption,omitempty"` | ||
FIPS bool `yaml:"fips,omitempty" json:"fips,omitempty"` | ||
STS bool `yaml:"sts,omitempty" json:"sts,omitempty"` | ||
Autoscale bool `yaml:"autoscale,omitempty" json:"autoscale,omitempty"` | ||
MultiAZ bool `yaml:"multi_az,omitempty" json:"multi_az,omitempty"` | ||
BYOVPC bool `yaml:"byo_vpc,omitempty" json:"byo_vpc,omitempty"` | ||
PrivateLink bool `yaml:"private_link,omitempty" json:"private_link,omitempty"` | ||
Private bool `yaml:"private,omitempty" json:"private,omitempty"` | ||
KMSKey bool `yaml:"kms_key,omitempty" json:"kms_key,omitempty"` | ||
ETCDKMS bool `yaml:"etcd_kms,omitempty" json:"etcd_kms,omitempty"` | ||
NetWorkingSet bool `yaml:"networking,omitempty" json:"networking,omitempty"` | ||
ProxyEnabled bool `yaml:"proxy_enabled,omitempty" json:"proxy_enabled,omitempty"` | ||
HCP bool `yaml:"hcp,omitempty" json:"hypershift,omitempty"` | ||
OIDCConfig string `yaml:"oidc_config,omitempty" json:"oidc_config,omitempty"` | ||
ProvisionShard string `yaml:"provision_shard,omitempty" json:"provision_shard,omitempty"` | ||
Ec2MetadataHttpTokens string `yaml:"imdsv2,omitempty" json:"imdsv2,omitempty"` | ||
AuditLogForward bool `yaml:"auditlog_forward,omitempty" json:"auditlog_forward,omitempty"` | ||
AdminEnabled bool `yaml:"admin_enabled,omitempty" json:"admin_enabled,omitempty"` | ||
ExpirationTime int `yaml:"expiration_time,omitempty" json:"expiration_time,omitempty"` | ||
VolumeSize int `yaml:"volume_size,omitempty" json:"volume_size,omitempty"` | ||
BillingAccount string `yaml:"billing_account,omitempty" json:"billing_account,omitempty"` | ||
AutoscalerEnabled bool `yaml:"autoscaler_enabled,omitempty" json:"autoscaler_enabled,omitempty"` | ||
DisableUserWorKloadMonitoring bool `yaml:"disable_uwm,omitempty" json:"disable_uwm,omitempty"` | ||
SharedVPC bool `yaml:"shared_vpc,omitempty" json:"shared_vpc,omitempty"` | ||
DisableSCPChecks bool `yaml:"disable_scp_checks,omitempty" json:"disable_scp_checks,omitempty"` | ||
AdditionalSGNumber int `yaml:"additional_sg_number" json:"additional_sg_number,omitempty"` | ||
WorkerPoolReplicas int `yaml:"replicas" json:"replicas,omitempty"` | ||
ExternalAuthConfig bool `yaml:"external_auth_config" json:"external_auth_config,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package profilehandler | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type profiles struct { | ||
Profiles []*Profile `yaml:"profiles,omitempty"` | ||
} | ||
|
||
func ParseProfiles(profilesDir string) map[string]*Profile { | ||
files, err := os.ReadDir(profilesDir) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
profileMap := make(map[string]*Profile) | ||
for _, file := range files { | ||
yfile, err := os.ReadFile(path.Join(profilesDir, file.Name())) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
p := new(profiles) | ||
err = yaml.Unmarshal(yfile, &p) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
for _, theProfile := range p.Profiles { | ||
profileMap[theProfile.Name] = theProfile | ||
} | ||
|
||
} | ||
|
||
return profileMap | ||
} | ||
|
||
func GetProfile(profileName string, profilesDir string) *Profile { | ||
profileMap := ParseProfiles(profilesDir) | ||
|
||
if _, exist := profileMap[profileName]; !exist { | ||
log.Fatalf("Can not find the profile %s in %s\n", profileName, profilesDir) | ||
} | ||
|
||
return profileMap[profileName] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package profilehandler | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/openshift/rosa/tests/ci/config" | ||
. "github.com/openshift/rosa/tests/utils/log" | ||
) | ||
|
||
func GetYAMLProfilesDir() string { | ||
return config.Test.YAMLProfilesDir | ||
} | ||
func LoadProfileYamlFile(profileName string) *Profile { | ||
p := GetProfile(profileName, GetYAMLProfilesDir()) | ||
Logger.Infof("Loaded cluster profile configuration from origional profile %s : %v", profileName, *p) | ||
Logger.Infof("Loaded cluster profile configuration from origional cluster %s : %v", profileName, *p.ClusterConfig) | ||
Logger.Infof("Loaded cluster profile configuration from origional account-roles %s : %v", profileName, *p.AccountRoleConfig) | ||
return p | ||
} | ||
|
||
func LoadProfileYamlFileByENV() *Profile { | ||
if config.Test.TestProfile == "" { | ||
panic(fmt.Errorf("ENV Variable TEST_PROFILE is empty, please make sure you set the env value")) | ||
} | ||
profile := LoadProfileYamlFile(config.Test.TestProfile) | ||
|
||
// Supporting global env setting to overrite profile settings | ||
if os.Getenv("CHANNEL_GROUP") != "" { | ||
Logger.Infof("Got global env settings for CHANNEL_GROUP, overwritten the profile setting with value %s", os.Getenv("CHANNEL_GROUP")) | ||
profile.ChannelGroup = os.Getenv("CHANNEL_GROUP") | ||
} | ||
if os.Getenv("VERSION") != "" { | ||
Logger.Infof("Got global env settings for VERSION, overwritten the profile setting with value %s", os.Getenv("VERSION")) | ||
profile.Version = os.Getenv("VERSION") | ||
} | ||
if os.Getenv("REGION") != "" { | ||
Logger.Infof("Got global env settings for REGION, overwritten the profile setting with value %s", os.Getenv("REGION")) | ||
profile.Region = os.Getenv("REGION") | ||
} | ||
if os.Getenv("PROVISION_SHARD") != "" { | ||
Logger.Infof("Got global env settings for PROVISION_SHARD, overwritten the profile setting with value %s", os.Getenv("PROVISION_SHARD")) | ||
profile.ClusterConfig.ProvisionShard = os.Getenv("PROVISION_SHARD") | ||
} | ||
return profile | ||
} |