Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support annotation service-tags: $POD_NAME #931

Merged
merged 2 commits into from
Dec 14, 2021

Conversation

lkysow
Copy link
Member

@lkysow lkysow commented Dec 14, 2021

Support the annotation

consul.hashicorp.com/service-tags: $POD_NAME

Where $POD_NAME will be replaced with the Pod's name.

This mimics support we had before the endpoints controller
where environment variable were interpolated for tags.

This PR only supports $POD_NAME for now because it's the only
environment variable we've been asked to support.

How I've tested this PR: unit tests

How I expect reviewers to test this PR: code

Checklist:

  • Tests added
  • CHANGELOG entry added

    HashiCorp engineers only, community PRs should not add a changelog entry.
    Entries should use present tense (e.g. Add support for...)

Support the annotation

```
consul.hashicorp.com/service-tags: $POD_NAME
```

Where $POD_NAME will be replaced with the Pod's name.

This mimics support we had before the endpoints controller
where environment variable were interpolated for tags.

This PR only supports $POD_NAME for now because it's the only
environment variable we've been asked to support.
@@ -416,15 +416,7 @@ func (r *EndpointsController) createServiceRegistrations(pod corev1.Pod, service
meta[strings.TrimPrefix(k, annotationMeta)] = v
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored this into a consulTags function

@@ -433,9 +425,7 @@ func (r *EndpointsController) createServiceRegistrations(pod corev1.Pod, service
Address: pod.Status.PodIP,
Meta: meta,
Namespace: r.consulNamespace(pod.Namespace),
}
if len(tags) > 0 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see why we were doing this if check rather than just assigning to the struct field.

Comment on lines +889 to +890
pod1.Annotations[annotationTags] = "abc,123,$POD_NAME"
pod1.Annotations[annotationConnectTags] = "def,456,$POD_NAME"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing both the supported and deprecated tags just for completeness

Copy link
Contributor

@thisisnotashwin thisisnotashwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

@lkysow lkysow requested review from a team, ndhanushkodi and kschoche and removed request for a team December 14, 2021 16:33
Copy link
Contributor

@kschoche kschoche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great!

@ndhanushkodi ndhanushkodi merged commit e3ad99e into main Dec 14, 2021
@ndhanushkodi ndhanushkodi deleted the lkysow/service-tags-pod-name branch December 14, 2021 17:33
@lkysow
Copy link
Member Author

lkysow commented Dec 14, 2021

image

Tested it out as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants