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

convert vm specs to provider specific instance type name #277

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cmd/mapt/cmd/aws/hosts/fedora.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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/provider/util/instancetypes"
"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/spf13/cobra"
Expand Down Expand Up @@ -60,6 +62,11 @@ func getFedoraCreate() *cobra.Command {
logging.Error(err)
}
}
instanceRequest := &instancetypes.AwsInstanceRequest{
CPUs: viper.GetInt32(params.CPUs),
MemoryGib: viper.GetInt32(params.Memory),
Arch: util.If(viper.GetString(params.LinuxArch) == "arm64", instancetypes.Arm64, instancetypes.Amd64),
}

// Run create
if err := fedora.Create(
Expand All @@ -68,6 +75,7 @@ func getFedoraCreate() *cobra.Command {
Version: viper.GetString(rhelVersion),
Arch: viper.GetString(params.LinuxArch),
VMType: viper.GetStringSlice(vmTypes),
InstanceRequest: instanceRequest,
Spot: viper.IsSet(spot),
SetupGHActionsRunner: viper.IsSet(params.InstallGHActionsRunner),
Airgap: viper.IsSet(airgap)}); err != nil {
Expand All @@ -85,6 +93,7 @@ func getFedoraCreate() *cobra.Command {
flagSet.Bool(airgap, false, airgapDesc)
flagSet.Bool(spot, false, spotDesc)
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/aws/hosts/rhel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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/provider/util/instancetypes"
"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/spf13/cobra"
Expand Down Expand Up @@ -67,12 +69,20 @@ func getRHELCreate() *cobra.Command {
}
}

instanceRequest := &instancetypes.AwsInstanceRequest{
CPUs: viper.GetInt32(params.CPUs),
MemoryGib: viper.GetInt32(params.Memory),
Arch: util.If(viper.GetString(params.LinuxArch) == "arm64", instancetypes.Arm64, instancetypes.Amd64),
NestedVirt: viper.GetBool(profileSNC) || viper.GetBool(params.NestedVirt),
}

// Run create
if err := rhel.Create(
&rhel.Request{
Prefix: "main",
Version: viper.GetString(rhelVersion),
Arch: viper.GetString(params.LinuxArch),
InstanceRequest: instanceRequest,
VMType: viper.GetStringSlice(vmTypes),
SubsUsername: viper.GetString(subsUsername),
SubsUserpass: viper.GetString(subsUserpass),
Expand All @@ -98,6 +108,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())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here paras are added but not process of the data?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh yes, this is missing the corresponding code to make use of the flags, will fix

c.PersistentFlags().AddFlagSet(flagSet)
return c
}
Expand Down
1 change: 0 additions & 1 deletion cmd/mapt/cmd/azure/hosts/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const (
defaultLocation = "West US"
paramVMSize = "vmsize"
paramVMSizeDesc = "size for the VM. Type requires to allow nested virtualization"
defaultVMSize = "Standard_D8as_v5"
paramUsername = "username"
paramUsernameDesc = "username for general user. SSH accessible + rdp with generated password"
defaultUsername = "rhqp"
Expand Down
32 changes: 22 additions & 10 deletions cmd/mapt/cmd/azure/hosts/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
azureLinux "github.com/redhat-developer/mapt/pkg/provider/azure/action/linux"
"github.com/redhat-developer/mapt/pkg/provider/util/instancetypes"
"github.com/redhat-developer/mapt/pkg/util"

spotprice "github.com/redhat-developer/mapt/pkg/provider/azure/module/spot-price"
"github.com/redhat-developer/mapt/pkg/util/logging"
Expand All @@ -19,6 +21,7 @@ const (
cmdUbuntuDesc = "ubuntu operations"
cmdRHEL = "rhel"
cmdRHELDesc = "ubuntu operations"
defaultVMSize = "Standard_D8as_v5"

paramLinuxVersion = "version"
paramLinuxVersionDesc = "linux version. Version should be formmated as X.Y (Major.minor)"
Expand Down Expand Up @@ -74,17 +77,25 @@ func getCreateLinux(ostype azureLinux.OSType, defaultOSVersion string) *cobra.Co
return fmt.Errorf("%s is not a valid spot tolerance value", viper.GetString(paramSpotTolerance))
}
}
instanceRequest := &instancetypes.AzureInstanceRequest{
CPUs: viper.GetInt32(params.CPUs),
MemoryGib: viper.GetInt32(params.Memory),
Arch: util.If(viper.GetString(params.LinuxArch) == "arm64", instancetypes.Arm64, instancetypes.Amd64),
NestedVirt: viper.GetBool(params.NestedVirt),
}

if err := azureLinux.Create(
&azureLinux.LinuxRequest{
Prefix: viper.GetString(params.ProjectName),
Location: viper.GetString(paramLocation),
VMSize: viper.GetString(paramVMSize),
Version: viper.GetString(paramLinuxVersion),
Arch: viper.GetString(params.LinuxArch),
OSType: ostype,
Username: viper.GetString(paramUsername),
Spot: viper.IsSet(paramSpot),
SpotTolerance: spotToleranceValue}); err != nil {
Prefix: viper.GetString(params.ProjectName),
Location: viper.GetString(paramLocation),
VMSizes: viper.GetStringSlice(paramVMSize),
InstanceRequest: instanceRequest,
Version: viper.GetString(paramLinuxVersion),
Arch: viper.GetString(params.LinuxArch),
OSType: ostype,
Username: viper.GetString(paramUsername),
Spot: viper.IsSet(paramSpot),
SpotTolerance: spotToleranceValue}); err != nil {
logging.Error(err)
}
return nil
Expand All @@ -95,11 +106,12 @@ func getCreateLinux(ostype azureLinux.OSType, defaultOSVersion string) *cobra.Co
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
flagSet.StringP(paramLocation, "", defaultLocation, paramLocationDesc)
flagSet.StringP(params.LinuxArch, "", params.LinuxArchDefault, params.LinuxArchDesc)
flagSet.StringP(paramVMSize, "", defaultVMSize, paramVMSizeDesc)
flagSet.StringSliceP(paramVMSize, "", []string{}, paramVMSizeDesc)
flagSet.StringP(paramLinuxVersion, "", defaultOSVersion, paramLinuxVersionDesc)
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
14 changes: 12 additions & 2 deletions cmd/mapt/cmd/azure/hosts/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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/provider/util/instancetypes"
"github.com/redhat-developer/mapt/pkg/util/ghactions"
"github.com/redhat-developer/mapt/pkg/util/logging"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -83,11 +84,19 @@ func getCreateWindowsDesktop() *cobra.Command {
}
}

