Skip to content

Commit

Permalink
feat: mac-pool service on AWS
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Riobo <[email protected]>
  • Loading branch information
adrianriobo committed Jan 21, 2025
1 parent 486138a commit a2e5446
Show file tree
Hide file tree
Showing 39 changed files with 1,611 additions and 595 deletions.
4 changes: 3 additions & 1 deletion cmd/mapt/cmd/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/hosts"
"github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/services"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -27,6 +28,7 @@ func GetCmd() *cobra.Command {
hosts.GetMacCmd(),
hosts.GetWindowsCmd(),
hosts.GetRHELCmd(),
hosts.GetFedoraCmd())
hosts.GetFedoraCmd(),
services.GetMacPoolCmd())
return c
}
21 changes: 21 additions & 0 deletions cmd/mapt/cmd/aws/constants/contants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package constants

import "github.com/redhat-developer/mapt/pkg/provider/aws/action/mac"

const (
MACRequestCmd = "request"
MACRRequestCmdDesc = "request mac machine"
MACReleaseCmd = "release"
MACReleaseCmdDesc = "release mac machine"

MACArch string = "arch"
MACArchDesc string = "MAC architecture allowed values x86, m1, m2"
MACArchDefault string = mac.DefaultArch
MACOSVersion string = "version"
MACOSVersionDesc string = "MACos operating system vestion 11, 12 on x86 and m1/m2; 13, 14 on all archs"
MACOSVersionDefault string = mac.DefaultOSVersion
MACFixedLocation string = "fixed-location"
MACFixedLocationDesc string = "if this flag is set the host will be created only on the region set by the AWS Env (AWS_DEFAULT_REGION)"
MACDHID string = "dedicated-host-id"
MACDHIDDesc string = "id for the dedicated host"
)
12 changes: 4 additions & 8 deletions cmd/mapt/cmd/aws/hosts/constans.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package hosts

const (
spot string = "spot"
spotDesc string = "if this flag is set the host will be created only on the region set by the AWS Env (AWS_DEFAULT_REGION)"
airgap string = "airgap"
airgapDesc string = "if this flag is set the host will be created as airgap machine. Access will done through a bastion"
serverless string = "serverless"
serverlessDesc string = "if serverless is set the command will be executed as a serverless action."
timeout string = "timeout"
timeoutDesc string = "if timeout is set a serverless destroy actions will be set on the time according to the timeout. The Timeout value is a duration conforming to Go ParseDuration format."
spot string = "spot"
spotDesc string = "if this flag is set the host will be created only on the region set by the AWS Env (AWS_DEFAULT_REGION)"
airgap string = "airgap"
airgapDesc string = "if this flag is set the host will be created as airgap machine. Access will done through a bastion"

vmTypes string = "vm-types"
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."
Expand Down
14 changes: 8 additions & 6 deletions cmd/mapt/cmd/aws/hosts/fedora.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func getFedoraCreate() *cobra.Command {
viper.GetString(params.ConnectionDetailsOutput),
viper.GetStringMapString(params.Tags),
viper.IsSet(params.Debug),
viper.GetUint(params.DebugLevel))
viper.GetUint(params.DebugLevel),
false)

// Initialize gh actions runner if needed
if viper.IsSet(params.InstallGHActionsRunner) {
Expand Down Expand Up @@ -81,7 +82,7 @@ func getFedoraCreate() *cobra.Command {
VMType: viper.GetStringSlice(vmTypes),
InstanceRequest: instanceRequest,
Spot: viper.IsSet(spot),
Timeout: viper.GetString(timeout),
Timeout: viper.GetString(params.Timeout),
SetupGHActionsRunner: viper.IsSet(params.InstallGHActionsRunner),
Airgap: viper.IsSet(airgap)}); err != nil {
logging.Error(err)
Expand All @@ -97,7 +98,7 @@ func getFedoraCreate() *cobra.Command {
flagSet.StringSliceP(vmTypes, "", []string{}, vmTypesDescription)
flagSet.Bool(airgap, false, airgapDesc)
flagSet.Bool(spot, false, spotDesc)
flagSet.StringP(timeout, "", "", timeout)
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
flagSet.AddFlagSet(params.GetGHActionsFlagset())
flagSet.AddFlagSet(params.GetCpusAndMemoryFlagset())
c.PersistentFlags().AddFlagSet(flagSet)
Expand All @@ -117,18 +118,19 @@ func getFedoraDestroy() *cobra.Command {
viper.GetString(params.ProjectName),
viper.GetString(params.BackedURL),
viper.IsSet(params.Debug),
viper.GetUint(params.DebugLevel))
viper.GetUint(params.DebugLevel),
viper.IsSet(params.Serverless))

logging.Debug("Run fedora destroy")

if err := fedora.Destroy(viper.IsSet(serverless)); err != nil {
if err := fedora.Destroy(); err != nil {
logging.Error(err)
}
return nil
},
}
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
flagSet.Bool(serverless, false, serverlessDesc)
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
59 changes: 23 additions & 36 deletions cmd/mapt/cmd/aws/hosts/mac.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hosts

