Skip to content
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
2 changes: 2 additions & 0 deletions cmd/mapt/cmd/aws/hosts/fedora.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ func getFedoraDestroy() *cobra.Command {
DebugLevel: viper.GetUint(params.DebugLevel),
Serverless: viper.IsSet(params.Serverless),
ForceDestroy: viper.IsSet(params.ForceDestroy),
CleanupState: viper.IsSet(params.CleanupState),
})
},
}
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
flagSet.Bool(params.ForceDestroy, false, params.ForceDestroyDesc)
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
6 changes: 4 additions & 2 deletions cmd/mapt/cmd/aws/hosts/mac.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,16 @@ func getMacDestroy() *cobra.Command {
}
return mac.Destroy(
&maptContext.ContextArgs{
Debug: viper.IsSet(params.Debug),
DebugLevel: viper.GetUint(params.DebugLevel),
Debug: viper.IsSet(params.Debug),
DebugLevel: viper.GetUint(params.DebugLevel),
CleanupState: viper.IsSet(params.CleanupState),
},
viper.GetString(awsParams.MACDHID))
},
}
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
flagSet.StringP(awsParams.MACDHID, "", "", awsParams.MACDHIDDesc)
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
c.PersistentFlags().AddFlagSet(flagSet)
err := c.MarkPersistentFlagRequired(awsParams.MACDHID)
if err != nil {
Expand Down
12 changes: 7 additions & 5 deletions cmd/mapt/cmd/aws/hosts/rhel.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,18 @@ func getRHELDestroy() *cobra.Command {
return err
}
return rhel.Destroy(&maptContext.ContextArgs{
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),
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),
CleanupState: viper.IsSet(params.CleanupState),
})
},
}
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
2 changes: 2 additions & 0 deletions cmd/mapt/cmd/aws/hosts/rhelai.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ func getRHELAIDestroy() *cobra.Command {
DebugLevel: viper.GetUint(params.DebugLevel),
Serverless: viper.IsSet(params.Serverless),
ForceDestroy: viper.IsSet(params.ForceDestroy),
CleanupState: viper.IsSet(params.CleanupState),
})
},
}
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
flagSet.Bool(params.ForceDestroy, false, params.ForceDestroyDesc)
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
15 changes: 10 additions & 5 deletions cmd/mapt/cmd/aws/hosts/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,22 @@ func getWindowsDestroy() *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 windows.Destroy(&maptContext.ContextArgs{
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),
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),
CleanupState: viper.IsSet(params.CleanupState),
})
},
}
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
15 changes: 10 additions & 5 deletions cmd/mapt/cmd/aws/services/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func getCreateEKS() *cobra.Command {
}

