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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ VERSION ?= 1.0.0-dev
CONTAINER_MANAGER ?= podman

# Image URL to use all building/pushing image targets
IMG ?= quay.io/redhat-developer/mapt:v${VERSION}
TKN_IMG ?= quay.io/redhat-developer/mapt:v${VERSION}-tkn
IMG ?= ghcr.io/redhat-developer/mapt:pr-421
TKN_IMG ?= ghcr.io/redhat-developer/mapt:pr-421-tkn

# Integrations
# renovate: datasource=github-releases depName=cirruslabs/cirrus-cli
Expand Down
75 changes: 54 additions & 21 deletions cmd/mapt/cmd/aws/services/mac-pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
cmdHousekeep = "house-keep"
cmdHousekeepDesc = "house keeping for mac pool. Detroy old machines on over capacity and create new ones if capacity not meet"

// Pool params
paramName = "name"
paramNameDesc = "pool name it is a unique identifier for the pool. The name should be unique for the whole AWS account"
paramOfferedCapacity = "offered-capacity"
Expand All @@ -28,6 +29,17 @@ const (
paramMaxSize = "max-size"
paramMaxSizeDesc = "max number of machines in the pool"
paramMaxSizeDefault = 2
// Machines in the pool params
paramVPCID = "vpcid"
paramVPCIDDesc = "VPC Id to setup mac machines"
paramVPCIDDefault = ""
paramSSHSGID = "ssh-sgid"
paramSSHSGIDDesc = "Security group Id to securize ssh access to machines. SSH can only be used from instances with this SG."
paramSSHSGIDDefault = ""
// Request / Release
paramTicket = "ticket"
paramTicketDesc = "this is a unique identifier to tag the dedicated host meanwhile it is being locked to identify the request which locked it. It will be used on release to identify the machine being released"
paramTicketDefault = ""
)

