diff --git a/apis/v1/jaeger_types.go b/apis/v1/jaeger_types.go index 81a4c7846..c6121baa5 100644 --- a/apis/v1/jaeger_types.go +++ b/apis/v1/jaeger_types.go @@ -216,6 +216,9 @@ type JaegerCommonSpec struct { // +optional // +listType=atomic ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"` + + // +optional + ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"` } // JaegerQuerySpec defines the options to be used when deploying the query diff --git a/bundle/manifests/jaegertracing.io_jaegers.yaml b/bundle/manifests/jaegertracing.io_jaegers.yaml index c778a30dc..a7b84f36b 100644 --- a/bundle/manifests/jaegertracing.io_jaegers.yaml +++ b/bundle/manifests/jaegertracing.io_jaegers.yaml @@ -774,6 +774,8 @@ spec: type: boolean image: type: string + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -2027,6 +2029,8 @@ spec: x-kubernetes-preserve-unknown-fields: true image: type: string + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -3249,6 +3253,8 @@ spec: x-kubernetes-preserve-unknown-fields: true image: type: string + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -4104,6 +4110,8 @@ spec: type: array x-kubernetes-list-type: atomic type: object + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -4480,6 +4488,8 @@ spec: x-kubernetes-preserve-unknown-fields: true image: type: string + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -5699,6 +5709,8 @@ spec: type: string type: array x-kubernetes-list-type: atomic + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -6923,6 +6935,8 @@ spec: type: integer image: type: string + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -8622,6 +8636,8 @@ spec: type: boolean image: type: string + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -9893,6 +9909,8 @@ spec: type: boolean image: type: string + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -11092,6 +11110,8 @@ spec: type: string image: type: string + imagePullPolicy: + type: string imagePullSecrets: items: properties: diff --git a/config/crd/bases/jaegertracing.io_jaegers.yaml b/config/crd/bases/jaegertracing.io_jaegers.yaml index 78d864f65..a8d4a091a 100644 --- a/config/crd/bases/jaegertracing.io_jaegers.yaml +++ b/config/crd/bases/jaegertracing.io_jaegers.yaml @@ -773,6 +773,8 @@ spec: type: boolean image: type: string + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -2026,6 +2028,8 @@ spec: x-kubernetes-preserve-unknown-fields: true image: type: string + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -3248,6 +3252,8 @@ spec: x-kubernetes-preserve-unknown-fields: true image: type: string + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -4103,6 +4109,8 @@ spec: type: array x-kubernetes-list-type: atomic type: object + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -4479,6 +4487,8 @@ spec: x-kubernetes-preserve-unknown-fields: true image: type: string + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -5698,6 +5708,8 @@ spec: type: string type: array x-kubernetes-list-type: atomic + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -6922,6 +6934,8 @@ spec: type: integer image: type: string + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -8621,6 +8635,8 @@ spec: type: boolean image: type: string + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -9892,6 +9908,8 @@ spec: type: boolean image: type: string + imagePullPolicy: + type: string imagePullSecrets: items: properties: @@ -11091,6 +11109,8 @@ spec: type: string image: type: string + imagePullPolicy: + type: string imagePullSecrets: items: properties: diff --git a/pkg/deployment/agent.go b/pkg/deployment/agent.go index 09d58768f..b4a5f3f09 100644 --- a/pkg/deployment/agent.go +++ b/pkg/deployment/agent.go @@ -175,8 +175,9 @@ func (a *Agent) Get() *appsv1.DaemonSet { }, InitialDelaySeconds: 1, }, - Resources: commonSpec.Resources, - VolumeMounts: commonSpec.VolumeMounts, + Resources: commonSpec.Resources, + VolumeMounts: commonSpec.VolumeMounts, + ImagePullPolicy: commonSpec.ImagePullPolicy, }}, DNSPolicy: dnsPolicy, HostNetwork: hostNetwork, diff --git a/pkg/deployment/agent_test.go b/pkg/deployment/agent_test.go index 1098377cc..02c2e4407 100644 --- a/pkg/deployment/agent_test.go +++ b/pkg/deployment/agent_test.go @@ -296,6 +296,18 @@ func TestAgentImagePullSecrets(t *testing.T) { assert.Equal(t, pullSecret, dep.Spec.Template.Spec.ImagePullSecrets[0].Name) } +func TestAgentImagePullPolicy(t *testing.T) { + jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestAgentImagePullPolicy"}) + const pullPolicy = corev1.PullPolicy("Always") + jaeger.Spec.Agent.Strategy = "daemonset" + jaeger.Spec.ImagePullPolicy = corev1.PullPolicy("Always") + + agent := NewAgent(jaeger) + dep := agent.Get() + + assert.Equal(t, pullPolicy, dep.Spec.Template.Spec.Containers[0].ImagePullPolicy) +} + func TestAgentServiceLinks(t *testing.T) { jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"}) jaeger.Spec.Agent.Strategy = "daemonset" diff --git a/pkg/deployment/all_in_one.go b/pkg/deployment/all_in_one.go index 5cbedb3ac..fa424b811 100644 --- a/pkg/deployment/all_in_one.go +++ b/pkg/deployment/all_in_one.go @@ -229,7 +229,8 @@ func (a *AllInOne) Get() *appsv1.Deployment { }, InitialDelaySeconds: 1, }, - Resources: commonSpec.Resources, + Resources: commonSpec.Resources, + ImagePullPolicy: commonSpec.ImagePullPolicy, }}, Volumes: commonSpec.Volumes, ServiceAccountName: account.JaegerServiceAccountFor(a.jaeger, account.AllInOneComponent), diff --git a/pkg/deployment/all_in_one_test.go b/pkg/deployment/all_in_one_test.go index a4205814b..d475db260 100644 --- a/pkg/deployment/all_in_one_test.go +++ b/pkg/deployment/all_in_one_test.go @@ -216,6 +216,17 @@ func TestAllInOneImagePullSecrets(t *testing.T) { assert.Equal(t, pullSecret, dep.Spec.Template.Spec.ImagePullSecrets[0].Name) } +func TestAllInOneImagePullPolicy(t *testing.T) { + jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestAllInOneImagePullPolicy"}) + const pullPolicy = corev1.PullPolicy("Always") + jaeger.Spec.ImagePullPolicy = corev1.PullPolicy("Always") + + allInOne := NewAllInOne(jaeger) + dep := allInOne.Get() + + assert.Equal(t, pullPolicy, dep.Spec.Template.Spec.Containers[0].ImagePullPolicy) +} + func TestAllInOneMountGlobalVolumes(t *testing.T) { name := "TestAllInOneMountGlobalVolumes" diff --git a/pkg/deployment/collector.go b/pkg/deployment/collector.go index 0accc9791..52a2fbabd 100644 --- a/pkg/deployment/collector.go +++ b/pkg/deployment/collector.go @@ -188,7 +188,8 @@ func (c *Collector) Get() *appsv1.Deployment { }, InitialDelaySeconds: 1, }, - Resources: commonSpec.Resources, + Resources: commonSpec.Resources, + ImagePullPolicy: commonSpec.ImagePullPolicy, }}, PriorityClassName: priorityClassName, Volumes: commonSpec.Volumes, diff --git a/pkg/deployment/collector_test.go b/pkg/deployment/collector_test.go index 5d5236db9..2dcf1049b 100644 --- a/pkg/deployment/collector_test.go +++ b/pkg/deployment/collector_test.go @@ -156,6 +156,17 @@ func TestCollectorImagePullSecrets(t *testing.T) { assert.Equal(t, pullSecret, dep.Spec.Template.Spec.ImagePullSecrets[0].Name) } +func TestCollectorImagePullPolicy(t *testing.T) { + jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestCollectorImagePullPolicy"}) + const pullPolicy = corev1.PullPolicy("Always") + jaeger.Spec.ImagePullPolicy = corev1.PullPolicy("Always") + + collector := NewCollector(jaeger) + dep := collector.Get() + + assert.Equal(t, pullPolicy, dep.Spec.Template.Spec.Containers[0].ImagePullPolicy) +} + func TestCollectorVolumeMountsWithVolumes(t *testing.T) { name := "my-instance" diff --git a/pkg/deployment/ingester.go b/pkg/deployment/ingester.go index 99fa7b143..ac4afbf8b 100644 --- a/pkg/deployment/ingester.go +++ b/pkg/deployment/ingester.go @@ -156,7 +156,8 @@ func (i *Ingester) Get() *appsv1.Deployment { }, InitialDelaySeconds: 1, }, - Resources: commonSpec.Resources, + Resources: commonSpec.Resources, + ImagePullPolicy: commonSpec.ImagePullPolicy, }}, Volumes: commonSpec.Volumes, ServiceAccountName: account.JaegerServiceAccountFor(i.jaeger, account.IngesterComponent), diff --git a/pkg/deployment/ingester_test.go b/pkg/deployment/ingester_test.go index 5434288ec..8a02fabfe 100644 --- a/pkg/deployment/ingester_test.go +++ b/pkg/deployment/ingester_test.go @@ -153,6 +153,17 @@ func TestIngeterImagePullSecrets(t *testing.T) { assert.Equal(t, pullSecret, dep.Spec.Template.Spec.ImagePullSecrets[0].Name) } +func TestIngesterImagePullPolicy(t *testing.T) { + jaeger := newIngesterJaeger("TestIngesterImagePullPolicy") + const pullPolicy = corev1.PullPolicy("Always") + jaeger.Spec.ImagePullPolicy = corev1.PullPolicy("Always") + + ingester := NewIngester(jaeger) + dep := ingester.Get() + + assert.Equal(t, pullPolicy, dep.Spec.Template.Spec.Containers[0].ImagePullPolicy) +} + func TestIngesterVolumeMountsWithVolumes(t *testing.T) { name := "TestIngesterVolumeMountsWithVolumes" diff --git a/pkg/deployment/query.go b/pkg/deployment/query.go index 8dd7d61b6..6598312f1 100644 --- a/pkg/deployment/query.go +++ b/pkg/deployment/query.go @@ -180,7 +180,8 @@ func (q *Query) Get() *appsv1.Deployment { }, InitialDelaySeconds: 1, }, - Resources: commonSpec.Resources, + Resources: commonSpec.Resources, + ImagePullPolicy: commonSpec.ImagePullPolicy, }}, PriorityClassName: priorityClassName, Volumes: commonSpec.Volumes, diff --git a/pkg/deployment/query_test.go b/pkg/deployment/query_test.go index 434da8bed..7b1b1459b 100644 --- a/pkg/deployment/query_test.go +++ b/pkg/deployment/query_test.go @@ -130,6 +130,17 @@ func TestQueryImagePullSecrets(t *testing.T) { assert.Equal(t, pullSecret, dep.Spec.Template.Spec.ImagePullSecrets[0].Name) } +func TestQueryImagePullPolicy(t *testing.T) { + jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestQueryImagePullPolicy"}) + const pullPolicy = corev1.PullPolicy("Always") + jaeger.Spec.ImagePullPolicy = corev1.PullPolicy("Always") + + query := NewQuery(jaeger) + dep := query.Get() + + assert.Equal(t, pullPolicy, dep.Spec.Template.Spec.Containers[0].ImagePullPolicy) +} + func TestQueryPodName(t *testing.T) { name := "TestQueryPodName" query := NewQuery(v1.NewJaeger(types.NamespacedName{Name: name})) diff --git a/pkg/util/util.go b/pkg/util/util.go index 3b2217339..3a11518c1 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -75,6 +75,7 @@ func Merge(commonSpecs []v1.JaegerCommonSpec) *v1.JaegerCommonSpec { var securityContext *corev1.PodSecurityContext var serviceAccount string var imagePullSecrets []corev1.LocalObjectReference + var imagePullPolicy corev1.PullPolicy for _, commonSpec := range commonSpecs { // Merge annotations @@ -115,6 +116,10 @@ func Merge(commonSpecs []v1.JaegerCommonSpec) *v1.JaegerCommonSpec { for _, ips := range commonSpec.ImagePullSecrets { imagePullSecrets = append(imagePullSecrets, ips) } + + if imagePullPolicy == corev1.PullPolicy("") { + imagePullPolicy = commonSpec.ImagePullPolicy + } } return &v1.JaegerCommonSpec{ @@ -123,6 +128,7 @@ func Merge(commonSpecs []v1.JaegerCommonSpec) *v1.JaegerCommonSpec { VolumeMounts: RemoveDuplicatedVolumeMounts(volumeMounts), Volumes: RemoveDuplicatedVolumes(volumes), ImagePullSecrets: RemoveDuplicatedImagePullSecrets(imagePullSecrets), + ImagePullPolicy: imagePullPolicy, Resources: *resources, Affinity: affinity, Tolerations: tolerations, diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go index 0fa884ff7..19d82bfc8 100644 --- a/pkg/util/util_test.go +++ b/pkg/util/util_test.go @@ -107,6 +107,23 @@ func TestMergeImagePullSecrets(t *testing.T) { assert.Equal(t, "hij", merged.ImagePullSecrets[3].Name) } +func TestMergeImagePullPolicy(t *testing.T) { + emptySpec := v1.JaegerCommonSpec{} + generalSpec := v1.JaegerCommonSpec{ + ImagePullPolicy: corev1.PullPolicy("Never"), + } + specificSpec := v1.JaegerCommonSpec{ + ImagePullPolicy: corev1.PullPolicy("Always"), + } + anotherSpec := v1.JaegerCommonSpec{ + ImagePullPolicy: corev1.PullPolicy("IfNotPresent"), + } + + merged := Merge([]v1.JaegerCommonSpec{specificSpec, generalSpec, emptySpec, anotherSpec}) + + assert.Equal(t, corev1.PullPolicy("Always"), merged.ImagePullPolicy) +} + func TestMergeAnnotations(t *testing.T) { generalSpec := v1.JaegerCommonSpec{ Annotations: map[string]string{