func getDestroyEKS() *cobra.Command {
return &cobra.Command{
c := &cobra.Command{
Use: params.DestroyCmdName,
Short: params.DestroyCmdName,
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -107,11 +107,16 @@ func getDestroyEKS() *cobra.Command {
}
return awsEKS.Destroy(
&maptContext.ContextArgs{
ProjectName: viper.GetString(params.ProjectName),
BackedURL: viper.GetString(params.BackedURL),
Debug: viper.IsSet(params.Debug),
DebugLevel: viper.GetUint(params.DebugLevel),
ProjectName: viper.GetString(params.ProjectName),
BackedURL: viper.GetString(params.BackedURL),
Debug: viper.IsSet(params.Debug),
DebugLevel: viper.GetUint(params.DebugLevel),
CleanupState: viper.IsSet(params.CleanupState),
})
},
}
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
2 changes: 2 additions & 0 deletions cmd/mapt/cmd/aws/services/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ func destroyKind() *cobra.Command {
DebugLevel: viper.GetUint(params.DebugLevel),
Serverless: viper.IsSet(params.Serverless),
ForceDestroy: viper.IsSet(params.ForceDestroy),
CleanupState: viper.IsSet(params.CleanupState),
})
},
}
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
flagSet.Bool(params.ForceDestroy, false, params.ForceDestroyDesc)
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
10 changes: 6 additions & 4 deletions cmd/mapt/cmd/aws/services/mac-pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,17 @@ func destroyMP() *cobra.Command {
return err
}
return macpool.Destroy(&maptContext.ContextArgs{
ProjectName: viper.GetString(params.ProjectName),
BackedURL: viper.GetString(params.BackedURL),
Debug: viper.IsSet(params.Debug),
DebugLevel: viper.GetUint(params.DebugLevel),
ProjectName: viper.GetString(params.ProjectName),
BackedURL: viper.GetString(params.BackedURL),
Debug: viper.IsSet(params.Debug),
DebugLevel: viper.GetUint(params.DebugLevel),
CleanupState: viper.IsSet(params.CleanupState),
})
},
}
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
params.AddCommonFlags(flagSet)
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
Expand Down
12 changes: 7 additions & 5 deletions cmd/mapt/cmd/aws/services/openshift-snc.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,18 @@ func destroySNC() *cobra.Command {
return err
}
return openshiftsnc.Destroy(&maptContext.ContextArgs{
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),
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),
CleanupState: viper.IsSet(params.CleanupState),
})
},
}
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
4 changes: 3 additions & 1 deletion cmd/mapt/cmd/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ const (
Serverless string = "serverless"
ServerlessDesc string = "if serverless is set the command will be executed as a serverless action."

// Desytoy
// Destroy
ForceDestroy string = "force-destroy"
ForceDestroyDesc string = "if force-destroy is set the command will destroy even if there is a lock."
CleanupState string = "cleanup-state"
CleanupStateDesc string = "automatically remove Pulumi state files from S3 backend after successful destroy"

// Kind
KindCmd = "kind"
Expand Down
6 changes: 6 additions & 0 deletions pkg/manager/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type ContextArgs struct {
Serverless bool
// This forces destroy even when lock exists
ForceDestroy bool
// Automatically remove Pulumi state files from backend after successful destroy
CleanupState bool
// integrations
GHRunnerArgs *github.GithubRunnerArgs
CirrusPWArgs *cirrus.PersistentWorkerArgs
Expand All @@ -57,6 +59,7 @@ type Context struct {
debugLevel uint
serverless bool
forceDestroy bool
cleanupState bool
// spotPriceIncreaseRate int
tags map[string]string
tagsAsPulumiStringMap pulumi.StringMap
Expand All @@ -83,6 +86,7 @@ func Init(ca *ContextArgs, provider Provider) (*Context, error) {
tags: ca.Tags,
serverless: ca.Serverless,
forceDestroy: ca.ForceDestroy,
cleanupState: ca.CleanupState,
}
addCommonTags(c)
hp, err := provider.DefaultHostingPlace()
Expand Down Expand Up @@ -126,6 +130,8 @@ func (c *Context) IsServerless() bool { return c.serverless }

func (c *Context) IsForceDestroy() bool { return c.forceDestroy }

func (c *Context) IsCleanupState() bool { return c.cleanupState }

func (c *Context) TargetHostingPlace() string { return c.targetHostingPlace }

// Get tags ready to be added to any pulumi resource
Expand Down
9 changes: 7 additions & 2 deletions pkg/provider/aws/action/eks/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,17 @@ func Destroy(ctx *mc.ContextArgs) error {
if err != nil {
return err
}
return aws.DestroyStack(
if err := aws.DestroyStack(
mCtx,
aws.DestroyStackRequest{
BackedURL: mCtx.BackedURL(),
Stackname: stackName,
})
}); err != nil {
return err
}

// Cleanup S3 state after all stacks have been destroyed
return aws.CleanupState(mCtx)
}

// Main function to deploy all requried resources to AWS
Expand Down
8 changes: 6 additions & 2 deletions pkg/provider/aws/action/fedora/fedora.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,13 @@ func Destroy(c *mc.ContextArgs) (err error) {

// Destroy spot orchestrated stack
if spot.Exist(mCtx) {
return spot.Destroy(mCtx)
if err := spot.Destroy(mCtx); err != nil {
return err
}
}
return nil

// Cleanup S3 state after all stacks have been destroyed
return aws.CleanupState(mCtx)
}

func (r *fedoraRequest) createMachine() error {
Expand Down
8 changes: 6 additions & 2 deletions pkg/provider/aws/action/kind/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ func Destroy(mCtxArgs *mc.ContextArgs) (err error) {
return err
}
if spot.Exist(mCtx) {
return spot.Destroy(mCtx)
if err := spot.Destroy(mCtx); err != nil {
return err
}
}
return nil

// Cleanup S3 state after all stacks have been destroyed
return aws.CleanupState(mCtx)
}

func (r *kindRequest) createHost() (*utilKind.KindResults, error) {
Expand Down
7 changes: 6 additions & 1 deletion pkg/provider/aws/action/mac-pool/mac-pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ func Destroy(mCtxArgs *mc.ContextArgs) error {
if err := iam.Destroy(mCtx); err != nil {
return err
}
return serverless.Destroy(mCtx)
if err := serverless.Destroy(mCtx); err != nil {
return err
}

// Cleanup S3 state after all stacks have been destroyed
return aws.CleanupState(mCtx)
}

// House keeper is the function executed serverless to check if is there any
Expand Down
9 changes: 7 additions & 2 deletions pkg/provider/aws/action/mac/mac.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,19 @@ func Destroy(mCtxArgs *mc.ContextArgs, hostID string) error {
}); err != nil {
return err
}
return aws.DestroyStack(
if err := aws.DestroyStack(
mCtx,
aws.DestroyStackRequest{
Stackname: mac.StackDedicatedHost,
// TODO check if needed to add region for backedURL
Region: *hi.Region,
BackedURL: *hi.BackedURL,
})
}); err != nil {
return err
}

// Cleanup S3 state after all stacks have been destroyed
return aws.CleanupState(mCtx)
}
logging.Debug("nothing to be destroyed")
return nil
Expand Down
8 changes: 6 additions & 2 deletions pkg/provider/aws/action/openshift-snc/openshift-snc.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,13 @@ func Destroy(mCtxArgs *mc.ContextArgs) (err error) {
}
// Destroy spot orchestrated stack
if spot.Exist(mCtx) {
return spot.Destroy(mCtx)
if err := spot.Destroy(mCtx); err != nil {
return err
}
}
return nil

