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

Enable annotations to be specified with the deployable components #86

Merged
merged 2 commits into from
Nov 6, 2018
Merged
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
30 changes: 17 additions & 13 deletions pkg/apis/io/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ type JaegerStatus struct {

// JaegerQuerySpec defines the options to be used when deploying the query
type JaegerQuerySpec struct {
Ingress JaegerIngressSpec `json:"ingress"`
Size int `json:"size"`
Image string `json:"image"`
Options Options `json:"options"`
Ingress JaegerIngressSpec `json:"ingress"`
Size int `json:"size"`
Image string `json:"image"`
Options Options `json:"options"`
Annotations map[string]string `json:"annotations,omitempty"`
}

// JaegerIngressSpec defines the options to be used when deploying the query ingress
Expand All @@ -53,23 +54,26 @@ type JaegerIngressSpec struct {

// JaegerAllInOneSpec defines the options to be used when deploying the query
type JaegerAllInOneSpec struct {
Ingress JaegerIngressSpec `json:"ingress"`
Image string `json:"image"`
Options Options `json:"options"`
Ingress JaegerIngressSpec `json:"ingress"`
Image string `json:"image"`
Options Options `json:"options"`
Annotations map[string]string `json:"annotations,omitempty"`
}

// JaegerCollectorSpec defines the options to be used when deploying the collector
type JaegerCollectorSpec struct {
Size int `json:"size"`
Image string `json:"image"`
Options Options `json:"options"`
Size int `json:"size"`
Image string `json:"image"`
Options Options `json:"options"`
Annotations map[string]string `json:"annotations,omitempty"`
}

// JaegerAgentSpec defines the options to be used when deploying the agent
type JaegerAgentSpec struct {
Strategy string `json:"strategy"` // can be either 'DaemonSet' or 'Sidecar' (default)
Image string `json:"image"`
Options Options `json:"options"`
Strategy string `json:"strategy"` // can be either 'DaemonSet' or 'Sidecar' (default)
Image string `json:"image"`
Options Options `json:"options"`
Annotations map[string]string `json:"annotations,omitempty"`
}

// JaegerStorageSpec defines the common storage options to be used for the query and collector
Expand Down
3 changes: 3 additions & 0 deletions pkg/deployment/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func (a *Agent) Get() *appsv1.DaemonSet {
"prometheus.io/port": "5778",
"sidecar.istio.io/inject": "false",
}
for k, v := range a.jaeger.Spec.Agent.Annotations {
annotations[k] = v
}

return &appsv1.DaemonSet{
TypeMeta: metav1.TypeMeta{
Expand Down
16 changes: 15 additions & 1 deletion pkg/deployment/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ func TestGetDaemonSetDeployment(t *testing.T) {

ds := agent.Get()
assert.NotNil(t, ds)
}

func TestDaemonSetAgentAnnotations(t *testing.T) {
jaeger := v1alpha1.NewJaeger("TestDaemonSetAgentAnnotations")
jaeger.Spec.Agent.Strategy = "daemonset"
jaeger.Spec.Agent.Annotations = map[string]string{
"hello": "world",
"prometheus.io/scrape": "false", // Override implicit value
}

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

assert.Equal(t, "false", ds.Spec.Template.Annotations["sidecar.istio.io/inject"])
assert.Equal(t, "false", dep.Spec.Template.Annotations["sidecar.istio.io/inject"])
assert.Equal(t, "world", dep.Spec.Template.Annotations["hello"])
assert.Equal(t, "false", dep.Spec.Template.Annotations["prometheus.io/scrape"])
}
3 changes: 3 additions & 0 deletions pkg/deployment/all-in-one.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func (a *AllInOne) Get() *appsv1.Deployment {
"prometheus.io/port": "16686",
"sidecar.istio.io/inject": "false",
}
for k, v := range a.jaeger.Spec.AllInOne.Annotations {
annotations[k] = v
}

return &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Expand Down
15 changes: 14 additions & 1 deletion pkg/deployment/all-in-one_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,21 @@ func TestDefaultAllInOneImage(t *testing.T) {
},
}
assert.Equal(t, envvars, d.Spec.Template.Spec.Containers[0].Env)
}

func TestAllInOneAnnotations(t *testing.T) {
jaeger := v1alpha1.NewJaeger("TestAllInOneAnnotations")
jaeger.Spec.AllInOne.Annotations = map[string]string{
"hello": "world",
"prometheus.io/scrape": "false", // Override implicit value
}

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

assert.Equal(t, "false", d.Spec.Template.ObjectMeta.Annotations["sidecar.istio.io/inject"])
assert.Equal(t, "false", dep.Spec.Template.Annotations["sidecar.istio.io/inject"])
assert.Equal(t, "world", dep.Spec.Template.Annotations["hello"])
assert.Equal(t, "false", dep.Spec.Template.Annotations["prometheus.io/scrape"])
}

func TestAllInOneHasOwner(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/deployment/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func (c *Collector) Get() *appsv1.Deployment {
"prometheus.io/port": "14268",
"sidecar.istio.io/inject": "false",
}
for k, v := range c.jaeger.Spec.Collector.Annotations {
annotations[k] = v
}

return &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Expand Down
15 changes: 14 additions & 1 deletion pkg/deployment/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ func TestDefaultCollectorImage(t *testing.T) {
},
}
assert.Equal(t, envvars, containers[0].Env)
}

func TestCollectorAnnotations(t *testing.T) {
jaeger := v1alpha1.NewJaeger("TestCollectorAnnotations")
jaeger.Spec.Collector.Annotations = map[string]string{
"hello": "world",
"prometheus.io/scrape": "false", // Override implicit value
}

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

assert.Equal(t, "false", dep.Spec.Template.ObjectMeta.Annotations["sidecar.istio.io/inject"])
assert.Equal(t, "false", dep.Spec.Template.Annotations["sidecar.istio.io/inject"])
assert.Equal(t, "world", dep.Spec.Template.Annotations["hello"])
assert.Equal(t, "false", dep.Spec.Template.Annotations["prometheus.io/scrape"])
}
3 changes: 3 additions & 0 deletions pkg/deployment/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func (q *Query) Get() *appsv1.Deployment {
// it at will. So, we leave this configured just like any other application would
"inject-jaeger-agent": q.jaeger.Name,
}
for k, v := range q.jaeger.Spec.Query.Annotations {
annotations[k] = v
}

return &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Expand Down
15 changes: 14 additions & 1 deletion pkg/deployment/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,21 @@ func TestDefaultQueryImage(t *testing.T) {

assert.Len(t, containers, 1)
assert.Equal(t, "org/custom-query-image:123", containers[0].Image)
}

func TestQueryAnnotations(t *testing.T) {
jaeger := v1alpha1.NewJaeger("TestQueryAnnotations")
jaeger.Spec.Query.Annotations = map[string]string{
"hello": "world",
"prometheus.io/scrape": "false", // Override implicit value
}

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

assert.Equal(t, "false", dep.Spec.Template.ObjectMeta.Annotations["sidecar.istio.io/inject"])
assert.Equal(t, "false", dep.Spec.Template.Annotations["sidecar.istio.io/inject"])
assert.Equal(t, "world", dep.Spec.Template.Annotations["hello"])
assert.Equal(t, "false", dep.Spec.Template.Annotations["prometheus.io/scrape"])
}

func TestQueryPodName(t *testing.T) {
Expand Down