Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashwin Venkatesh committed Mar 7, 2022
1 parent fa539f4 commit a25a183
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion charts/consul/templates/server-acl-init-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ spec:
{{- end }}
{{- if .Values.syncCatalog.enabled }}
-create-sync-policy=true \
-sync-catalog=true \
{{- if .Values.syncCatalog.consulNodeName }}
-sync-consul-node-name={{ .Values.syncCatalog.consulNodeName }} \
{{- end }}
Expand Down
4 changes: 2 additions & 2 deletions charts/consul/test/unit/server-acl-init-job.bats
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ load _helpers
-s templates/server-acl-init-job.yaml \
--set 'global.acls.manageSystemACLs=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command | any(contains("-create-sync-policy"))' | tee /dev/stderr)
yq '.spec.template.spec.containers[0].command | any(contains("-sync-catalog"))' | tee /dev/stderr)
[ "${actual}" = "false" ]
}

Expand All @@ -260,7 +260,7 @@ load _helpers
--set 'global.acls.manageSystemACLs=true' \
--set 'syncCatalog.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command | any(contains("-create-sync-policy"))' | tee /dev/stderr)
yq '.spec.template.spec.containers[0].command | any(contains("-sync-catalog"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

Expand Down
10 changes: 5 additions & 5 deletions control-plane/subcommand/server-acl-init/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Command struct {

flagCreateClientToken bool

flagCreateSyncPolicy bool
flagEnableCatalogSync bool
flagSyncConsulNodeName string

flagEnableConnectInject bool
Expand Down Expand Up @@ -126,7 +126,7 @@ func (c *Command) init() {
c.flags.BoolVar(&c.flagCreateClientToken, "create-client-token", true,
"Toggle for creating a client agent token. Default is true.")

c.flags.BoolVar(&c.flagCreateSyncPolicy, "create-sync-policy", false,
c.flags.BoolVar(&c.flagEnableCatalogSync, "sync-catalog", false,
"Toggle for creating a catalog sync policy.")
c.flags.StringVar(&c.flagSyncConsulNodeName, "sync-consul-node-name", "k8s-sync",
"The Consul node name to register for catalog sync. Defaults to k8s-sync. To be discoverable "+
Expand Down Expand Up @@ -481,7 +481,7 @@ func (c *Command) Run(args []string) int {
}
}

if c.flagCreateSyncPolicy {
if c.flagEnableCatalogSync {
syncRules, err := c.syncRules()
if err != nil {
c.log.Error("Error templating sync rules", "err", err)
Expand All @@ -499,9 +499,9 @@ func (c *Command) Run(args []string) int {
if !primary {
componentAuthMethodName = globalComponentAuthMethodName
}
err = c.createACLPolicyRoleAndBindingRule("sync-catalog", syncRules, consulDC, primaryDC, globalToken, primary, componentAuthMethodName, serviceAccountName, consulClient)
err = c.createACLPolicyRoleAndBindingRule("sync-catalog", syncRules, consulDC, primaryDC, globalPolicy, primary, componentAuthMethodName, serviceAccountName, consulClient)
} else {
err = c.createACLPolicyRoleAndBindingRule("sync-catalog", syncRules, consulDC, primaryDC, localToken, primary, componentAuthMethodName, serviceAccountName, consulClient)
err = c.createACLPolicyRoleAndBindingRule("sync-catalog", syncRules, consulDC, primaryDC, localPolicy, primary, componentAuthMethodName, serviceAccountName, consulClient)
}
if err != nil {
c.log.Error(err.Error())
Expand Down
6 changes: 3 additions & 3 deletions control-plane/subcommand/server-acl-init/command_ent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func TestRun_ACLPolicyUpdates(t *testing.T) {
"-create-client-token",
"-allow-dns",
"-create-mesh-gateway-token",
"-create-sync-policy",
"-sync-catalog",
"-connect-inject",
"-create-snapshot-agent-token",
"-create-enterprise-license-token",
Expand Down Expand Up @@ -1073,7 +1073,7 @@ func TestRun_NamespaceEnabled_ValidateLoginToken_PrimaryDatacenter(t *testing.T)
},
{
ComponentName: "sync-catalog",
TokenFlags: []string{"-create-sync-policy"},
TokenFlags: []string{"-sync-catalog"},
Roles: []string{resourcePrefix + "-sync-catalog-acl-role"},
Namespace: ns,
GlobalToken: false,
Expand Down Expand Up @@ -1164,7 +1164,7 @@ func TestRun_NamespaceEnabled_ValidateLoginToken_SecondaryDatacenter(t *testing.
},
{
ComponentName: "sync-catalog",
TokenFlags: []string{"-create-sync-policy"},
TokenFlags: []string{"-sync-catalog"},
Roles: []string{resourcePrefix + "-sync-catalog-acl-role-dc2"},
Namespace: ns,
GlobalToken: true,
Expand Down
12 changes: 6 additions & 6 deletions control-plane/subcommand/server-acl-init/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ func TestRun_SyncPolicyUpdates(t *testing.T) {
"-k8s-namespace=" + ns,
"-server-address", strings.Split(testSvr.HTTPAddr, ":")[0],
"-server-port", strings.Split(testSvr.HTTPAddr, ":")[1],
"-create-sync-policy",
"-sync-catalog",
}
firstRunArgs := append(commonArgs,
"-sync-consul-node-name=k8s-sync",
Expand Down Expand Up @@ -1122,7 +1122,7 @@ func TestRun_ErrorsOnDuplicateACLPolicy(t *testing.T) {
"-k8s-namespace=" + ns,
"-server-address", strings.Split(testAgent.HTTPAddr, ":")[0],
"-server-port", strings.Split(testAgent.HTTPAddr, ":")[1],
"-create-sync-policy",
"-sync-catalog",
}
responseCode := cmd.Run(cmdArgs)

Expand Down Expand Up @@ -2159,7 +2159,7 @@ func TestRun_PoliciesAndBindingRulesForACLLogin_PrimaryDatacenter(t *testing.T)
},
{
TestName: "Sync Catalog",
TokenFlags: []string{"-create-sync-policy"},
TokenFlags: []string{"-sync-catalog"},
PolicyNames: []string{"sync-catalog-policy"},
Roles: []string{resourcePrefix + "-sync-catalog-acl-role"},
},
Expand Down Expand Up @@ -2269,7 +2269,7 @@ func TestRun_PoliciesAndBindingRulesACLLogin_SecondaryDatacenter(t *testing.T) {
},
{
TestName: "Sync Catalog",
TokenFlags: []string{"-create-sync-policy"},
TokenFlags: []string{"-sync-catalog"},
PolicyNames: []string{"sync-catalog-policy-" + secondaryDatacenter},
Roles: []string{resourcePrefix + "-sync-catalog-acl-role-" + secondaryDatacenter},
GlobalAuthMethod: false,
Expand Down Expand Up @@ -2378,7 +2378,7 @@ func TestRun_ValidateLoginToken_PrimaryDatacenter(t *testing.T) {
},
{
ComponentName: "sync-catalog",
TokenFlags: []string{"-create-sync-policy"},
TokenFlags: []string{"-sync-catalog"},
Roles: []string{resourcePrefix + "-sync-catalog-acl-role"},
},
}
Expand Down Expand Up @@ -2471,7 +2471,7 @@ func TestRun_ValidateLoginToken_SecondaryDatacenter(t *testing.T) {
},
{
ComponentName: "sync-catalog",
TokenFlags: []string{"-create-sync-policy"},
TokenFlags: []string{"-sync-catalog"},
Roles: []string{resourcePrefix + "-sync-catalog-acl-role-dc2"},
GlobalAuthMethod: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (c *Command) createOrUpdateACLPolicy(policy api.ACLPolicy, consulClient *ap
// Allowing the Consul node name to be configurable also requires any sync
// policy to be updated in case the node name has changed.
if isPolicyExistsErr(err, policy.Name) {
if c.flagEnableNamespaces || c.flagCreateSyncPolicy {
if c.flagEnableNamespaces || c.flagEnableCatalogSync {
c.log.Info(fmt.Sprintf("Policy %q already exists, updating", policy.Name))

// The policy ID is required in any PolicyUpdate call, so first we need to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ func TestCreateOrUpdateACLPolicy_ErrorsIfDescriptionDoesNotMatch(t *testing.T) {
ui := cli.NewMockUi()
k8s := fake.NewSimpleClientset()
cmd := Command{
UI: ui,
clientset: k8s,
log: hclog.NewNullLogger(),
flagCreateSyncPolicy: true,
UI: ui,
clientset: k8s,
log: hclog.NewNullLogger(),
flagEnableCatalogSync: true,
}

// Start Consul.
Expand Down

0 comments on commit a25a183

Please sign in to comment.