instanceRequest := &instancetypes.AzureInstanceRequest{
CPUs: viper.GetInt32(params.CPUs),
MemoryGib: viper.GetInt32(params.Memory),
Arch: instancetypes.Amd64,
NestedVirt: viper.GetBool(params.NestedVirt),
}

if err := azureWindows.Create(
&azureWindows.WindowsRequest{
Prefix: viper.GetString(params.ProjectName),
Location: viper.GetString(paramLocation),
VMSize: viper.GetString(paramVMSize),
VMSizes: viper.GetStringSlice(paramVMSize),
InstaceTypeRequest: instanceRequest,
Version: viper.GetString(paramWindowsVersion),
Feature: viper.GetString(paramFeature),
Username: viper.GetString(paramUsername),
Expand All @@ -105,7 +114,7 @@ func getCreateWindowsDesktop() *cobra.Command {
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc)
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
flagSet.StringP(paramLocation, "", defaultLocation, paramLocationDesc)
flagSet.StringP(paramVMSize, "", defaultVMSize, paramVMSizeDesc)
flagSet.StringSliceP(paramVMSize, "", []string{}, paramVMSizeDesc)
flagSet.StringP(paramWindowsVersion, "", defaultWindowsVersion, paramWindowsVersionDesc)
flagSet.StringP(paramFeature, "", defaultFeature, paramFeatureDesc)
flagSet.StringP(paramUsername, "", defaultUsername, paramUsernameDesc)
Expand All @@ -114,6 +123,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
18 changes: 17 additions & 1 deletion cmd/mapt/cmd/constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package constants

import "github.com/spf13/pflag"
import (
"github.com/spf13/pflag"
)

const (
ProjectName string = "project-name"
Expand Down Expand Up @@ -38,6 +40,12 @@ 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"
NestedVirt string = "nested-virt"
NestedVirtDesc string = "Use cloud instance that has nested virtualization support"

CreateCmdName string = "create"
DestroyCmdName string = "destroy"
Expand All @@ -56,3 +64,11 @@ 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)
flagSet.BoolP(NestedVirt, "", false, NestedVirtDesc)
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