From 9af874d81032fd365b776be7e270bfbaa94c38a1 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Tue, 21 Jul 2020 10:38:44 +0300 Subject: [PATCH] Add examples to all tk commands --- cmd/tk/bootstrap_github.go | 10 +++++----- cmd/tk/bootstrap_gitlab.go | 8 ++++---- cmd/tk/create_kustomization.go | 6 +++--- cmd/tk/create_source_git.go | 14 +++++++------- cmd/tk/delete_kustomization.go | 5 ++++- cmd/tk/delete_source_git.go | 5 ++++- cmd/tk/export_kustomization.go | 4 ++-- cmd/tk/export_source_git.go | 8 ++++---- cmd/tk/get_kustomization.go | 7 +++++-- cmd/tk/get_source_git.go | 5 ++++- cmd/tk/reconcile_source_helm.go | 2 +- cmd/tk/resume_helmrelease.go | 3 +++ cmd/tk/resume_kustomization.go | 3 +++ cmd/tk/suspend_helmrelease.go | 5 ++++- cmd/tk/suspend_kustomization.go | 5 ++++- cmd/tk/uninstall.go | 4 ++-- 16 files changed, 59 insertions(+), 35 deletions(-) diff --git a/cmd/tk/bootstrap_github.go b/cmd/tk/bootstrap_github.go index 4e7f8d5f..ad4a6fbb 100644 --- a/cmd/tk/bootstrap_github.go +++ b/cmd/tk/bootstrap_github.go @@ -42,19 +42,19 @@ the bootstrap command will perform an upgrade if needed.`, export GITHUB_TOKEN= # Run bootstrap for a private repo owned by a GitHub organization - bootstrap github --owner= --repository= + tk bootstrap github --owner= --repository= # Run bootstrap for a private repo and assign organization teams to it - bootstrap github --owner= --repository= --team= --team= + tk bootstrap github --owner= --repository= --team= --team= # Run bootstrap for a repository path - bootstrap github --owner= --repository= --path=dev-cluster + tk bootstrap github --owner= --repository= --path=dev-cluster # Run bootstrap for a public repository on a personal account - bootstrap github --owner= --repository= --private=false --personal=true + tk bootstrap github --owner= --repository= --private=false --personal=true # Run bootstrap for a private repo hosted on GitHub Enterprise - bootstrap github --owner= --repository= --hostname= + tk bootstrap github --owner= --repository= --hostname= `, RunE: bootstrapGitHubCmdRun, } diff --git a/cmd/tk/bootstrap_gitlab.go b/cmd/tk/bootstrap_gitlab.go index d35aab4f..b259e7bc 100644 --- a/cmd/tk/bootstrap_gitlab.go +++ b/cmd/tk/bootstrap_gitlab.go @@ -42,16 +42,16 @@ the bootstrap command will perform an upgrade if needed.`, export GITLAB_TOKEN= # Run bootstrap for a private repo owned by a GitLab group - bootstrap gitlab --owner= --repository= + tk bootstrap gitlab --owner= --repository= # Run bootstrap for a repository path - bootstrap gitlab --owner= --repository= --path=dev-cluster + tk bootstrap gitlab --owner= --repository= --path=dev-cluster # Run bootstrap for a public repository on a personal account - bootstrap gitlab --owner= --repository= --private=false --personal=true + tk bootstrap gitlab --owner= --repository= --private=false --personal=true # Run bootstrap for a private repo hosted on a GitLab server - bootstrap gitlab --owner= --repository= --hostname= + tk bootstrap gitlab --owner= --repository= --hostname= `, RunE: bootstrapGitLabCmdRun, } diff --git a/cmd/tk/create_kustomization.go b/cmd/tk/create_kustomization.go index 13ce334e..e358f533 100644 --- a/cmd/tk/create_kustomization.go +++ b/cmd/tk/create_kustomization.go @@ -40,7 +40,7 @@ var createKsCmd = &cobra.Command{ Short: "Create or update a Kustomization resource", Long: "The kustomization source create command generates a Kustomize resource for a given GitRepository source.", Example: ` # Create a Kustomization resource from a source at a given path - create kustomization contour \ + tk create kustomization contour \ --source=contour \ --path="./examples/contour/" \ --prune=true \ @@ -51,7 +51,7 @@ var createKsCmd = &cobra.Command{ --health-check-timeout=3m # Create a Kustomization resource that depends on the previous one - create kustomization webapp \ + tk create kustomization webapp \ --depends-on=contour \ --source=webapp \ --path="./deploy/overlays/dev" \ @@ -60,7 +60,7 @@ var createKsCmd = &cobra.Command{ --validation=client # Create a Kustomization resource that runs under a service account - create kustomization webapp \ + tk create kustomization webapp \ --source=webapp \ --path="./deploy/overlays/staging" \ --prune=true \ diff --git a/cmd/tk/create_source_git.go b/cmd/tk/create_source_git.go index 78d183eb..9fa7d6f2 100644 --- a/cmd/tk/create_source_git.go +++ b/cmd/tk/create_source_git.go @@ -46,35 +46,35 @@ The create source git command generates a GitRepository resource and waits for i For Git over SSH, host and SSH keys are automatically generated and stored in a Kubernetes secret. For private Git repositories, the basic authentication credentials are stored in a Kubernetes secret.`, Example: ` # Create a source from a public Git repository master branch - create source git podinfo \ + tk create source git podinfo \ --url=https://github.com/stefanprodan/podinfo \ --branch=master # Create a source from a Git repository pinned to specific git tag - create source git podinfo \ + tk create source git podinfo \ --url=https://github.com/stefanprodan/podinfo \ --tag="3.2.3" # Create a source from a public Git repository tag that matches a semver range - create source git podinfo \ + tk create source git podinfo \ --url=https://github.com/stefanprodan/podinfo \ --tag-semver=">=3.2.0 <3.3.0" # Create a source from a Git repository using SSH authentication - create source git podinfo \ + tk create source git podinfo \ --url=ssh://git@github.com/stefanprodan/podinfo \ --branch=master # Create a source from a Git repository using SSH authentication and an # ECDSA P-521 curve public key - create source git podinfo \ + tk create source git podinfo \ --url=ssh://git@github.com/stefanprodan/podinfo \ --branch=master \ --ssh-key-algorithm=ecdsa \ --ssh-ecdsa-curve=p521 # Create a source from a Git repository using basic authentication - create source git podinfo \ + tk create source git podinfo \ --url=https://github.com/stefanprodan/podinfo \ --username=username \ --password=password @@ -115,7 +115,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error { name := args[0] if sourceGitURL == "" { - return fmt.Errorf("git-url is required") + return fmt.Errorf("url is required") } tmpDir, err := ioutil.TempDir("", name) diff --git a/cmd/tk/delete_kustomization.go b/cmd/tk/delete_kustomization.go index d72bf186..68c61851 100644 --- a/cmd/tk/delete_kustomization.go +++ b/cmd/tk/delete_kustomization.go @@ -31,7 +31,10 @@ var deleteKsCmd = &cobra.Command{ Aliases: []string{"ks"}, Short: "Delete a Kustomization resource", Long: "The delete kustomization command deletes the given Kustomization from the cluster.", - RunE: deleteKsCmdRun, + Example: ` # Delete a kustomization and the Kubernetes resources created by it + tk delete kustomization podinfo +`, + RunE: deleteKsCmdRun, } func init() { diff --git a/cmd/tk/delete_source_git.go b/cmd/tk/delete_source_git.go index cbb4f092..e307905e 100644 --- a/cmd/tk/delete_source_git.go +++ b/cmd/tk/delete_source_git.go @@ -30,7 +30,10 @@ var deleteSourceGitCmd = &cobra.Command{ Use: "git [name]", Short: "Delete a GitRepository source", Long: "The delete source git command deletes the given GitRepository from the cluster.", - RunE: deleteSourceGitCmdRun, + Example: ` # Delete a Git repository + tk delete source git podinfo +`, + RunE: deleteSourceGitCmdRun, } func init() { diff --git a/cmd/tk/export_kustomization.go b/cmd/tk/export_kustomization.go index 17fc2800..71032de4 100644 --- a/cmd/tk/export_kustomization.go +++ b/cmd/tk/export_kustomization.go @@ -34,10 +34,10 @@ var exportKsCmd = &cobra.Command{ Short: "Export Kustomization resources in YAML format", Long: "The export kustomization command exports one or all Kustomization resources in YAML format.", Example: ` # Export all Kustomization resources - export kustomization --all > kustomizations.yaml + tk export kustomization --all > kustomizations.yaml # Export a Kustomization - export kustomization my-app > kustomization.yaml + tk export kustomization my-app > kustomization.yaml `, RunE: exportKsCmdRun, } diff --git a/cmd/tk/export_source_git.go b/cmd/tk/export_source_git.go index 6b8dafa8..f891748c 100644 --- a/cmd/tk/export_source_git.go +++ b/cmd/tk/export_source_git.go @@ -34,10 +34,10 @@ var exportSourceGitCmd = &cobra.Command{ Short: "Export GitRepository sources in YAML format", Long: "The export source git command exports on or all GitRepository sources in YAML format.", Example: ` # Export all GitRepository sources - export source git --all > sources.yaml + tk export source git --all > sources.yaml # Export a GitRepository source including the SSH key pair or basic auth credentials - export source git my-private-repo --with-credentials > source.yaml + tk export source git my-private-repo --with-credentials > source.yaml `, RunE: exportSourceGitCmdRun, } @@ -48,7 +48,7 @@ func init() { func exportSourceGitCmdRun(cmd *cobra.Command, args []string) error { if !exportAll && len(args) < 1 { - return fmt.Errorf("kustomization name is required") + return fmt.Errorf("name is required") } ctx, cancel := context.WithTimeout(context.Background(), timeout) @@ -103,7 +103,7 @@ func exportSourceGitCmdRun(cmd *cobra.Command, args []string) error { } func exportGit(source sourcev1.GitRepository) error { - gvk := sourcev1.GroupVersion.WithKind("GitRepository") + gvk := sourcev1.GroupVersion.WithKind(sourcev1.GitRepositoryKind) export := sourcev1.GitRepository{ TypeMeta: metav1.TypeMeta{ Kind: gvk.Kind, diff --git a/cmd/tk/get_kustomization.go b/cmd/tk/get_kustomization.go index f53d9600..83ad4aac 100644 --- a/cmd/tk/get_kustomization.go +++ b/cmd/tk/get_kustomization.go @@ -28,9 +28,12 @@ import ( var getKsCmd = &cobra.Command{ Use: "kustomizations", Aliases: []string{"ks"}, - Short: "Get Kustomization source statuses", + Short: "Get Kustomization statuses", Long: "The get kustomizations command prints the statuses of the resources.", - RunE: getKsCmdRun, + Example: ` # List all kustomizations and their status + tk get kustomizations +`, + RunE: getKsCmdRun, } func init() { diff --git a/cmd/tk/get_source_git.go b/cmd/tk/get_source_git.go index f490b66d..9492a2c5 100644 --- a/cmd/tk/get_source_git.go +++ b/cmd/tk/get_source_git.go @@ -29,7 +29,10 @@ var getSourceGitCmd = &cobra.Command{ Use: "git", Short: "Get GitRepository source statuses", Long: "The get sources git command prints the status of the GitRepository sources.", - RunE: getSourceGitCmdRun, + Example: ` # List all Git repositories and their status + tk get sources git +`, + RunE: getSourceGitCmdRun, } func init() { diff --git a/cmd/tk/reconcile_source_helm.go b/cmd/tk/reconcile_source_helm.go index e5fa9662..efffc261 100644 --- a/cmd/tk/reconcile_source_helm.go +++ b/cmd/tk/reconcile_source_helm.go @@ -34,7 +34,7 @@ var reconcileSourceHelmCmd = &cobra.Command{ Use: "helm [name]", Short: "Reconcile a HelmRepository source", Long: `The reconcile source command triggers a reconciliation of a HelmRepository resource and waits for it to finish.`, - Example: ` # Trigger a helm repo update for an existing source + Example: ` # Trigger a reconciliation for an existing source tk reconcile source helm podinfo `, RunE: syncSourceHelmCmdRun, diff --git a/cmd/tk/resume_helmrelease.go b/cmd/tk/resume_helmrelease.go index ce588b5e..a98ac07c 100644 --- a/cmd/tk/resume_helmrelease.go +++ b/cmd/tk/resume_helmrelease.go @@ -35,6 +35,9 @@ var resumeHrCmd = &cobra.Command{ Short: "Resume a suspended HelmRelease", Long: `The resume command marks a previously suspended HelmRelease resource for reconciliation and waits for it to finish the apply.`, + Example: ` # Resume reconciliation for an existing Helm release + tk resume hr podinfo +`, RunE: resumeHrCmdRun, } diff --git a/cmd/tk/resume_kustomization.go b/cmd/tk/resume_kustomization.go index a1d708a8..bac1bf88 100644 --- a/cmd/tk/resume_kustomization.go +++ b/cmd/tk/resume_kustomization.go @@ -35,6 +35,9 @@ var resumeKsCmd = &cobra.Command{ Short: "Resume a suspended Kustomization", Long: `The resume command marks a previously suspended Kustomization resource for reconciliation and waits for it to finish the apply.`, + Example: ` # Resume reconciliation for an existing Kustomization + tk resume ks podinfo +`, RunE: resumeKsCmdRun, } diff --git a/cmd/tk/suspend_helmrelease.go b/cmd/tk/suspend_helmrelease.go index eafeab62..c7840ef7 100644 --- a/cmd/tk/suspend_helmrelease.go +++ b/cmd/tk/suspend_helmrelease.go @@ -31,7 +31,10 @@ var suspendHrCmd = &cobra.Command{ Aliases: []string{"hr"}, Short: "Suspend reconciliation of HelmRelease", Long: "The suspend command disables the reconciliation of a HelmRelease resource.", - RunE: suspendHrCmdRun, + Example: ` # Suspend reconciliation for an existing Helm release + tk suspend hr podinfo +`, + RunE: suspendHrCmdRun, } func init() { diff --git a/cmd/tk/suspend_kustomization.go b/cmd/tk/suspend_kustomization.go index d879a44e..0a9593f5 100644 --- a/cmd/tk/suspend_kustomization.go +++ b/cmd/tk/suspend_kustomization.go @@ -29,7 +29,10 @@ var suspendKsCmd = &cobra.Command{ Aliases: []string{"ks"}, Short: "Suspend reconciliation of Kustomization", Long: "The suspend command disables the reconciliation of a Kustomization resource.", - RunE: suspendKsCmdRun, + Example: ` # Suspend reconciliation for an existing Kustomization + tk suspend ks podinfo +`, + RunE: suspendKsCmdRun, } func init() { diff --git a/cmd/tk/uninstall.go b/cmd/tk/uninstall.go index 7e145c73..a9295119 100644 --- a/cmd/tk/uninstall.go +++ b/cmd/tk/uninstall.go @@ -30,10 +30,10 @@ var uninstallCmd = &cobra.Command{ Short: "Uninstall the toolkit components", Long: "The uninstall command removes the namespace, cluster roles, cluster role bindings and CRDs from the cluster.", Example: ` # Dry-run uninstall of all components - uninstall --dry-run --namespace=gitops-system + tk uninstall --dry-run --namespace=gitops-system # Uninstall all components and delete custom resource definitions - uninstall --crds --namespace=gitops-system + tk uninstall --crds --namespace=gitops-system `, RunE: uninstallCmdRun, }