From 7781b40cd9200c152da594c3a4ff85c071111d66 Mon Sep 17 00:00:00 2001 From: escho Date: Mon, 9 May 2022 13:33:21 +0900 Subject: [PATCH] docs: update a user-guide --- README.md | 217 ++++++++++++++------- cmd/cmd.go | 5 +- cmd/config/config.go | 31 +-- cmd/create/connecton.go | 31 +-- cmd/create/create.go | 17 +- cmd/create/credential.go | 7 +- cmd/create/driver.go | 9 +- cmd/create/namespace.go | 9 +- cmd/create/region.go | 19 +- cmd/delete/delete.go | 53 ++--- cmd/get-key/get-key.go | 7 +- cmd/update-kubeconfig/update-kubeconfig.go | 7 +- 12 files changed, 266 insertions(+), 146 deletions(-) diff --git a/README.md b/README.md index b2b5421..b3eb0c1 100644 --- a/README.md +++ b/README.md @@ -1,45 +1,37 @@ # cbctl * Cloud-Barista MCKS Command Line Interface -* MCKS : Multi Cloud Kubernetes Service -* https://github.com/cloud-barista/cb-mcks +* [MCKS : Multi Cloud Kubernetes Service](https://github.com/cloud-barista/cb-mcks) ## Quick Started -### Installation +* Installation -* MacOS ``` +### MacOS $ curl -LO "https://github.com/itnpeople/cbctl/releases/download/$(curl -s https://api.github.com/repos/itnpeople/cbctl/releases/latest | grep tag_name | sed -E 's/.*"([^"]+)".*/\1/')/cbctl-darwin-amd64" $ mv cbctl-darwin-amd64 /usr/local/bin/cbctl $ chmod +x /usr/local/bin/cbctl $ cbctl version -``` -* Linux -``` +###Linux $ curl -LO "https://github.com/itnpeople/cbctl/releases/download/$(curl -s https://api.github.com/repos/itnpeople/cbctl/releases/latest | grep tag_name | sed -E 's/.*"([^"]+)".*/\1/')/cbctl-linux-amd64" $ mv cbctl-linux-amd64 /usr/local/bin/cbctl $ chmod +x /usr/local/bin/cbctl $ cbctl version -``` - -* Windows -``` +### Windows https://github.com/itnpeople/cbctl/releases/download/v0.0.0/cbctl-windows-amd64.exe ``` -### Start-up the MCKS - -* start up +* start up the MCKS ``` $ ./examples/lab/startup.sh ``` -* Verify running +* verify running ``` $ docker ps @@ -51,9 +43,7 @@ CONTAINER ID IMAGE COMMAND CRE $ docker logs cb-mcks -f ``` -### Create a Cluster - -* Initialize (cb-spider) +* Initialize cloud connection (cb-spider) ``` $ cbctl create driver --csp aws @@ -76,7 +66,6 @@ $ cbctl create cluster \ ## User Guide -* Commands ``` $ cbctl create [cluster/node/driver/credential/region/connection] $ cbctl get [cluster/node/driver/credential/region/connection/mcis] @@ -88,8 +77,35 @@ $ cbctl clean [mcis] ### Create -* Create a Cloud Driver. +* Create a Cluster + +``` +$ cbctl create cluster \ + --namespace "acornsoft"\ + --name "cb-cluster"\ + --control-plane-connection="config-aws-tokyo"\ + --control-plane-count="1"\ + --control-plane-spec="t2.medium"\ + --worker-connection="config-gcp-tokyo"\ + --worker-count="1"\ + --worker-spec="e2-highcpu-4" +``` + +* Create Nodes +``` +$ cbctl create node \ + --namespace "acornsoft"\ + --cluster "cb-cluster"\ + --worker-connection="config-aws-tokyo"\ + --worker-count="1"\ + --worker-spec="t2.medium" +``` + +* Create a cloud driver. ``` +$ cbctl create driver --csp [CSP] + +# examples $ cbctl create driver --csp aws $ cbctl create driver --csp gcp $ cbctl create driver --csp azure @@ -100,7 +116,21 @@ $ cbctl create driver --csp openstack $ cbctl create driver --csp cloudit ``` -* Create a Credential +* Create a Region +``` +$ cbctl create region [region name] --csp [CSP] --region [CSP region name] --zone [CSP zone name] +$ cbctl create region [region name] --csp azure --location [location] --resource-group [resource group name] # if azure + +# examples +$ cbctl create region region-aws-tokyo --csp aws --region ap-northeast-1 --zone ap-northeast-1a +$ cbctl create region region-gcp-tokyo --csp gcp --region asia-northeast1 --zone asia-northeast1-a +$ cbctl create region region-azure-tokyo --csp azure --location japaneast --resource-group cb-mcks +$ cbctl create region region-alibaba-tokyo --csp alibaba --region ap-northeast-1 --zone ap-northeast-1a +$ cbctl create region region-tencent-tokyo --csp tencent --region ap-tokyo --zone ap-tokyo-2 +$ cbctl create region region-ibm-tokyo --csp ibm --region jp-tok --zone jp-tok-1 +``` + +* Create a credential ``` $ source ./examples/credentials.sh \ aws="${HOME}/.aws/credentials" \ @@ -121,18 +151,12 @@ $ cbctl create credential credential-openstack --csp openstack --endpoint "$OS_A $ cbctl create credential credential-cloudit --csp cloudit --endpoint "$CLOUDIT_ENDPOINT" --username "$CLOUDIT_USERNAME" --password "$CLOUDIT_PASSWORD" --token "$CLOUDIT_TOKEN" --tenant "$CLOUDIT_TENANT_ID" ``` -* Create a Region -``` -$ cbctl create region region-aws-tokyo --csp aws --region ap-northeast-1 --zone ap-northeast-1a -$ cbctl create region region-gcp-tokyo --csp gcp --region asia-northeast1 --zone asia-northeast1-a -$ cbctl create region region-azure-tokyo --csp azure --location japaneast --resource-group cb-mcks -$ cbctl create region region-alibaba-tokyo --csp alibaba --region ap-northeast-1 --zone ap-northeast-1a -$ cbctl create region region-tencent-tokyo --csp tencent --region ap-tokyo --zone ap-tokyo-2 -$ cbctl create region region-ibm-tokyo --csp ibm --region jp-tok --zone jp-tok-1 -``` * Create a Connection Info. ``` +$ cbctl create connection [connection name] --csp [CSP] --region [region name] --credential [credential name] + +# examples $ cbctl create connection config-aws-tokyo --csp aws --region region-aws-tokyo --credential credential-aws $ cbctl create connection config-gcp-tokyo --csp gcp --region region-gcp-tokyo --credential credential-gcp $ cbctl create connection config-azure-tokyo --csp azure --region region-azure-tokyo --credential credential-azure @@ -144,46 +168,11 @@ $ cbctl create connection config-ibm-tokyo --csp ibm --region region-ibm-tokyo - * Create a cloud-barista namespace ``` -$ cbctl create namespace acornsoft -``` - -* Create a Cluster +$ cbctl create namespace [namespace name] +# example +$ cbctl create namespace acornsoft ``` -$ cbctl create cluster \ - --namespace "acornsoft"\ - --name "cb-cluster"\ - --control-plane-connection="config-aws-tokyo"\ - --control-plane-count="1"\ - --control-plane-spec="t2.medium"\ - --worker-connection="config-gcp-tokyo"\ - --worker-count="1"\ - --worker-spec="e2-highcpu-4" -``` - -* Create Nodes -``` -$ cbctl create node \ - --namespace "acornsoft"\ - --cluster "cb-cluster"\ - --worker-connection="config-aws-tokyo"\ - --worker-count="1"\ - --worker-spec="t2.medium" -``` - -* Using Yaml File - -``` -$ cbctl create cluster -f examples/yaml/create-cluster.yaml - -$ cbctl create node --cluster cb-cluster -f - < 0 { @@ -175,10 +177,10 @@ func NewCommandConfig(options *app.Options) *cobra.Command { // set-namespace cmds.AddCommand(&cobra.Command{ - Use: "set-namespace [namespace]", + Use: "set-namespace (NAME | --name NAME) [options]", Short: "Get a current context", + Args: app.BindCommandArgs(&o.Name), DisableFlagsInUseLine: true, - Args: app.BindCommandArgs(&o.Namespace), Run: func(c *cobra.Command, args []string) { app.ValidateError(c, func() error { if len(o.Namespace) == 0 { @@ -195,9 +197,10 @@ func NewCommandConfig(options *app.Options) *cobra.Command { // delete-context cmds.AddCommand(&cobra.Command{ - Use: "delete-context", - Short: "Delete a context", - Args: app.BindCommandArgs(&o.Name), + Use: "delete-context (NAME | --name NAME) [options]", + Short: "Delete a context", + Args: app.BindCommandArgs(&o.Name), + DisableFlagsInUseLine: true, Run: func(c *cobra.Command, args []string) { app.ValidateError(c, func() error { if o.Name == "" { diff --git a/cmd/create/connecton.go b/cmd/create/connecton.go index baab658..2800151 100644 --- a/cmd/create/connecton.go +++ b/cmd/create/connecton.go @@ -25,22 +25,25 @@ func NewCommandConnection(options *app.Options) *cobra.Command { // create cmd := &cobra.Command{ - Use: "connection", - Short: "Create a cloud connection info.", - Args: app.BindCommandArgs(&o.Name), + Use: "connection (NAME | --name NAME | -f FILENAME) [options]", + Short: "Create a cloud connection info.", + Args: app.BindCommandArgs(&o.Name), + DisableFlagsInUseLine: true, Run: func(c *cobra.Command, args []string) { app.ValidateError(c, func() error { - if o.Name == "" { - return fmt.Errorf("Name is required.") - } - if o.CSP == "" { - return fmt.Errorf("CSP is required.") - } - if o.Credential == "" { - return fmt.Errorf("Credential name is required.") - } - if o.Region == "" { - return fmt.Errorf("Region name is required.") + if o.Filename == "" { + if o.Name == "" { + return fmt.Errorf("Name is required.") + } + if o.CSP == "" { + return fmt.Errorf("CSP is required.") + } + if o.Credential == "" { + return fmt.Errorf("Credential name is required.") + } + if o.Region == "" { + return fmt.Errorf("Region name is required.") + } } if out, err := app.GetBody(o, `{ "ConfigName" : "{{ .Name }}", diff --git a/cmd/create/create.go b/cmd/create/create.go index 4ed6345..bf522b2 100644 --- a/cmd/create/create.go +++ b/cmd/create/create.go @@ -31,6 +31,9 @@ func (o *CreateClusterOptions) Validate() error { if o.Namespace == "" { return fmt.Errorf("Namespace is required.") } + if o.Filename == "" && o.Name == "" { + return fmt.Errorf("Name is required.") + } return nil } @@ -88,6 +91,9 @@ func (o *CreateNodeOptions) Validate() error { if o.clusterName == "" { return fmt.Errorf("Cluster is required.") } + if o.Filename == "" && o.Name == "" { + return fmt.Errorf("Name is required.") + } return nil } @@ -128,8 +134,10 @@ func NewCommandCreate(options *app.Options) *cobra.Command { // cbctl create cluster cmdC := &cobra.Command{ - Use: "cluster", - Short: "Create a cluster", + Use: "cluster (NAME | --name NAME | -f FILENAME) [options]", + Short: "Create a cluster", + DisableFlagsInUseLine: true, + Args: app.BindCommandArgs(&oCluster.Name), Run: func(c *cobra.Command, args []string) { app.ValidateError(c, oCluster.Validate()) app.ValidateError(c, oCluster.Run()) @@ -149,8 +157,9 @@ func NewCommandCreate(options *app.Options) *cobra.Command { // cbctl create node cmdN := &cobra.Command{ - Use: "node", - Short: "Add nodes", + Use: "node --cluster CLUSTER_NAME [options]", + Short: "Add nodes", + DisableFlagsInUseLine: true, Run: func(c *cobra.Command, args []string) { app.ValidateError(c, oNode.Validate()) app.ValidateError(c, oNode.Run()) diff --git a/cmd/create/credential.go b/cmd/create/credential.go index 5882710..cc4b21d 100644 --- a/cmd/create/credential.go +++ b/cmd/create/credential.go @@ -35,6 +35,11 @@ func (o *CredentialOptions) Validate() error { if o.Namespace == "" { return fmt.Errorf("Namespace is required.") } + + if o.Filename != "" { + return nil + } + if o.Name == "" { return fmt.Errorf("Name is required.") } @@ -83,7 +88,7 @@ func NewCommandCredential(options *app.Options) *cobra.Command { // create cmd := &cobra.Command{ - Use: "credential [name]", + Use: "credential (NAME | --name NAME | -f FILENAME) [options]", Short: "Create a cloud credential", Args: app.BindCommandArgs(&o.Name), DisableFlagsInUseLine: true, diff --git a/cmd/create/driver.go b/cmd/create/driver.go index 897ee1c..6e39488 100644 --- a/cmd/create/driver.go +++ b/cmd/create/driver.go @@ -23,11 +23,14 @@ func NewCommandDriver(options *app.Options) *cobra.Command { // create cmd := &cobra.Command{ - Use: "driver", - Short: "Create a cloud driver", - Args: app.BindCommandArgs(&o.CSP), + Use: "driver (CSP | --csp CSP | -f FILENAME) [options]", + Short: "Create a cloud driver", + DisableFlagsInUseLine: true, Run: func(c *cobra.Command, args []string) { app.ValidateError(c, func() error { + if o.Filename == "" && o.CSP == "" { + return fmt.Errorf("CSP is required.") + } if out, err := app.GetBody(o, `{ "DriverName" : "{{ .CSP }}-driver-v1.0", "ProviderName" : "{{ .CSP | ToUpper }}", diff --git a/cmd/create/namespace.go b/cmd/create/namespace.go index fe06cb1..a95117d 100644 --- a/cmd/create/namespace.go +++ b/cmd/create/namespace.go @@ -22,10 +22,15 @@ func NewCommandNamespace(options *app.Options) *cobra.Command { } cmd := &cobra.Command{ - Use: "create", - Short: "Create a namespace.", + Use: "namespace (NAME | --name NAME | -f FILENAME) [options]", + Short: "Create a namespace.", + Args: app.BindCommandArgs(&o.Name), + DisableFlagsInUseLine: true, Run: func(c *cobra.Command, args []string) { app.ValidateError(c, func() error { + if o.Filename == "" && o.Name == "" { + return fmt.Errorf("Name is required.") + } if out, err := app.GetBody(o, `{ "name" : "{{NAME}}", "description" : "{{Description}}" diff --git a/cmd/create/region.go b/cmd/create/region.go index 8c66b7a..59f124b 100644 --- a/cmd/create/region.go +++ b/cmd/create/region.go @@ -27,16 +27,19 @@ func NewCommandRegion(options *app.Options) *cobra.Command { } cmd := &cobra.Command{ - Use: "region", - Short: "Create a cloud region", - Args: app.BindCommandArgs(&o.Name), + Use: "region (NAME | --name NAME | -f FILENAME) [options]", + Short: "Create a cloud region", + Args: app.BindCommandArgs(&o.Name), + DisableFlagsInUseLine: true, Run: func(c *cobra.Command, args []string) { app.ValidateError(c, func() error { - if o.CSP == "" { - return fmt.Errorf("CSP is required.") - } - if o.CSP == "azure" && (o.Location == "" || o.ResourceGroup == "") { - return fmt.Errorf("Invalid location/resource-group flag (csp=%s, key=%s, secret=%s)", o.CSP, o.Location, o.ResourceGroup) + if o.Filename == "" { + if o.CSP == "" { + return fmt.Errorf("CSP is required.") + } + if o.CSP == "azure" && (o.Location == "" || o.ResourceGroup == "") { + return fmt.Errorf("Invalid location/resource-group flag (csp=%s, key=%s, secret=%s)", o.CSP, o.Location, o.ResourceGroup) + } } if out, err := app.GetBody(o, `{ "RegionName" : "{{ .Name }}", diff --git a/cmd/delete/delete.go b/cmd/delete/delete.go index 8c75af6..f65e3c6 100644 --- a/cmd/delete/delete.go +++ b/cmd/delete/delete.go @@ -36,10 +36,10 @@ func NewCommandDelete(o *app.Options) *cobra.Command { // cluster cmds.AddCommand(&cobra.Command{ - Use: "cluster", + Use: "cluster (NAME | --name NAME) [options]", Short: "Delete a cluster", - DisableFlagsInUseLine: false, Args: app.BindCommandArgs(&o.Name), + DisableFlagsInUseLine: false, Run: func(c *cobra.Command, args []string) { app.ValidateError(c, fnValidate()) app.ValidateError(c, func() error { @@ -57,9 +57,10 @@ func NewCommandDelete(o *app.Options) *cobra.Command { // node var clusterName string cmdNode := &cobra.Command{ - Use: "node", - Short: "Get nodes", - Args: app.BindCommandArgs(&o.Name), + Use: "node (NAME | --name NAME) --cluster CLUSTER_NAME [options]", + Short: "Get nodes", + Args: app.BindCommandArgs(&o.Name), + DisableFlagsInUseLine: true, Run: func(c *cobra.Command, args []string) { app.ValidateError(c, fnValidate()) app.ValidateError(c, func() error { @@ -83,9 +84,10 @@ func NewCommandDelete(o *app.Options) *cobra.Command { // driver var csp string cmdDrv := &cobra.Command{ - Use: "driver", - Short: "Delete a cloud driver", - Args: app.BindCommandArgs(&o.Name), + Use: "driver (NAME | --name NAME) [options]", + Short: "Delete a cloud driver", + Args: app.BindCommandArgs(&o.Name), + DisableFlagsInUseLine: true, Run: func(c *cobra.Command, args []string) { app.ValidateError(c, func() error { url := fmt.Sprintf("%s/driver", app.Config.GetCurrentContext().Urls.Spider) @@ -110,9 +112,10 @@ func NewCommandDelete(o *app.Options) *cobra.Command { // region cmds.AddCommand(&cobra.Command{ - Use: "region", - Short: "Delete a cloud region", - Args: app.BindCommandArgs(&o.Name), + Use: "region (NAME | --name NAME) [options]", + Short: "Delete a cloud region", + Args: app.BindCommandArgs(&o.Name), + DisableFlagsInUseLine: true, Run: func(c *cobra.Command, args []string) { app.ValidateError(c, func() error { if o.Name == "" { @@ -130,9 +133,10 @@ func NewCommandDelete(o *app.Options) *cobra.Command { // credential cmds.AddCommand(&cobra.Command{ - Use: "credential", - Short: "Delete a cloud credential", - Args: app.BindCommandArgs(&o.Name), + Use: "credential (NAME | --name NAME) [options]", + Short: "Delete a cloud credential", + Args: app.BindCommandArgs(&o.Name), + DisableFlagsInUseLine: true, Run: func(c *cobra.Command, args []string) { app.ValidateError(c, func() error { if o.Name == "" { @@ -150,9 +154,10 @@ func NewCommandDelete(o *app.Options) *cobra.Command { // connection cmds.AddCommand(&cobra.Command{ - Use: "connection", - Short: "Delete a cloud connection info.", - Args: app.BindCommandArgs(&o.Name), + Use: "connection (NAME | --name NAME) [options]", + Short: "Delete a cloud connection info.", + Args: app.BindCommandArgs(&o.Name), + DisableFlagsInUseLine: true, Run: func(c *cobra.Command, args []string) { app.ValidateError(c, func() error { if o.Name == "" { @@ -170,9 +175,10 @@ func NewCommandDelete(o *app.Options) *cobra.Command { // namespace cmds.AddCommand(&cobra.Command{ - Use: "namespace", - Short: "Delete a namespace.", - Args: app.BindCommandArgs(&o.Name), + Use: "namespace (NAME | --name NAME) [options]", + Short: "Delete a namespace.", + Args: app.BindCommandArgs(&o.Name), + DisableFlagsInUseLine: true, Run: func(c *cobra.Command, args []string) { app.ValidateError(c, func() error { if o.Name == "" { @@ -191,9 +197,10 @@ func NewCommandDelete(o *app.Options) *cobra.Command { // mcis cmds.AddCommand(&cobra.Command{ - Use: "mcis", - Short: "Delete a MCIS.", - Args: app.BindCommandArgs(&o.Name), + Use: "mcis (NAME | --name NAME) [options]", + Short: "Delete a MCIS.", + Args: app.BindCommandArgs(&o.Name), + DisableFlagsInUseLine: true, Run: func(c *cobra.Command, args []string) { app.ValidateError(c, func() error { url := fmt.Sprintf("%s/ns/%s/mcis/%s?action=terminate", app.Config.GetCurrentContext().Urls.Tumblebug, o.Namespace, o.Name) diff --git a/cmd/get-key/get-key.go b/cmd/get-key/get-key.go index 71fbc48..06d39f3 100644 --- a/cmd/get-key/get-key.go +++ b/cmd/get-key/get-key.go @@ -16,9 +16,10 @@ func NewCommandGetKey(o *app.Options) *cobra.Command { // update-kubeconfig var clusterName string cmd := &cobra.Command{ - Use: "get-key", - Short: "Get a SSH private key", - Args: app.BindCommandArgs(&o.Name), + Use: "get-key (NAME | --name NAME) --cluster CLUSTER_NAME [options]", + Short: "Get a SSH private key", + Args: app.BindCommandArgs(&o.Name), + DisableFlagsInUseLine: true, Run: func(c *cobra.Command, args []string) { app.ValidateError(c, func() error { // vlidation diff --git a/cmd/update-kubeconfig/update-kubeconfig.go b/cmd/update-kubeconfig/update-kubeconfig.go index 5eb8426..412c98b 100644 --- a/cmd/update-kubeconfig/update-kubeconfig.go +++ b/cmd/update-kubeconfig/update-kubeconfig.go @@ -24,9 +24,10 @@ func NewCommandUpdateKubeconfig(options *app.Options) *cobra.Command { // update-kubeconfig return &cobra.Command{ - Use: "update-kubeconfig", - Short: "Update a kubeconfig", - Args: app.BindCommandArgs(&o.Name), + Use: "update-kubeconfig (NAME | --name NAME) [options]", + Short: "Update a kubeconfig", + Args: app.BindCommandArgs(&o.Name), + DisableFlagsInUseLine: true, Run: func(c *cobra.Command, args []string) { app.ValidateError(c, func() error { // vlidation