Skip to content
Snippets Groups Projects
Commit 499ba150 authored by stefanprodan's avatar stefanprodan
Browse files

Add export option to tk install

parent b04abe98
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ import ( ...@@ -24,6 +24,7 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"strings" "strings"
"time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"sigs.k8s.io/kustomize/api/filesys" "sigs.k8s.io/kustomize/api/filesys"
...@@ -43,11 +44,15 @@ If a previous version is installed, then an in-place upgrade will be performed.` ...@@ -43,11 +44,15 @@ If a previous version is installed, then an in-place upgrade will be performed.`
# Dry-run install with manifests preview # Dry-run install with manifests preview
tk install --dry-run --verbose tk install --dry-run --verbose
# Write install manifests to file
tk install --export > gitops-system.yaml
`, `,
RunE: installCmdRun, RunE: installCmdRun,
} }
var ( var (
installExport bool
installDryRun bool installDryRun bool
installManifestsPath string installManifestsPath string
installVersion string installVersion string
...@@ -55,6 +60,8 @@ var ( ...@@ -55,6 +60,8 @@ var (
) )
func init() { func init() {
installCmd.Flags().BoolVar(&installExport, "export", false,
"write the install manifests to stdout and exit")
installCmd.Flags().BoolVarP(&installDryRun, "dry-run", "", false, installCmd.Flags().BoolVarP(&installDryRun, "dry-run", "", false,
"only print the object that would be applied") "only print the object that would be applied")
installCmd.Flags().StringVarP(&installVersion, "version", "v", defaultVersion, installCmd.Flags().StringVarP(&installVersion, "version", "v", defaultVersion,
...@@ -84,7 +91,9 @@ func installCmdRun(cmd *cobra.Command, args []string) error { ...@@ -84,7 +91,9 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
} }
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
if !installExport {
logger.Generatef("generating manifests") logger.Generatef("generating manifests")
}
if kustomizePath == "" { if kustomizePath == "" {
err = genInstallManifests(installVersion, namespace, installComponents, tmpDir) err = genInstallManifests(installVersion, namespace, installComponents, tmpDir)
if err != nil { if err != nil {
...@@ -104,6 +113,12 @@ func installCmdRun(cmd *cobra.Command, args []string) error { ...@@ -104,6 +113,12 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
} else { } else {
if verbose { if verbose {
fmt.Print(yaml) 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") logger.Successf("manifests build completed")
......
...@@ -23,6 +23,9 @@ tk install [flags] ...@@ -23,6 +23,9 @@ tk install [flags]
# Dry-run install with manifests preview # Dry-run install with manifests preview
tk install --dry-run --verbose tk install --dry-run --verbose
# Write install manifests to file
tk install --export > gitops-system.yaml
``` ```
### Options ### Options
...@@ -30,6 +33,7 @@ tk install [flags] ...@@ -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]) --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 --dry-run only print the object that would be applied
--export write the install manifests to stdout and exit
-h, --help help for install -h, --help help for install
--manifests string path to the manifest directory, dev only --manifests string path to the manifest directory, dev only
-v, --version string toolkit tag or branch (default "master") -v, --version string toolkit tag or branch (default "master")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment