blob: 47d92ab77b703afe8c730981eb4d67bdb63033a4 [file] [log] [blame]
Serge Bazanskibe538db2020-11-12 00:22:42 +01001// Copyright 2017 The kubecfg authors
2//
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16package cmd
17
18import (
19 "github.com/spf13/cobra"
20
21 "code.hackerspace.pl/hscloud/cluster/tools/kartongips/pkg/kubecfg"
22)
23
24const (
25 flagDiffStrategy = "diff-strategy"
26 flagOmitSecrets = "omit-secrets"
27)
28
29func init() {
30 diffCmd.PersistentFlags().String(flagDiffStrategy, "all", "Diff strategy, all or subset.")
31 diffCmd.PersistentFlags().Bool(flagOmitSecrets, false, "hide secret details when showing diff")
32 RootCmd.AddCommand(diffCmd)
33}
34
35var diffCmd = &cobra.Command{
36 Use: "diff",
37 Short: "Display differences between server and local config",
38 Args: cobra.ArbitraryArgs,
39 RunE: func(cmd *cobra.Command, args []string) error {
40 flags := cmd.Flags()
41 var err error
42
43 c := kubecfg.DiffCmd{}
44
45 c.DiffStrategy, err = flags.GetString(flagDiffStrategy)
46 if err != nil {
47 return err
48 }
49
50 c.OmitSecrets, err = flags.GetBool(flagOmitSecrets)
51 if err != nil {
52 return err
53 }
54
55 c.Client, c.Mapper, _, err = getDynamicClients(cmd)
56 if err != nil {
57 return err
58 }
59
60 c.DefaultNamespace, err = defaultNamespace(clientConfig)
61 if err != nil {
62 return err
63 }
64
65 objs, err := readObjs(cmd, args)
66 if err != nil {
67 return err
68 }
69
70 return c.Run(cmd.Context(), objs, cmd.OutOrStdout())
71 },
72}