diff --git a/clustermesh/clustermesh.go b/clustermesh/clustermesh.go index 58851522fc..2095c90565 100644 --- a/clustermesh/clustermesh.go +++ b/clustermesh/clustermesh.go @@ -474,11 +474,6 @@ type Parameters struct { Output string } -const ( - OutputJSON = "json" - OutputSummary = "summary" -) - func (p Parameters) validateParams() error { if p.ApiserverImage != defaults.ClusterMeshApiserverImage { return nil @@ -505,7 +500,7 @@ func NewK8sClusterMesh(client k8sClusterMeshImplementation, p Parameters) *K8sCl } func (k *K8sClusterMesh) Log(format string, a ...interface{}) { - if k.params.Output == OutputSummary { + if k.params.Output == status.OutputSummary { fmt.Fprintf(k.params.Writer, format+"\n", a...) } } @@ -1312,7 +1307,7 @@ func (k *K8sClusterMesh) Status(ctx context.Context) (*Status, error) { s.Connectivity, err = k.statusConnectivity(ctx) - if k.params.Output == OutputJSON { + if k.params.Output == status.OutputJSON { jsonStatus, err := json.MarshalIndent(s, "", " ") if err != nil { return nil, fmt.Errorf("failed to marshal status to JSON") diff --git a/internal/cli/cmd/clustermesh.go b/internal/cli/cmd/clustermesh.go index 630f973f0b..dd394835a7 100644 --- a/internal/cli/cmd/clustermesh.go +++ b/internal/cli/cmd/clustermesh.go @@ -15,6 +15,7 @@ import ( "github.com/cilium/cilium-cli/clustermesh" "github.com/cilium/cilium-cli/defaults" + "github.com/cilium/cilium-cli/status" ) func newCmdClusterMesh() *cobra.Command { diff --git a/internal/cli/cmd/status.go b/internal/cli/cmd/status.go index e07b9d2956..214cc48c18 100644 --- a/internal/cli/cmd/status.go +++ b/internal/cli/cmd/status.go @@ -35,7 +35,7 @@ func newCmdStatus() *cobra.Command { fmt.Print(s.Format()) fatalf("Unable to determine status: %s", err) } - if params.Output == "json" { + if params.Output == status.OutputJSON { jsonStatus, err := json.MarshalIndent(s, "", " ") if err != nil { // Report the most recent status even if an error occurred. @@ -55,7 +55,7 @@ func newCmdStatus() *cobra.Command { cmd.Flags().IntVar(¶ms.WorkerCount, "worker-count", status.DefaultWorkerCount, "The number of workers to use") - cmd.Flags().StringVarP(¶ms.Output, "output", "o", "summary", "Output format. One of: json, summary") + cmd.Flags().StringVarP(¶ms.Output, "output", "o", status.OutputSummary, "Output format. One of: json, summary") return cmd } diff --git a/status/status.go b/status/status.go index 036e51f788..1e7ecaab33 100644 --- a/status/status.go +++ b/status/status.go @@ -26,6 +26,11 @@ const ( Reset = "\033[0m" ) +const ( + OutputJSON = "json" + OutputSummary = "summary" +) + // MapCount is a map to count number of occurrences of a string type MapCount map[string]int