From bfa7f46e18d6ee0bd3f9d53d12b55fd0a4c9d0b9 Mon Sep 17 00:00:00 2001 From: Luke Kysow <1034429+lkysow@users.noreply.github.com> Date: Thu, 7 May 2020 15:47:39 -0700 Subject: [PATCH] Extract http flags from consul/command pkg This decouples us from an internal Consul package. We've removed flags that we aren't using. --- go.mod | 2 + subcommand/acl-init/command.go | 7 +- .../create-federation-secret/command.go | 12 +- subcommand/delete-completed-job/command.go | 7 +- subcommand/flags/flag_duration_value.go | 64 ++++++++ subcommand/flags/flag_map_value.go | 40 +++++ subcommand/flags/flag_map_value_test.go | 83 ++++++++++ subcommand/flags/flag_slice_value.go | 23 +++ subcommand/flags/flag_slice_value_test.go | 38 +++++ subcommand/flags/flags.go | 2 + subcommand/flags/http.go | 144 ++++++++++++++++++ subcommand/flags/k8s.go | 4 +- subcommand/flags/usage.go | 117 ++++++++++++++ subcommand/get-consul-client-ca/command.go | 2 +- subcommand/inject-connect/command.go | 12 +- subcommand/lifecycle-sidecar/command.go | 6 +- subcommand/lifecycle-sidecar/command_test.go | 6 - subcommand/server-acl-init/command.go | 2 +- subcommand/service-address/command.go | 2 +- subcommand/sync-catalog/command.go | 10 +- 20 files changed, 537 insertions(+), 46 deletions(-) create mode 100644 subcommand/flags/flag_duration_value.go create mode 100644 subcommand/flags/flag_map_value.go create mode 100644 subcommand/flags/flag_map_value_test.go create mode 100644 subcommand/flags/flag_slice_value.go create mode 100644 subcommand/flags/flag_slice_value_test.go create mode 100644 subcommand/flags/flags.go create mode 100644 subcommand/flags/http.go create mode 100644 subcommand/flags/usage.go diff --git a/go.mod b/go.mod index 6c52d0ce26..e7ae78f33b 100644 --- a/go.mod +++ b/go.mod @@ -18,9 +18,11 @@ require ( github.com/hashicorp/golang-lru v0.5.3 // indirect github.com/imdario/mergo v0.3.8 // indirect github.com/json-iterator/go v1.1.8 // indirect + github.com/kr/text v0.1.0 github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a github.com/mitchellh/cli v1.0.0 github.com/mitchellh/go-homedir v1.1.0 + github.com/mitchellh/mapstructure v1.1.2 github.com/onsi/ginkgo v1.10.3 // indirect github.com/onsi/gomega v1.7.1 // indirect github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 diff --git a/subcommand/acl-init/command.go b/subcommand/acl-init/command.go index 2825ac12b3..bcf41fae0f 100644 --- a/subcommand/acl-init/command.go +++ b/subcommand/acl-init/command.go @@ -12,8 +12,7 @@ import ( "time" "github.com/hashicorp/consul-k8s/subcommand" - k8sflags "github.com/hashicorp/consul-k8s/subcommand/flags" - "github.com/hashicorp/consul/command/flags" + "github.com/hashicorp/consul-k8s/subcommand/flags" "github.com/mitchellh/cli" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" @@ -23,7 +22,7 @@ type Command struct { UI cli.Ui flags *flag.FlagSet - k8s *k8sflags.K8SFlags + k8s *flags.K8SFlags flagSecretName string flagInitType string flagNamespace string @@ -49,7 +48,7 @@ func (c *Command) init() { c.flags.StringVar(&c.flagTokenSinkFile, "token-sink-file", "", "Optional filepath to write acl token") - c.k8s = &k8sflags.K8SFlags{} + c.k8s = &flags.K8SFlags{} flags.Merge(c.flags, c.k8s.Flags()) c.help = flags.Usage(help, c.flags) } diff --git a/subcommand/create-federation-secret/command.go b/subcommand/create-federation-secret/command.go index 0ecefc6eb1..17924de105 100644 --- a/subcommand/create-federation-secret/command.go +++ b/subcommand/create-federation-secret/command.go @@ -14,9 +14,8 @@ import ( "github.com/cenkalti/backoff" "github.com/hashicorp/consul-k8s/subcommand" "github.com/hashicorp/consul-k8s/subcommand/common" - k8sflags "github.com/hashicorp/consul-k8s/subcommand/flags" + "github.com/hashicorp/consul-k8s/subcommand/flags" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/command/flags" "github.com/hashicorp/go-hclog" "github.com/mitchellh/cli" corev1 "k8s.io/api/core/v1" @@ -38,7 +37,7 @@ var retryInterval = 1 * time.Second type Command struct { UI cli.Ui flags *flag.FlagSet - k8s *k8sflags.K8SFlags + k8s *flags.K8SFlags http *flags.HTTPFlags // flagExportReplicationToken controls whether we include the acl replication @@ -90,12 +89,11 @@ func (c *Command) init() { "Log verbosity level. Supported values (in order of detail) are \"trace\", "+ "\"debug\", \"info\", \"warn\", and \"error\".") - c.help = flags.Usage(help, c.flags) c.http = &flags.HTTPFlags{} - c.k8s = &k8sflags.K8SFlags{} - flags.Merge(c.flags, c.http.ClientFlags()) - flags.Merge(c.flags, c.http.ServerFlags()) + c.k8s = &flags.K8SFlags{} + flags.Merge(c.flags, c.http.Flags()) flags.Merge(c.flags, c.k8s.Flags()) + c.help = flags.Usage(help, c.flags) } // Run creates a Kubernetes secret with data needed by secondary datacenters diff --git a/subcommand/delete-completed-job/command.go b/subcommand/delete-completed-job/command.go index 7b34fa8f43..6144bd8c4c 100644 --- a/subcommand/delete-completed-job/command.go +++ b/subcommand/delete-completed-job/command.go @@ -5,8 +5,7 @@ import ( "flag" "fmt" "github.com/hashicorp/consul-k8s/subcommand" - k8sflags "github.com/hashicorp/consul-k8s/subcommand/flags" - "github.com/hashicorp/consul/command/flags" + "github.com/hashicorp/consul-k8s/subcommand/flags" "github.com/hashicorp/go-hclog" "github.com/mitchellh/cli" v1 "k8s.io/api/batch/v1" @@ -24,7 +23,7 @@ type Command struct { UI cli.Ui flags *flag.FlagSet - k8s *k8sflags.K8SFlags + k8s *flags.K8SFlags flagNamespace string flagTimeout string @@ -39,7 +38,7 @@ type Command struct { func (c *Command) init() { c.flags = flag.NewFlagSet("", flag.ContinueOnError) - c.k8s = &k8sflags.K8SFlags{} + c.k8s = &flags.K8SFlags{} c.flags.StringVar(&c.flagNamespace, "k8s-namespace", "", "Name of Kubernetes namespace where the job is deployed") c.flags.StringVar(&c.flagTimeout, "timeout", "30m", diff --git a/subcommand/flags/flag_duration_value.go b/subcommand/flags/flag_duration_value.go new file mode 100644 index 0000000000..dd3dff27b0 --- /dev/null +++ b/subcommand/flags/flag_duration_value.go @@ -0,0 +1,64 @@ +package flags + +import ( + "reflect" + "time" + + "github.com/mitchellh/mapstructure" +) + +// Taken from https://github.com/hashicorp/consul/blob/master/command/flags/flag_duration_value.go +// This was done so we don't depend on internal Consul implementation. + +// DurationValue provides a flag value that's aware if it has been set. +type DurationValue struct { + v *time.Duration +} + +// Merge will overlay this value if it has been set. +func (d *DurationValue) Merge(onto *time.Duration) { + if d.v != nil { + *onto = *(d.v) + } +} + +// Set implements the flag.Value interface. +func (d *DurationValue) Set(v string) error { + if d.v == nil { + d.v = new(time.Duration) + } + var err error + *(d.v), err = time.ParseDuration(v) + return err +} + +// String implements the flag.Value interface. +func (d *DurationValue) String() string { + var current time.Duration + if d.v != nil { + current = *(d.v) + } + return current.String() +} + +// StringToDurationValueFunc is a mapstructure hook that looks for an incoming +// string mapped to a DurationValue and does the translation. +func StringToDurationValueFunc() mapstructure.DecodeHookFunc { + return func( + f reflect.Type, + t reflect.Type, + data interface{}) (interface{}, error) { + if f.Kind() != reflect.String { + return data, nil + } + + val := DurationValue{} + if t != reflect.TypeOf(val) { + return data, nil + } + if err := val.Set(data.(string)); err != nil { + return nil, err + } + return val, nil + } +} diff --git a/subcommand/flags/flag_map_value.go b/subcommand/flags/flag_map_value.go new file mode 100644 index 0000000000..26741abce8 --- /dev/null +++ b/subcommand/flags/flag_map_value.go @@ -0,0 +1,40 @@ +package flags + +import ( + "flag" + "fmt" + "strings" +) + +// Taken from https://github.com/hashicorp/consul/blob/master/command/flags/flag_map_value.go +// This was done so we don't depend on internal Consul implementation. + +// Ensure implements +var _ flag.Value = (*FlagMapValue)(nil) + +// FlagMapValue is a flag implementation used to provide key=value semantics +// multiple times. +type FlagMapValue map[string]string + +func (h *FlagMapValue) String() string { + return fmt.Sprintf("%v", *h) +} + +func (h *FlagMapValue) Set(value string) error { + idx := strings.Index(value, "=") + if idx == -1 { + return fmt.Errorf("Missing \"=\" value in argument: %s", value) + } + + key, value := value[0:idx], value[idx+1:] + + if *h == nil { + *h = make(map[string]string) + } + + headers := *h + headers[key] = value + *h = headers + + return nil +} diff --git a/subcommand/flags/flag_map_value_test.go b/subcommand/flags/flag_map_value_test.go new file mode 100644 index 0000000000..9871bef511 --- /dev/null +++ b/subcommand/flags/flag_map_value_test.go @@ -0,0 +1,83 @@ +package flags + +import ( + "fmt" + "testing" +) + +// Taken from https://github.com/hashicorp/consul/blob/master/command/flags/flag_map_value_test.go +// This was done so we don't depend on internal Consul implementation. + +func TestFlagMapValueSet(t *testing.T) { + t.Parallel() + + t.Run("missing =", func(t *testing.T) { + + f := new(FlagMapValue) + if err := f.Set("foo"); err == nil { + t.Fatal("expected error, got nil") + } + }) + + t.Run("sets", func(t *testing.T) { + + f := new(FlagMapValue) + if err := f.Set("foo=bar"); err != nil { + t.Fatal(err) + } + + r, ok := (*f)["foo"] + if !ok { + t.Errorf("missing value: %#v", f) + } + if exp := "bar"; r != exp { + t.Errorf("expected %q to be %q", r, exp) + } + }) + + t.Run("sets multiple", func(t *testing.T) { + + f := new(FlagMapValue) + + r := map[string]string{ + "foo": "bar", + "zip": "zap", + "cat": "dog", + } + + for k, v := range r { + if err := f.Set(fmt.Sprintf("%s=%s", k, v)); err != nil { + t.Fatal(err) + } + } + + for k, v := range r { + r, ok := (*f)[k] + if !ok { + t.Errorf("missing value %q: %#v", k, f) + } + if exp := v; r != exp { + t.Errorf("expected %q to be %q", r, exp) + } + } + }) + + t.Run("overwrites", func(t *testing.T) { + + f := new(FlagMapValue) + if err := f.Set("foo=bar"); err != nil { + t.Fatal(err) + } + if err := f.Set("foo=zip"); err != nil { + t.Fatal(err) + } + + r, ok := (*f)["foo"] + if !ok { + t.Errorf("missing value: %#v", f) + } + if exp := "zip"; r != exp { + t.Errorf("expected %q to be %q", r, exp) + } + }) +} diff --git a/subcommand/flags/flag_slice_value.go b/subcommand/flags/flag_slice_value.go new file mode 100644 index 0000000000..880297671c --- /dev/null +++ b/subcommand/flags/flag_slice_value.go @@ -0,0 +1,23 @@ +package flags + +import "strings" + +// Taken from https://github.com/hashicorp/consul/blob/master/command/flags/flag_slice_value.go +// This was done so we don't depend on internal Consul implementation. + +// AppendSliceValue implements the flag.Value interface and allows multiple +// calls to the same variable to append a list. +type AppendSliceValue []string + +func (s *AppendSliceValue) String() string { + return strings.Join(*s, ",") +} + +func (s *AppendSliceValue) Set(value string) error { + if *s == nil { + *s = make([]string, 0, 1) + } + + *s = append(*s, value) + return nil +} diff --git a/subcommand/flags/flag_slice_value_test.go b/subcommand/flags/flag_slice_value_test.go new file mode 100644 index 0000000000..58c05c8303 --- /dev/null +++ b/subcommand/flags/flag_slice_value_test.go @@ -0,0 +1,38 @@ +package flags + +import ( + "flag" + "reflect" + "testing" +) + +// Taken from https://github.com/hashicorp/consul/blob/master/command/flags/flag_slice_value_test.go +// This was done so we don't depend on internal Consul implementation. + +func TestAppendSliceValue_implements(t *testing.T) { + t.Parallel() + var raw interface{} + raw = new(AppendSliceValue) + if _, ok := raw.(flag.Value); !ok { + t.Fatalf("AppendSliceValue should be a Value") + } +} + +func TestAppendSliceValueSet(t *testing.T) { + t.Parallel() + sv := new(AppendSliceValue) + err := sv.Set("foo") + if err != nil { + t.Fatalf("err: %s", err) + } + + err = sv.Set("bar") + if err != nil { + t.Fatalf("err: %s", err) + } + + expected := []string{"foo", "bar"} + if !reflect.DeepEqual([]string(*sv), expected) { + t.Fatalf("Bad: %#v", sv) + } +} diff --git a/subcommand/flags/flags.go b/subcommand/flags/flags.go new file mode 100644 index 0000000000..e290e876d7 --- /dev/null +++ b/subcommand/flags/flags.go @@ -0,0 +1,2 @@ +// Package flags holds common flags that are shared between our commands. +package flags diff --git a/subcommand/flags/http.go b/subcommand/flags/http.go new file mode 100644 index 0000000000..e48c699032 --- /dev/null +++ b/subcommand/flags/http.go @@ -0,0 +1,144 @@ +package flags + +import ( + "flag" + "io/ioutil" + "strings" + + "github.com/hashicorp/consul/api" +) + +// Taken from https://github.com/hashicorp/consul/blob/master/command/flags/http.go +// with flags we don't use removed. This was done so we don't depend on internal +// Consul implementation. + +// HTTPFlags are flags used to configure communication with a Consul agent. +type HTTPFlags struct { + address StringValue + token StringValue + tokenFile StringValue + caFile StringValue + caPath StringValue + tlsServerName StringValue +} + +func (f *HTTPFlags) Flags() *flag.FlagSet { + fs := flag.NewFlagSet("", flag.ContinueOnError) + fs.Var(&f.address, "http-addr", + "The `address` and port of the Consul HTTP agent. The value can be an IP "+ + "address or DNS address, but it must also include the port. This can "+ + "also be specified via the CONSUL_HTTP_ADDR environment variable. The "+ + "default value is http://127.0.0.1:8500. The scheme can also be set to "+ + "HTTPS by setting the environment variable CONSUL_HTTP_SSL=true.") + fs.Var(&f.token, "token", + "ACL token to use in the request. This can also be specified via the "+ + "CONSUL_HTTP_TOKEN environment variable. If unspecified, the query will "+ + "default to the token of the Consul agent at the HTTP address.") + fs.Var(&f.tokenFile, "token-file", + "File containing the ACL token to use in the request instead of one specified "+ + "via the -token argument or CONSUL_HTTP_TOKEN environment variable. "+ + "This can also be specified via the CONSUL_HTTP_TOKEN_FILE environment variable.") + fs.Var(&f.caFile, "ca-file", + "Path to a CA file to use for TLS when communicating with Consul. This "+ + "can also be specified via the CONSUL_CACERT environment variable.") + fs.Var(&f.caPath, "ca-path", + "Path to a directory of CA certificates to use for TLS when communicating "+ + "with Consul. This can also be specified via the CONSUL_CAPATH environment variable.") + fs.Var(&f.tlsServerName, "tls-server-name", + "The server name to use as the SNI host when connecting via TLS. This "+ + "can also be specified via the CONSUL_TLS_SERVER_NAME environment variable.") + return fs +} + +func (f *HTTPFlags) Addr() string { + return f.address.String() +} + +func (f *HTTPFlags) Token() string { + return f.token.String() +} + +func (f *HTTPFlags) SetToken(v string) error { + return f.token.Set(v) +} + +func (f *HTTPFlags) TokenFile() string { + return f.tokenFile.String() +} + +func (f *HTTPFlags) SetTokenFile(v string) error { + return f.tokenFile.Set(v) +} + +func (f *HTTPFlags) ReadTokenFile() (string, error) { + tokenFile := f.tokenFile.String() + if tokenFile == "" { + return "", nil + } + + data, err := ioutil.ReadFile(tokenFile) + if err != nil { + return "", err + } + + return strings.TrimSpace(string(data)), nil +} + +func (f *HTTPFlags) APIClient() (*api.Client, error) { + c := api.DefaultConfig() + + f.MergeOntoConfig(c) + + return api.NewClient(c) +} + +func (f *HTTPFlags) MergeOntoConfig(c *api.Config) { + f.address.Merge(&c.Address) + f.token.Merge(&c.Token) + f.tokenFile.Merge(&c.TokenFile) + f.caFile.Merge(&c.TLSConfig.CAFile) + f.caPath.Merge(&c.TLSConfig.CAPath) + f.tlsServerName.Merge(&c.TLSConfig.Address) +} + +func Merge(dst, src *flag.FlagSet) { + if dst == nil { + panic("dst cannot be nil") + } + if src == nil { + return + } + src.VisitAll(func(f *flag.Flag) { + dst.Var(f.Value, f.Name, f.Usage) + }) +} + +// StringValue provides a flag value that's aware if it has been set. +type StringValue struct { + v *string +} + +// Merge will overlay this value if it has been set. +func (s *StringValue) Merge(onto *string) { + if s.v != nil { + *onto = *(s.v) + } +} + +// Set implements the flag.Value interface. +func (s *StringValue) Set(v string) error { + if s.v == nil { + s.v = new(string) + } + *(s.v) = v + return nil +} + +// String implements the flag.Value interface. +func (s *StringValue) String() string { + var current string + if s.v != nil { + current = *(s.v) + } + return current +} diff --git a/subcommand/flags/k8s.go b/subcommand/flags/k8s.go index ee3d951180..31a2284f65 100644 --- a/subcommand/flags/k8s.go +++ b/subcommand/flags/k8s.go @@ -2,12 +2,10 @@ package flags import ( "flag" - - "github.com/hashicorp/consul/command/flags" ) type K8SFlags struct { - kubeconfig flags.StringValue + kubeconfig StringValue } func (f *K8SFlags) Flags() *flag.FlagSet { diff --git a/subcommand/flags/usage.go b/subcommand/flags/usage.go new file mode 100644 index 0000000000..f34adabac0 --- /dev/null +++ b/subcommand/flags/usage.go @@ -0,0 +1,117 @@ +package flags + +import ( + "bytes" + "flag" + "fmt" + "io" + "strings" + + text "github.com/kr/text" +) + +// Taken from https://github.com/hashicorp/consul/blob/master/command/flags/usage.go +// This was done so we don't depend on internal Consul implementation. + +// Usage returns a usage string nicely formatted. +func Usage(txt string, flags *flag.FlagSet) string { + u := &Usager{ + Usage: txt, + Flags: flags, + } + return u.String() +} + +type Usager struct { + Usage string + Flags *flag.FlagSet +} + +func (u *Usager) String() string { + out := new(bytes.Buffer) + out.WriteString(strings.TrimSpace(u.Usage)) + out.WriteString("\n") + out.WriteString("\n") + + if u.Flags != nil { + f := &HTTPFlags{} + httpFlagSet := f.Flags() + + var httpFlags, cmdFlags *flag.FlagSet + u.Flags.VisitAll(func(f *flag.Flag) { + if contains(httpFlagSet, f) { + if httpFlags == nil { + httpFlags = flag.NewFlagSet("", flag.ContinueOnError) + } + httpFlags.Var(f.Value, f.Name, f.Usage) + } else { + if cmdFlags == nil { + cmdFlags = flag.NewFlagSet("", flag.ContinueOnError) + } + cmdFlags.Var(f.Value, f.Name, f.Usage) + } + }) + + if httpFlags != nil { + printTitle(out, "HTTP API Options") + httpFlags.VisitAll(func(f *flag.Flag) { + printFlag(out, f) + }) + } + + if cmdFlags != nil { + printTitle(out, "Command Options") + cmdFlags.VisitAll(func(f *flag.Flag) { + printFlag(out, f) + }) + } + } + + return strings.TrimRight(out.String(), "\n") +} + +// printTitle prints a consistently-formatted title to the given writer. +func printTitle(w io.Writer, s string) { + fmt.Fprintf(w, "%s\n\n", s) +} + +// printFlag prints a single flag to the given writer. +func printFlag(w io.Writer, f *flag.Flag) { + example, _ := flag.UnquoteUsage(f) + if example != "" { + fmt.Fprintf(w, " -%s=<%s>\n", f.Name, example) + } else { + fmt.Fprintf(w, " -%s\n", f.Name) + } + + indented := wrapAtLength(f.Usage, 5) + fmt.Fprintf(w, "%s\n\n", indented) +} + +// contains returns true if the given flag is contained in the given flag +// set or false otherwise. +func contains(fs *flag.FlagSet, f *flag.Flag) bool { + if fs == nil { + return false + } + + var in bool + fs.VisitAll(func(hf *flag.Flag) { + in = in || f.Name == hf.Name + }) + return in +} + +// maxLineLength is the maximum width of any line. +const maxLineLength int = 72 + +// wrapAtLength wraps the given text at the maxLineLength, taking into account +// any provided left padding. +func wrapAtLength(s string, pad int) string { + wrapped := text.Wrap(s, maxLineLength-pad) + lines := strings.Split(wrapped, "\n") + for i, line := range lines { + lines[i] = strings.Repeat(" ", pad) + line + } + return strings.Join(lines, "\n") +} diff --git a/subcommand/get-consul-client-ca/command.go b/subcommand/get-consul-client-ca/command.go index 4453f48a8e..2cea786540 100644 --- a/subcommand/get-consul-client-ca/command.go +++ b/subcommand/get-consul-client-ca/command.go @@ -11,8 +11,8 @@ import ( "github.com/cenkalti/backoff" godiscover "github.com/hashicorp/consul-k8s/helper/go-discover" + "github.com/hashicorp/consul-k8s/subcommand/flags" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/command/flags" "github.com/hashicorp/go-discover" "github.com/hashicorp/go-hclog" "github.com/mitchellh/cli" diff --git a/subcommand/inject-connect/command.go b/subcommand/inject-connect/command.go index 430abb5493..935d355f67 100644 --- a/subcommand/inject-connect/command.go +++ b/subcommand/inject-connect/command.go @@ -16,8 +16,8 @@ import ( "github.com/deckarep/golang-set" "github.com/hashicorp/consul-k8s/connect-inject" "github.com/hashicorp/consul-k8s/helper/cert" + "github.com/hashicorp/consul-k8s/subcommand/flags" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/command/flags" "github.com/hashicorp/go-hclog" "github.com/mitchellh/cli" "k8s.io/apimachinery/pkg/types" @@ -25,13 +25,6 @@ import ( "k8s.io/client-go/rest" ) -type arrayFlags []string - -func (i *arrayFlags) Set(value string) error { - *i = append(*i, value) - return nil -} - type Command struct { UI cli.Ui @@ -113,8 +106,7 @@ func (c *Command) init() { "discovery across Consul namespaces. Only necessary if ACLs are enabled.") c.http = &flags.HTTPFlags{} - flags.Merge(c.flagSet, c.http.ClientFlags()) - flags.Merge(c.flagSet, c.http.ServerFlags()) + flags.Merge(c.flagSet, c.http.Flags()) c.help = flags.Usage(help, c.flagSet) } diff --git a/subcommand/lifecycle-sidecar/command.go b/subcommand/lifecycle-sidecar/command.go index 4dc94dec56..a2093859ff 100644 --- a/subcommand/lifecycle-sidecar/command.go +++ b/subcommand/lifecycle-sidecar/command.go @@ -10,7 +10,7 @@ import ( "sync" "time" - "github.com/hashicorp/consul/command/flags" + "github.com/hashicorp/consul-k8s/subcommand/flags" "github.com/hashicorp/go-hclog" "github.com/mitchellh/cli" "github.com/prometheus/common/log" @@ -44,7 +44,7 @@ func (c *Command) init() { c.help = flags.Usage(help, c.flagSet) c.http = &flags.HTTPFlags{} - flags.Merge(c.flagSet, c.http.ClientFlags()) + flags.Merge(c.flagSet, c.http.Flags()) c.help = flags.Usage(help, c.flagSet) // Wait on an interrupt to exit. This channel must be initialized before @@ -153,7 +153,7 @@ func (c *Command) validateFlags() error { // from command's HTTP flags and returns them as an array of strings. func (c *Command) parseConsulFlags() []string { var consulCommandFlags []string - c.http.ClientFlags().VisitAll(func(f *flag.Flag) { + c.http.Flags().VisitAll(func(f *flag.Flag) { if f.Value.String() != "" { consulCommandFlags = append(consulCommandFlags, fmt.Sprintf("-%s=%s", f.Name, f.Value.String())) } diff --git a/subcommand/lifecycle-sidecar/command_test.go b/subcommand/lifecycle-sidecar/command_test.go index 5e434847b5..1a7f2f966a 100644 --- a/subcommand/lifecycle-sidecar/command_test.go +++ b/subcommand/lifecycle-sidecar/command_test.go @@ -233,9 +233,6 @@ func TestRun_ConsulCommandFlags(t *testing.T) { "-token-file=/token/file", "-ca-file=/ca/file", "-ca-path=/ca/path", - "-client-cert=/client/cert", - "-client-key=/client/key", - "-tls-server-name=consul.foo.com", }) defer stopCommand(t, &cmd, exitChan) @@ -247,9 +244,6 @@ func TestRun_ConsulCommandFlags(t *testing.T) { "-token-file=/token/file", "-ca-file=/ca/file", "-ca-path=/ca/path", - "-client-cert=/client/cert", - "-client-key=/client/key", - "-tls-server-name=consul.foo.com", configFile, } timer := &retry.Timer{Timeout: 1000 * time.Millisecond, Wait: 100 * time.Millisecond} diff --git a/subcommand/server-acl-init/command.go b/subcommand/server-acl-init/command.go index 1f8161ebef..e3c8949cfe 100644 --- a/subcommand/server-acl-init/command.go +++ b/subcommand/server-acl-init/command.go @@ -14,9 +14,9 @@ import ( godiscover "github.com/hashicorp/consul-k8s/helper/go-discover" "github.com/hashicorp/consul-k8s/subcommand" "github.com/hashicorp/consul-k8s/subcommand/common" + "github.com/hashicorp/consul-k8s/subcommand/flags" k8sflags "github.com/hashicorp/consul-k8s/subcommand/flags" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/command/flags" "github.com/hashicorp/go-discover" "github.com/hashicorp/go-hclog" "github.com/mitchellh/cli" diff --git a/subcommand/service-address/command.go b/subcommand/service-address/command.go index 83e24c29b1..78b58a26cd 100644 --- a/subcommand/service-address/command.go +++ b/subcommand/service-address/command.go @@ -12,8 +12,8 @@ import ( "github.com/cenkalti/backoff" "github.com/hashicorp/consul-k8s/subcommand" + "github.com/hashicorp/consul-k8s/subcommand/flags" k8sflags "github.com/hashicorp/consul-k8s/subcommand/flags" - "github.com/hashicorp/consul/command/flags" "github.com/hashicorp/go-hclog" "github.com/mitchellh/cli" v1 "k8s.io/api/core/v1" diff --git a/subcommand/sync-catalog/command.go b/subcommand/sync-catalog/command.go index b9738f2145..25353d99c9 100644 --- a/subcommand/sync-catalog/command.go +++ b/subcommand/sync-catalog/command.go @@ -15,9 +15,8 @@ import ( catalogtok8s "github.com/hashicorp/consul-k8s/catalog/to-k8s" "github.com/hashicorp/consul-k8s/helper/controller" "github.com/hashicorp/consul-k8s/subcommand" - k8sflags "github.com/hashicorp/consul-k8s/subcommand/flags" + "github.com/hashicorp/consul-k8s/subcommand/flags" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/command/flags" "github.com/hashicorp/go-hclog" "github.com/mitchellh/cli" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -32,7 +31,7 @@ type Command struct { flags *flag.FlagSet http *flags.HTTPFlags - k8s *k8sflags.K8SFlags + k8s *flags.K8SFlags flagListen string flagToConsul bool flagToK8S bool @@ -130,9 +129,8 @@ func (c *Command) init() { "discovery across Consul namespaces. Only necessary if ACLs are enabled.") c.http = &flags.HTTPFlags{} - c.k8s = &k8sflags.K8SFlags{} - flags.Merge(c.flags, c.http.ClientFlags()) - flags.Merge(c.flags, c.http.ServerFlags()) + c.k8s = &flags.K8SFlags{} + flags.Merge(c.flags, c.http.Flags()) flags.Merge(c.flags, c.k8s.Flags()) c.help = flags.Usage(help, c.flags)