Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
Add test for v2

Fix bats tests

Fix CONSUL_NAMESPACE to be default

Fix consul telemetry collector login namespace

Finish namespace/partition logic changes

Update v2 too

Remove more $roots
  • Loading branch information
jjti committed Nov 8, 2023
1 parent a3d1715 commit b2f7f00
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 33 deletions.
63 changes: 46 additions & 17 deletions charts/consul/templates/telemetry-collector-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,46 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: CONSUL_NODE_NAME
value: $(NODE_NAME)-virtual
{{- include "consul.consulK8sConsulServerEnvVars" . | nindent 10 }}
# acl login info
{{- if .Values.global.acls.manageSystemACLs }}
- name: CONSUL_LOGIN_AUTH_METHOD
value: {{ template "consul.fullname" . }}-k8s-auth-method
value: {{ template "consul.fullname" $root }}-k8s-auth-method
- name: CONSUL_LOGIN_DATACENTER
value: {{ .Values.global.datacenter }}
- name: CONSUL_LOGIN_META
value: "component=consul-telemetry-collector,pod=$(NAMESPACE)/$(POD_NAME)"
value: "component=consul-telemetry-gateway,pod=$(NAMESPACE)/$(POD_NAME)"
{{- end }}
- name: CONSUL_NODE_NAME
value: $(NODE_NAME)-virtual
{{- include "consul.consulK8sConsulServerEnvVars" . | nindent 10 }}
# service and login namespace
# this is attempting to replicate the behavior of webhooks in calculating namespace
# https://github.com/hashicorp/consul-k8s/blob/b84339050bb2c4b62b60cec96275f74952b0ac9d/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go#L200
{{- if .Values.global.enableConsulNamespaces }}
{{- if .Values.connectInject.consulNamespaces.mirroringK8S }}
- name: CONSUL_NAMESPACE
value: {{ .Values.syncCatalog.consulNamespaces.consulDestinationNamespace }}
{{- if .Values.syncCatalog.consulNamespaces.mirroringK8S }}
value: {{ .Values.connectInject.consulNamespaces.mirroringK8SPrefix }}{{ .Release.Namespace }}
{{- else }}
- name: CONSUL_NAMESPACE
value: {{ .Values.connectInject.consulNamespaces.consulDestinationNamespace }}
{{- end }}
{{- if .Values.global.acls.manageSystemACLs }}
{{- if .Values.connectInject.consulNamespaces.mirroringK8S }}
- name: CONSUL_LOGIN_NAMESPACE
value: "default"
{{- else }}
- name: CONSUL_LOGIN_NAMESPACE
value: {{ .Values.syncCatalog.consulNamespaces.consulDestinationNamespace }}
value: {{ .Values.connectInject.consulNamespaces.consulDestinationNamespace }}
{{- end }}
{{- end }}
{{- end }}
# service and login partition
{{- if .Values.global.adminPartitions.enabled }}
- name: CONSUL_PARTITION
value: {{ .Values.global.adminPartitions.name }}
{{- if .Values.global.acls.manageSystemACLs }}
- name: CONSUL_LOGIN_PARTITION
value: {{ .Values.global.adminPartitions.name }}
{{- end }}
{{- end }}
command:
Expand Down Expand Up @@ -284,24 +306,31 @@ spec:
{{- if .Values.global.acls.manageSystemACLs }}
- -credential-type=login
- -login-bearer-token-path=/var/run/secrets/kubernetes.io/serviceaccount/token
- -login-auth-method={{ template "consul.fullname" . }}-k8s-auth-method
- -login-auth-method={{ template "consul.fullname" $root }}-k8s-component-auth-method
{{- end }}
# service and login namespace
{{- if .Values.global.enableConsulNamespaces }}
{{- if .Values.syncCatalog.consulNamespaces.mirroringK8S }}
{{- if .Values.connectInject.consulNamespaces.mirroringK8S }}
- -service-namespace={{ .Values.connectInject.consulNamespaces.mirroringK8SPrefix }}{{ .Release.Namespace }}
{{- else }}
- -service-namespace={{ .Values.connectInject.consulNamespaces.consulDestinationNamespace }}
{{- end }}
{{- if .Values.global.acls.manageSystemACLs }}
{{- if .Values.connectInject.consulNamespaces.mirroringK8S }}
- -login-namespace=default
{{- else }}
- -login-namespace={{ .Values.syncCatalog.consulNamespaces.consulDestinationNamespace }}
- -login-namespace={{ .Values.connectInject.consulNamespaces.consulDestinationNamespace }}
{{- end }}
{{- end }}
{{- end }}
# service and login partition
{{- if .Values.global.adminPartitions.enabled }}
- -service-partition={{ .Values.global.adminPartitions.name }}
{{- if .Values.global.acls.manageSystemACLs }}
- -login-partition={{ .Values.global.adminPartitions.name }}
{{- end }}
{{- end }}
{{- if .Values.global.enableConsulNamespaces }}
- -service-namespace={{ .Values.syncCatalog.consulNamespaces.consulDestinationNamespace }}
{{- end }}
{{- if .Values.global.adminPartitions.enabled }}
- -service-partition={{ .Values.global.adminPartitions.name }}
{{- end }}
# telemetry
{{- if .Values.global.metrics.enabled }}
- -telemetry-prom-scrape-path=/metrics
{{- end }}
Expand Down
58 changes: 43 additions & 15 deletions charts/consul/templates/telemetry-collector-v2-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,43 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.name
# acl login info
{{- if .Values.global.acls.manageSystemACLs }}
- name: CONSUL_LOGIN_AUTH_METHOD
value: {{ template "consul.fullname" . }}-k8s-auth-method
value: {{ template "consul.fullname" $root }}-k8s-auth-method
- name: CONSUL_LOGIN_DATACENTER
value: {{ .Values.global.datacenter }}
- name: CONSUL_LOGIN_META
value: "component=consul-telemetry-collector,pod=$(NAMESPACE)/$(POD_NAME)"
value: "component=consul-telemetry-gateway,pod=$(NAMESPACE)/$(POD_NAME)"
{{- end }}
{{- include "consul.consulK8sConsulServerEnvVars" . | nindent 10 }}
# service and login namespace
# this is attempting to replicate the behavior of webhooks in calculating namespace
# https://github.com/hashicorp/consul-k8s/blob/b84339050bb2c4b62b60cec96275f74952b0ac9d/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go#L200
{{- if .Values.global.enableConsulNamespaces }}
{{- if .Values.connectInject.consulNamespaces.mirroringK8S }}
- name: CONSUL_NAMESPACE
value: {{ .Values.syncCatalog.consulNamespaces.consulDestinationNamespace }}
{{- if .Values.syncCatalog.consulNamespaces.mirroringK8S }}
value: {{ .Values.connectInject.consulNamespaces.mirroringK8SPrefix }}{{ .Release.Namespace }}
{{- else }}
- name: CONSUL_NAMESPACE
value: {{ .Values.connectInject.consulNamespaces.consulDestinationNamespace }}
{{- end }}
{{- if .Values.global.acls.manageSystemACLs }}
{{- if .Values.connectInject.consulNamespaces.mirroringK8S }}
- name: CONSUL_LOGIN_NAMESPACE
value: "default"
{{- else }}
- name: CONSUL_LOGIN_NAMESPACE
value: {{ .Values.syncCatalog.consulNamespaces.consulDestinationNamespace }}
value: {{ .Values.connectInject.consulNamespaces.consulDestinationNamespace }}
{{- end }}
{{- end }}
{{- end }}
# service and login partition
{{- if .Values.global.adminPartitions.enabled }}
- name: CONSUL_PARTITION
value: {{ .Values.global.adminPartitions.name }}
{{- if .Values.global.acls.manageSystemACLs }}
- name: CONSUL_LOGIN_PARTITION
value: {{ .Values.global.adminPartitions.name }}
{{- end }}
{{- end }}
command:
Expand Down Expand Up @@ -272,24 +293,31 @@ spec:
{{- if .Values.global.acls.manageSystemACLs }}
- -credential-type=login
- -login-bearer-token-path=/var/run/secrets/kubernetes.io/serviceaccount/token
- -login-auth-method={{ template "consul.fullname" . }}-k8s-auth-method
- -login-auth-method={{ template "consul.fullname" $root }}-k8s-component-auth-method
{{- end }}
# service and login namespace
{{- if .Values.global.enableConsulNamespaces }}
{{- if .Values.syncCatalog.consulNamespaces.mirroringK8S }}
{{- if .Values.connectInject.consulNamespaces.mirroringK8S }}
- -service-namespace={{ .Values.connectInject.consulNamespaces.mirroringK8SPrefix }}{{ .Release.Namespace }}
{{- else }}
- -service-namespace={{ .Values.connectInject.consulNamespaces.consulDestinationNamespace }}
{{- end }}
{{- if .Values.global.acls.manageSystemACLs }}
{{- if .Values.connectInject.consulNamespaces.mirroringK8S }}
- -login-namespace=default
{{- else }}
- -login-namespace={{ .Values.syncCatalog.consulNamespaces.consulDestinationNamespace }}
- -login-namespace={{ .Values.connectInject.consulNamespaces.consulDestinationNamespace }}
{{- end }}
{{- end }}
{{- end }}
# service and login partition
{{- if .Values.global.adminPartitions.enabled }}
- -service-partition={{ .Values.global.adminPartitions.name }}
{{- if .Values.global.acls.manageSystemACLs }}
- -login-partition={{ .Values.global.adminPartitions.name }}
{{- end }}
{{- end }}
{{- if .Values.global.enableConsulNamespaces }}
- -service-namespace={{ .Values.syncCatalog.consulNamespaces.consulDestinationNamespace }}
{{- end }}
{{- if .Values.global.adminPartitions.enabled }}
- -service-partition={{ .Values.global.adminPartitions.name }}
{{- end }}
# telemetry
{{- if .Values.global.metrics.enabled }}
- -telemetry-prom-scrape-path=/metrics
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1387,4 +1387,4 @@ MIICFjCCAZsCCQCdwLtdjbzlYzAKBggqhkjOPQQDAjB0MQswCQYDVQQGEwJDQTEL' \

local actual=$(echo $object | jq -r '.[1].args | any(contains("-login-namespace=fakenamespace"))' | tee /dev/stderr)
[ "${actual}" = 'true' ]
}
}

0 comments on commit b2f7f00

Please sign in to comment.