func GetMacPoolCmd() *cobra.Command {
Expand Down Expand Up @@ -67,14 +79,13 @@ func createMP() *cobra.Command {
DebugLevel: viper.GetUint(params.DebugLevel),
Tags: viper.GetStringMapString(params.Tags),
},
&macpool.MacPoolRequestArgs{
&macpool.PoolRequestArgs{
Prefix: "main",
PoolName: viper.GetString(paramName),
Name: viper.GetString(paramName),
Architecture: viper.GetString(awsParams.MACArch),
OSVersion: viper.GetString(awsParams.MACOSVersion),
OfferedCapacity: viper.GetInt(paramOfferedCapacity),
MaxSize: viper.GetInt(paramMaxSize),
FixedLocation: viper.IsSet(awsParams.MACFixedLocation)}); err != nil {
MaxSize: viper.GetInt(paramMaxSize)}); err != nil {
logging.Error(err)
}
return nil
Expand All @@ -89,7 +100,6 @@ func createMP() *cobra.Command {
flagSet.StringP(awsParams.MACArch, "", awsParams.MACArchDefault, awsParams.MACArchDesc)
flagSet.StringP(awsParams.MACOSVersion, "", awsParams.MACOSVersionDefault, awsParams.MACOSVersionDesc)
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
flagSet.Bool(awsParams.MACFixedLocation, false, awsParams.MACFixedLocationDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
Expand Down Expand Up @@ -138,28 +148,35 @@ func houseKeep() *cobra.Command {
DebugLevel: viper.GetUint(params.DebugLevel),
Tags: viper.GetStringMapString(params.Tags),
},
&macpool.MacPoolRequestArgs{
Prefix: "main",
PoolName: viper.GetString(paramName),
Architecture: viper.GetString(awsParams.MACArch),
OSVersion: viper.GetString(awsParams.MACOSVersion),
OfferedCapacity: viper.GetInt(paramOfferedCapacity),
MaxSize: viper.GetInt(paramMaxSize),
FixedLocation: viper.IsSet(awsParams.MACFixedLocation)}); err != nil {
&macpool.HouseKeepRequestArgs{
Pool: &macpool.PoolRequestArgs{
Prefix: "main",
Name: viper.GetString(paramName),
Architecture: viper.GetString(awsParams.MACArch),
OSVersion: viper.GetString(awsParams.MACOSVersion),
OfferedCapacity: viper.GetInt(paramOfferedCapacity),
MaxSize: viper.GetInt(paramMaxSize),
},
Machine: &macpool.MachineRequestArgs{
VPCID: viper.GetString(paramVPCID),
SSHSGID: viper.GetString(paramSSHSGID)},
}); err != nil {
logging.Error(err)
}
return nil
},
}
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
params.AddCommonFlags(flagSet)
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
flagSet.StringP(paramName, "", "", paramNameDesc)
flagSet.Int(paramOfferedCapacity, paramOfferedCapacityDefault, paramOfferedCapacityDesc)
flagSet.Int(paramMaxSize, paramMaxSizeDefault, paramMaxSizeDesc)
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(params.Serverless, false, params.ServerlessDesc)
flagSet.StringP(paramVPCID, "", paramVPCIDDefault, paramVPCIDDesc)
flagSet.StringP(paramSSHSGID, "", paramSSHSGIDDefault, paramSSHSGIDDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
Expand All @@ -177,6 +194,8 @@ func request() *cobra.Command {
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
Debug: viper.IsSet(params.Debug),
DebugLevel: viper.GetUint(params.DebugLevel),
Serverless: viper.IsSet(params.Serverless),
Remote: viper.IsSet(params.Remote),
Tags: viper.GetStringMapString(params.Tags),
}

Expand Down Expand Up @@ -207,7 +226,12 @@ func request() *cobra.Command {
PoolName: viper.GetString(paramName),
Architecture: viper.GetString(awsParams.MACArch),
OSVersion: viper.GetString(awsParams.MACOSVersion),
Timeout: viper.GetString(params.Timeout),
Machine: &macpool.MachineRequestArgs{
VPCID: viper.GetString(paramVPCID),
SSHSGID: viper.GetString(paramSSHSGID),
},
Ticket: viper.GetString(paramTicket),
Timeout: viper.GetString(params.Timeout),
}); err != nil {
logging.Error(err)
}
Expand All @@ -221,6 +245,11 @@ func request() *cobra.Command {
flagSet.StringP(awsParams.MACArch, "", awsParams.MACArchDefault, awsParams.MACArchDesc)
flagSet.StringP(awsParams.MACOSVersion, "", awsParams.MACOSVersion, awsParams.MACOSVersionDefault)
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
flagSet.StringP(paramVPCID, "", paramVPCIDDefault, paramVPCIDDesc)
flagSet.StringP(paramSSHSGID, "", paramSSHSGIDDefault, paramSSHSGIDDesc)
flagSet.StringP(paramTicket, "", paramTicketDefault, paramTicketDesc)
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
flagSet.Bool(params.Remote, false, params.RemoteDesc)
flagSet.AddFlagSet(params.GetGHActionsFlagset())
params.AddCirrusFlags(flagSet)
c.PersistentFlags().AddFlagSet(flagSet)
Expand All @@ -241,20 +270,24 @@ func release() *cobra.Command {
Debug: viper.IsSet(params.Debug),
DebugLevel: viper.GetUint(params.DebugLevel),
Serverless: viper.IsSet(params.Serverless),
Remote: viper.IsSet(params.Remote),
},
viper.GetString(awsParams.MACDHID)); err != nil {
&macpool.MachineRequestArgs{
VPCID: viper.GetString(paramVPCID),
SSHSGID: viper.GetString(paramSSHSGID),
},
viper.GetString(paramTicket)); err != nil {
logging.Error(err)
}
return nil
},
}
flagSet := pflag.NewFlagSet(awsParams.MACReleaseCmd, pflag.ExitOnError)
flagSet.StringP(awsParams.MACDHID, "", "", awsParams.MACDHIDDesc)
flagSet.StringP(paramVPCID, "", paramVPCIDDefault, paramVPCIDDesc)
flagSet.StringP(paramSSHSGID, "", paramSSHSGIDDefault, paramSSHSGIDDesc)
flagSet.StringP(paramTicket, "", paramTicketDefault, paramTicketDesc)
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
flagSet.Bool(params.Remote, false, params.RemoteDesc)
c.PersistentFlags().AddFlagSet(flagSet)
err := c.MarkPersistentFlagRequired(awsParams.MACDHID)
if err != nil {
logging.Error(err)
}
return c
}
7 changes: 5 additions & 2 deletions cmd/mapt/cmd/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ const (
RhelVersionDefault string = "9.4"

// Serverless
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."
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."
// TODO we should be able to know if it is being executed serverless just checking the ENVs??
Serverless string = "serverless"
ServerlessDesc string = "if serverless is set the command will be executed as a serverless action."
Remote string = "remote"
RemoteDesc string = "run the action remote through a servlerss execution."

// Desytoy
ForceDestroy string = "force-destroy"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/aws/aws-sdk-go-v2 v1.36.3
github.com/aws/aws-sdk-go-v2/config v1.29.14
github.com/aws/aws-sdk-go-v2/service/ec2 v1.222.0
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.26.3
github.com/aws/aws-sdk-go-v2/service/s3 v1.79.3
github.com/pulumi/pulumi-aws-native/sdk v1.28.0
github.com/pulumi/pulumi-aws/sdk/v6 v6.81.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.15 h1:moLQUoVq91Liq
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.15/go.mod h1:ZH34PJUc8ApjBIfgQCFvkWcUDBtl/WTD+uiYHjd8igA=
github.com/aws/aws-sdk-go-v2/service/pricing v1.34.3 h1:vAv0hi3SWcc8cotkWRP4mPkmRbp/XqWKFyPW4Nwpzv0=
github.com/aws/aws-sdk-go-v2/service/pricing v1.34.3/go.mod h1:giTP9ufzBQJRB6bc7P30PO8s35hCp6au5uM70zkohU4=
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.26.3 h1:P87jejqS8WvQvRWyXlHUylt99VXt0y/WUIFuU6gBU7A=
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.26.3/go.mod h1:cgPfPTC/V3JqwCKed7Q6d0FrgarV7ltz4Bz6S4Q+Dqk=
github.com/aws/aws-sdk-go-v2/service/s3 v1.79.3 h1:BRXS0U76Z8wfF+bnkilA2QwpIch6URlm++yPUt9QPmQ=
github.com/aws/aws-sdk-go-v2/service/s3 v1.79.3/go.mod h1:bNXKFFyaiVvWuR6O16h/I1724+aXe/tAkA9/QS01t5k=
github.com/aws/aws-sdk-go-v2/service/sso v1.25.3 h1:1Gw+9ajCV1jogloEv1RRnvfRFia2cL6c9cuKV2Ps+G8=
Expand Down
24 changes: 12 additions & 12 deletions pkg/integrations/cirrus/persistentworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (args *PersistentWorkerArgs) GetUserDataValues() *integrations.UserDataValu
CliURL: downloadURL(),
Name: pwa.Name,
Token: pwa.Token,
Labels: getLabelsAsString(),
Labels: GetLabelsAsString(),
Port: cirrusPort,
}
}
Expand Down Expand Up @@ -74,18 +74,8 @@ func GetToken() string {
"")
}

