Skip to content
Open
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
11 changes: 5 additions & 6 deletions cmd/mapt/cmd/aws/hosts/rhelai.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
rhelai "github.com/redhat-developer/mapt/pkg/provider/aws/action/rhel-ai"
apiRHELAI "github.com/redhat-developer/mapt/pkg/targets/host/rhelai"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
Expand Down Expand Up @@ -52,12 +53,11 @@ func getRHELAICreate() *cobra.Command {
DebugLevel: viper.GetUint(params.DebugLevel),
Tags: viper.GetStringMapString(params.Tags),
},
&rhelai.RHELAIArgs{
&apiRHELAI.RHELAIArgs{
Prefix: "main",
Version: viper.GetString(params.RhelAIVersion),
Accelerator: viper.GetString(params.RhelAIAccelerator),
CustomAMI: viper.GetString(params.RhelAIAMICustom),
SubsUsername: viper.GetString(params.SubsUsername),
SubsUserpass: viper.GetString(params.SubsUserpass),
ComputeRequest: params.ComputeRequestArgs(),
Spot: params.SpotArgs(),
Timeout: viper.GetString(params.Timeout),
Expand All @@ -68,9 +68,8 @@ func getRHELAICreate() *cobra.Command {
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc)
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
flagSet.StringP(params.RhelAIVersion, "", params.RhelAIVersionDefault, params.RhelAIVersionDesc)
flagSet.StringP(params.RhelAIAccelerator, "", params.RhelAIAccelearatorDefault, params.RhelAIAccelearatorDesc)
flagSet.StringP(params.RhelAIAMICustom, "", "", params.RhelAIAMICustomDesc)
flagSet.StringP(params.SubsUsername, "", "", params.SubsUsernameDesc)
flagSet.StringP(params.SubsUserpass, "", "", params.SubsUserpassDesc)
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
params.AddComputeRequestFlags(flagSet)
params.AddSpotFlags(flagSet)
Expand All @@ -87,7 +86,7 @@ func getRHELAIDestroy() *cobra.Command {
return err
}
return rhelai.Destroy(&maptContext.ContextArgs{
Context: cmd.Context(),
Context: cmd.Context(),
ProjectName: viper.GetString(params.ProjectName),
BackedURL: viper.GetString(params.BackedURL),
Debug: viper.IsSet(params.Debug),
Expand Down
1 change: 1 addition & 0 deletions cmd/mapt/cmd/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func GetCmd() *cobra.Command {
hosts.GetWindowsDesktopCmd(),
hosts.GetUbuntuCmd(),
hosts.GetRHELCmd(),
hosts.GetRHELAICmd(),
hosts.GetFedoraCmd(),
services.GetAKSCmd(),
services.GetKindCmd())
Expand Down
106 changes: 106 additions & 0 deletions cmd/mapt/cmd/azure/hosts/rhelai.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package hosts

import (
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
rhelai "github.com/redhat-developer/mapt/pkg/provider/azure/action/rhel-ai"
apiRHELAI "github.com/redhat-developer/mapt/pkg/targets/host/rhelai"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)

const (
cmdRHELAI = "rhel-ai"
cmdRHELAIDesc = "manage rhel ai host"
)

func GetRHELAICmd() *cobra.Command {
c := &cobra.Command{
Use: cmdRHELAI,
Short: cmdRHELAIDesc,
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return err
}
return nil
},
}

flagSet := pflag.NewFlagSet(cmdRHELAI, pflag.ExitOnError)
params.AddCommonFlags(flagSet)
c.PersistentFlags().AddFlagSet(flagSet)

c.AddCommand(getRHELAICreate(), getRHELAIDestroy())
return c
}

func getRHELAICreate() *cobra.Command {
c := &cobra.Command{
Use: params.CreateCmdName,
Short: params.CreateCmdName,
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return err
}
return rhelai.Create(
&maptContext.ContextArgs{
Context: cmd.Context(),
ProjectName: viper.GetString(params.ProjectName),
BackedURL: viper.GetString(params.BackedURL),
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
Debug: viper.IsSet(params.Debug),
DebugLevel: viper.GetUint(params.DebugLevel),
Tags: viper.GetStringMapString(params.Tags),
},
&apiRHELAI.RHELAIArgs{
Prefix: "main",
Version: viper.GetString(params.RhelAIVersion),
Accelerator: viper.GetString(params.RhelAIAccelerator),
CustomAMI: viper.GetString(params.RhelAIAMICustom),
ComputeRequest: params.ComputeRequestArgs(),
Spot: params.SpotArgs(),
Timeout: viper.GetString(params.Timeout),
})
},
}
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc)
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
flagSet.StringP(params.RhelAIVersion, "", params.RhelAIVersionDefault, params.RhelAIVersionDesc)
flagSet.StringP(params.RhelAIAccelerator, "", params.RhelAIAccelearatorDefault, params.RhelAIAccelearatorDesc)
flagSet.StringP(params.RhelAIAMICustom, "", "", params.RhelAIAMICustomDesc)
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
params.AddComputeRequestFlags(flagSet)
params.AddSpotFlags(flagSet)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}

