Skip to content

Commit 2a831cb

Browse files
committed
chore: refactor aws actions to make use of allocation module
In 871a0b1 an allocation module was introduced to reuse code when checking type of machines for aws targets, the param for spot increase rate is being used in that module, so this commit refactor the code on every aws target to make all will use same code so the spot increase rate param can be applied to all of them. Signed-off-by: Adrian Riobo <ariobolo@redhat.com>
1 parent 5d2955a commit 2a831cb

35 files changed

Lines changed: 470 additions & 517 deletions

cmd/mapt/cmd/aws/hosts/constans.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,4 @@ package hosts
33
const (
44
airgap string = "airgap"
55
airgapDesc string = "if this flag is set the host will be created as airgap machine. Access will done through a bastion"
6-
7-
vmTypes string = "vm-types"
8-
vmTypesDescription string = "set an specific set of vm-types and ignore any CPUs, Memory, Arch parameters set. Note vm-type should match requested arch. Also if --spot flag is used set at least 3 types."
96
)

cmd/mapt/cmd/aws/hosts/fedora.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ func getFedoraCreate() *cobra.Command {
5454
}
5555

5656
ctx := &maptContext.ContextArgs{
57-
ProjectName: viper.GetString(params.ProjectName),
58-
BackedURL: viper.GetString(params.BackedURL),
59-
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
60-
Debug: viper.IsSet(params.Debug),
61-
DebugLevel: viper.GetUint(params.DebugLevel),
62-
Tags: viper.GetStringMapString(params.Tags),
57+
ProjectName: viper.GetString(params.ProjectName),
58+
BackedURL: viper.GetString(params.BackedURL),
59+
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
60+
Debug: viper.IsSet(params.Debug),
61+
DebugLevel: viper.GetUint(params.DebugLevel),
62+
SpotPriceIncreaseRate: viper.GetInt(params.SpotPriceIncreaseRate),
63+
Tags: viper.GetStringMapString(params.Tags),
6364
}
6465