// platform: darwin, linux, windows
// arch: amd64, arm64
func downloadURL() string {
url := fmt.Sprintf(baseURL, version, *pwa.Platform, *pwa.Arch)
if pwa.Platform == &Windows {
url = fmt.Sprintf("%s.exe", url)
}
return url
}

// Get labels in format
func getLabelsAsString() string {
func GetLabelsAsString() string {
return util.IfNillable(pwa != nil,
func() string {
if len(pwa.Labels) > 0 {
Expand All @@ -101,3 +91,13 @@ func getLabelsAsString() string {
},
"")
}

// platform: darwin, linux, windows
// arch: amd64, arm64
func downloadURL() string {
url := fmt.Sprintf(baseURL, version, *pwa.Platform, *pwa.Arch)
if pwa.Platform == &Windows {
url = fmt.Sprintf("%s.exe", url)
}
return url
}
22 changes: 22 additions & 0 deletions pkg/manager/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type ContextArgs struct {
Serverless bool
// This forces destroy even when lock exists
ForceDestroy bool
// If remote is set we will run the action through the serverless task spec
Remote bool
// integrations
GHRunnerArgs *github.GithubRunnerArgs
CirrusPWArgs *cirrus.PersistentWorkerArgs
Expand All @@ -58,15 +60,19 @@ type context struct {
serverless bool
forceDestroy bool
spotPriceIncreaseRate int
remote bool
tags map[string]string
tagsAsPulumiStringMap pulumi.StringMap
// This will be set if we need specific customization on a specfici execution
provider Provider
}

// mapt context
var mc *context

type Provider interface {
Init(backedURL string) error
Custom(ctx *pulumi.Context) (*pulumi.ProviderResource, error)
}

func Init(ca *ContextArgs, provider Provider) error {
Expand All @@ -81,6 +87,8 @@ func Init(ca *ContextArgs, provider Provider) error {
serverless: ca.Serverless,
forceDestroy: ca.ForceDestroy,
spotPriceIncreaseRate: ca.SpotPriceIncreaseRate,
remote: ca.Remote,
provider: provider,
}
addCommonTags()
// Init provider
Expand Down Expand Up @@ -119,6 +127,20 @@ func IsForceDestroy() bool { return mc.forceDestroy }

func SpotPriceIncreaseRate() int { return mc.spotPriceIncreaseRate }

func IsRemote() bool { return mc.remote }

func CommonOptions(ctx *pulumi.Context) (co []pulumi.ResourceOption) {
// Check if provider requires customization
cp, err := mc.provider.Custom(ctx)
if cp != nil {
co = append(co, pulumi.Provider(*cp))
}
if err != nil {
logging.Errorf("Error registering custom provider %v", err)
}
return
}

// It will create a runID
// if context has been intialized it will set it as the runID for the context
// otherwise it will return the value (one time value)
Expand Down
1 change: 1 addition & 0 deletions pkg/provider/aws/action/fedora/fedora.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func (r *fedoraRequest) deploy(ctx *pulumi.Context) error {
c.GetHostIP(!*r.airgap))
if len(*r.timeout) > 0 {
if err = serverless.OneTimeDelayedTask(ctx,
fmt.Sprintf("fedora-timeout-%s", maptContext.RunID()),
*r.allocationData.Region, *r.prefix,
awsFedoraDedicatedID,
fmt.Sprintf("aws %s destroy --project-name %s --backed-url %s --serverless",
Expand Down
1 change: 1 addition & 0 deletions pkg/provider/aws/action/kind/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (r *kindRequest) deploy(ctx *pulumi.Context) error {
c.GetHostIP(true))
if len(*r.timeout) > 0 {
if err = serverless.OneTimeDelayedTask(ctx,
fmt.Sprintf("kind-destroy-%s", maptContext.RunID()),
*r.allocationData.Region, *r.prefix,
awsKindID,
fmt.Sprintf("aws %s destroy --project-name %s --backed-url %s --serverless --force-destroy",
Expand Down
Loading