-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2853 from bryan-cox/HOSTEDCP-1029
HOSTEDCP-1029: Add HCP CLI Command to Destroy a Cluster on AWS
- Loading branch information
Showing
5 changed files
with
119 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package aws | ||
|
||
import ( | ||
"github.com/openshift/hypershift/cmd/cluster/core" | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func Test_ValidateCredentialInfo(t *testing.T) { | ||
tests := map[string]struct { | ||
inputOptions *core.DestroyOptions | ||
expectError bool | ||
}{ | ||
"when CredentialSecretName is blank and aws-creds is also blank": { | ||
inputOptions: &core.DestroyOptions{ | ||
CredentialSecretName: "", | ||
AWSPlatform: core.AWSPlatformDestroyOptions{ | ||
AWSCredentialsFile: "", | ||
}, | ||
}, | ||
expectError: true, | ||
}, | ||
"when CredentialSecretName is blank and aws-creds is not blank": { | ||
inputOptions: &core.DestroyOptions{ | ||
CredentialSecretName: "", | ||
AWSPlatform: core.AWSPlatformDestroyOptions{ | ||
AWSCredentialsFile: "asdf", | ||
}, | ||
}, | ||
expectError: false, | ||
}, | ||
} | ||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
g := NewGomegaWithT(t) | ||
err := ValidateCredentialInfo(test.inputOptions) | ||
if test.expectError { | ||
g.Expect(err).To(HaveOccurred()) | ||
} else { | ||
g.Expect(err).To(BeNil()) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package aws | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
hypershiftaws "github.com/openshift/hypershift/cmd/cluster/aws" | ||
"github.com/openshift/hypershift/cmd/cluster/core" | ||
"github.com/openshift/hypershift/cmd/log" | ||
) | ||
|
||
func NewDestroyCommand(opts *core.DestroyOptions) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "aws", | ||
Short: "Destroys a HostedCluster and its associated infrastructure on AWS.", | ||
SilenceUsage: true, | ||
} | ||
|
||
opts.AWSPlatform = core.AWSPlatformDestroyOptions{ | ||
AWSCredentialsFile: "", | ||
PreserveIAM: false, | ||
Region: "us-east-1", | ||
} | ||
|
||
cmd.Flags().StringVar(&opts.AWSPlatform.AWSCredentialsFile, "aws-creds", opts.AWSPlatform.AWSCredentialsFile, "Filepath to an AWS credentials file.") | ||
cmd.Flags().BoolVar(&opts.AWSPlatform.PreserveIAM, "preserve-iam", opts.AWSPlatform.PreserveIAM, "If set to true, skip deleting IAM. Otherwise, destroy any default generated IAM along with other infrastructure.") | ||
cmd.Flags().StringVar(&opts.AWSPlatform.Region, "region", opts.AWSPlatform.Region, "A HostedCluster's region.") | ||
cmd.Flags().StringVar(&opts.AWSPlatform.BaseDomain, "base-domain", opts.AWSPlatform.BaseDomain, "A HostedCluster's base domain.") | ||
cmd.Flags().StringVar(&opts.AWSPlatform.BaseDomainPrefix, "base-domain-prefix", opts.AWSPlatform.BaseDomainPrefix, "A HostedCluster's base domain prefix.") | ||
cmd.Flags().StringVar(&opts.CredentialSecretName, "secret-creds", opts.CredentialSecretName, "A Kubernetes secret with a platform credentials: pull-secret and base-domain. The secret must exist in the supplied \"--namespace\".") | ||
|
||
cmd.RunE = func(cmd *cobra.Command, args []string) error { | ||
err := hypershiftaws.ValidateCredentialInfo(opts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err = hypershiftaws.DestroyCluster(cmd.Context(), opts); err != nil { | ||
log.Log.Error(err, "Failed to destroy cluster") | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters