Skip to content

Commit

Permalink
Add label to the common spec (#445)
Browse files Browse the repository at this point in the history
Signed-off-by: Gary Brown <[email protected]>
  • Loading branch information
objectiser authored May 31, 2019
1 parent e57b8ec commit 682e23c
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 27 deletions.
1 change: 1 addition & 0 deletions pkg/apis/jaegertracing/v1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type JaegerCommonSpec struct {
Volumes []v1.Volume `json:"volumes"`
VolumeMounts []v1.VolumeMount `json:"volumeMounts"`
Annotations map[string]string `json:"annotations,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Resources v1.ResourceRequirements `json:"resources,omitempty"`
Affinity *v1.Affinity `json:"affinity,omitempty"`
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pkg/deployment/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (a *Agent) Get() *appsv1.DaemonSet {
"prometheus.io/port": strconv.Itoa(int(adminPort)),
"sidecar.istio.io/inject": "false",
},
Labels: labels,
}

commonSpec := util.Merge([]v1.JaegerCommonSpec{a.jaeger.Spec.Agent.JaegerCommonSpec, a.jaeger.Spec.JaegerCommonSpec, baseCommonSpec})
Expand All @@ -80,7 +81,7 @@ func (a *Agent) Get() *appsv1.DaemonSet {
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-agent-daemonset", a.jaeger.Name),
Namespace: a.jaeger.Namespace,
Labels: labels,
Labels: commonSpec.Labels,
OwnerReferences: []metav1.OwnerReference{
metav1.OwnerReference{
APIVersion: a.jaeger.APIVersion,
Expand All @@ -97,7 +98,7 @@ func (a *Agent) Get() *appsv1.DaemonSet {
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Labels: commonSpec.Labels,
Annotations: commonSpec.Annotations,
},
Spec: corev1.PodSpec{
Expand Down
20 changes: 20 additions & 0 deletions pkg/deployment/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ func TestDaemonSetAgentAnnotations(t *testing.T) {
assert.Equal(t, "false", dep.Spec.Template.Annotations["prometheus.io/scrape"])
}

func TestDaemonSetAgentLabels(t *testing.T) {
jaeger := v1.NewJaeger("TestDaemonSetAgentLabels")
jaeger.Spec.Agent.Strategy = "daemonset"
jaeger.Spec.Labels = map[string]string{
"name": "operator",
"hello": "jaeger",
}
jaeger.Spec.Agent.Labels = map[string]string{
"hello": "world", // Override top level label
"another": "false",
}

agent := NewAgent(jaeger)
dep := agent.Get()

assert.Equal(t, "operator", dep.Spec.Template.Labels["name"])
assert.Equal(t, "world", dep.Spec.Template.Labels["hello"])
assert.Equal(t, "false", dep.Spec.Template.Labels["another"])
}

func TestDaemonSetAgentResources(t *testing.T) {
jaeger := v1.NewJaeger("TestDaemonSetAgentResources")
jaeger.Spec.Agent.Strategy = "daemonset"
Expand Down
5 changes: 3 additions & 2 deletions pkg/deployment/all-in-one.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (a *AllInOne) Get() *appsv1.Deployment {
"prometheus.io/port": strconv.Itoa(int(adminPort)),
"sidecar.istio.io/inject": "false",
},
Labels: labels,
}

commonSpec := util.Merge([]v1.JaegerCommonSpec{a.jaeger.Spec.AllInOne.JaegerCommonSpec, a.jaeger.Spec.JaegerCommonSpec, baseCommonSpec})
Expand Down Expand Up @@ -83,7 +84,7 @@ func (a *AllInOne) Get() *appsv1.Deployment {
ObjectMeta: metav1.ObjectMeta{
Name: a.jaeger.Name,
Namespace: a.jaeger.Namespace,
Labels: labels,
Labels: commonSpec.Labels,
Annotations: commonSpec.Annotations,
OwnerReferences: []metav1.OwnerReference{
metav1.OwnerReference{
Expand All @@ -101,7 +102,7 @@ func (a *AllInOne) Get() *appsv1.Deployment {
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Labels: commonSpec.Labels,
Annotations: commonSpec.Annotations,
},
Spec: corev1.PodSpec{
Expand Down
23 changes: 21 additions & 2 deletions pkg/deployment/all-in-one_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ func TestAllInOneAnnotations(t *testing.T) {
assert.Equal(t, "false", dep.Spec.Template.Annotations["prometheus.io/scrape"])
}

func TestAllInOneLabels(t *testing.T) {
jaeger := v1.NewJaeger("TestAllInOneLabels")
jaeger.Spec.Labels = map[string]string{
"name": "operator",
"hello": "jaeger",
}
jaeger.Spec.AllInOne.Labels = map[string]string{
"hello": "world", // Override top level annotation
"another": "false",
}

allinone := NewAllInOne(jaeger)
dep := allinone.Get()

assert.Equal(t, "operator", dep.Spec.Template.Labels["name"])
assert.Equal(t, "world", dep.Spec.Template.Labels["hello"])
assert.Equal(t, "false", dep.Spec.Template.Labels["another"])
}

func TestAllInOneHasOwner(t *testing.T) {
name := "TestAllInOneHasOwner"
a := NewAllInOne(v1.NewJaeger(name))
Expand Down Expand Up @@ -233,8 +252,8 @@ func TestAllInOneResources(t *testing.T) {
assert.Equal(t, *resource.NewQuantity(512, resource.DecimalSI), dep.Spec.Template.Spec.Containers[0].Resources.Requests[corev1.ResourceRequestsEphemeralStorage])
}

func TestAllInOneLabels(t *testing.T) {
a := NewAllInOne(v1.NewJaeger("TestAllInOneLabels"))
func TestAllInOneStandardLabels(t *testing.T) {
a := NewAllInOne(v1.NewJaeger("TestAllInOneStandardLabels"))
dep := a.Get()
assert.Equal(t, "jaeger-operator", dep.Spec.Template.Labels["app.kubernetes.io/managed-by"])
assert.Equal(t, "all-in-one", dep.Spec.Template.Labels["app.kubernetes.io/component"])
Expand Down
5 changes: 3 additions & 2 deletions pkg/deployment/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (c *Collector) Get() *appsv1.Deployment {
"prometheus.io/port": strconv.Itoa(int(adminPort)),
"sidecar.istio.io/inject": "false",
},
Labels: labels,
}

commonSpec := util.Merge([]v1.JaegerCommonSpec{c.jaeger.Spec.Collector.JaegerCommonSpec, c.jaeger.Spec.JaegerCommonSpec, baseCommonSpec})
Expand Down Expand Up @@ -99,7 +100,7 @@ func (c *Collector) Get() *appsv1.Deployment {
ObjectMeta: metav1.ObjectMeta{
Name: c.name(),
Namespace: c.jaeger.Namespace,
Labels: labels,
Labels: commonSpec.Labels,
Annotations: commonSpec.Annotations,
OwnerReferences: []metav1.OwnerReference{
metav1.OwnerReference{
Expand All @@ -118,7 +119,7 @@ func (c *Collector) Get() *appsv1.Deployment {
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Labels: commonSpec.Labels,
Annotations: commonSpec.Annotations,
},
Spec: corev1.PodSpec{
Expand Down
23 changes: 21 additions & 2 deletions pkg/deployment/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,25 @@ func TestCollectorAnnotations(t *testing.T) {
assert.Equal(t, "false", dep.Spec.Template.Annotations["prometheus.io/scrape"])
}

func TestCollectorLabels(t *testing.T) {
jaeger := v1.NewJaeger("TestCollectorLabels")
jaeger.Spec.Labels = map[string]string{
"name": "operator",
"hello": "jaeger",
}
jaeger.Spec.Collector.Labels = map[string]string{
"hello": "world", // Override top level annotation
"another": "false",
}

collector := NewCollector(jaeger)
dep := collector.Get()

assert.Equal(t, "operator", dep.Spec.Template.Labels["name"])
assert.Equal(t, "world", dep.Spec.Template.Labels["hello"])
assert.Equal(t, "false", dep.Spec.Template.Labels["another"])
}

func TestCollectorSecrets(t *testing.T) {
jaeger := v1.NewJaeger("TestCollectorSecrets")
secret := "mysecret"
Expand Down Expand Up @@ -309,8 +328,8 @@ func TestCollectorResources(t *testing.T) {
assert.Equal(t, *resource.NewQuantity(512, resource.DecimalSI), dep.Spec.Template.Spec.Containers[0].Resources.Requests[corev1.ResourceRequestsEphemeralStorage])
}

func TestCollectorLabels(t *testing.T) {
c := NewCollector(v1.NewJaeger("TestCollectorLabels"))
func TestCollectorStandardLabels(t *testing.T) {
c := NewCollector(v1.NewJaeger("TestCollectorStandardLabels"))
dep := c.Get()
assert.Equal(t, "jaeger-operator", dep.Spec.Template.Labels["app.kubernetes.io/managed-by"])
assert.Equal(t, "collector", dep.Spec.Template.Labels["app.kubernetes.io/component"])
Expand Down
5 changes: 3 additions & 2 deletions pkg/deployment/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (i *Ingester) Get() *appsv1.Deployment {
"prometheus.io/port": strconv.Itoa(int(adminPort)),
"sidecar.istio.io/inject": "false",
},
Labels: labels,
}

commonSpec := util.Merge([]v1.JaegerCommonSpec{i.jaeger.Spec.Ingester.JaegerCommonSpec, i.jaeger.Spec.JaegerCommonSpec, baseCommonSpec})
Expand Down Expand Up @@ -93,7 +94,7 @@ func (i *Ingester) Get() *appsv1.Deployment {
ObjectMeta: metav1.ObjectMeta{
Name: i.name(),
Namespace: i.jaeger.Namespace,
Labels: labels,
Labels: commonSpec.Labels,
OwnerReferences: []metav1.OwnerReference{
metav1.OwnerReference{
APIVersion: i.jaeger.APIVersion,
Expand All @@ -111,7 +112,7 @@ func (i *Ingester) Get() *appsv1.Deployment {
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Labels: commonSpec.Labels,
Annotations: commonSpec.Annotations,
},
Spec: corev1.PodSpec{
Expand Down
23 changes: 21 additions & 2 deletions pkg/deployment/ingester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,25 @@ func TestIngesterAnnotations(t *testing.T) {
assert.Equal(t, "false", dep.Spec.Template.Annotations["prometheus.io/scrape"])
}

func TestIngesterLabels(t *testing.T) {
jaeger := newIngesterJaeger("TestIngesterLabels")
jaeger.Spec.Labels = map[string]string{
"name": "operator",
"hello": "jaeger",
}
jaeger.Spec.Ingester.Labels = map[string]string{
"hello": "world", // Override top level annotation
"another": "false",
}

ingester := NewIngester(jaeger)
dep := ingester.Get()

assert.Equal(t, "operator", dep.Spec.Template.Labels["name"])
assert.Equal(t, "world", dep.Spec.Template.Labels["hello"])
assert.Equal(t, "false", dep.Spec.Template.Labels["another"])
}

func TestIngesterSecrets(t *testing.T) {
jaeger := newIngesterJaeger("TestIngesterSecrets")
secret := "mysecret"
Expand Down Expand Up @@ -340,8 +359,8 @@ func TestIngesterWithStorageType(t *testing.T) {
assert.Equal(t, "--kafka.consumer.topic=mytopic", dep.Spec.Template.Spec.Containers[0].Args[2])
}

func TestIngesterLabels(t *testing.T) {
ingester := NewIngester(newIngesterJaeger("TestIngesterLabels"))
func TestIngesterStandardLabels(t *testing.T) {
ingester := NewIngester(newIngesterJaeger("TestIngesterStandardLabels"))
dep := ingester.Get()
assert.Equal(t, "jaeger-operator", dep.Spec.Template.Labels["app.kubernetes.io/managed-by"])
assert.Equal(t, "ingester", dep.Spec.Template.Labels["app.kubernetes.io/component"])
Expand Down
5 changes: 3 additions & 2 deletions pkg/deployment/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (q *Query) Get() *appsv1.Deployment {
// it at will. So, we leave this configured just like any other application would
"sidecar.jaegertracing.io/inject": q.jaeger.Name,
},
Labels: labels,
}

commonSpec := util.Merge([]v1.JaegerCommonSpec{q.jaeger.Spec.Query.JaegerCommonSpec, q.jaeger.Spec.JaegerCommonSpec, baseCommonSpec})
Expand Down Expand Up @@ -97,7 +98,7 @@ func (q *Query) Get() *appsv1.Deployment {
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-query", q.jaeger.Name),
Namespace: q.jaeger.Namespace,
Labels: labels,
Labels: commonSpec.Labels,
Annotations: commonSpec.Annotations,
OwnerReferences: []metav1.OwnerReference{
metav1.OwnerReference{
Expand All @@ -116,7 +117,7 @@ func (q *Query) Get() *appsv1.Deployment {
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Labels: commonSpec.Labels,
Annotations: commonSpec.Annotations,
},
Spec: corev1.PodSpec{
Expand Down
23 changes: 21 additions & 2 deletions pkg/deployment/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,25 @@ func TestQueryAnnotations(t *testing.T) {
assert.Equal(t, "false", dep.Spec.Template.Annotations["prometheus.io/scrape"])
}

func TestQueryLabels(t *testing.T) {
jaeger := v1.NewJaeger("TestQueryLabels")
jaeger.Spec.Labels = map[string]string{
"name": "operator",
"hello": "jaeger",
}
jaeger.Spec.Query.Labels = map[string]string{
"hello": "world", // Override top level annotation
"another": "false",
}

query := NewQuery(jaeger)
dep := query.Get()

assert.Equal(t, "operator", dep.Spec.Template.Labels["name"])
assert.Equal(t, "world", dep.Spec.Template.Labels["hello"])
assert.Equal(t, "false", dep.Spec.Template.Labels["another"])
}

func TestQuerySecrets(t *testing.T) {
jaeger := v1.NewJaeger("TestQuerySecrets")
secret := "mysecret"
Expand Down Expand Up @@ -295,8 +314,8 @@ func TestQueryResources(t *testing.T) {
assert.Equal(t, *resource.NewQuantity(512, resource.DecimalSI), dep.Spec.Template.Spec.Containers[0].Resources.Requests[corev1.ResourceRequestsEphemeralStorage])
}

func TestQueryLabels(t *testing.T) {
query := NewQuery(v1.NewJaeger("TestQueryLabels"))
func TestQueryStandardLabels(t *testing.T) {
query := NewQuery(v1.NewJaeger("TestQueryStandardLabels"))
dep := query.Get()
assert.Equal(t, "jaeger-operator", dep.Spec.Template.Labels["app.kubernetes.io/managed-by"])
assert.Equal(t, "query", dep.Spec.Template.Labels["app.kubernetes.io/component"])
Expand Down
22 changes: 13 additions & 9 deletions pkg/ingress/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@ func (i *QueryIngress) Get() *extv1beta1.Ingress {

trueVar := true

commonSpec := util.Merge([]v1.JaegerCommonSpec{i.jaeger.Spec.Ingress.JaegerCommonSpec, i.jaeger.Spec.JaegerCommonSpec})
baseCommonSpec := v1.JaegerCommonSpec{
Labels: map[string]string{
"app": "jaeger",
"app.kubernetes.io/name": fmt.Sprintf("%s-query", i.jaeger.Name),
"app.kubernetes.io/instance": i.jaeger.Name,
"app.kubernetes.io/component": "query-ingress",
"app.kubernetes.io/part-of": "jaeger",
"app.kubernetes.io/managed-by": "jaeger-operator",
},
}

commonSpec := util.Merge([]v1.JaegerCommonSpec{i.jaeger.Spec.Ingress.JaegerCommonSpec, i.jaeger.Spec.JaegerCommonSpec, baseCommonSpec})

spec := extv1beta1.IngressSpec{}
backend := extv1beta1.IngressBackend{
Expand All @@ -54,14 +65,7 @@ func (i *QueryIngress) Get() *extv1beta1.Ingress {
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-query", i.jaeger.Name),
Namespace: i.jaeger.Namespace,
Labels: map[string]string{
"app": "jaeger",
"app.kubernetes.io/name": fmt.Sprintf("%s-query", i.jaeger.Name),
"app.kubernetes.io/instance": i.jaeger.Name,
"app.kubernetes.io/component": "query-ingress",
"app.kubernetes.io/part-of": "jaeger",
"app.kubernetes.io/managed-by": "jaeger-operator",
},
Labels: commonSpec.Labels,
OwnerReferences: []metav1.OwnerReference{
metav1.OwnerReference{
APIVersion: i.jaeger.APIVersion,
Expand Down
19 changes: 19 additions & 0 deletions pkg/ingress/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,22 @@ func TestQueryIngressAnnotations(t *testing.T) {
assert.Equal(t, "world", dep.Annotations["hello"])
assert.Equal(t, "false", dep.Annotations["prometheus.io/scrape"])
}

func TestQueryIngressLabels(t *testing.T) {
jaeger := v1.NewJaeger("TestQueryIngressLabels")
jaeger.Spec.Labels = map[string]string{
"name": "operator",
"hello": "jaeger",
}
jaeger.Spec.Ingress.Labels = map[string]string{
"hello": "world", // Override top level annotation
"another": "false",
}

ingress := NewQueryIngress(jaeger)
dep := ingress.Get()

assert.Equal(t, "operator", dep.Labels["name"])
assert.Equal(t, "world", dep.Labels["hello"])
assert.Equal(t, "false", dep.Labels["another"])
}
Loading

0 comments on commit 682e23c

Please sign in to comment.