Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #179 from alexbrand/sync-annot
Browse files Browse the repository at this point in the history
discovery: set annotation on discovered services and endpoints
  • Loading branch information
stevesloka authored Jul 10, 2018
2 parents 1bcf1a6 + 662064a commit fa10a18
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
14 changes: 8 additions & 6 deletions discovery/pkg/k8s/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
func translateService(svc *v1.Service, backendName string) *v1.Service {
newService := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: svc.Namespace,
Name: translator.BuildDiscoveredName(backendName, svc.Name),
Labels: translator.AddGimbalLabels(backendName, svc.ObjectMeta.Name, svc.ObjectMeta.Labels),
Namespace: svc.Namespace,
Name: translator.BuildDiscoveredName(backendName, svc.Name),
Labels: translator.AddGimbalLabels(backendName, svc.ObjectMeta.Name, svc.ObjectMeta.Labels),
Annotations: svc.Annotations,
},
Spec: v1.ServiceSpec{
ClusterIP: "None",
Expand All @@ -44,9 +45,10 @@ func translateService(svc *v1.Service, backendName string) *v1.Service {
func translateEndpoints(endpoints *v1.Endpoints, backendName string) *v1.Endpoints {
newEndpoint := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Namespace: endpoints.Namespace,
Name: translator.BuildDiscoveredName(backendName, endpoints.Name),
Labels: translator.AddGimbalLabels(backendName, endpoints.ObjectMeta.Name, endpoints.ObjectMeta.Labels),
Namespace: endpoints.Namespace,
Name: translator.BuildDiscoveredName(backendName, endpoints.Name),
Labels: translator.AddGimbalLabels(backendName, endpoints.ObjectMeta.Name, endpoints.ObjectMeta.Labels),
Annotations: endpoints.Annotations,
},
Subsets: endpoints.Subsets,
}
Expand Down
42 changes: 24 additions & 18 deletions discovery/pkg/k8s/translate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ func TestTranslateService(t *testing.T) {
backendName: "cluster1",
service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "kuard",
Labels: map[string]string{"app": "kuard"},
Namespace: "default",
Name: "kuard",
Labels: map[string]string{"app": "kuard"},
Annotations: map[string]string{"foo": "bar"},
},
Spec: v1.ServiceSpec{
ClusterIP: "10.99.179.252",
Expand All @@ -48,9 +49,10 @@ func TestTranslateService(t *testing.T) {
},
expected: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "cluster1-kuard",
Labels: map[string]string{"app": "kuard", "gimbal.heptio.com/backend": "cluster1", "gimbal.heptio.com/service": "kuard"},
Namespace: "default",
Name: "cluster1-kuard",
Labels: map[string]string{"app": "kuard", "gimbal.heptio.com/backend": "cluster1", "gimbal.heptio.com/service": "kuard"},
Annotations: map[string]string{"foo": "bar"},
},
Spec: v1.ServiceSpec{
ClusterIP: "None",
Expand All @@ -64,9 +66,10 @@ func TestTranslateService(t *testing.T) {
backendName: "cluster1",
service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "kuard",
Labels: map[string]string{"app": "kuard"},
Namespace: "default",
Name: "kuard",
Labels: map[string]string{"app": "kuard"},
Annotations: map[string]string{"foo": "bar"},
},
Spec: v1.ServiceSpec{
ClusterIP: "10.99.179.252",
Expand All @@ -80,9 +83,10 @@ func TestTranslateService(t *testing.T) {
},
expected: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "cluster1-kuard",
Labels: map[string]string{"app": "kuard", "gimbal.heptio.com/backend": "cluster1", "gimbal.heptio.com/service": "kuard"},
Namespace: "default",
Name: "cluster1-kuard",
Labels: map[string]string{"app": "kuard", "gimbal.heptio.com/backend": "cluster1", "gimbal.heptio.com/service": "kuard"},
Annotations: map[string]string{"foo": "bar"},
},
Spec: v1.ServiceSpec{
ClusterIP: "None",
Expand Down Expand Up @@ -116,9 +120,10 @@ func TestTranslateEndpoints(t *testing.T) {
backendName: "cluster1",
endpoints: &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "kuard",
Labels: map[string]string{"app": "kuard"},
Namespace: "default",
Name: "kuard",
Labels: map[string]string{"app": "kuard"},
Annotations: map[string]string{"foo": "bar"},
},
Subsets: []v1.EndpointSubset{
{
Expand All @@ -129,9 +134,10 @@ func TestTranslateEndpoints(t *testing.T) {
},
expected: &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "cluster1-kuard",
Labels: map[string]string{"app": "kuard", "gimbal.heptio.com/backend": "cluster1", "gimbal.heptio.com/service": "kuard"},
Namespace: "default",
Name: "cluster1-kuard",
Labels: map[string]string{"app": "kuard", "gimbal.heptio.com/backend": "cluster1", "gimbal.heptio.com/service": "kuard"},
Annotations: map[string]string{"foo": "bar"},
},
Subsets: []v1.EndpointSubset{
{
Expand Down

0 comments on commit fa10a18

Please sign in to comment.