6566
if viper.IsSet(params.CirrusPWToken) {
@@ -86,11 +87,10 @@ func getFedoraCreate() *cobra.Command {
8687
// Run create
8788
if err := fedora.Create(
8889
ctx,
89-
&fedora.Request{
90+
&fedora.FedoraArgs{
9091
Prefix: "main",
9192
Version: viper.GetString(fedoraVersion),
9293
Arch: viper.GetString(params.LinuxArch),
93-
VMType: viper.GetStringSlice(vmTypes),
9494
InstanceRequest: &instancetypes.AwsInstanceRequest{
9595
CPUs: viper.GetInt32(params.CPUs),
9696
MemoryGib: viper.GetInt32(params.Memory),
@@ -111,9 +111,9 @@ func getFedoraCreate() *cobra.Command {
111111
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
112112
flagSet.StringP(fedoraVersion, "", fedoraVersionDefault, fedoraVersionDesc)
113113
flagSet.StringP(params.LinuxArch, "", params.LinuxArchDefault, params.LinuxArchDesc)
114-
flagSet.StringSliceP(vmTypes, "", []string{}, vmTypesDescription)
115114
flagSet.Bool(airgap, false, airgapDesc)
116115
flagSet.Bool(awsParams.Spot, false, awsParams.SpotDesc)
116+
flagSet.IntP(params.SpotPriceIncreaseRate, "", params.SpotPriceIncreaseRateDefault, params.SpotPriceIncreaseRateDesc)
117117
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
118118
flagSet.AddFlagSet(params.GetGHActionsFlagset())
119119
params.AddCirrusFlags(flagSet)

cmd/mapt/cmd/aws/hosts/rhel.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ func getRHELCreate() *cobra.Command {
5050
}
5151

5252
ctx := &maptContext.ContextArgs{
53-
ProjectName: viper.GetString(params.ProjectName),
54-
BackedURL: viper.GetString(params.BackedURL),
55-
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
56-
Debug: viper.IsSet(params.Debug),
57-
DebugLevel: viper.GetUint(params.DebugLevel),
58-
Tags: viper.GetStringMapString(params.Tags),
53+
ProjectName: viper.GetString(params.ProjectName),
54+
BackedURL: viper.GetString(params.BackedURL),
55+
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
56+
Debug: viper.IsSet(params.Debug),
57+
DebugLevel: viper.GetUint(params.DebugLevel),
58+
SpotPriceIncreaseRate: viper.GetInt(params.SpotPriceIncreaseRate),
59+
Tags: viper.GetStringMapString(params.Tags),
5960
}
6061

6162
if viper.IsSet(params.CirrusPWToken) {
@@ -82,7 +83,7 @@ func getRHELCreate() *cobra.Command {
8283
// Run create
8384
if err := rhel.Create(
8485
ctx,
85-
&rhel.Request{
86+
&rhel.RHELArgs{
8687
Prefix: "main",
8788
Version: viper.GetString(params.RhelVersion),
8889
Arch: viper.GetString(params.LinuxArch),
@@ -93,7 +94,6 @@ func getRHELCreate() *cobra.Command {
9394
instancetypes.Arm64, instancetypes.Amd64),
9495
NestedVirt: viper.GetBool(params.ProfileSNC) || viper.GetBool(params.NestedVirt),
9596
},
96-
VMType: viper.GetStringSlice(vmTypes),
9797
SubsUsername: viper.GetString(params.SubsUsername),
9898
SubsUserpass: viper.GetString(params.SubsUserpass),
9999
ProfileSNC: viper.IsSet(params.ProfileSNC),
@@ -111,11 +111,11 @@ func getRHELCreate() *cobra.Command {
111111
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
112112
flagSet.StringP(params.RhelVersion, "", params.RhelVersionDefault, params.RhelVersionDesc)
113113
flagSet.StringP(params.LinuxArch, "", params.LinuxArchDefault, params.LinuxArchDesc)
114-
flagSet.StringSliceP(vmTypes, "", []string{}, vmTypesDescription)
115114
flagSet.StringP(params.SubsUsername, "", "", params.SubsUsernameDesc)
116115
flagSet.StringP(params.SubsUserpass, "", "", params.SubsUserpassDesc)
117116
flagSet.Bool(airgap, false, airgapDesc)
118117
flagSet.Bool(awsParams.Spot, false, awsParams.SpotDesc)
118+
flagSet.IntP(params.SpotPriceIncreaseRate, "", params.SpotPriceIncreaseRateDefault, params.SpotPriceIncreaseRateDesc)
119119
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
120120
flagSet.Bool(params.ProfileSNC, false, params.ProfileSNCDesc)
121121
flagSet.AddFlagSet(params.GetGHActionsFlagset())

cmd/mapt/cmd/aws/hosts/windows.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ func getWindowsCreate() *cobra.Command {
6161
}
6262

6363
ctx := &maptContext.ContextArgs{
64-
ProjectName: viper.GetString(params.ProjectName),
65-
BackedURL: viper.GetString(params.BackedURL),
66-
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
67-
Debug: viper.IsSet(params.Debug),
68-
DebugLevel: viper.GetUint(params.DebugLevel),
69-
Tags: viper.GetStringMapString(params.Tags),
64+
ProjectName: viper.GetString(params.ProjectName),
65+
BackedURL: viper.GetString(params.BackedURL),
66+
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
67+
Debug: viper.IsSet(params.Debug),
68+
DebugLevel: viper.GetUint(params.DebugLevel),
69+
SpotPriceIncreaseRate: viper.GetInt(params.SpotPriceIncreaseRate),
70+
Tags: viper.GetStringMapString(params.Tags),
7071
}
7172

7273
if viper.IsSet(params.CirrusPWToken) {
@@ -92,7 +93,7 @@ func getWindowsCreate() *cobra.Command {
9293
// Run create
9394
if err := windows.Create(
9495
ctx,
95-
&windows.Request{
96+
&windows.WindowsServerArgs{
9697
Prefix: "main",
9798
AMIName: viper.GetString(amiName),
9899
AMIUser: viper.GetString(amiUsername),
@@ -117,6 +118,7 @@ func getWindowsCreate() *cobra.Command {
117118
flagSet.StringP(amiLang, "", amiLangDefault, amiLangDesc)
118119
flagSet.Bool(airgap, false, airgapDesc)
119120
flagSet.Bool(awsParams.Spot, false, awsParams.SpotDesc)
121+
flagSet.IntP(params.SpotPriceIncreaseRate, "", params.SpotPriceIncreaseRateDefault, params.SpotPriceIncreaseRateDesc)
120122
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
121123
flagSet.Bool(amiKeepCopy, false, amiKeepCopyDesc)
122124
flagSet.AddFlagSet(params.GetGHActionsFlagset())

cmd/mapt/cmd/aws/services/openshift-snc.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ func createSNC() *cobra.Command {
5454
}
5555
if err := openshiftsnc.Create(
5656
&maptContext.ContextArgs{
57-
ProjectName: viper.GetString(params.ProjectName),
58-
BackedURL: viper.GetString(params.BackedURL),
59-
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
60-
Debug: viper.IsSet(params.Debug),
61-
DebugLevel: viper.GetUint(params.DebugLevel),
62-
Tags: viper.GetStringMapString(params.Tags),
57+
ProjectName: viper.GetString(params.ProjectName),
58+
BackedURL: viper.GetString(params.BackedURL),
59+
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
60+
Debug: viper.IsSet(params.Debug),
61+
DebugLevel: viper.GetUint(params.DebugLevel),
62+
SpotPriceIncreaseRate: viper.GetInt(params.SpotPriceIncreaseRate),
63+
Tags: viper.GetStringMapString(params.Tags),
6364
},
6465
&openshiftsnc.OpenshiftSNCArgs{
6566
InstanceRequest: &instancetypes.AwsInstanceRequest{
@@ -87,6 +88,7 @@ func createSNC() *cobra.Command {
8788
flagSet.StringP(pullSecretFile, "", "", pullSecretFileDesc)
8889
flagSet.StringP(caCertFile, "", "", caCertFileDesc)
8990
flagSet.Bool(awsParams.Spot, false, awsParams.SpotDesc)
91+
flagSet.IntP(params.SpotPriceIncreaseRate, "", params.SpotPriceIncreaseRateDefault, params.SpotPriceIncreaseRateDesc)
9092
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
9193
flagSet.AddFlagSet(params.GetCpusAndMemoryFlagset())
9294
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)

pkg/provider/aws/action/fedora/cloud-config-base

Lines changed: 0 additions & 24 deletions
This file was deleted.

pkg/provider/aws/action/fedora/constants.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ var (
1414
// This is the ID for AMIS from https://fedoraproject.org/cloud
1515
amiOwner = "125523088429"
1616
amiUserDefault = "fedora"
17-
18-
supportedInstanceTypes = map[string][]string{
19-
"x86_64": {"c5.metal", "c5d.metal", "c5n.metal"},
20-
"arm64": {"c7gd.metal", "c7gn.metal", "m6gd.metal"}}
17+
amiProduct = "Linux/UNIX"
2118

2219
outputHost = "afdHost"
2320
outputUsername = "afdUsername"

0 commit comments

Comments
 (0)