Skip to content

Commit

Permalink
convert vm specs to provider specific instance type name
Browse files Browse the repository at this point in the history
  • Loading branch information
anjannath committed Aug 13, 2024
1 parent 03a6284 commit 14d8432
Show file tree
Hide file tree
Showing 257 changed files with 127,234 additions and 1,532 deletions.
20 changes: 19 additions & 1 deletion cmd/mapt/cmd/aws/hosts/fedora.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
"github.com/redhat-developer/mapt/pkg/provider/aws/action/fedora"
"github.com/redhat-developer/mapt/pkg/util"
"github.com/redhat-developer/mapt/pkg/util/logging"
"github.com/redhat-developer/mapt/pkg/util/resources"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
Expand Down Expand Up @@ -50,13 +52,28 @@ func getFedoraCreate() *cobra.Command {
viper.GetString(params.ConnectionDetailsOutput),
viper.GetStringMapString(params.Tags))

// Get the VM instance type name based on cpus, memory and arch
var ec2Types []string
if viper.GetInt32(params.CPUs) > 0 && viper.GetInt32(params.Memory) > 0 {
var arch resources.Arch = resources.Amd64
if viper.GetString(params.LinuxArch) == "arm64" {
arch = resources.Arm64
}
ec2Types, _ = resources.GetAwsMachineTypes(viper.GetInt32(params.CPUs), viper.GetInt32(params.Memory), arch)
if len(ec2Types) > 0 {
logging.Info("Using dynamic vm types: ", ec2Types)
} else {
logging.Info("Using the default instance type")
}
}

