From 1bc637a43fe07aa98b4ea147a39dde83890d98bf Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Tue, 9 Jun 2020 12:15:31 +0300 Subject: [PATCH] Add export flag to create commands --- cmd/tk/create.go | 2 ++ cmd/tk/create_kustomization.go | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/tk/create.go b/cmd/tk/create.go index a227e327..d8f1aa0e 100644 --- a/cmd/tk/create.go +++ b/cmd/tk/create.go @@ -13,9 +13,11 @@ var createCmd = &cobra.Command{ var ( interval time.Duration + export bool ) func init() { createCmd.PersistentFlags().DurationVarP(&interval, "interval", "", time.Minute, "source sync interval") + createCmd.PersistentFlags().BoolVar(&export, "export", false, "export in yaml format to stdout") rootCmd.AddCommand(createCmd) } diff --git a/cmd/tk/create_kustomization.go b/cmd/tk/create_kustomization.go index b8981483..24bc652a 100644 --- a/cmd/tk/create_kustomization.go +++ b/cmd/tk/create_kustomization.go @@ -3,11 +3,9 @@ package main import ( "context" "fmt" - kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1alpha1" "strings" "time" - sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1" "github.com/spf13/cobra" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -15,6 +13,9 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/wait" "sigs.k8s.io/controller-runtime/pkg/client" + + kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1alpha1" + sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1" ) var createKsCmd = &cobra.Command{ @@ -106,7 +107,9 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error { return err } - logGenerate("generating kustomization") + if !export { + logGenerate("generating kustomization") + } emptyAPIGroup := "" kustomization := kustomizev1.Kustomization{ @@ -171,6 +174,10 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error { } } + if export { + return exportKs(kustomization) + } + logAction("applying kustomization") if err := upsertKustomization(ctx, kubeClient, kustomization); err != nil { return err