Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create interface for parameter cross cloud providers #632

Merged
merged 8 commits into from
Feb 20, 2024
Merged
28 changes: 17 additions & 11 deletions common/config/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ const (
type CommonEnvironment struct {
providerRegistry

Ctx *pulumi.Context
CommonNamer namer.Namer
Ctx *pulumi.Context
CommonNamer namer.Namer
CloudProviderEnvironment CloudProviderEnvironment

InfraConfig *sdkconfig.Config
AgentConfig *sdkconfig.Config
Expand All @@ -71,16 +72,21 @@ type CommonEnvironment struct {
username string
}

func NewCommonEnvironment(ctx *pulumi.Context) (CommonEnvironment, error) {
type CloudProviderEnvironment interface {
InternalRegistry() string
}

func NewCommonEnvironment(ctx *pulumi.Context, cloudProviderEnvironment CloudProviderEnvironment) (CommonEnvironment, error) {
env := CommonEnvironment{
Ctx: ctx,
InfraConfig: sdkconfig.New(ctx, DDInfraConfigNamespace),
AgentConfig: sdkconfig.New(ctx, DDAgentConfigNamespace),
TestingWorkloadConfig: sdkconfig.New(ctx, DDTestingWorkloadNamespace),
DogstatsdConfig: sdkconfig.New(ctx, DDDogstatsdNamespace),
UpdaterConfig: sdkconfig.New(ctx, DDUpdaterConfigNamespace),
CommonNamer: namer.NewNamer(ctx, ""),
providerRegistry: newProviderRegistry(ctx),
Ctx: ctx,
InfraConfig: sdkconfig.New(ctx, DDInfraConfigNamespace),
AgentConfig: sdkconfig.New(ctx, DDAgentConfigNamespace),
TestingWorkloadConfig: sdkconfig.New(ctx, DDTestingWorkloadNamespace),
DogstatsdConfig: sdkconfig.New(ctx, DDDogstatsdNamespace),
UpdaterConfig: sdkconfig.New(ctx, DDUpdaterConfigNamespace),
CommonNamer: namer.NewNamer(ctx, ""),
CloudProviderEnvironment: cloudProviderEnvironment,
providerRegistry: newProviderRegistry(ctx),
}
// store username
user, err := user.Current()
Expand Down
12 changes: 11 additions & 1 deletion resources/aws/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
DDInfraDefaultPrivateKeyPassword = "aws/defaultPrivateKeyPassword"
DDInfraDefaultInstanceStorageSize = "aws/defaultInstanceStorageSize"
DDInfraDefaultShutdownBehavior = "aws/defaultShutdownBehavior"
DDInfraDefaultInternalRegistry = "aws/defaultInternalRegistry"

// AWS ECS
DDInfraEcsExecKMSKeyID = "aws/ecs/execKMSKeyID"
Expand Down Expand Up @@ -62,9 +63,12 @@ type Environment struct {
randomSubnets pulumi.StringArrayOutput
}

var _ config.CloudProviderEnvironment = (*Environment)(nil)

func WithCommonEnvironment(e *config.CommonEnvironment) func(*Environment) {
return func(awsEnv *Environment) {
awsEnv.CommonEnvironment = e
awsEnv.CommonEnvironment.CloudProviderEnvironment = awsEnv
}
}

Expand All @@ -77,8 +81,9 @@ func NewEnvironment(ctx *pulumi.Context, options ...func(*Environment)) (Environ
for _, opt := range options {
opt(&env)
}

if env.CommonEnvironment == nil {
commonEnv, err := config.NewCommonEnvironment(ctx)
commonEnv, err := config.NewCommonEnvironment(ctx, &env)
if err != nil {
return Environment{}, err
}
Expand Down Expand Up @@ -112,6 +117,11 @@ func NewEnvironment(ctx *pulumi.Context, options ...func(*Environment)) (Environ
return env, nil
}

// Cross Cloud Provider config
func (e *Environment) InternalRegistry() string {
return e.GetStringWithDefault(e.InfraConfig, DDInfraDefaultInternalRegistry, e.envDefault.ddInfra.defaultInternalRegistry)
}

// Common
func (e *Environment) Region() string {
return e.GetStringWithDefault(e.awsConfig, awsRegionParamName, e.envDefault.aws.region)
Expand Down
4 changes: 4 additions & 0 deletions resources/aws/environmentDefaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type ddInfra struct {
defaultARMInstanceType string
defaultInstanceStorageSize int
defaultShutdownBehavior string
defaultInternalRegistry string

ecs ddInfraECS
eks ddInfraEKS
Expand Down Expand Up @@ -87,6 +88,7 @@ func sandboxDefault() environmentDefault {
defaultARMInstanceType: "t4g.medium",
defaultInstanceStorageSize: 200,
defaultShutdownBehavior: "stop",
defaultInternalRegistry: "669783387624.dkr.ecr.us-east-1.amazonaws.com",

ecs: ddInfraECS{
execKMSKeyID: "arn:aws:kms:us-east-1:601427279990:key/c84f93c2-a562-4a59-a326-918fbe7235c7",
Expand Down Expand Up @@ -127,6 +129,7 @@ func agentSandboxDefault() environmentDefault {
defaultARMInstanceType: "t4g.medium",
defaultInstanceStorageSize: 200,
defaultShutdownBehavior: "stop",
defaultInternalRegistry: "669783387624.dkr.ecr.us-east-1.amazonaws.com",

ecs: ddInfraECS{
execKMSKeyID: "arn:aws:kms:us-east-1:376334461865:key/1d1fe533-a4f1-44ee-99ec-225b44fcb9ed",
Expand Down Expand Up @@ -167,6 +170,7 @@ func agentQADefault() environmentDefault {
defaultARMInstanceType: "t4g.medium",
defaultInstanceStorageSize: 200,
defaultShutdownBehavior: "stop",
defaultInternalRegistry: "669783387624.dkr.ecr.us-east-1.amazonaws.com",

ecs: ddInfraECS{
execKMSKeyID: "arn:aws:kms:us-east-1:669783387624:key/384373bc-6d99-4d68-84b5-b76b756b0af3",
Expand Down
21 changes: 14 additions & 7 deletions resources/azure/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ type Environment struct {
envDefault environmentDefault
}

var _ config.CloudProviderEnvironment = (*Environment)(nil)

func NewEnvironment(ctx *pulumi.Context) (Environment, error) {
commonEnv, err := config.NewCommonEnvironment(ctx)
if err != nil {
return Environment{}, err
}

env := Environment{
CommonEnvironment: &commonEnv,
Namer: namer.NewNamer(ctx, azNamerNamespace),
envDefault: getEnvironmentDefault(config.FindEnvironmentName(commonEnv.InfraEnvironmentNames(), azNamerNamespace)),
Namer: namer.NewNamer(ctx, azNamerNamespace),
}
commonEnv, err := config.NewCommonEnvironment(ctx, &env)
if err != nil {
return Environment{}, err
}
env.CommonEnvironment = &commonEnv
env.envDefault = getEnvironmentDefault(config.FindEnvironmentName(commonEnv.InfraEnvironmentNames(), azNamerNamespace))

azureProvider, err := sdkazure.NewProvider(ctx, string(config.ProviderAzure), &sdkazure.ProviderArgs{
DisablePulumiPartnerId: pulumi.BoolPtr(true),
Expand All @@ -58,6 +60,11 @@ func NewEnvironment(ctx *pulumi.Context) (Environment, error) {
return env, nil
}

// Cross Cloud Provider config
func (p *Environment) InternalRegistry() string {
return "none"
}

// Common
func (e *Environment) DefaultResourceGroup() string {
return e.GetStringWithDefault(e.InfraConfig, DDInfraDefaultResourceGroup, e.envDefault.ddInfra.defaultResourceGroup)
Expand Down
18 changes: 13 additions & 5 deletions resources/hyperv/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,28 @@ type Environment struct {
Namer namer.Namer
}

var _ config.CloudProviderEnvironment = (*Environment)(nil)

func NewEnvironment(ctx *pulumi.Context) (Environment, error) {
commonEnv, err := config.NewCommonEnvironment(ctx)
env := Environment{
Namer: namer.NewNamer(ctx, hvNamerNamespace),
}

commonEnv, err := config.NewCommonEnvironment(ctx, &env)
if err != nil {
return Environment{}, err
}

env := Environment{
CommonEnvironment: &commonEnv,
Namer: namer.NewNamer(ctx, hvNamerNamespace),
}
env.CommonEnvironment = &commonEnv

return env, nil
}

// Cross Cloud Provider config
func (p *Environment) InternalRegistry() string {
return "none"
}

// Common
func (e *Environment) DefaultPublicKeyPath() string {
return e.InfraConfig.Get(DDInfraDefaultPublicKeyPath)
Expand Down
2 changes: 1 addition & 1 deletion scenarios/aws/microVMs/microvms/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func RunAndReturnInstances(e commonConfig.CommonEnvironment) (*ScenarioDone, err
}

func Run(ctx *pulumi.Context) error {
commonEnv, err := commonConfig.NewCommonEnvironment(ctx)
commonEnv, err := commonConfig.NewCommonEnvironment(ctx, nil)
if err != nil {
return err
}
Expand Down
Loading