Skip to content

Commit

Permalink
Add review changes suggested by Luke
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashwin Venkatesh committed Dec 1, 2021
1 parent 3996a05 commit ec91c64
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
11 changes: 5 additions & 6 deletions charts/consul/templates/partition-init-job.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{- $serverEnabled := (or (and (ne (.Values.server.enabled | toString) "-") .Values.server.enabled) (and (eq (.Values.server.enabled | toString) "-") .Values.global.enabled)) -}}
{{- if (and .Values.global.adminPartitions.enabled (not $serverEnabled)) }}
{{- template "consul.reservedNamesFailer" (list .Values.global.adminPartitions.name "global.adminPartitions.name") }}
{{- if and (not .Values.externalServers.enabled) (ne .Values.global.adminPartitions.name "default") }}{{ fail "externalServers.enabled needs to be true and configured to create a non-default partition." }}{{ end -}}
{{- if (and .Values.global.adminPartitions.enabled (not $serverEnabled) (ne .Values.global.adminPartitions.name "default") .Values.externalServers.enabled) }}
apiVersion: batch/v1
kind: Job
metadata:
Expand Down Expand Up @@ -31,7 +32,7 @@ spec:
restartPolicy: Never
serviceAccountName: {{ template "consul.fullname" . }}-partition-init
{{- if .Values.global.tls.enabled }}
{{- if not (and .Values.externalServers.enabled .Values.externalServers.useSystemRoots) }}
{{- if not .Values.externalServers.useSystemRoots }}
volumes:
- name: consul-ca-cert
secret:
Expand Down Expand Up @@ -61,7 +62,7 @@ spec:
key: {{ .Values.global.acls.bootstrapToken.secretKey }}
{{- end }}
{{- if .Values.global.tls.enabled }}
{{- if not (and .Values.externalServers.enabled .Values.externalServers.useSystemRoots) }}
{{- if not .Values.externalServers.useSystemRoots }}
volumeMounts:
- name: consul-ca-cert
mountPath: /consul/tls/ca
Expand All @@ -72,8 +73,6 @@ spec:
- "/bin/sh"
- "-ec"
- |
CONSUL_FULLNAME="{{template "consul.fullname" . }}"
consul-k8s-control-plane partition-init \
-log-level={{ .Values.global.logLevel }} \
-log-json={{ .Values.global.logJSON }} \
Expand All @@ -86,7 +85,7 @@ spec:
{{- if .Values.global.tls.enabled }}
-use-https \
{{- if not (and .Values.externalServers.enabled .Values.externalServers.useSystemRoots) }}
{{- if not .Values.externalServers.useSystemRoots }}
-consul-ca-cert=/consul/tls/ca/tls.crt \
{{- end }}
{{- if .Values.externalServers.tlsServerName }}
Expand Down
34 changes: 34 additions & 0 deletions charts/consul/test/unit/partition-init-job.bats
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ load _helpers
-s templates/partition-init-job.yaml \
--set 'global.adminPartitions.enabled=true' \
--set 'server.enabled=false' \
--set 'global.adminPartitions.name=bar' \
--set 'externalServers.enabled=true' \
--set 'externalServers.hosts[0]=foo' \
. | tee /dev/stderr |
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "true" ]
Expand All @@ -29,6 +32,15 @@ load _helpers
.
}

@test "partitionInit/Job: disabled with global.adminPartitions.enabled=true and adminPartition.name = default" {
cd `chart_dir`
assert_empty helm template \
-s templates/partition-init-job.yaml \
--set 'global.adminPartitions.enabled=true' \
--set 'server.enabled=false' \
.
}

@test "partitionInit/Job: disabled with global.adminPartitions.enabled=true and global.enabled = true" {
cd `chart_dir`
assert_empty helm template \
Expand All @@ -47,6 +59,18 @@ load _helpers
.
}

@test "partitionInit/Job: fails if externalServers.enabled = false with non-default adminPartition" {
cd `chart_dir`
run helm template \
-s templates/partition-init-job.yaml \
--set 'global.adminPartitions.enabled=true' \
--set 'global.adminPartitions.name=bar' \
--set 'server.enabled=false' \
--set 'externalServers.enabled=false' .
[ "$status" -eq 1 ]
[[ "$output" =~ "externalServers.enabled needs to be true and configured to create a non-default partition." ]]
}

#--------------------------------------------------------------------
# global.tls.enabled

Expand All @@ -57,6 +81,9 @@ load _helpers
--set 'global.enabled=false' \
--set 'global.adminPartitions.enabled=true' \
--set 'global.tls.enabled=true' \
--set 'global.adminPartitions.name=bar' \
--set 'externalServers.enabled=true' \
--set 'externalServers.hosts[0]=foo' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].command' | tee /dev/stderr)

Expand All @@ -77,6 +104,7 @@ load _helpers
-s templates/partition-init-job.yaml \
--set 'global.enabled=false' \
--set 'global.adminPartitions.enabled=true' \
--set 'global.adminPartitions.name=bar' \
--set 'global.tls.enabled=true' \
--set 'externalServers.enabled=true' \
--set 'externalServers.hosts[0]=foo' \
Expand All @@ -95,6 +123,9 @@ load _helpers
-s templates/partition-init-job.yaml \
--set 'global.enabled=false' \
--set 'global.adminPartitions.enabled=true' \
--set 'global.adminPartitions.name=bar' \
--set 'externalServers.enabled=true' \
--set 'externalServers.hosts[0]=foo' \
--set 'global.tls.enabled=true' \
--set 'global.tls.caCert.secretName=foo-ca-cert' \
--set 'global.tls.caCert.secretKey=key' \
Expand Down Expand Up @@ -122,6 +153,9 @@ load _helpers
-s templates/partition-init-job.yaml \
--set 'global.enabled=false' \
--set 'global.adminPartitions.enabled=true' \
--set 'global.adminPartitions.name=bar' \
--set 'externalServers.enabled=true' \
--set 'externalServers.hosts[0]=foo' \
--set 'global.acls.bootstrapToken.secretName=partition-token' \
--set 'global.acls.bootstrapToken.secretKey=token' \
. | tee /dev/stderr |
Expand Down

0 comments on commit ec91c64

Please sign in to comment.