// Cleanup S3 state after all stacks have been destroyed
return aws.CleanupState(mCtx)
}

func (r *openshiftSNCRequest) createCluster() (*OpenshiftSncResultsMetadata, error) {
Expand Down
8 changes: 6 additions & 2 deletions pkg/provider/aws/action/rhel-ai/rhelai.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,13 @@ func Destroy(mCtxArgs *mc.ContextArgs) error {
return err
}
if spot.Exist(mCtx) {
return spot.Destroy(mCtx)
if err := spot.Destroy(mCtx); err != nil {
return err
}
}
return nil

// Cleanup S3 state after all stacks have been destroyed
return aws.CleanupState(mCtx)
}

func (r *rhelAIRequest) createMachine() error {
Expand Down
8 changes: 6 additions & 2 deletions pkg/provider/aws/action/rhel/rhel.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,13 @@ func Destroy(mCtxArgs *mc.ContextArgs) error {
return err
}
if spot.Exist(mCtx) {
return spot.Destroy(mCtx)
if err := spot.Destroy(mCtx); err != nil {
return err
}
}
return nil

// Cleanup S3 state after all stacks have been destroyed
return aws.CleanupState(mCtx)
}

func (r *rhelRequest) createMachine() error {
Expand Down
8 changes: 6 additions & 2 deletions pkg/provider/aws/action/windows/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,13 @@ func Destroy(mCtxArgs *mc.ContextArgs) (err error) {
}
}
if spot.Exist(mCtx) {
return spot.Destroy(mCtx)
if err := spot.Destroy(mCtx); err != nil {
return err
}
}
return nil

// Cleanup S3 state after all stacks have been destroyed
return aws.CleanupState(mCtx)
}

func (r *windowsServerRequest) createMachine() error {
Expand Down
Loading