Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server-acl-init: Add -server-address and -server-port #238

Merged
merged 4 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions subcommand/server-acl-init/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ type Command struct {

flags *flag.FlagSet
k8s *k8sflags.K8SFlags
flagReleaseName string
flagServerLabelSelector string
flagResourcePrefix string
flagReplicas int
flagK8sNamespace string
flagAllowDNS bool
flagCreateClientToken bool
Expand All @@ -46,7 +43,7 @@ type Command struct {
flagConsulCACert string
ishustava marked this conversation as resolved.
Show resolved Hide resolved
flagConsulTLSServerName string
flagUseHTTPS bool
flagServerHosts []string
flagServerAddresses []string
flagServerPort uint

// Flags to support namespaces
Expand Down Expand Up @@ -77,9 +74,9 @@ func (c *Command) init() {
c.flags = flag.NewFlagSet("", flag.ContinueOnError)
c.flags.StringVar(&c.flagResourcePrefix, "resource-prefix", "",
"Prefix to use for Kubernetes resources. If not set, the \"<release-name>-consul\" prefix is used, where <release-name> is the value set by the -release-name flag.")
c.flags.Var((*flags.AppendSliceValue)(&c.flagServerHosts), "server-address",
"The address of the Consul server(s), may be provided multiple times. At least one value is required.")
c.flags.UintVar(&c.flagServerPort, "server-port", 8500, "The HTTP or HTTPS port of the Consul server.")
c.flags.Var((*flags.AppendSliceValue)(&c.flagServerAddresses), "server-address",
"The IP or DNS name of the Consul server(s), may be provided multiple times. At least one value is required.")
c.flags.UintVar(&c.flagServerPort, "server-port", 8500, "The HTTP or HTTPS port of the Consul server. Defaults to 8500.")
c.flags.StringVar(&c.flagK8sNamespace, "k8s-namespace", "",
"Name of Kubernetes namespace where the servers are deployed")
c.flags.BoolVar(&c.flagAllowDNS, "allow-dns", false,
Expand Down Expand Up @@ -166,12 +163,13 @@ func (c *Command) Run(args []string) int {
c.UI.Error("Should have no non-flag arguments.")
return 1
}
if len(c.flagServerHosts) == 0 {
if len(c.flagServerAddresses) == 0 {
c.UI.Error("-server-address must be set at least once")
return 1
}
if c.flagResourcePrefix == "" {
c.UI.Error("-resource-prefix must be set")
ishustava marked this conversation as resolved.
Show resolved Hide resolved
return 1
}
var aclReplicationToken string
if c.flagACLReplicationTokenFile != "" {
Expand Down Expand Up @@ -256,7 +254,7 @@ func (c *Command) Run(args []string) int {
}

// For all of the next operations we'll need a Consul client.
serverAddr := fmt.Sprintf("%s:%d", c.flagServerHosts[0], c.flagServerPort)
serverAddr := fmt.Sprintf("%s:%d", c.flagServerAddresses[0], c.flagServerPort)
consulClient, err := api.NewClient(&api.Config{
Address: serverAddr,
Scheme: scheme,
Expand Down Expand Up @@ -504,7 +502,7 @@ func (c *Command) untilSucceeds(opName string, op func() error) error {
}

// withPrefix returns the name of resource with the correct prefix based
// on the -resource-prefix flags.
// on the -resource-prefix flag.
func (c *Command) withPrefix(resource string) string {
return fmt.Sprintf("%s-%s", c.flagResourcePrefix, resource)
}
Expand Down
6 changes: 3 additions & 3 deletions subcommand/server-acl-init/command_ent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestRun_ConnectInject_SingleDestinationNamespace(t *testing.T) {
require.Len(methods, 1)

// Check the ACL auth method is created in the expected namespace.
authMethodName := releaseName + "-consul-k8s-auth-method"
authMethodName := resourcePrefix + "-k8s-auth-method"
actMethod, _, err := consul.ACL().AuthMethodRead(authMethodName, namespaceQuery)
require.NoError(err)
require.NotNil(actMethod)
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestRun_ConnectInject_NamespaceMirroring(t *testing.T) {
require.NoError(err)

// Check the ACL auth method is as expected.
authMethodName := releaseName + "-consul-k8s-auth-method"
authMethodName := resourcePrefix + "-k8s-auth-method"
method, _, err := consul.ACL().AuthMethodRead(authMethodName, nil)
require.NoError(err)
require.NotNil(method, authMethodName+" not found")
Expand Down Expand Up @@ -544,7 +544,7 @@ func TestRun_ConnectInject_Updates(t *testing.T) {
require.NoError(err)

// Check the ACL auth method is as expected.
authMethodName := releaseName + "-consul-k8s-auth-method"
authMethodName := resourcePrefix + "-k8s-auth-method"
method, _, err := consul.ACL().AuthMethodRead(authMethodName, &api.QueryOptions{
Namespace: c.AuthMethodExpectedNS,
})
Expand Down
Loading