From feb55f27c294ca588fe4ffa6aa757aaf89eca205 Mon Sep 17 00:00:00 2001 From: zhewang Date: Wed, 20 Nov 2024 12:30:37 +0800 Subject: [PATCH] OCM-11855 | test: Support bastion proxy --- README.md | 14 ++++++++++++ cmd/rosa-support/create/bastion/cmd.go | 31 ++++++++++++++++++++++++-- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bfbe490..b0652a5 100644 --- a/README.md +++ b/README.md @@ -78,4 +78,18 @@ git push origin v0.0.1 `$ rosa-support delete vpc --vpc-id --region ` +* Prepare bastion + * *--region* is required where created the vpc-id + * *--availability-zone* is required on which zone to launch the bastion instance + * *--vpc-id* is required which should be VPC id used to launch cluster + * *--keypair-name* is required to generate temporary used to launch the proxy instance + * *--private-key-path* is required to record the generated private ssh key + * *--cidr-block* is NOT required, only IP address within CIDR block can access other resources through bastion proxy(default is 0.0.0.0/0) + + `$ rosa-support create bastion --region us-east-2 --availability-zone us-east-2a --vpc-id --keypair-name --private-key-path ` + +* Destroy bastion,the bastion and related resources with VPC will be destroyed when clean VPC + + `$ rosa-support delete vpc --vpc-id --region ` + Note that a repository administrator may need to push the tag to the repository due to access restrictions. \ No newline at end of file diff --git a/cmd/rosa-support/create/bastion/cmd.go b/cmd/rosa-support/create/bastion/cmd.go index ab18c19..1c486cd 100644 --- a/cmd/rosa-support/create/bastion/cmd.go +++ b/cmd/rosa-support/create/bastion/cmd.go @@ -12,6 +12,8 @@ var args struct { region string vpcID string availabilityZone string + privateKeyPath string + keyPairName string cidr string } @@ -20,7 +22,8 @@ var Cmd = &cobra.Command{ Short: "Create bastion proxy", Long: "Create bastion proxy.", Example: ` # Create a bastion proxy in region 'us-east-2' - rosa-support create bastion --region us-east-2 --availability-zone us-east-2a --vpc-id `, + rosa-support create bastion --region us-east-2 --availability-zone us-east-2a --vpc-id --keypair-name +--private-key-path `, Run: run, } @@ -64,6 +67,30 @@ func init() { logger.LogError(err.Error()) os.Exit(1) } + flags.StringVarP( + &args.keyPairName, + "keypair-name", + "", + "", + "key pair will be created with the name (required)", + ) + err = Cmd.MarkFlagRequired("keypair-name") + if err != nil { + logger.LogError(err.Error()) + os.Exit(1) + } + flags.StringVarP( + &args.privateKeyPath, + "private-key-path", + "", + "", + "record generated private ssh key in the given path (required)", + ) + err = Cmd.MarkFlagRequired("private-key-path") + if err != nil { + logger.LogError(err.Error()) + os.Exit(1) + } flags.StringVarP( &args.cidr, "cidr-block", @@ -79,7 +106,7 @@ func run(cmd *cobra.Command, _ []string) { if err != nil { panic(err) } - instance, err := vpc.PrepareBastionProxy(args.availabilityZone, args.cidr) + instance, err := vpc.PrepareBastionProxy(args.availabilityZone, args.cidr, args.keyPairName, args.privateKeyPath) if err != nil { panic(err) } diff --git a/go.mod b/go.mod index 771a3e4..e4a8c0d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/openshift-online/rosa-support go 1.21 require ( - github.com/openshift-online/ocm-common v0.0.13 + github.com/openshift-online/ocm-common v0.0.14-0.20241121072829-c1150dfc4289 github.com/spf13/cobra v1.8.0 ) diff --git a/go.sum b/go.sum index 06bc315..64d1929 100644 --- a/go.sum +++ b/go.sum @@ -56,8 +56,8 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= -github.com/openshift-online/ocm-common v0.0.13 h1:FUn4PwuxOLsGbyJIC+izQQxYP3hA6dW5z/ep4HbTE4Q= -github.com/openshift-online/ocm-common v0.0.13/go.mod h1:6MWje2NFNJ3IWpGs7BYj6DWagWXHyp8EnmYY7XFTtI4= +github.com/openshift-online/ocm-common v0.0.14-0.20241121072829-c1150dfc4289 h1:CYX7p1cLo4+BwjHlJXHDP/zPiNit32b6YO6R0lGW+ZQ= +github.com/openshift-online/ocm-common v0.0.14-0.20241121072829-c1150dfc4289/go.mod h1:6MWje2NFNJ3IWpGs7BYj6DWagWXHyp8EnmYY7XFTtI4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=