diff --git a/cmd/apply.go b/cmd/apply.go index 3dd08cb..e96bfeb 100644 --- a/cmd/apply.go +++ b/cmd/apply.go @@ -116,7 +116,7 @@ func applyAppGroup(group string, namespace string, outputDir string, appFilter s var applyCmd = &cobra.Command{ Use: "apply", Short: "Apply resources to k8s", - Args: cobra.MinimumNArgs(1), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { namespace, _ := cmd.Flags().GetString("namespace") diff --git a/cmd/applyNamespace.go b/cmd/applyNamespace.go index 658baf1..2ce1219 100644 --- a/cmd/applyNamespace.go +++ b/cmd/applyNamespace.go @@ -28,7 +28,7 @@ import ( var namespaceCmd = &cobra.Command{ Use: "apply-namespace", Short: "Namespace apply", - Args: cobra.MinimumNArgs(1), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { lint, _ := cmd.Flags().GetBool("lint") diff --git a/cmd/delete.go b/cmd/delete.go index 0970eb5..cf50bb2 100644 --- a/cmd/delete.go +++ b/cmd/delete.go @@ -41,7 +41,7 @@ func deleteAppGroup(group string, namespace string, appFilter string) error { var deleteCmd = &cobra.Command{ Use: "delete", Short: "Delete app group or app", - Args: cobra.MinimumNArgs(1), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { group := args[0] diff --git a/cmd/deleteNamespace.go b/cmd/deleteNamespace.go index 6efe961..de1c884 100644 --- a/cmd/deleteNamespace.go +++ b/cmd/deleteNamespace.go @@ -28,7 +28,7 @@ import ( var deleteNamespaceCmd = &cobra.Command{ Use: "delete-namespace", Short: "Namespace apply", - Args: cobra.MinimumNArgs(1), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { appFilter, _ := cmd.Flags().GetString("app") diff --git a/cmd/syncRepos.go b/cmd/syncRepos.go new file mode 100644 index 0000000..4be5ee1 --- /dev/null +++ b/cmd/syncRepos.go @@ -0,0 +1,41 @@ +/* +Copyright © 2020 Artyom Topchyan a.topchyan@reply.de + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "github.com/spf13/cobra" +) + +// syncReposCmd represents the delete command +var syncReposCmd = &cobra.Command{ + Use: "sync-repos", + Short: "Sync repositories listed in a state file, primarily useful for Helmfile", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + + err := templateEngine.SyncRepos(args[0]) + if err != nil { + return err + } + + return nil + }, +} + +func init() { + rootCmd.AddCommand(syncReposCmd) + +} diff --git a/pkg/template/helmfile.go b/pkg/template/helmfile.go index 83cb502..8b75eb5 100644 --- a/pkg/template/helmfile.go +++ b/pkg/template/helmfile.go @@ -33,6 +33,7 @@ func NewHelmFileEngine(Opts Opts, log logr.Logger) *HelmFileEngine { } func (e *HelmFileEngine) Template(name string, inputFilePath string, outputFilePath string) error { + inputArgs := append([]string{"--environment", e.Opts.Environment, "--file", inputFilePath, "--state-values-set", fmt.Sprintf("app=%s", name), "template", "--output-dir", outputFilePath}, e.Opts.ExtraArgs...) @@ -69,3 +70,21 @@ func (e *HelmFileEngine) Lint(name string, inputFilePath string) error { return nil } + +func (e *HelmFileEngine) SyncRepos(file string) error { + + inputArgs := append([]string{"-f", file, "repos"}, e.Opts.ExtraArgs...) + + cmd := exec.Command("helmfile", inputArgs...) + + print := func(in string) { + e.log.Info(in) + } + + err := utils.ExecWithOutput(cmd, print, print) + + if err != nil { + return err + } + return nil +} diff --git a/pkg/template/interfaces.go b/pkg/template/interfaces.go index b146be3..a78252d 100644 --- a/pkg/template/interfaces.go +++ b/pkg/template/interfaces.go @@ -22,6 +22,7 @@ const ( type TemplateEngine interface { Template(name string, inputFilePath string, outputFilePath string) error Lint(name string, inputFilePath string) error + SyncRepos(file string) error } type Opts struct { diff --git a/pkg/template/kontemplate.go b/pkg/template/kontemplate.go index c1eeefd..cc1d837 100644 --- a/pkg/template/kontemplate.go +++ b/pkg/template/kontemplate.go @@ -51,3 +51,7 @@ func (e *KontemplateEngine) Lint(name string, inputFilePath string) error { return nil } + +func (e *KontemplateEngine) SyncRepos(file string) error { + return nil +} diff --git a/pkg/utils/stringUtils.go b/pkg/utils/stringUtils.go index 78c6540..a4cfa6f 100644 --- a/pkg/utils/stringUtils.go +++ b/pkg/utils/stringUtils.go @@ -36,7 +36,11 @@ func ConcatDirs(strs ...string) string { return filepath.Clean(sb.String()) } -func GetNamespaceDir(namespace string) string { + +func GetRealmeDir() string { dir, _ := os.Getwd() - return ConcatDirs(dir, "realm", "namespaces", namespace) + return ConcatDirs(dir, "realm") +} +func GetNamespaceDir(namespace string) string { + return ConcatDirs(GetRealmeDir(), "namespaces", namespace) } diff --git a/realm/namespaces/_defaults.yaml b/realm/namespaces/_defaults.yaml new file mode 100644 index 0000000..b1668a0 --- /dev/null +++ b/realm/namespaces/_defaults.yaml @@ -0,0 +1,8 @@ +repositories: +# To use official "stable" charts a.k.a https://github.com/helm/charts/tree/master/stable +- name: stable + url: https://kubernetes-charts.storage.googleapis.com + +releases: + - name: dummy + chart: stable/raw \ No newline at end of file