import (
awsParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/constants"
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/mac"
Expand All @@ -12,23 +13,8 @@ import (
)

const (
cmdMac = "mac"
cmdMacDesc = "manage mac instances"
requestCmd = "request"
requestCmdDesc = "request mac machine"
releaseCmd = "release"
releaseCmdDesc = "release mac machine"

dhID string = "dedicated-host-id"
dhIDDesc string = "id for the dedicated host"
arch string = "arch"
archDesc string = "mac architecture allowed values x86, m1, m2"
archDefault string = mac.DefaultArch
osVersion string = "version"
osVersionDesc string = "macos operating system vestion 11, 12 on x86 and m1/m2; 13, 14 on all archs"
osDefault string = mac.DefaultOSVersion
fixedLocation string = "fixed-location"
fixedLocationDesc string = "if this flag is set the host will be created only on the region set by the AWS Env (AWS_DEFAULT_REGION)"
cmdMac = "mac"
cmdMacDesc = "manage mac instances"
)

func GetMacCmd() *cobra.Command {
Expand All @@ -48,8 +34,8 @@ func GetMacCmd() *cobra.Command {

func getMacRequest() *cobra.Command {
c := &cobra.Command{
Use: requestCmd,
Short: requestCmd,
Use: awsParams.MACRequestCmd,
Short: awsParams.MACRequestCmd,
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return err
Expand All @@ -62,7 +48,8 @@ func getMacRequest() *cobra.Command {
viper.GetString(params.ConnectionDetailsOutput),
viper.GetStringMapString(params.Tags),
viper.IsSet(params.Debug),
viper.GetUint(params.DebugLevel))
viper.GetUint(params.DebugLevel),
false)

// Initialize gh actions runner if needed
if viper.IsSet(params.InstallGHActionsRunner) {
Expand All @@ -79,22 +66,22 @@ func getMacRequest() *cobra.Command {
if err := mac.Request(
&mac.MacRequest{
Prefix: "main",
Architecture: viper.GetString(arch),
Version: viper.GetString(osVersion),
FixedLocation: viper.IsSet(fixedLocation),
Architecture: viper.GetString(awsParams.MACArch),
Version: viper.GetString(awsParams.MACOSVersion),
FixedLocation: viper.IsSet(awsParams.MACFixedLocation),
SetupGHActionsRunner: viper.GetBool(params.InstallGHActionsRunner),
Airgap: viper.IsSet(airgap)}); err != nil {
logging.Error(err)
}
return nil
},
}
flagSet := pflag.NewFlagSet(requestCmd, pflag.ExitOnError)
flagSet := pflag.NewFlagSet(awsParams.MACRequestCmd, pflag.ExitOnError)
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc)
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
flagSet.StringP(arch, "", archDefault, archDesc)
flagSet.StringP(osVersion, "", osDefault, osVersionDesc)
flagSet.Bool(fixedLocation, false, fixedLocationDesc)
flagSet.StringP(awsParams.MACArch, "", awsParams.MACArchDefault, awsParams.MACArchDesc)
flagSet.StringP(awsParams.MACOSVersion, "", awsParams.MACOSVersion, awsParams.MACOSVersionDefault)
flagSet.Bool(awsParams.MACFixedLocation, false, awsParams.MACFixedLocationDesc)
flagSet.Bool(airgap, false, airgapDesc)
flagSet.AddFlagSet(params.GetGHActionsFlagset())
c.PersistentFlags().AddFlagSet(flagSet)
Expand All @@ -104,8 +91,8 @@ func getMacRequest() *cobra.Command {
// Required dedicatedHostID as mandatory
func getMacRelease() *cobra.Command {
c := &cobra.Command{
Use: releaseCmd,
Short: releaseCmd,
Use: awsParams.MACReleaseCmd,
Short: awsParams.MACReleaseCmd,
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return err
Expand All @@ -114,19 +101,19 @@ func getMacRelease() *cobra.Command {
// Run create
if err := mac.Release(
"main",
viper.GetString(dhID),
viper.GetString(awsParams.MACDHID),
viper.IsSet(params.Debug),
viper.GetUint(params.DebugLevel)); err != nil {
logging.Error(err)
}
return nil
},
}
flagSet := pflag.NewFlagSet(releaseCmd, pflag.ExitOnError)
flagSet := pflag.NewFlagSet(awsParams.MACReleaseCmd, pflag.ExitOnError)
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
flagSet.StringP(dhID, "", "", dhIDDesc)
flagSet.StringP(awsParams.MACDHID, "", "", awsParams.MACDHIDDesc)
c.PersistentFlags().AddFlagSet(flagSet)
err := c.MarkPersistentFlagRequired(dhID)
err := c.MarkPersistentFlagRequired(awsParams.MACDHID)
if err != nil {
logging.Error(err)
}
Expand All @@ -144,7 +131,7 @@ func getMacDestroy() *cobra.Command {

if err := mac.Destroy(
"main",
viper.GetString(dhID),
viper.GetString(awsParams.MACDHID),
viper.IsSet(params.Debug),
viper.GetUint(params.DebugLevel)); err != nil {
logging.Error(err)
Expand All @@ -153,10 +140,10 @@ func getMacDestroy() *cobra.Command {
},
}
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
flagSet.StringP(dhID, "", "", dhIDDesc)
flagSet.StringP(awsParams.MACDHID, "", "", awsParams.MACDHIDDesc)
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
c.PersistentFlags().AddFlagSet(flagSet)
err := c.MarkPersistentFlagRequired(dhID)
err := c.MarkPersistentFlagRequired(awsParams.MACDHID)
if err != nil {
logging.Error(err)
}
Expand Down
14 changes: 8 additions & 6 deletions cmd/mapt/cmd/aws/hosts/rhel.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func getRHELCreate() *cobra.Command {
viper.GetString(params.ConnectionDetailsOutput),
viper.GetStringMapString(params.Tags),
viper.IsSet(params.Debug),
viper.GetUint(params.DebugLevel))
viper.GetUint(params.DebugLevel),
false)

// Initialize gh actions runner if needed
if viper.IsSet(params.InstallGHActionsRunner) {
Expand Down Expand Up @@ -81,7 +82,7 @@ func getRHELCreate() *cobra.Command {
SubsUserpass: viper.GetString(params.SubsUserpass),
ProfileSNC: viper.IsSet(params.ProfileSNC),
Spot: viper.IsSet(spot),
Timeout: viper.GetString(timeout),
Timeout: viper.GetString(params.Timeout),
Airgap: viper.IsSet(airgap),
SetupGHActionsRunner: viper.IsSet(params.InstallGHActionsRunner),
}); err != nil {
Expand All @@ -100,7 +101,7 @@ func getRHELCreate() *cobra.Command {
flagSet.StringP(params.SubsUserpass, "", "", params.SubsUserpassDesc)
flagSet.Bool(airgap, false, airgapDesc)
flagSet.Bool(spot, false, spotDesc)
flagSet.StringP(timeout, "", "", timeout)
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
flagSet.Bool(params.ProfileSNC, false, params.ProfileSNCDesc)
flagSet.AddFlagSet(params.GetGHActionsFlagset())
flagSet.AddFlagSet(params.GetCpusAndMemoryFlagset())
Expand All @@ -121,16 +122,17 @@ func getRHELDestroy() *cobra.Command {
viper.GetString(params.ProjectName),
viper.GetString(params.BackedURL),
viper.IsSet(params.Debug),
viper.GetUint(params.DebugLevel))
viper.GetUint(params.DebugLevel),
viper.IsSet(params.Serverless))

if err := rhel.Destroy(viper.IsSet(serverless)); err != nil {
if err := rhel.Destroy(); err != nil {
logging.Error(err)
}
return nil
},
}
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
flagSet.Bool(serverless, false, serverlessDesc)
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
14 changes: 8 additions & 6 deletions cmd/mapt/cmd/aws/hosts/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func getWindowsCreate() *cobra.Command {
viper.GetString(params.ConnectionDetailsOutput),
viper.GetStringMapString(params.Tags),
viper.IsSet(params.Debug),
viper.GetUint(params.DebugLevel))
viper.GetUint(params.DebugLevel),
false)

// Initialize gh actions runner if needed
if viper.IsSet(params.InstallGHActionsRunner) {
Expand All @@ -86,7 +87,7 @@ func getWindowsCreate() *cobra.Command {
AMIKeepCopy: viper.IsSet(amiKeepCopy),
Spot: viper.IsSet(spot),
Airgap: viper.IsSet(airgap),
Timeout: viper.GetString(timeout),
Timeout: viper.GetString(params.Timeout),
SetupGHActionsRunner: viper.IsSet(params.InstallGHActionsRunner),
}); err != nil {
logging.Error(err)
Expand All @@ -103,7 +104,7 @@ func getWindowsCreate() *cobra.Command {
flagSet.StringP(amiLang, "", amiLangDefault, amiLangDesc)
flagSet.Bool(airgap, false, airgapDesc)
flagSet.Bool(spot, false, spotDesc)
flagSet.StringP(timeout, "", "", timeout)
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
flagSet.Bool(amiKeepCopy, false, amiKeepCopyDesc)
flagSet.AddFlagSet(params.GetGHActionsFlagset())
c.PersistentFlags().AddFlagSet(flagSet)
Expand All @@ -123,16 +124,17 @@ func getWindowsDestroy() *cobra.Command {
viper.GetString(params.ProjectName),
viper.GetString(params.BackedURL),
viper.IsSet(params.Debug),
viper.GetUint(params.DebugLevel))
viper.GetUint(params.DebugLevel),
viper.IsSet(params.Serverless))

if err := windows.Destroy(viper.IsSet(serverless)); err != nil {
if err := windows.Destroy(); err != nil {
logging.Error(err)
}
return nil
},
}
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
flagSet.Bool(serverless, false, serverlessDesc)
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
Loading

0 comments on commit a2e5446

Please sign in to comment.