func getRHELAIDestroy() *cobra.Command {
c := &cobra.Command{
Use: params.DestroyCmdName,
Short: params.DestroyCmdName,
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return err
}
return rhelai.Destroy(&maptContext.ContextArgs{
Context: cmd.Context(),
ProjectName: viper.GetString(params.ProjectName),
BackedURL: viper.GetString(params.BackedURL),
Debug: viper.IsSet(params.Debug),
DebugLevel: viper.GetUint(params.DebugLevel),
Serverless: viper.IsSet(params.Serverless),
ForceDestroy: viper.IsSet(params.ForceDestroy),
KeepState: viper.IsSet(params.KeepState),
})
},
}
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
flagSet.Bool(params.ForceDestroy, false, params.ForceDestroyDesc)
flagSet.Bool(params.KeepState, false, params.KeepStateDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
31 changes: 17 additions & 14 deletions cmd/mapt/cmd/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,23 @@ const (
cirrusPWLabelsDesc string = "additional labels to use on the persistent worker (--it-cirrus-pw-labels key1=value1,key2=value2)"

//RHEL
SubsUsername string = "rh-subscription-username"
SubsUsernameDesc string = "username to register the subscription"
SubsUserpass string = "rh-subscription-password"
SubsUserpassDesc string = "password to register the subscription"
ProfileSNC string = "snc"
ProfileSNCDesc string = "if this flag is set the RHEL will be setup with SNC profile. Setting up all requirements to run https://github.com/crc-org/snc"
RhelVersion string = "version"
RhelVersionDesc string = "version for the RHEL OS"
RhelVersionDefault string = "9.4"
RhelAIVersion string = "version"
RhelAIVersionDesc string = "version for the RHELAI OS"
RhelAIVersionDefault string = "3.0.0"
RhelAIAMICustom string = "custom-ami"
RhelAIAMICustomDesc string = "custom AMI to spin RHEL AI OS"
SubsUsername string = "rh-subscription-username"
SubsUsernameDesc string = "username to register the subscription"
SubsUserpass string = "rh-subscription-password"
SubsUserpassDesc string = "password to register the subscription"
ProfileSNC string = "snc"
ProfileSNCDesc string = "if this flag is set the RHEL will be setup with SNC profile. Setting up all requirements to run https://github.com/crc-org/snc"
RhelVersion string = "version"
RhelVersionDesc string = "version for the RHEL OS"
RhelVersionDefault string = "9.4"
RhelAIVersion string = "version"
RhelAIVersionDesc string = "version for the RHELAI OS"
RhelAIVersionDefault string = "3.0.0"
RhelAIAccelerator string = "accelerator"
RhelAIAccelearatorDesc string = "accelerator type. Valid types: cuda and rocm"
RhelAIAccelearatorDefault string = "cuda"
RhelAIAMICustom string = "custom-ami"
RhelAIAMICustomDesc string = "custom AMI to spin RHEL AI OS"

// Serverless
Timeout string = "timeout"
Expand Down
6 changes: 3 additions & 3 deletions pkg/provider/aws/action/rhel-ai/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
// amiProduct = "Red Hat Enterprise Linux"
amiProduct = "Linux/UNIX"
amiV1Regex = "rhel-ai-nvidia-aws-%s-*"
amiRegex = "rhel-ai-cuda-aws-%s-*"
amiRegex = "rhel-ai-%s-aws-%s-*"
amiOwner = "610952687893"
// amiOwnerSelf = "self"
amiArch = "x86_64"
Expand Down Expand Up @@ -48,10 +48,10 @@ var (
outputUserPrivateKey = "ardPrivatekey"
)

func amiName(version *string) string {
func amiName(accelerator, version *string) string {
return util.If(strings.HasPrefix(*version, "1"),
fmt.Sprintf(amiV1Regex, *version),
fmt.Sprintf(amiRegex, *version))
fmt.Sprintf(amiRegex, *accelerator, *version))
}

// NVIDIA A100 X2
Expand Down
34 changes: 8 additions & 26 deletions pkg/provider/aws/action/rhel-ai/rhelai.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/redhat-developer/mapt/pkg/manager"
mc "github.com/redhat-developer/mapt/pkg/manager/context"
infra "github.com/redhat-developer/mapt/pkg/provider"
cr "github.com/redhat-developer/mapt/pkg/provider/api/compute-request"
spotTypes "github.com/redhat-developer/mapt/pkg/provider/api/spot"
"github.com/redhat-developer/mapt/pkg/provider/aws"
awsConstants "github.com/redhat-developer/mapt/pkg/provider/aws/constants"
"github.com/redhat-developer/mapt/pkg/provider/aws/data"
Expand All @@ -26,32 +24,18 @@ import (
securityGroup "github.com/redhat-developer/mapt/pkg/provider/aws/services/ec2/security-group"
"github.com/redhat-developer/mapt/pkg/provider/util/command"
"github.com/redhat-developer/mapt/pkg/provider/util/output"
apiRHELAI "github.com/redhat-developer/mapt/pkg/targets/host/rhelai"
"github.com/redhat-developer/mapt/pkg/util"
"github.com/redhat-developer/mapt/pkg/util/logging"
resourcesUtil "github.com/redhat-developer/mapt/pkg/util/resources"
)

type RHELAIArgs struct {
Prefix string
Version string
CustomAMI string
Arch string
ComputeRequest *cr.ComputeRequestArgs
SubsUsername string
SubsUserpass string
Spot *spotTypes.SpotArgs
// If timeout is set a severless scheduled task will be created to self destroy the resources
Timeout string
}

type rhelAIRequest struct {
mCtx *mc.Context
prefix *string
amiName *string
arch *string
spot bool
subsUsername *string
subsUserpass *string
timeout *string
allocationData *allocation.AllocationResult
}
Expand All @@ -68,26 +52,24 @@ func (r *rhelAIRequest) validate() error {
// Create orchestrate 2 stacks:
// If spot is enable it will run best spot option to get the best option to spin the machine
// Then it will run the stack for windows dedicated host
func Create(mCtxArgs *mc.ContextArgs, args *RHELAIArgs) (err error) {
func Create(mCtxArgs *mc.ContextArgs, args *apiRHELAI.RHELAIArgs) (err error) {
// Create mapt Context
mCtx, err := mc.Init(mCtxArgs, aws.Provider())
if err != nil {
return err
}
// Compose request
amiName := amiName(&args.Version)
amiName := amiName(&args.Accelerator, &args.Version)
if len(args.CustomAMI) != 0 {
amiName = fmt.Sprintf("%s*", args.CustomAMI)
}
prefix := util.If(len(args.Prefix) > 0, args.Prefix, "main")
r := rhelAIRequest{
mCtx: mCtx,
prefix: &prefix,
amiName: &amiName,
arch: &args.Arch,
timeout: &args.Timeout,
subsUsername: &args.SubsUsername,
subsUserpass: &args.SubsUserpass}
mCtx: mCtx,
prefix: &prefix,
amiName: &amiName,
arch: &args.Arch,
timeout: &args.Timeout}
if args.Spot != nil {
r.spot = args.Spot.Spot
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/provider/azure/action/kind/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,7 @@ func (r *kindRequest) deployer(ctx *pulumi.Context) error {
NetworkInteface: n.NetworkInterface,
// Check this
VMSize: r.allocationData.ComputeSizes[0],
Publisher: r.allocationData.ImageRef.Publisher,
Offer: r.allocationData.ImageRef.Offer,
Sku: r.allocationData.ImageRef.Sku,
ImageID: r.allocationData.ImageRef.ID,
Image: r.allocationData.ImageRef,
PrivateKey: privateKey,
SpotPrice: r.allocationData.Price,
UserDataAsBase64: udB64,
Expand Down
Loading