Skip to content

Commit 655d95a

Browse files
committed
chore: unified way to manage spot related flags
Previously mapt supported several params to control spot allocation details, this commit ensures all params are managed in an unified way and taken into consideration Signed-off-by: Adrian Riobo <[email protected]>
1 parent 36ae7c7 commit 655d95a

File tree

35 files changed

+599
-724
lines changed

35 files changed

+599
-724
lines changed

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

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package hosts
22

33
import (
4-
awsParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/constants"
54
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
6-
"github.com/redhat-developer/mapt/pkg/integrations/cirrus"
7-
"github.com/redhat-developer/mapt/pkg/integrations/github"
85
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
96
"github.com/redhat-developer/mapt/pkg/provider/aws/action/fedora"
107
"github.com/redhat-developer/mapt/pkg/util/logging"
@@ -52,34 +49,14 @@ func getFedoraCreate() *cobra.Command {
5249
}
5350

5451
ctx := &maptContext.ContextArgs{
55-
ProjectName: viper.GetString(params.ProjectName),
56-
BackedURL: viper.GetString(params.BackedURL),
57-
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
58-
Debug: viper.IsSet(params.Debug),
59-
DebugLevel: viper.GetUint(params.DebugLevel),
60-
SpotPriceIncreaseRate: viper.GetInt(params.SpotPriceIncreaseRate),
61-
Tags: viper.GetStringMapString(params.Tags),
62-
}
63-
64-
if viper.IsSet(params.CirrusPWToken) {
65-
ctx.CirrusPWArgs = &cirrus.PersistentWorkerArgs{
66-
Token: viper.GetString(params.CirrusPWToken),
67-
Labels: viper.GetStringMapString(params.CirrusPWLabels),
68-
Platform: &cirrus.Linux,
69-
Arch: params.LinuxArchAsCirrusArch(
70-
viper.GetString(params.LinuxArch)),
71-
}
72-
}
73-
74-
if viper.IsSet(params.GHActionsRunnerToken) {
75-
ctx.GHRunnerArgs = &github.GithubRunnerArgs{
76-
Token: viper.GetString(params.GHActionsRunnerToken),
77-
RepoURL: viper.GetString(params.GHActionsRunnerRepo),
78-
Labels: viper.GetStringSlice(params.GHActionsRunnerLabels),
79-
Platform: &github.Linux,
80-
Arch: params.LinuxArchAsGithubActionsArch(
81-
viper.GetString(params.LinuxArch)),
82-
}
52+
ProjectName: viper.GetString(params.ProjectName),
53+
BackedURL: viper.GetString(params.BackedURL),
54+
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
55+
Debug: viper.IsSet(params.Debug),
56+
DebugLevel: viper.GetUint(params.DebugLevel),
57+
CirrusPWArgs: params.CirrusPersistentWorkerArgs(),
58+
GHRunnerArgs: params.GithubRunnerArgs(),
59+
Tags: viper.GetStringMapString(params.Tags),
8360
}
8461

8562
// Run create
@@ -89,8 +66,8 @@ func getFedoraCreate() *cobra.Command {
8966
Prefix: "main",
9067
Version: viper.GetString(fedoraVersion),
9168
Arch: viper.GetString(params.LinuxArch),
92-
ComputeRequest: params.GetComputeRequest(),
93-
Spot: viper.IsSet(awsParams.Spot),
69+
ComputeRequest: params.ComputeRequestArgs(),
70+
Spot: params.SpotArgs(),
9471
Timeout: viper.GetString(params.Timeout),
9572
Airgap: viper.IsSet(airgap)}); err != nil {
9673
logging.Error(err)
@@ -104,12 +81,11 @@ func getFedoraCreate() *cobra.Command {
10481
flagSet.StringP(fedoraVersion, "", fedoraVersionDefault, fedoraVersionDesc)
10582
flagSet.StringP(params.LinuxArch, "", params.LinuxArchDefault, params.LinuxArchDesc)
10683
flagSet.Bool(airgap, false, airgapDesc)
107-
flagSet.Bool(awsParams.Spot, false, awsParams.SpotDesc)
108-
flagSet.IntP(params.SpotPriceIncreaseRate, "", params.SpotPriceIncreaseRateDefault, params.SpotPriceIncreaseRateDesc)
10984
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
110-
flagSet.AddFlagSet(params.GetGHActionsFlagset())
85+
params.AddComputeRequestFlags(flagSet)
86+
params.AddSpotFlags(flagSet)
87+
params.AddGHActionsFlags(flagSet)
11188
params.AddCirrusFlags(flagSet)
112-
flagSet.AddFlagSet(params.GetCpusAndMemoryFlagset())
11389
c.PersistentFlags().AddFlagSet(flagSet)
11490
return c
11591
}

cmd/mapt/cmd/aws/hosts/mac.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package hosts
22

33
import (
4-
awsParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/constants"
4+
awsParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/params"
55
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
6-
"github.com/redhat-developer/mapt/pkg/integrations/github"
76
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
87
"github.com/redhat-developer/mapt/pkg/provider/aws/action/mac"
98
"github.com/redhat-developer/mapt/pkg/util/logging"
@@ -47,20 +46,10 @@ func getMacRequest() *cobra.Command {
4746
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
4847
Debug: viper.IsSet(params.Debug),
4948
DebugLevel: viper.GetUint(params.DebugLevel),
49+
GHRunnerArgs: params.GithubRunnerArgs(),
5050
Tags: viper.GetStringMapString(params.Tags),
5151
}
5252

53-
if viper.IsSet(params.GHActionsRunnerToken) {
54-
ctx.GHRunnerArgs = &github.GithubRunnerArgs{
55-
Token: viper.GetString(params.GHActionsRunnerToken),
56-
RepoURL: viper.GetString(params.GHActionsRunnerRepo),
57-
Labels: viper.GetStringSlice(params.GHActionsRunnerLabels),
58-
Platform: &github.Linux,
59-
Arch: awsParams.MACArchAsGithubArch(
60-
viper.GetString(awsParams.MACArch)),
61-
}
62-
}
63-
6453
// Run create
6554
if err := mac.Request(
6655
ctx,
@@ -83,7 +72,7 @@ func getMacRequest() *cobra.Command {
8372
flagSet.StringP(awsParams.MACOSVersion, "", awsParams.MACOSVersion, awsParams.MACOSVersionDefault)
8473
flagSet.Bool(awsParams.MACFixedLocation, false, awsParams.MACFixedLocationDesc)
8574
flagSet.Bool(airgap, false, airgapDesc)
86-
flagSet.AddFlagSet(params.GetGHActionsFlagset())
75+
params.AddGHActionsFlags(flagSet)
8776
c.PersistentFlags().AddFlagSet(flagSet)
8877
return c
8978
}

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

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package hosts
22

33
import (
4-
awsParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/constants"
54
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
6-
"github.com/redhat-developer/mapt/pkg/integrations/cirrus"
7-
"github.com/redhat-developer/mapt/pkg/integrations/github"
85
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
96
"github.com/redhat-developer/mapt/pkg/provider/aws/action/rhel"
107
"github.com/redhat-developer/mapt/pkg/util/logging"
@@ -48,34 +45,14 @@ func getRHELCreate() *cobra.Command {
4845
}
4946

5047
ctx := &maptContext.ContextArgs{
51-
ProjectName: viper.GetString(params.ProjectName),
52-
BackedURL: viper.GetString(params.BackedURL),
53-
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
54-
Debug: viper.IsSet(params.Debug),
55-
DebugLevel: viper.GetUint(params.DebugLevel),
56-
SpotPriceIncreaseRate: viper.GetInt(params.SpotPriceIncreaseRate),
57-
Tags: viper.GetStringMapString(params.Tags),
58-
}
59-
60-
if viper.IsSet(params.CirrusPWToken) {
61-
ctx.CirrusPWArgs = &cirrus.PersistentWorkerArgs{
62-
Token: viper.GetString(params.CirrusPWToken),
63-
Labels: viper.GetStringMapString(params.CirrusPWLabels),
64-
Platform: &cirrus.Linux,
65-
Arch: params.LinuxArchAsCirrusArch(
66-
viper.GetString(params.LinuxArch)),
67-
}
68-
}
69-
70-
if viper.IsSet(params.GHActionsRunnerToken) {
71-
ctx.GHRunnerArgs = &github.GithubRunnerArgs{
72-
Token: viper.GetString(params.GHActionsRunnerToken),
73-
RepoURL: viper.GetString(params.GHActionsRunnerRepo),
74-
Labels: viper.GetStringSlice(params.GHActionsRunnerLabels),
75-
Platform: &github.Linux,
76-
Arch: params.LinuxArchAsGithubActionsArch(
77-
viper.GetString(params.LinuxArch)),
78-
}
48+
ProjectName: viper.GetString(params.ProjectName),
49+
BackedURL: viper.GetString(params.BackedURL),
50+
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
51+
Debug: viper.IsSet(params.Debug),
52+
DebugLevel: viper.GetUint(params.DebugLevel),
53+
CirrusPWArgs: params.CirrusPersistentWorkerArgs(),
54+
GHRunnerArgs: params.GithubRunnerArgs(),
55+
Tags: viper.GetStringMapString(params.Tags),
7956
}
8057

8158
// Run create
@@ -85,11 +62,11 @@ func getRHELCreate() *cobra.Command {
8562
Prefix: "main",
8663
Version: viper.GetString(params.RhelVersion),
8764
Arch: viper.GetString(params.LinuxArch),
88-
ComputeRequest: params.GetComputeRequest(),
65+
ComputeRequest: params.ComputeRequestArgs(),
8966
SubsUsername: viper.GetString(params.SubsUsername),
9067
SubsUserpass: viper.GetString(params.SubsUserpass),
9168
ProfileSNC: viper.IsSet(params.ProfileSNC),
92-
Spot: viper.IsSet(awsParams.Spot),
69+
Spot: params.SpotArgs(),
9370
Timeout: viper.GetString(params.Timeout),
9471
Airgap: viper.IsSet(airgap),
9572
}); err != nil {
@@ -106,13 +83,12 @@ func getRHELCreate() *cobra.Command {
10683
flagSet.StringP(params.SubsUsername, "", "", params.SubsUsernameDesc)
10784
flagSet.StringP(params.SubsUserpass, "", "", params.SubsUserpassDesc)
10885
flagSet.Bool(airgap, false, airgapDesc)
109-
flagSet.Bool(awsParams.Spot, false, awsParams.SpotDesc)
110-
flagSet.IntP(params.SpotPriceIncreaseRate, "", params.SpotPriceIncreaseRateDefault, params.SpotPriceIncreaseRateDesc)
11186
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
11287
flagSet.Bool(params.ProfileSNC, false, params.ProfileSNCDesc)
113-
flagSet.AddFlagSet(params.GetGHActionsFlagset())
88+
params.AddComputeRequestFlags(flagSet)
89+
params.AddSpotFlags(flagSet)
90+
params.AddGHActionsFlags(flagSet)
11491
params.AddCirrusFlags(flagSet)
115-
flagSet.AddFlagSet(params.GetCpusAndMemoryFlagset())
11692
c.PersistentFlags().AddFlagSet(flagSet)
11793
return c
11894
}

cmd/mapt/cmd/aws/hosts/rhelai.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package hosts
22

33
import (
4-
awsParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/constants"
54
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
65
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
76
rhelai "github.com/redhat-developer/mapt/pkg/provider/aws/action/rhel-ai"
@@ -46,13 +45,12 @@ func getRHELAICreate() *cobra.Command {
4645
}
4746

4847
ctx := &maptContext.ContextArgs{
49-
ProjectName: viper.GetString(params.ProjectName),
50-
BackedURL: viper.GetString(params.BackedURL),
51-
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
52-
Debug: viper.IsSet(params.Debug),
53-
DebugLevel: viper.GetUint(params.DebugLevel),
54-
SpotPriceIncreaseRate: viper.GetInt(params.SpotPriceIncreaseRate),
55-
Tags: viper.GetStringMapString(params.Tags),
48+
ProjectName: viper.GetString(params.ProjectName),
49+
BackedURL: viper.GetString(params.BackedURL),
50+
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
51+
Debug: viper.IsSet(params.Debug),
52+
DebugLevel: viper.GetUint(params.DebugLevel),
53+
Tags: viper.GetStringMapString(params.Tags),
5654
}
5755

5856
// Run create
@@ -63,8 +61,8 @@ func getRHELAICreate() *cobra.Command {
6361
Version: viper.GetString(params.RhelAIVersion),
6462
SubsUsername: viper.GetString(params.SubsUsername),
6563
SubsUserpass: viper.GetString(params.SubsUserpass),
66-
ComputeRequest: params.GetComputeRequest(),
67-
Spot: viper.IsSet(awsParams.Spot),
64+
ComputeRequest: params.ComputeRequestArgs(),
65+
Spot: params.SpotArgs(),
6866
Timeout: viper.GetString(params.Timeout),
6967
}); err != nil {
7068
logging.Error(err)
@@ -78,10 +76,9 @@ func getRHELAICreate() *cobra.Command {
7876
flagSet.StringP(params.RhelAIVersion, "", params.RhelAIVersionDefault, params.RhelAIVersionDesc)
7977
flagSet.StringP(params.SubsUsername, "", "", params.SubsUsernameDesc)
8078
flagSet.StringP(params.SubsUserpass, "", "", params.SubsUserpassDesc)
81-
flagSet.Bool(awsParams.Spot, false, awsParams.SpotDesc)
82-
flagSet.IntP(params.SpotPriceIncreaseRate, "", params.SpotPriceIncreaseRateDefault, params.SpotPriceIncreaseRateDesc)
8379
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
84-
flagSet.AddFlagSet(params.GetCpusAndMemoryFlagset())
80+
params.AddComputeRequestFlags(flagSet)
81+
params.AddSpotFlags(flagSet)
8582
c.PersistentFlags().AddFlagSet(flagSet)
8683
return c
8784
}

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

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package hosts
22

33
import (
4-
awsParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/constants"
54
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
6-
"github.com/redhat-developer/mapt/pkg/integrations/cirrus"
7-
"github.com/redhat-developer/mapt/pkg/integrations/github"
85
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
96
"github.com/redhat-developer/mapt/pkg/provider/aws/action/windows"
107
"github.com/redhat-developer/mapt/pkg/util/logging"
@@ -61,33 +58,14 @@ func getWindowsCreate() *cobra.Command {
6158
}
6259

6360
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-
SpotPriceIncreaseRate: viper.GetInt(params.SpotPriceIncreaseRate),
70-
Tags: viper.GetStringMapString(params.Tags),
71-
}
72-
73-
if viper.IsSet(params.CirrusPWToken) {
74-
ctx.CirrusPWArgs = &cirrus.PersistentWorkerArgs{
75-
Token: viper.GetString(params.CirrusPWToken),
76-
Labels: viper.GetStringMapString(params.CirrusPWLabels),
77-
Platform: &cirrus.Windows,
78-
// Currently we only provide amd64 support for windows
79-
Arch: &cirrus.Amd64,
80-
}
81-
}
82-
83-
if viper.IsSet(params.GHActionsRunnerToken) {
84-
ctx.GHRunnerArgs = &github.GithubRunnerArgs{
85-
Token: viper.GetString(params.GHActionsRunnerToken),
86-
RepoURL: viper.GetString(params.GHActionsRunnerRepo),
87-
Labels: viper.GetStringSlice(params.GHActionsRunnerLabels),
88-
Platform: &github.Windows,
89-
Arch: &github.Amd64,
90-
}
61+
ProjectName: viper.GetString(params.ProjectName),
62+
BackedURL: viper.GetString(params.BackedURL),
63+
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
64+
Debug: viper.IsSet(params.Debug),
65+
DebugLevel: viper.GetUint(params.DebugLevel),
66+
CirrusPWArgs: params.CirrusPersistentWorkerArgs(),
67+
GHRunnerArgs: params.GithubRunnerArgs(),
68+
Tags: viper.GetStringMapString(params.Tags),
9169
}
9270

9371
// Run create
@@ -100,7 +78,7 @@ func getWindowsCreate() *cobra.Command {
10078
AMIOwner: viper.GetString(amiOwner),
10179
AMILang: viper.GetString(amiLang),
10280
AMIKeepCopy: viper.IsSet(amiKeepCopy),
103-
Spot: viper.IsSet(awsParams.Spot),
81+
Spot: params.SpotArgs(),
10482
Airgap: viper.IsSet(airgap),
10583
Timeout: viper.GetString(params.Timeout),
10684
}); err != nil {
@@ -117,11 +95,10 @@ func getWindowsCreate() *cobra.Command {
11795
flagSet.StringP(amiOwner, "", amiOwnerDefault, amiOwnerDesc)
11896
flagSet.StringP(amiLang, "", amiLangDefault, amiLangDesc)
11997
flagSet.Bool(airgap, false, airgapDesc)
120-
flagSet.Bool(awsParams.Spot, false, awsParams.SpotDesc)
121-
flagSet.IntP(params.SpotPriceIncreaseRate, "", params.SpotPriceIncreaseRateDefault, params.SpotPriceIncreaseRateDesc)
12298
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
12399
flagSet.Bool(amiKeepCopy, false, amiKeepCopyDesc)
124-
flagSet.AddFlagSet(params.GetGHActionsFlagset())
100+
params.AddSpotFlags(flagSet)
101+
params.AddGHActionsFlags(flagSet)
125102
params.AddCirrusFlags(flagSet)
126103
c.PersistentFlags().AddFlagSet(flagSet)
127104
return c
Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
package constants
1+
package params
22

33
import (
4-
"github.com/redhat-developer/mapt/pkg/integrations/cirrus"
5-
"github.com/redhat-developer/mapt/pkg/integrations/github"
64
"github.com/redhat-developer/mapt/pkg/provider/aws/action/mac"
75
)
86

@@ -22,23 +20,4 @@ const (
2220
MACFixedLocationDesc string = "if this flag is set the host will be created only on the region set by the AWS Env (AWS_DEFAULT_REGION)"
2321
MACDHID string = "dedicated-host-id"
2422
MACDHIDDesc string = "id for the dedicated host"
25-
26-
Spot string = "spot"
27-
SpotDesc string = "if spot is set the spot prices across all regions will be checked and machine will be started on best spot option (price / eviction)"
2823
)
29-
30-
func MACArchAsCirrusArch(arch string) *cirrus.Arch {
31-
switch arch {
32-
case "x86":
33-
return &cirrus.Amd64
34-
}
35-
return &cirrus.Arm64
36-
}
37-
38-
func MACArchAsGithubArch(arch string) *github.Arch {
39-
switch arch {
40-
case "x86_64":
41-
return &github.Amd64
42-
}
43-
return &github.Arm64
44-
}

0 commit comments

Comments
 (0)