Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCM-10076 | bump ocm-common and fix readme to make it work #17

Merged
merged 1 commit into from
Aug 1, 2024
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: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ build: clean

.PHONY: install
install: clean
go build -o $(GOPATH)/bin/rosa-support -ldflags="$(ldflags)" ./cmd/rosa-support || exit 1
go build -o $(GOPATH)/bin/rosa-support -ldflags="$(ldflags)" . || exit 1

.PHONY: clean
clean:
Expand Down
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,50 @@ git pull
git tag -a -m 'Release 0.0.1' v0.0.1
git push origin v0.0.1
```
## Install from online
* Call below command to install the rosa-support command line tool
```$ go install github.com/openshift-online/rosa-support@latest```

* Put the go binary path to PATH env variable
```$ export PATH=$PATH:/$GOPATH/bin:/usr/local/bin```
## How to use the binary of rosa-support to create resources
* Check the help message

`$ rosa-support -h`

* Create a vpc on the indicated region
`$ rosa-support create vpc --region us-west-2 --name <your-alias>-vpc`
* When you have a vpc on the indicated region and you want to re-use it, if cannot find create it
`$ rosa-support create vpc --region us-west-2 --name <your-alias>-vpc --find-existing`

* Prepare a pair of subnets on the indicated zone of the region.
* NOTE: If the subnets had been existing, it will reuse the exsiting subnets in the zone
`$ ./rosa-support create subnets --region us-west-2 --availability-zones us-west-2a --vpc-id <vpc id>`

* Prepare proxy server
* *--region* is required where created the vpc-id
* *--vpc-id* is required which should be vpc id used to launch cluster
* *--availability-zone* is required on which zone to launch the proxy instance
* *--ca-file* is required which is a abs path used to record the ca-bundle file generated when 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

`$ rosa-support create proxy --region <region> --vpc-id <vpc-id> --availability-zone <az> --ca-file <abs path of ca file> --keypair-name <keypair name> --private-key-path <path>`

* Prepare addtional security groups, output the sg IDs with comma seperated

`$ rosa-support create security-groups --region <region> --vpc-id <vpc id> --count <security group number>`

* Tag a resource

`$ rosa-support tag --resource-id <resource id> --region <region> --tags aaa:ddd,fff:bbb`

* Delete a tag from a resource

`$ rosa-support delete tag --resource-id <resource id> --region <region> --tag-key <key> --tag-value <value>`

* Clean the vpc and the resources, there is a flag --total-clean supported to do a total clean even the resources is not created by this package

`$ rosa-support delete vpc --vpc-id <vpc id> --region <region>`

Note that a repository administrator may need to push the tag to the repository due to access restrictions.
8 changes: 4 additions & 4 deletions cmd/rosa-support/create/proxy/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func init() {
"vpc-id",
"",
"",
"Creates a pair of subnets (required)",
"vpc id is needed for instance launch",
)
flags.StringVarP(
&args.availabilityZone,
Expand All @@ -58,22 +58,22 @@ func init() {
"ca-file",
"",
"",
"Creates a proxy and stores the ca file (required)",
"Creates a proxy and stores the ca file (required) to the indicated file name",
)

flags.StringVarP(
&args.keyPairName,
"keypair-name",
"",
"",
"Create a key pair with the name (required)",
"key pair will be created with the name (required)",
)
flags.StringVarP(
&args.privateKeyPath,
"private-key-path",
"",
"",
"Stores key pair in the given path (required)",
"record generated private ssh key in the given path (required)",
)

err := Cmd.MarkFlagRequired("vpc-id")
Expand Down
2 changes: 1 addition & 1 deletion cmd/rosa-support/create/vpc/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func init() {
)
}
func run(cmd *cobra.Command, _ []string) {
vpc, err := vpcClient.PrepareVPC(args.name, args.region, args.cidr, args.findExisting)
vpc, err := vpcClient.PrepareVPC(args.name, args.region, args.cidr, args.findExisting, "")
if err != nil {
logger.LogError(err.Error())
os.Exit(1)
Expand Down
2 changes: 2 additions & 0 deletions cmd/rosa-support/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/openshift-online/rosa-support/cmd/rosa-support/create"
"github.com/openshift-online/rosa-support/cmd/rosa-support/delete"
"github.com/openshift-online/rosa-support/cmd/rosa-support/tag"
"github.com/openshift-online/rosa-support/cmd/rosa-support/version"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -60,4 +61,5 @@ func init() {
rootCmd.AddCommand(version.NewVersionCmd())
rootCmd.AddCommand(create.Cmd)
rootCmd.AddCommand(delete.Cmd)
rootCmd.AddCommand(tag.Cmd)
}
83 changes: 83 additions & 0 deletions cmd/rosa-support/tag/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package tag

import (
"os"
"strings"

awsV2 "github.com/openshift-online/ocm-common/pkg/aws/aws_client"
logger "github.com/openshift-online/ocm-common/pkg/log"
"github.com/spf13/cobra"
)

var args struct {
resourceID string
tags string
region string
}
var Cmd = &cobra.Command{
Use: "tag",
Short: "tag a resource",
Long: "Tag a resource with the resource ID",
Example: ` #Tag a vpc with vpc ID
ocmqe tag --resource-id <vpc id> --tags tag1:tagv,tag2:tagv2`,

Run: run,
}

func init() {
flags := Cmd.Flags()
flags.SortFlags = false
flags.StringVarP(
&args.resourceID,
"resource-id",
"",
"",
"resource ID",
)
flags.StringVarP(
&args.region,
"region",
"",
"",
"region ID",
)
flags.StringVarP(
&args.tags,
"tags",
"",
"",
"key of the tag",
)

requiredFlags := []string{
"resource-id",
"key",
"region",
}
for _, requiredFlag := range requiredFlags {
err := Cmd.MarkFlagRequired(requiredFlag)
if err != nil {
logger.LogError(err.Error())
os.Exit(1)
}
}
}
func run(cmd *cobra.Command, _ []string) {
console, err := awsV2.CreateAWSClient("", args.region)
if err != nil {
panic(err)
}
splitedTags := map[string]string{}

for _, tag := range strings.Split(args.tags, ",") {
tagPair := strings.Split(tag, ":")
if len(tagPair) < 2 {
tagPair = append(tagPair, "")
}
splitedTags[tagPair[0]] = tagPair[1]
}
_, err = console.TagResource(args.resourceID, splitedTags)
if err != nil {
panic(err)
}
}
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ module github.com/openshift-online/rosa-support
go 1.21

require (
github.com/openshift-online/ocm-common v0.0.0-20240508111534-37822c515806
github.com/openshift-online/ocm-common v0.0.8
github.com/spf13/cobra v1.8.0
)

require (
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.26.1 // indirect
github.com/aws/aws-sdk-go-v2 v1.30.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.9 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.9 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/service/cloudformation v1.48.0 // indirect
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.35.1 // indirect
Expand All @@ -25,6 +25,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.6 // indirect
github.com/aws/aws-sdk-go-v2/service/kms v1.30.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ram v1.26.1 // indirect
github.com/aws/aws-sdk-go-v2/service/route53 v1.40.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.20.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.3 // indirect
Expand Down
18 changes: 10 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/apparentlymart/go-cidr v1.1.0 h1:2mAhrMoF+nhXqxTzSZMUzDHkLjmIHC+Zzn4tdgBZjnU=
github.com/apparentlymart/go-cidr v1.1.0/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc=
github.com/aws/aws-sdk-go-v2 v1.26.1 h1:5554eUqIYVWpU0YmeeYZ0wU64H2VLBs8TlhRB2L+EkA=
github.com/aws/aws-sdk-go-v2 v1.26.1/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM=
github.com/aws/aws-sdk-go-v2 v1.30.0 h1:6qAwtzlfcTtcL8NHtbDQAqgM5s6NDipQTkPxyH/6kAA=
github.com/aws/aws-sdk-go-v2 v1.30.0/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 h1:x6xsQXGSmW6frevwDA+vi/wqhp1ct18mVXYN08/93to=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2/go.mod h1:lPprDr1e6cJdyYeGXnRaJoP4Md+cDBvi2eOj00BlGmg=
github.com/aws/aws-sdk-go-v2/config v1.27.9 h1:gRx/NwpNEFSk+yQlgmk1bmxxvQ5TyJ76CWXs9XScTqg=
Expand All @@ -10,10 +10,10 @@ github.com/aws/aws-sdk-go-v2/credentials v1.17.9 h1:N8s0/7yW+h8qR8WaRlPQeJ6czVMN
github.com/aws/aws-sdk-go-v2/credentials v1.17.9/go.mod h1:446YhIdmSV0Jf/SLafGZalQo+xr2iw7/fzXGDPTU1yQ=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.0 h1:af5YzcLf80tv4Em4jWVD75lpnOHSBkPUZxZfGkrI3HI=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.0/go.mod h1:nQ3how7DMnFMWiU1SpECohgC82fpn4cKZ875NDMmwtA=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 h1:aw39xVGeRWlWx9EzGVnhOR4yOjQDHPQ6o6NmBlscyQg=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5/go.mod h1:FSaRudD0dXiMPK2UjknVwwTYyZMRsHv3TtkabsZih5I=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 h1:PG1F3OD1szkuQPzDw3CIQsRIrtTlUC3lP84taWzHlq0=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5/go.mod h1:jU1li6RFryMz+so64PpKtudI+QzbKoIEivqdf6LNpOc=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12 h1:SJ04WXGTwnHlWIODtC5kJzKbeuHt+OUNOgKg7nfnUGw=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12/go.mod h1:FkpvXhA92gb3GE9LD6Og0pHHycTxW7xGpnEh5E7Opwo=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12 h1:hb5KgeYfObi5MHkSSZMEudnIvX30iB+E21evI4r6BnQ=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12/go.mod h1:CroKe/eWJdyfy9Vx4rljP5wTUjNJfb+fPz1uMYUhEGM=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY=
github.com/aws/aws-sdk-go-v2/service/cloudformation v1.48.0 h1:uMlYsoHdd2Gr9sDGq2ieUR5jVu7F5AqPYz6UBJmdRhY=
Expand All @@ -32,6 +32,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.6 h1:b+E7zIUHM
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.6/go.mod h1:S2fNV0rxrP78NhPbCZeQgY8H9jdDMeGtwcfZIRxzBqU=
github.com/aws/aws-sdk-go-v2/service/kms v1.30.0 h1:yS0JkEdV6h9JOo8sy2JSpjX+i7vsKifU8SIeHrqiDhU=
github.com/aws/aws-sdk-go-v2/service/kms v1.30.0/go.mod h1:+I8VUUSVD4p5ISQtzpgSva4I8cJ4SQ4b1dcBcof7O+g=
github.com/aws/aws-sdk-go-v2/service/ram v1.26.1 h1:1UcUsMsHB7ZnpcUYNwBTX90hFjIZrhf8Xu00R9Vo+Kg=
github.com/aws/aws-sdk-go-v2/service/ram v1.26.1/go.mod h1:e/3wE+afnOAeolpqyg8fKAQK/kKya+ycDW62/X4vjK8=
github.com/aws/aws-sdk-go-v2/service/route53 v1.40.3 h1:wr5gulbwbb8PSRMWjCROoP0TIMccpF8x5A7hEk2SjpA=
github.com/aws/aws-sdk-go-v2/service/route53 v1.40.3/go.mod h1:/Gyl9xjGcjIVe80ar75YlmA8m6oFh0A4XfLciBmdS8s=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.3 h1:mnbuWHOcM70/OFUlZZ5rcdfA8PflGXXiefU/O+1S3+8=
Expand All @@ -54,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.0-20240508111534-37822c515806 h1:YEDgruMDet/LJyav5G6VuvMhCf3tm7mQxR9ZS/yjn2E=
github.com/openshift-online/ocm-common v0.0.0-20240508111534-37822c515806/go.mod h1:aAE9ThwbT6pHKyVP15TW724yV0uvdNL3ZnIxena2j5s=
github.com/openshift-online/ocm-common v0.0.8 h1:5PMgNoPqHkEF90+8+dH20hT8gkouH2V8kaSRxH/wcWw=
github.com/openshift-online/ocm-common v0.0.8/go.mod h1:gsBWQYLZB0w0ZRR+NLASuTr29uFo5nekEODasFKxESc=
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=
Expand Down
Loading