Skip to content

Commit

Permalink
Support the value $POD_NAME for the annotation `consul.hashicorp.co…
Browse files Browse the repository at this point in the history
…m/service-meta-pod_name`
  • Loading branch information
thisisnotashwin committed Jan 20, 2022
1 parent ca980cb commit 6ff8ff6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ IMPROVEMENTS:
* Allow customization of `terminationGracePeriodSeconds` on the ingress gateways. [[GH-947](https://github.com/hashicorp/consul-k8s/pull/947)]
* Support `ui.dashboardURLTemplates.service` value for setting [dashboard URL templates](https://www.consul.io/docs/agent/options#ui_config_dashboard_url_templates_service). [[GH-937](https://github.com/hashicorp/consul-k8s/pull/937)]
* Allow using dash-separated names for config entries when using `kubectl`. [[GH-965](https://github.com/hashicorp/consul-k8s/pull/965)]
* Control Plane
* Support the value `$POD_NAME` for the annotation `consul.hashicorp.com/service-meta-pod_name` that will now be interpolated and set to the pod name in the service's metadata. [[GH-982](https://github.com/hashicorp/consul-k8s/pull/982)]

BUG FIXES:
* Helm
Expand Down
6 changes: 5 additions & 1 deletion control-plane/connect-inject/endpoints_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,11 @@ func (r *EndpointsController) createServiceRegistrations(pod corev1.Pod, service
}
for k, v := range pod.Annotations {
if strings.HasPrefix(k, annotationMeta) && strings.TrimPrefix(k, annotationMeta) != "" {
meta[strings.TrimPrefix(k, annotationMeta)] = v
if v == "$POD_NAME" {
meta[strings.TrimPrefix(k, annotationMeta)] = pod.Name
} else {
meta[strings.TrimPrefix(k, annotationMeta)] = v
}
}
}
tags := consulTags(pod)
Expand Down
3 changes: 3 additions & 0 deletions control-plane/connect-inject/endpoints_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ func TestReconcileCreateEndpoint(t *testing.T) {
pod1.Annotations[annotationService] = "different-consul-svc-name"
pod1.Annotations[fmt.Sprintf("%sname", annotationMeta)] = "abc"
pod1.Annotations[fmt.Sprintf("%sversion", annotationMeta)] = "2"
pod1.Annotations[fmt.Sprintf("%spod_name", annotationMeta)] = "$POD_NAME"
pod1.Annotations[annotationTags] = "abc,123,$POD_NAME"
pod1.Annotations[annotationConnectTags] = "def,456,$POD_NAME"
pod1.Annotations[annotationUpstreams] = "upstream1:1234"
Expand Down Expand Up @@ -925,6 +926,7 @@ func TestReconcileCreateEndpoint(t *testing.T) {
ServiceMeta: map[string]string{
"name": "abc",
"version": "2",
"pod_name": "pod1",
MetaKeyPodName: "pod1",
MetaKeyKubeServiceName: "service-created",
MetaKeyKubeNS: "default",
Expand Down Expand Up @@ -958,6 +960,7 @@ func TestReconcileCreateEndpoint(t *testing.T) {
ServiceMeta: map[string]string{
"name": "abc",
"version": "2",
"pod_name": "pod1",
MetaKeyPodName: "pod1",
MetaKeyKubeServiceName: "service-created",
MetaKeyKubeNS: "default",
Expand Down

0 comments on commit 6ff8ff6

Please sign in to comment.