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

Include pod name as tag for connect svcs #848

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
IMPROVEMENTS:
* Control Plane
* TLS: Support PKCS1 and PKCS8 private keys for Consul certificate authority. [[GH-843](https://github.com/hashicorp/consul-k8s/pull/843)]
* Connect: Add pod name as tag to service instances and proxies. [[GH-848](https://github.com/hashicorp/consul-k8s/pull/848)]
* CLI
* Delete jobs, cluster roles, and cluster role bindings on `uninstall`. [[GH-820](https://github.com/hashicorp/consul-k8s/pull/820)]

Expand Down
12 changes: 4 additions & 8 deletions control-plane/connect-inject/endpoints_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,9 @@ func (r *EndpointsController) createServiceRegistrations(pod corev1.Pod, service
}
}

var tags []string
tags := []string{pod.Name}
if raw, ok := pod.Annotations[annotationTags]; ok && raw != "" {
tags = strings.Split(raw, ",")
tags = append(tags, strings.Split(raw, ",")...)
}
// Get the tags from the deprecated tags annotation and combine.
if raw, ok := pod.Annotations[annotationConnectTags]; ok && raw != "" {
Expand All @@ -432,9 +432,7 @@ func (r *EndpointsController) createServiceRegistrations(pod corev1.Pod, service
Address: pod.Status.PodIP,
Meta: meta,
Namespace: r.consulNamespace(pod.Namespace),
}
if len(tags) > 0 {
service.Tags = tags
Tags: tags,
}

proxyServiceName := getProxyServiceName(pod, serviceEndpoints)
Expand Down Expand Up @@ -495,9 +493,7 @@ func (r *EndpointsController) createServiceRegistrations(pod corev1.Pod, service
AliasService: serviceID,
},
},
}
if len(tags) > 0 {
proxyService.Tags = tags
Tags: tags,
}

// A user can enable/disable tproxy for an entire namespace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ func TestReconcileCreateEndpointWithNamespaces(t *testing.T) {
ServiceName: "service-created",
ServiceAddress: "1.2.3.4",
ServiceMeta: map[string]string{MetaKeyPodName: "pod1", MetaKeyKubeServiceName: "service-created", MetaKeyKubeNS: test.SourceKubeNS, MetaKeyManagedBy: managedByValue},
ServiceTags: []string{},
ServiceTags: []string{"pod1"},
Namespace: test.ExpConsulNS,
},
{
ServiceID: "pod2-service-created",
ServiceName: "service-created",
ServiceAddress: "2.2.3.4",
ServiceMeta: map[string]string{MetaKeyPodName: "pod2", MetaKeyKubeServiceName: "service-created", MetaKeyKubeNS: test.SourceKubeNS, MetaKeyManagedBy: managedByValue},
ServiceTags: []string{},
ServiceTags: []string{"pod2"},
Namespace: test.ExpConsulNS,
},
},
Expand All @@ -153,7 +153,7 @@ func TestReconcileCreateEndpointWithNamespaces(t *testing.T) {
DestinationServiceID: "pod1-service-created",
},
ServiceMeta: map[string]string{MetaKeyPodName: "pod1", MetaKeyKubeServiceName: "service-created", MetaKeyKubeNS: test.SourceKubeNS, MetaKeyManagedBy: managedByValue},
ServiceTags: []string{},
ServiceTags: []string{"pod1"},
Namespace: test.ExpConsulNS,
},
{
Expand All @@ -166,7 +166,7 @@ func TestReconcileCreateEndpointWithNamespaces(t *testing.T) {
DestinationServiceID: "pod2-service-created",
},
ServiceMeta: map[string]string{MetaKeyPodName: "pod2", MetaKeyKubeServiceName: "service-created", MetaKeyKubeNS: test.SourceKubeNS, MetaKeyManagedBy: managedByValue},
ServiceTags: []string{},
ServiceTags: []string{"pod2"},
Namespace: test.ExpConsulNS,
},
},
Expand Down
24 changes: 12 additions & 12 deletions control-plane/connect-inject/endpoints_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ func TestReconcileCreateEndpoint(t *testing.T) {
ServiceAddress: "1.2.3.4",
ServicePort: 0,
ServiceMeta: map[string]string{MetaKeyPodName: "pod1", MetaKeyKubeServiceName: "service-created", MetaKeyKubeNS: "default", MetaKeyManagedBy: managedByValue},
ServiceTags: []string{},
ServiceTags: []string{"pod1"},
},
},
expectedProxySvcInstances: []*api.CatalogService{
Expand All @@ -629,7 +629,7 @@ func TestReconcileCreateEndpoint(t *testing.T) {
LocalServicePort: 0,
},
ServiceMeta: map[string]string{MetaKeyPodName: "pod1", MetaKeyKubeServiceName: "service-created", MetaKeyKubeNS: "default", MetaKeyManagedBy: managedByValue},
ServiceTags: []string{},
ServiceTags: []string{"pod1"},
},
},
expectedAgentHealthChecks: []*api.AgentCheck{
Expand Down Expand Up @@ -691,15 +691,15 @@ func TestReconcileCreateEndpoint(t *testing.T) {
ServiceAddress: "1.2.3.4",
ServicePort: 0,
ServiceMeta: map[string]string{MetaKeyPodName: "pod1", MetaKeyKubeServiceName: "service-created", MetaKeyKubeNS: "default", MetaKeyManagedBy: managedByValue},
ServiceTags: []string{},
ServiceTags: []string{"pod1"},
},
{
ServiceID: "pod2-service-created",
ServiceName: "service-created",
ServiceAddress: "2.2.3.4",
ServicePort: 0,
ServiceMeta: map[string]string{MetaKeyPodName: "pod2", MetaKeyKubeServiceName: "service-created", MetaKeyKubeNS: "default", MetaKeyManagedBy: managedByValue},
ServiceTags: []string{},
ServiceTags: []string{"pod2"},
},
},
expectedProxySvcInstances: []*api.CatalogService{
Expand All @@ -715,7 +715,7 @@ func TestReconcileCreateEndpoint(t *testing.T) {
LocalServicePort: 0,
},
ServiceMeta: map[string]string{MetaKeyPodName: "pod1", MetaKeyKubeServiceName: "service-created", MetaKeyKubeNS: "default", MetaKeyManagedBy: managedByValue},
ServiceTags: []string{},
ServiceTags: []string{"pod1"},
},
{
ServiceID: "pod2-service-created-sidecar-proxy",
Expand All @@ -729,7 +729,7 @@ func TestReconcileCreateEndpoint(t *testing.T) {
LocalServicePort: 0,
},
ServiceMeta: map[string]string{MetaKeyPodName: "pod2", MetaKeyKubeServiceName: "service-created", MetaKeyKubeNS: "default", MetaKeyManagedBy: managedByValue},
ServiceTags: []string{},
ServiceTags: []string{"pod2"},
},
},
expectedAgentHealthChecks: []*api.AgentCheck{
Expand Down Expand Up @@ -814,15 +814,15 @@ func TestReconcileCreateEndpoint(t *testing.T) {
ServiceAddress: "1.2.3.4",
ServicePort: 0,
ServiceMeta: map[string]string{MetaKeyPodName: "pod1", MetaKeyKubeServiceName: "service-created", MetaKeyKubeNS: "default", MetaKeyManagedBy: managedByValue},
ServiceTags: []string{},
ServiceTags: []string{"pod1"},
},
{
ServiceID: "pod2-service-created",
ServiceName: "service-created",
ServiceAddress: "2.2.3.4",
ServicePort: 0,
ServiceMeta: map[string]string{MetaKeyPodName: "pod2", MetaKeyKubeServiceName: "service-created", MetaKeyKubeNS: "default", MetaKeyManagedBy: managedByValue},
ServiceTags: []string{},
ServiceTags: []string{"pod2"},
},
},
expectedProxySvcInstances: []*api.CatalogService{
Expand All @@ -838,7 +838,7 @@ func TestReconcileCreateEndpoint(t *testing.T) {
LocalServicePort: 0,
},
ServiceMeta: map[string]string{MetaKeyPodName: "pod1", MetaKeyKubeServiceName: "service-created", MetaKeyKubeNS: "default", MetaKeyManagedBy: managedByValue},
ServiceTags: []string{},
ServiceTags: []string{"pod1"},
},
{
ServiceID: "pod2-service-created-sidecar-proxy",
Expand All @@ -852,7 +852,7 @@ func TestReconcileCreateEndpoint(t *testing.T) {
LocalServicePort: 0,
},
ServiceMeta: map[string]string{MetaKeyPodName: "pod2", MetaKeyKubeServiceName: "service-created", MetaKeyKubeNS: "default", MetaKeyManagedBy: managedByValue},
ServiceTags: []string{},
ServiceTags: []string{"pod2"},
},
},
expectedAgentHealthChecks: []*api.AgentCheck{
Expand Down Expand Up @@ -930,7 +930,7 @@ func TestReconcileCreateEndpoint(t *testing.T) {
MetaKeyKubeNS: "default",
MetaKeyManagedBy: managedByValue,
},
ServiceTags: []string{"abc", "123", "def", "456"},
ServiceTags: []string{"pod1", "abc", "123", "def", "456"},
},
},
expectedProxySvcInstances: []*api.CatalogService{
Expand Down Expand Up @@ -963,7 +963,7 @@ func TestReconcileCreateEndpoint(t *testing.T) {
MetaKeyKubeNS: "default",
MetaKeyManagedBy: managedByValue,
},
ServiceTags: []string{"abc", "123", "def", "456"},
ServiceTags: []string{"pod1", "abc", "123", "def", "456"},
},
},
expectedAgentHealthChecks: []*api.AgentCheck{
Expand Down