// Run create
if err := fedora.Create(
&fedora.Request{
Prefix: "main",
Version: viper.GetString(rhelVersion),
Arch: viper.GetString(params.LinuxArch),
VMType: viper.GetStringSlice(vmTypes),
VMType: util.If(len(ec2Types) > 0, ec2Types, viper.GetStringSlice(vmTypes)),
Spot: viper.IsSet(spot),
Airgap: viper.IsSet(airgap)}); err != nil {
logging.Error(err)
Expand All @@ -72,6 +89,7 @@ func getFedoraCreate() *cobra.Command {
flagSet.StringSliceP(vmTypes, "", []string{}, vmTypesDescription)
flagSet.Bool(airgap, false, airgapDesc)
flagSet.Bool(spot, false, spotDesc)
flagSet.AddFlagSet(params.GetCpusAndMemoryFlagset())
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
Expand Down
20 changes: 19 additions & 1 deletion cmd/mapt/cmd/aws/hosts/rhel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
"github.com/redhat-developer/mapt/pkg/provider/aws/action/rhel"
"github.com/redhat-developer/mapt/pkg/util"
"github.com/redhat-developer/mapt/pkg/util/ghactions"
"github.com/redhat-developer/mapt/pkg/util/logging"
"github.com/redhat-developer/mapt/pkg/util/resources"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
Expand Down Expand Up @@ -67,13 +69,28 @@ func getRHELCreate() *cobra.Command {
}
}

// Get the VM instance type name based on cpus, memory and arch
var ec2Types []string
if viper.GetInt32(params.CPUs) > 0 && viper.GetInt32(params.Memory) > 0 {
var arch resources.Arch = resources.Amd64
if viper.GetString(params.LinuxArch) == "arm64" {
arch = resources.Arm64
}
ec2Types, _ = resources.GetAwsMachineTypes(viper.GetInt32(params.CPUs), viper.GetInt32(params.Memory), arch)
if len(ec2Types) > 0 {
logging.Info("Using dynamic vm types: ", ec2Types)
} else {
logging.Info("Using the default instance type")
}
}

// Run create
if err := rhel.Create(
&rhel.Request{
Prefix: "main",
Version: viper.GetString(rhelVersion),
Arch: viper.GetString(params.LinuxArch),
VMType: viper.GetStringSlice(vmTypes),
VMType: util.If(len(ec2Types) > 0, ec2Types, viper.GetStringSlice(vmTypes)),
SubsUsername: viper.GetString(subsUsername),
SubsUserpass: viper.GetString(subsUserpass),
ProfileSNC: viper.IsSet(profileSNC),
Expand All @@ -98,6 +115,7 @@ func getRHELCreate() *cobra.Command {
flagSet.Bool(spot, false, spotDesc)
flagSet.Bool(profileSNC, false, profileSNCDesc)
flagSet.AddFlagSet(params.GetGHActionsFlagset())
flagSet.AddFlagSet(params.GetCpusAndMemoryFlagset())
c.PersistentFlags().AddFlagSet(flagSet)
// if err := c.MarkFlagRequired(subsUsername); err != nil {
// logging.Error(err)
Expand Down
1 change: 1 addition & 0 deletions cmd/mapt/cmd/aws/hosts/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func getWindowsCreate() *cobra.Command {
flagSet.Bool(spot, false, spotDesc)
flagSet.Bool(amiKeepCopy, false, amiKeepCopyDesc)
flagSet.AddFlagSet(params.GetGHActionsFlagset())
flagSet.AddFlagSet(params.GetCpusAndMemoryFlagset())
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
Expand Down
20 changes: 19 additions & 1 deletion cmd/mapt/cmd/azure/hosts/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

spotprice "github.com/redhat-developer/mapt/pkg/provider/azure/module/spot-price"
"github.com/redhat-developer/mapt/pkg/util/logging"
"github.com/redhat-developer/mapt/pkg/util/resources"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
Expand Down Expand Up @@ -74,11 +75,27 @@ func getCreateLinux(ostype azureLinux.OSType, defaultOSVersion string) *cobra.Co
return fmt.Errorf("%s is not a valid spot tolerance value", viper.GetString(paramSpotTolerance))
}
}

// Get the VM instance type name based on cpus, memory and arch
var vmTypes []string
if viper.GetInt32(params.CPUs) > 0 && viper.GetInt32(params.Memory) > 0 {
var arch resources.Arch = resources.Amd64
if viper.GetString(params.LinuxArch) == "arm64" {
arch = resources.Arm64
}
vmTypes = resources.GetAzureMachineTypes(viper.GetInt32(params.CPUs), viper.GetInt32(params.Memory), arch)
if len(vmTypes) > 0 {
logging.Info("Using dynamic vm types: ", vmTypes)
} else {
logging.Info("Using the default instance type")
}
}

if err := azureLinux.Create(
&azureLinux.LinuxRequest{
Prefix: viper.GetString(params.ProjectName),
Location: viper.GetString(paramLocation),
VMSize: viper.GetString(paramVMSize),
VMSizes: vmTypes,
Version: viper.GetString(paramLinuxVersion),
Arch: viper.GetString(params.LinuxArch),
OSType: ostype,
Expand All @@ -100,6 +117,7 @@ func getCreateLinux(ostype azureLinux.OSType, defaultOSVersion string) *cobra.Co
flagSet.StringP(paramUsername, "", defaultUsername, paramUsernameDesc)
flagSet.Bool(paramSpot, false, paramSpotDesc)
flagSet.StringP(paramSpotTolerance, "", defaultSpotTolerance, paramSpotToleranceDesc)
flagSet.AddFlagSet(params.GetCpusAndMemoryFlagset())
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
Expand Down
16 changes: 15 additions & 1 deletion cmd/mapt/cmd/azure/hosts/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
azureWindows "github.com/redhat-developer/mapt/pkg/provider/azure/action/windows"
spotprice "github.com/redhat-developer/mapt/pkg/provider/azure/module/spot-price"
"github.com/redhat-developer/mapt/pkg/util"
"github.com/redhat-developer/mapt/pkg/util/ghactions"
"github.com/redhat-developer/mapt/pkg/util/logging"
"github.com/redhat-developer/mapt/pkg/util/resources"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
Expand Down Expand Up @@ -83,11 +85,22 @@ func getCreateWindowsDesktop() *cobra.Command {
}
}

// Get the VM instance type name based on cpus, memory and arch
var vmTypes []string
if viper.GetInt32(params.CPUs) > 0 && viper.GetInt32(params.Memory) > 0 {
vmTypes = resources.GetAzureMachineTypes(viper.GetInt32(params.CPUs), viper.GetInt32(params.Memory), resources.Amd64)
if len(vmTypes) > 0 {
logging.Info("Using dynamic vm types: ", vmTypes)
} else {
logging.Info("Using the default instance type")
}
}

if err := azureWindows.Create(
&azureWindows.WindowsRequest{
Prefix: viper.GetString(params.ProjectName),
Location: viper.GetString(paramLocation),
VMSize: viper.GetString(paramVMSize),
VMSizes: util.If(len(vmTypes) > 0, vmTypes, []string{viper.GetString(paramVMSize)}),
Version: viper.GetString(paramWindowsVersion),
Feature: viper.GetString(paramFeature),
Username: viper.GetString(paramUsername),
Expand All @@ -114,6 +127,7 @@ func getCreateWindowsDesktop() *cobra.Command {
flagSet.Bool(paramSpot, false, paramSpotDesc)
flagSet.StringP(paramSpotTolerance, "", defaultSpotTolerance, paramSpotToleranceDesc)
flagSet.AddFlagSet(params.GetGHActionsFlagset())
flagSet.AddFlagSet(params.GetCpusAndMemoryFlagset())
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
Expand Down
11 changes: 11 additions & 0 deletions cmd/mapt/cmd/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ const (
GHActionsRunnerTokenDesc string = "Token needed for registering the Github Actions Runner token"
GHActionsRunnerNameDesc string = "Name for the Github Actions Runner"
GHActionsRunnerRepoDesc string = "Full URL of the repository where the Github Actions Runner should be registered"
Memory string = "memory"
MemoryDesc string = "Amount of RAM for the cloud instance in GiB"
CPUs string = "cpus"
CPUsDesc string = "Number of CPUs for the cloud instance"

CreateCmdName string = "create"
DestroyCmdName string = "destroy"
Expand All @@ -56,3 +60,10 @@ func GetGHActionsFlagset() *pflag.FlagSet {
flagSet.StringP(GHActionsRunnerRepo, "", "", GHActionsRunnerRepoDesc)
return flagSet
}

func GetCpusAndMemoryFlagset() *pflag.FlagSet {
flagSet := pflag.NewFlagSet(CreateCmdName, pflag.ExitOnError)
flagSet.Int32P(CPUs, "", 0, CPUsDesc)
flagSet.Int32P(Memory, "", 0, MemoryDesc)
return flagSet
}
29 changes: 20 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ require (
)

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.12.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.13.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v6 v6.0.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph v0.9.0
github.com/aws/amazon-ec2-instance-selector/v2 v2.4.2-0.20231006140257-d989c5d76f0e
github.com/aws/aws-sdk-go-v2 v1.27.2
github.com/aws/aws-sdk-go-v2/config v1.27.18
github.com/aws/aws-sdk-go-v2/service/ec2 v1.142.0
Expand All @@ -28,14 +30,23 @@ require (
)

require (
github.com/aws/aws-sdk-go v1.45.6 // indirect
github.com/aws/aws-sdk-go-v2/service/pricing v1.21.6 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/evertras/bubble-table v0.15.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/sahilm/fuzzy v0.1.0 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/tools v0.22.0 // indirect
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.9.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
Expand Down Expand Up @@ -93,7 +104,7 @@ require (
github.com/spf13/cast v1.6.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/zclconf/go-cty v1.13.2 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/sync v0.7.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down Expand Up @@ -125,7 +136,7 @@ require (
github.com/nxadm/tail v1.4.11 // indirect
github.com/opentracing/basictracer-go v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/errors v0.9.1
github.com/pkg/term v1.1.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
Expand All @@ -139,10 +150,10 @@ require (
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.2 // indirect
Expand Down
Loading

0 comments on commit 14d8432

Please sign in to comment.