Skip to content

Commit

Permalink
Add custom annotations support for catalog sync and connectInject pod…
Browse files Browse the repository at this point in the history
…s via Helm (#775)

* Add custom annotations support for catalog sync and connectInject pods via Helm
  • Loading branch information
jeanmorais authored Jun 29, 2022
1 parent c901d66 commit da13b71
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
3 changes: 3 additions & 0 deletions charts/consul/templates/connect-inject-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ spec:
component: connect-injector
annotations:
"consul.hashicorp.com/connect-inject": "false"
{{- if .Values.connectInject.annotations }}
{{- tpl .Values.connectInject.annotations . | nindent 8 }}
{{- end }}
{{- if (and .Values.global.secretsBackend.vault.enabled .Values.global.tls.enabled) }}
"vault.hashicorp.com/agent-init-first": "true"
"vault.hashicorp.com/agent-inject": "true"
Expand Down
3 changes: 3 additions & 0 deletions charts/consul/templates/sync-catalog-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ spec:
{{- end }}
annotations:
"consul.hashicorp.com/connect-inject": "false"
{{- if .Values.syncCatalog.annotations }}
{{- tpl .Values.syncCatalog.annotations . | nindent 8 }}
{{- end }}
{{- if (and .Values.global.secretsBackend.vault.enabled .Values.global.tls.enabled) }}
"vault.hashicorp.com/agent-init-first": "true"
"vault.hashicorp.com/agent-inject": "true"
Expand Down
24 changes: 24 additions & 0 deletions charts/consul/test/unit/connect-inject-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,30 @@ EOF
[ "${actual}" = "name" ]
}

#--------------------------------------------------------------------
# annotations

@test "connectInject/Deployment: no annotations defined by default" {
cd `chart_dir`
local actual=$(helm template \
-s templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations | del(."consul.hashicorp.com/connect-inject")' | tee /dev/stderr)
[ "${actual}" = "{}" ]
}

@test "connectInject/Deployment: annotations can be set" {
cd `chart_dir`
local actual=$(helm template \
-s templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
--set 'connectInject.annotations=foo: bar' \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations.foo' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}

#--------------------------------------------------------------------
# logLevel

Expand Down
24 changes: 24 additions & 0 deletions charts/consul/test/unit/sync-catalog-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,30 @@ load _helpers
[ "${actual}" = "bar" ]
}
#--------------------------------------------------------------------
# annotations
@test "syncCatalog/Deployment: no annotations defined by default" {
cd `chart_dir`
local actual=$(helm template \
-s templates/sync-catalog-deployment.yaml \
--set 'syncCatalog.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations | del(."consul.hashicorp.com/connect-inject")' | tee /dev/stderr)
[ "${actual}" = "{}" ]
}
@test "syncCatalog/Deployment: annotations can be set" {
cd `chart_dir`
local actual=$(helm template \
-s templates/sync-catalog-deployment.yaml \
--set 'syncCatalog.enabled=true' \
--set 'syncCatalog.annotations=foo: bar' \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations.foo' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}
#--------------------------------------------------------------------
# logLevel
Expand Down
24 changes: 24 additions & 0 deletions charts/consul/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,18 @@ syncCatalog:
# @type: map
extraLabels: null

# This value defines additional annotations for
# the catalog sync pods. This should be formatted as a multi-line string.
#
# ```yaml
# annotations: |
# "sample/annotation1": "foo"
# "sample/annotation2": "bar"
# ```
#
# @type: string
annotations: null

# Configures the automatic Connect sidecar injector.
connectInject:
# True if you want to enable connect injection. Set to "-" to inherit from
Expand Down Expand Up @@ -1894,6 +1906,18 @@ connectInject:
# Optional priorityClassName.
priorityClassName: ""

# This value defines additional annotations for
# connect inject pods. This should be formatted as a multi-line string.
#
# ```yaml
# annotations: |
# "sample/annotation1": "foo"
# "sample/annotation2": "bar"
# ```
#
# @type: string
annotations: null

# The Docker image for Consul to use when performing Connect injection.
# Defaults to global.image.
# @type: string
Expand Down

0 comments on commit da13b71

Please sign in to comment.