From 499ba15004ea240fe29341cf664bf52833863cc2 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Thu, 16 Jul 2020 15:56:05 +0300 Subject: [PATCH] Add export option to tk install --- cmd/tk/install.go | 17 ++++++++++++++++- docs/cmd/tk_install.md | 4 ++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cmd/tk/install.go b/cmd/tk/install.go index c1671152..2e929dd5 100644 --- a/cmd/tk/install.go +++ b/cmd/tk/install.go @@ -24,6 +24,7 @@ import ( "path" "path/filepath" "strings" + "time" "github.com/spf13/cobra" "sigs.k8s.io/kustomize/api/filesys" @@ -43,11 +44,15 @@ If a previous version is installed, then an in-place upgrade will be performed.` # Dry-run install with manifests preview tk install --dry-run --verbose + + # Write install manifests to file + tk install --export > gitops-system.yaml `, RunE: installCmdRun, } var ( + installExport bool installDryRun bool installManifestsPath string installVersion string @@ -55,6 +60,8 @@ var ( ) func init() { + installCmd.Flags().BoolVar(&installExport, "export", false, + "write the install manifests to stdout and exit") installCmd.Flags().BoolVarP(&installDryRun, "dry-run", "", false, "only print the object that would be applied") installCmd.Flags().StringVarP(&installVersion, "version", "v", defaultVersion, @@ -84,7 +91,9 @@ func installCmdRun(cmd *cobra.Command, args []string) error { } defer os.RemoveAll(tmpDir) - logger.Generatef("generating manifests") + if !installExport { + logger.Generatef("generating manifests") + } if kustomizePath == "" { err = genInstallManifests(installVersion, namespace, installComponents, tmpDir) if err != nil { @@ -104,6 +113,12 @@ func installCmdRun(cmd *cobra.Command, args []string) error { } else { if verbose { fmt.Print(yaml) + } else if installExport { + fmt.Println("---") + fmt.Println("# GitOps Toolkit revision", installVersion, time.Now().Format(time.RFC3339)) + fmt.Print(yaml) + fmt.Println("---") + return nil } } logger.Successf("manifests build completed") diff --git a/docs/cmd/tk_install.md b/docs/cmd/tk_install.md index 18418220..39becb37 100644 --- a/docs/cmd/tk_install.md +++ b/docs/cmd/tk_install.md @@ -23,6 +23,9 @@ tk install [flags] # Dry-run install with manifests preview tk install --dry-run --verbose + # Write install manifests to file + tk install --export > gitops-system.yaml + ``` ### Options @@ -30,6 +33,7 @@ tk install [flags] ``` --components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller]) --dry-run only print the object that would be applied + --export write the install manifests to stdout and exit -h, --help help for install --manifests string path to the manifest directory, dev only -v, --version string toolkit tag or branch (default "master")