Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Commit

Permalink
feat: Customizable command-line option "node-meta" to the agent
Browse files Browse the repository at this point in the history
  • Loading branch information
carnei-ro committed Dec 9, 2020
1 parent 3ae0369 commit 98cf2ab
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
4 changes: 3 additions & 1 deletion templates/client-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ spec:
-advertise="${ADVERTISE_IP}" \
-bind=0.0.0.0 \
-client=0.0.0.0 \
-node-meta=pod-name:${HOSTNAME} \
{{- range $k, $v := .Values.client.nodeMeta }}
-node-meta={{ $k }}:{{ $v }} \
{{- end }}
-hcl='leave_on_terminate = true' \
{{- if .Values.global.tls.enabled }}
-hcl='ca_file = "/consul/tls/ca/tls.crt"' \
Expand Down
32 changes: 32 additions & 0 deletions test/unit/client-daemonset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,38 @@ load _helpers
[ "${actual}" = "false" ]
}

#--------------------------------------------------------------------
# nodeMeta

@test "client/DaemonSet: meta-data pod-name:\${HOSTNAME} by default at nodeMeta" {
cd `chart_dir`
local actual=$(helm template \
-s templates/client-daemonset.yaml \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command | any(contains("-node-meta=pod-name:${HOSTNAME}"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "client/DaemonSet: pod-name can be configured at nodeMeta" {
cd `chart_dir`
local actual=$(helm template \
-s templates/client-daemonset.yaml \
--set 'client.nodeMeta.pod-name=foobar' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command | any(contains("-node-meta=pod-name:foobar"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "client/DaemonSet: additional meta-data at nodeMeta" {
cd `chart_dir`
local actual=$(helm template \
-s templates/client-daemonset.yaml \
--set 'client.nodeMeta.cluster-name=cluster01' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command | any(contains("-node-meta=cluster-name:cluster01"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# resources

Expand Down
5 changes: 5 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,11 @@ client:
# This should be set to true if connectInject or meshGateway is enabled.
grpc: true

# nodeMeta specifies an arbitrary metadata key/value pair to associate with the node
# (see https://www.consul.io/docs/agent/options.html#_node_meta)
nodeMeta:
pod-name: ${HOSTNAME}

# exposeGossipPorts exposes the clients' gossip ports as hostPorts.
# This is only necessary if pod IPs in the k8s cluster are not directly
# routable and the Consul servers are outside of the k8s cluster. This
Expand Down

0 comments on commit 98cf2ab

Please sign in to comment.