From 9d3abd07c5cb0de9c00955e61abf4dc287d3affc 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 --- .github/workflows/check-pull-request.yml | 4 +-- Makefile | 2 +- README.md | 14 +++++++++ cmd/rosa-support/create/bastion/cmd.go | 36 ++++++++++++++++++++---- cmd/rosa-support/create/proxy/cmd.go | 12 ++++---- cmd/rosa-support/create/sg/cmd.go | 4 +-- cmd/rosa-support/create/subnets/cmd.go | 6 ++-- cmd/rosa-support/create/vpc/cmd.go | 4 +-- cmd/rosa-support/delete/tag/cmd.go | 4 +-- cmd/rosa-support/delete/vpc/cmd.go | 4 +-- cmd/rosa-support/tag/cmd.go | 2 +- go.mod | 2 +- go.sum | 4 +-- 13 files changed, 69 insertions(+), 29 deletions(-) diff --git a/.github/workflows/check-pull-request.yml b/.github/workflows/check-pull-request.yml index d3d7460..07d83b8 100644 --- a/.github/workflows/check-pull-request.yml +++ b/.github/workflows/check-pull-request.yml @@ -51,12 +51,12 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version: '1.23.2' cache: false - name: Ensure dependencies are downloaded run: go mod download - name: golangci-lint uses: golangci/golangci-lint-action@v4 with: - version: v1.54 + version: v1.62.0 skip-cache: true \ No newline at end of file diff --git a/Makefile b/Makefile index 5b9aa9e..2015811 100644 --- a/Makefile +++ b/Makefile @@ -33,4 +33,4 @@ fmt: .PHONY: lint lint: - golangci-lint run --timeout 5m0s \ No newline at end of file + golangci-lint run --timeout 10m0s \ No newline at end of file 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..ef37b81 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,7 @@ 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, } @@ -37,7 +39,7 @@ func init() { ) err := Cmd.MarkFlagRequired("region") if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } flags.StringVarP( @@ -49,7 +51,7 @@ func init() { ) err = Cmd.MarkFlagRequired("vpc-id") if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } flags.StringVarP( @@ -61,7 +63,31 @@ func init() { ) err = Cmd.MarkFlagRequired("availability-zone") if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", 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("%s", 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("%s", err.Error()) os.Exit(1) } flags.StringVarP( @@ -79,7 +105,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/cmd/rosa-support/create/proxy/cmd.go b/cmd/rosa-support/create/proxy/cmd.go index 77b4b4d..275b29d 100644 --- a/cmd/rosa-support/create/proxy/cmd.go +++ b/cmd/rosa-support/create/proxy/cmd.go @@ -78,33 +78,33 @@ func init() { err := Cmd.MarkFlagRequired("vpc-id") if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } err = Cmd.MarkFlagRequired("region") if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } err = Cmd.MarkFlagRequired("availability-zone") if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } err = Cmd.MarkFlagRequired("ca-file") if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } err = Cmd.MarkFlagRequired("keypair-name") if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } err = Cmd.MarkFlagRequired("private-key-path") if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } } diff --git a/cmd/rosa-support/create/sg/cmd.go b/cmd/rosa-support/create/sg/cmd.go index 838af33..9e4b3d8 100644 --- a/cmd/rosa-support/create/sg/cmd.go +++ b/cmd/rosa-support/create/sg/cmd.go @@ -63,12 +63,12 @@ func init() { ) err := Cmd.MarkFlagRequired("vpc-id") if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } err = Cmd.MarkFlagRequired("region") if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } } diff --git a/cmd/rosa-support/create/subnets/cmd.go b/cmd/rosa-support/create/subnets/cmd.go index a8d4a62..2639164 100644 --- a/cmd/rosa-support/create/subnets/cmd.go +++ b/cmd/rosa-support/create/subnets/cmd.go @@ -39,7 +39,7 @@ func init() { ) err := Cmd.MarkFlagRequired("region") if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } flags.StringVarP( @@ -51,7 +51,7 @@ func init() { ) err = Cmd.MarkFlagRequired("availability-zones") if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } flags.StringVarP( @@ -63,7 +63,7 @@ func init() { ) err = Cmd.MarkFlagRequired("vpc-id") if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } } diff --git a/cmd/rosa-support/create/vpc/cmd.go b/cmd/rosa-support/create/vpc/cmd.go index 35313e9..bc1b84f 100644 --- a/cmd/rosa-support/create/vpc/cmd.go +++ b/cmd/rosa-support/create/vpc/cmd.go @@ -69,7 +69,7 @@ func init() { func run(cmd *cobra.Command, _ []string) { vpc, err := vpcClient.PrepareVPC(args.name, args.region, args.cidr, args.findExisting, "") if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } @@ -92,7 +92,7 @@ func run(cmd *cobra.Command, _ []string) { } _, err = vpc.AWSClient.TagResource(vpc.VpcID, tagMap) if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } } diff --git a/cmd/rosa-support/delete/tag/cmd.go b/cmd/rosa-support/delete/tag/cmd.go index 64ca2bc..a38f449 100644 --- a/cmd/rosa-support/delete/tag/cmd.go +++ b/cmd/rosa-support/delete/tag/cmd.go @@ -80,12 +80,12 @@ func init() { func run(_ *cobra.Command, _ []string) { client, err := awsClient.CreateAWSClient(args.profileName, args.region) if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } _, err = client.RemoveResourceTag(args.resourceID, args.tagKey, args.tagValue) if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } } diff --git a/cmd/rosa-support/delete/vpc/cmd.go b/cmd/rosa-support/delete/vpc/cmd.go index 26fac55..8d3713a 100644 --- a/cmd/rosa-support/delete/vpc/cmd.go +++ b/cmd/rosa-support/delete/vpc/cmd.go @@ -60,12 +60,12 @@ func init() { func run(cmd *cobra.Command, _ []string) { vpc, err := vpcClient.GenerateVPCByID(args.vpcID, args.region) if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } err = vpc.DeleteVPCChain(args.totalClean) if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } } diff --git a/cmd/rosa-support/tag/cmd.go b/cmd/rosa-support/tag/cmd.go index 223ada4..dd67476 100644 --- a/cmd/rosa-support/tag/cmd.go +++ b/cmd/rosa-support/tag/cmd.go @@ -57,7 +57,7 @@ func init() { for _, requiredFlag := range requiredFlags { err := Cmd.MarkFlagRequired(requiredFlag) if err != nil { - logger.LogError(err.Error()) + logger.LogError("%s", err.Error()) os.Exit(1) } } 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=