Skip to content

Commit 4acdb0b

Browse files
committed
chore: spot refactor
Signed-off-by: Adrian Riobo <ariobolo@redhat.com>
1 parent b258853 commit 4acdb0b

2,812 files changed

Lines changed: 1341187 additions & 1055 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/mapt/cmd/aws/aws.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package aws
33
import (
44
"github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/hosts"
55
"github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/services"
6-
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
6+
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
77
"github.com/spf13/cobra"
88
"github.com/spf13/pflag"
99
"github.com/spf13/viper"
@@ -34,6 +34,7 @@ func GetCmd() *cobra.Command {
3434
hosts.GetMacCmd(),
3535
hosts.GetWindowsCmd(),
3636
hosts.GetRHELCmd(),
37+
hosts.GetRHELAICmd(),
3738
hosts.GetFedoraCmd(),
3839
services.GetMacPoolCmd(),
3940
services.GetOpenshiftSNCCmd(),

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

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package hosts
22

33
import (
44
awsParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/constants"
5-
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
5+
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
66
"github.com/redhat-developer/mapt/pkg/integrations/cirrus"
77
"github.com/redhat-developer/mapt/pkg/integrations/github"
88
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
99
"github.com/redhat-developer/mapt/pkg/provider/aws/action/fedora"
10-
"github.com/redhat-developer/mapt/pkg/provider/util/instancetypes"
11-
"github.com/redhat-developer/mapt/pkg/util"
1210
"github.com/redhat-developer/mapt/pkg/util/logging"
1311
"github.com/spf13/cobra"
1412
"github.com/spf13/pflag"
@@ -88,21 +86,13 @@ func getFedoraCreate() *cobra.Command {
8886
if err := fedora.Create(
8987
ctx,
9088
&fedora.FedoraArgs{
91-
Prefix: "main",
92-
Version: viper.GetString(fedoraVersion),
93-
Arch: viper.GetString(params.LinuxArch),
94-
InstanceRequest: &instancetypes.AwsInstanceRequest{
95-
CPUs: viper.GetInt32(params.CPUs),
96-
GPUs: viper.GetInt32(params.GPUs),
97-
GPUManufacturer: viper.GetString(params.GPUManufacturer),
98-
MemoryGib: viper.GetInt32(params.Memory),
99-
Arch: util.If(viper.GetString(params.LinuxArch) == "arm64",
100-
instancetypes.Arm64, instancetypes.Amd64),
101-
NestedVirt: viper.GetBool(params.ProfileSNC) || viper.GetBool(params.NestedVirt),
102-
},
103-
Spot: viper.IsSet(awsParams.Spot),
104-
Timeout: viper.GetString(params.Timeout),
105-
Airgap: viper.IsSet(airgap)}); err != nil {
89+
Prefix: "main",
90+
Version: viper.GetString(fedoraVersion),
91+
Arch: viper.GetString(params.LinuxArch),
92+
ComputeRequest: params.GetComputeRequest(),
93+
Spot: viper.IsSet(awsParams.Spot),
94+
Timeout: viper.GetString(params.Timeout),
95+
Airgap: viper.IsSet(airgap)}); err != nil {
10696
logging.Error(err)
10797
}
10898
return nil

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package hosts
22

33
import (
44
awsParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/constants"
5-
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
5+
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
66
"github.com/redhat-developer/mapt/pkg/integrations/github"
77
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
88
"github.com/redhat-developer/mapt/pkg/provider/aws/action/mac"

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

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package hosts
22

33
import (
44
awsParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/constants"
5-
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
5+
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
66
"github.com/redhat-developer/mapt/pkg/integrations/cirrus"
77
"github.com/redhat-developer/mapt/pkg/integrations/github"
88
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
99
"github.com/redhat-developer/mapt/pkg/provider/aws/action/rhel"
10-
"github.com/redhat-developer/mapt/pkg/provider/util/instancetypes"
11-
"github.com/redhat-developer/mapt/pkg/util"
1210
"github.com/redhat-developer/mapt/pkg/util/logging"
1311
"github.com/spf13/cobra"
1412
"github.com/spf13/pflag"
@@ -84,22 +82,16 @@ func getRHELCreate() *cobra.Command {
8482
if err := rhel.Create(
8583
ctx,
8684
&rhel.RHELArgs{
87-
Prefix: "main",
88-
Version: viper.GetString(params.RhelVersion),
89-
Arch: viper.GetString(params.LinuxArch),
90-
InstanceRequest: &instancetypes.AwsInstanceRequest{
91-
CPUs: viper.GetInt32(params.CPUs),
92-
MemoryGib: viper.GetInt32(params.Memory),
93-
Arch: util.If(viper.GetString(params.LinuxArch) == "arm64",
94-
instancetypes.Arm64, instancetypes.Amd64),
95-
NestedVirt: viper.GetBool(params.ProfileSNC) || viper.GetBool(params.NestedVirt),
96-
},
97-
SubsUsername: viper.GetString(params.SubsUsername),
98-
SubsUserpass: viper.GetString(params.SubsUserpass),
99-
ProfileSNC: viper.IsSet(params.ProfileSNC),
100-
Spot: viper.IsSet(awsParams.Spot),
101-
Timeout: viper.GetString(params.Timeout),
102-
Airgap: viper.IsSet(airgap),
85+
Prefix: "main",
86+
Version: viper.GetString(params.RhelVersion),
87+
Arch: viper.GetString(params.LinuxArch),
88+
ComputeRequest: params.GetComputeRequest(),
89+
SubsUsername: viper.GetString(params.SubsUsername),
90+
SubsUserpass: viper.GetString(params.SubsUserpass),
91+
ProfileSNC: viper.IsSet(params.ProfileSNC),
92+
Spot: viper.IsSet(awsParams.Spot),
93+
Timeout: viper.GetString(params.Timeout),
94+
Airgap: viper.IsSet(airgap),
10395
}); err != nil {
10496
logging.Error(err)
10597
}

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

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package hosts
2+
3+
import (
4+
awsParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/constants"
5+
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
6+
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
7+
rhelai "github.com/redhat-developer/mapt/pkg/provider/aws/action/rhel-ai"
8+
"github.com/redhat-developer/mapt/pkg/util/logging"
9+
"github.com/spf13/cobra"
10+
"github.com/spf13/pflag"
11+
"github.com/spf13/viper"
12+
)
13+
14+
const (
15+
cmdRHELAI = "rhel-ai"
16+
cmdRHELAIDesc = "manage rhel ai host"
17+
)
18+
19+
func GetRHELAICmd() *cobra.Command {
20+
c := &cobra.Command{
21+
Use: cmdRHELAI,
22+
Short: cmdRHELAIDesc,
23+
RunE: func(cmd *cobra.Command, args []string) error {
24+
if err := viper.BindPFlags(cmd.Flags()); err != nil {
25+
return err
26+
}
27+
return nil
28+
},
29+
}
30+
31+
flagSet := pflag.NewFlagSet(cmdRHELAI, pflag.ExitOnError)
32+
params.AddCommonFlags(flagSet)
33+
c.PersistentFlags().AddFlagSet(flagSet)
34+
35+
c.AddCommand(getRHELAICreate(), getRHELAIDestroy())
36+
return c
37+
}
38+
39+
func getRHELAICreate() *cobra.Command {
40+
c := &cobra.Command{
41+
Use: params.CreateCmdName,
42+
Short: params.CreateCmdName,
43+
RunE: func(cmd *cobra.Command, args []string) error {
44+
if err := viper.BindPFlags(cmd.Flags()); err != nil {
45+
return err
46+
}
47+
48+
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),
56+
}
57+
58+
// Run create
59+
if err := rhelai.Create(
60+
ctx,
61+
&rhelai.RHELAIArgs{
62+
Prefix: "main",
63+
SubsUsername: viper.GetString(params.SubsUsername),
64+
SubsUserpass: viper.GetString(params.SubsUserpass),
65+
ComputeRequest: params.GetComputeRequest(),
66+
Spot: viper.IsSet(awsParams.Spot),
67+
Timeout: viper.GetString(params.Timeout),
68+
}); err != nil {
69+
logging.Error(err)
70+
}
71+
return nil
72+
},
73+
}
74+
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
75+
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc)
76+
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
77+
flagSet.StringP(params.SubsUsername, "", "", params.SubsUsernameDesc)
78+
flagSet.StringP(params.SubsUserpass, "", "", params.SubsUserpassDesc)
79+
flagSet.Bool(awsParams.Spot, false, awsParams.SpotDesc)
80+
flagSet.IntP(params.SpotPriceIncreaseRate, "", params.SpotPriceIncreaseRateDefault, params.SpotPriceIncreaseRateDesc)
81+
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
82+
flagSet.AddFlagSet(params.GetCpusAndMemoryFlagset())
83+
c.PersistentFlags().AddFlagSet(flagSet)
84+
return c
85+
}
86+
87+
func getRHELAIDestroy() *cobra.Command {
88+
c := &cobra.Command{
89+
Use: params.DestroyCmdName,
90+
Short: params.DestroyCmdName,
91+
RunE: func(cmd *cobra.Command, args []string) error {
92+
if err := viper.BindPFlags(cmd.Flags()); err != nil {
93+
return err
94+
}
95+
96+
if err := rhelai.Destroy(&maptContext.ContextArgs{
97+
ProjectName: viper.GetString(params.ProjectName),
98+
BackedURL: viper.GetString(params.BackedURL),
99+
Debug: viper.IsSet(params.Debug),
100+
DebugLevel: viper.GetUint(params.DebugLevel),
101+
Serverless: viper.IsSet(params.Serverless),
102+
}); err != nil {
103+
logging.Error(err)
104+
}
105+
return nil
106+
},
107+
}
108+
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
109+
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
110+
c.PersistentFlags().AddFlagSet(flagSet)
111+
return c
112+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package hosts
22

33
import (
44
awsParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/constants"
5-
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
5+
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
66
"github.com/redhat-developer/mapt/pkg/integrations/cirrus"
77
"github.com/redhat-developer/mapt/pkg/integrations/github"
88
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"

cmd/mapt/cmd/aws/services/eks.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ package services
22

33
import (
44
awsparams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/constants"
5-
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
5+
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
66
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
77
awsEKS "github.com/redhat-developer/mapt/pkg/provider/aws/action/eks"
8-
"github.com/redhat-developer/mapt/pkg/provider/util/instancetypes"
9-
"github.com/redhat-developer/mapt/pkg/util"
108
"github.com/redhat-developer/mapt/pkg/util/logging"
119
"github.com/spf13/cobra"
1210
"github.com/spf13/pflag"
@@ -71,13 +69,8 @@ func getCreateEKS() *cobra.Command {
7169
SpotPriceIncreaseRate: viper.GetInt(params.SpotPriceIncreaseRate),
7270
},
7371
&awsEKS.EKSRequest{
74-
Prefix: viper.GetString(params.ProjectName),
75-
InstanceRequest: &instancetypes.AwsInstanceRequest{
76-
CPUs: viper.GetInt32(params.CPUs),
77-
MemoryGib: viper.GetInt32(params.Memory),
78-
Arch: util.If(viper.GetString(params.LinuxArch) == "arm64",
79-
instancetypes.Arm64, instancetypes.Amd64),
80-
},
72+
Prefix: viper.GetString(params.ProjectName),
73+
ComputeRequest: params.GetComputeRequest(),
8174
KubernetesVersion: viper.GetString(paramVersion),
8275
ScalingDesiredSize: viper.GetInt(paramScalingDesiredSize),
8376
ScalingMaxSize: viper.GetInt(paramScalingMaxSize),

cmd/mapt/cmd/aws/services/kind.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ package services
22

33
import (
44
awsParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/constants"
5-
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
5+
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
66
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
77
"github.com/redhat-developer/mapt/pkg/provider/aws/action/kind"
8-
"github.com/redhat-developer/mapt/pkg/provider/util/instancetypes"
9-
"github.com/redhat-developer/mapt/pkg/util"
108
"github.com/redhat-developer/mapt/pkg/util/logging"
119
"github.com/spf13/cobra"
1210
"github.com/spf13/pflag"
@@ -51,17 +49,11 @@ func createKind() *cobra.Command {
5149
Tags: viper.GetStringMapString(params.Tags),
5250
},
5351
&kind.KindArgs{
54-
InstanceRequest: &instancetypes.AwsInstanceRequest{
55-
CPUs: viper.GetInt32(params.CPUs),
56-
MemoryGib: viper.GetInt32(params.Memory),
57-
Arch: util.If(viper.GetString(params.LinuxArch) == "arm64",
58-
instancetypes.Arm64, instancetypes.Amd64),
59-
NestedVirt: viper.GetBool(params.ProfileSNC) || viper.GetBool(params.NestedVirt),
60-
},
61-
Version: viper.GetString(params.KindK8SVersion),
62-
Arch: viper.GetString(params.LinuxArch),
63-
Spot: viper.IsSet(awsParams.Spot),
64-
Timeout: viper.GetString(params.Timeout)}); err != nil {
52+
ComputeRequest: params.GetComputeRequest(),
53+
Version: viper.GetString(params.KindK8SVersion),
54+
Arch: viper.GetString(params.LinuxArch),
55+
Spot: viper.IsSet(awsParams.Spot),
56+
Timeout: viper.GetString(params.Timeout)}); err != nil {
6557
logging.Error(err)
6658
}
6759
return nil

cmd/mapt/cmd/aws/services/mac-pool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package services
22

33
import (
44
awsParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/constants"
5-
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
5+
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
66
"github.com/redhat-developer/mapt/pkg/integrations/cirrus"
77
"github.com/redhat-developer/mapt/pkg/integrations/github"
88
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ package services
22

33
import (
44
awsParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/constants"
5-
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
5+
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
66
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
77
openshiftsnc "github.com/redhat-developer/mapt/pkg/provider/aws/action/openshift-snc"
8-
"github.com/redhat-developer/mapt/pkg/provider/util/instancetypes"
9-
"github.com/redhat-developer/mapt/pkg/util"
108
"github.com/redhat-developer/mapt/pkg/util/logging"
119
"github.com/spf13/cobra"
1210
"github.com/spf13/pflag"
@@ -61,13 +59,7 @@ func createSNC() *cobra.Command {
6159
Tags: viper.GetStringMapString(params.Tags),
6260
},
6361
&openshiftsnc.OpenshiftSNCArgs{
64-
InstanceRequest: &instancetypes.AwsInstanceRequest{
65-
CPUs: viper.GetInt32(params.CPUs),
66-
MemoryGib: viper.GetInt32(params.Memory),
67-
Arch: util.If(viper.GetString(params.LinuxArch) == "arm64",
68-
instancetypes.Arm64, instancetypes.Amd64),
69-
NestedVirt: viper.GetBool(params.ProfileSNC) || viper.GetBool(params.NestedVirt),
70-
},
62+
ComputeRequest: params.GetComputeRequest(),
7163
Version: viper.GetString(ocpVersion),
7264
Arch: viper.GetString(params.LinuxArch),
7365
PullSecretFile: viper.GetString(pullSecretFile),

0 commit comments

Comments
 (0)