From 0e3a6b09b27be032b65e4050c28c6af62503e477 Mon Sep 17 00:00:00 2001 From: edenkoveshi Date: Mon, 21 Feb 2022 20:57:53 +0200 Subject: [PATCH 1/2] Added pImagePullPolicy/Secrets properties to AllInOne Signed-off-by: edenkoveshi --- .gitignore | 1 + apis/v1/jaeger_types.go | 6 ++++++ apis/v1/zz_generated.deepcopy.go | 6 +++++- config/crd/bases/jaegertracing.io_jaegers.yaml | 9 +++++++++ pkg/deployment/all_in_one.go | 10 +++++++++- pkg/kafka/v1beta2/zz_generated.deepcopy.go | 1 - 6 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2b8970f9f..26e50c886 100644 --- a/.gitignore +++ b/.gitignore @@ -88,3 +88,4 @@ import.log ### Kubernetes ### kubeconfig bin +temp \ No newline at end of file diff --git a/apis/v1/jaeger_types.go b/apis/v1/jaeger_types.go index c92e010a1..375ae7f50 100644 --- a/apis/v1/jaeger_types.go +++ b/apis/v1/jaeger_types.go @@ -340,6 +340,12 @@ type JaegerAllInOneSpec struct { // +optional Image string `json:"image,omitempty"` + // +optional + ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"` + + // +optional + ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"` + // +optional // +kubebuilder:pruning:PreserveUnknownFields Options Options `json:"options,omitempty"` diff --git a/apis/v1/zz_generated.deepcopy.go b/apis/v1/zz_generated.deepcopy.go index 1f09341bc..52fd22d5f 100644 --- a/apis/v1/zz_generated.deepcopy.go +++ b/apis/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated // Code generated by controller-gen. DO NOT EDIT. @@ -178,6 +177,11 @@ func (in *JaegerAgentSpec) DeepCopy() *JaegerAgentSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *JaegerAllInOneSpec) DeepCopyInto(out *JaegerAllInOneSpec) { *out = *in + if in.ImagePullSecrets != nil { + in, out := &in.ImagePullSecrets, &out.ImagePullSecrets + *out = make([]corev1.LocalObjectReference, len(*in)) + copy(*out, *in) + } in.Options.DeepCopyInto(&out.Options) in.Config.DeepCopyInto(&out.Config) in.JaegerCommonSpec.DeepCopyInto(&out.JaegerCommonSpec) diff --git a/config/crd/bases/jaegertracing.io_jaegers.yaml b/config/crd/bases/jaegertracing.io_jaegers.yaml index df1028ca5..706c2fb06 100644 --- a/config/crd/bases/jaegertracing.io_jaegers.yaml +++ b/config/crd/bases/jaegertracing.io_jaegers.yaml @@ -2026,6 +2026,15 @@ spec: x-kubernetes-preserve-unknown-fields: true image: type: string + imagePullPolicy: + type: string + imagePullSecrets: + items: + properties: + name: + type: string + type: object + type: array labels: additionalProperties: type: string diff --git a/pkg/deployment/all_in_one.go b/pkg/deployment/all_in_one.go index 281f57607..68a00b03f 100644 --- a/pkg/deployment/all_in_one.go +++ b/pkg/deployment/all_in_one.go @@ -110,7 +110,7 @@ func (a *AllInOne) Get() *appsv1.Deployment { strategy = *a.jaeger.Spec.AllInOne.Strategy } - return &appsv1.Deployment{ + dep := &appsv1.Deployment{ TypeMeta: metav1.TypeMeta{ APIVersion: "apps/v1", Kind: "Deployment", @@ -237,6 +237,14 @@ func (a *AllInOne) Get() *appsv1.Deployment { }, }, } + if a.jaeger.Spec.AllInOne.ImagePullPolicy != "" { + dep.Spec.Template.Spec.Containers[0].ImagePullPolicy = a.jaeger.Spec.AllInOne.ImagePullPolicy + } + if a.jaeger.Spec.AllInOne.ImagePullSecrets != nil { + dep.Spec.Template.Spec.ImagePullSecrets = a.jaeger.Spec.AllInOne.ImagePullSecrets + } + + return dep } // Services returns a list of services to be deployed along with the all-in-one deployment diff --git a/pkg/kafka/v1beta2/zz_generated.deepcopy.go b/pkg/kafka/v1beta2/zz_generated.deepcopy.go index db3174b2c..8084faa05 100644 --- a/pkg/kafka/v1beta2/zz_generated.deepcopy.go +++ b/pkg/kafka/v1beta2/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated // Code generated by controller-gen. DO NOT EDIT. From 471c4854cd1fdece1afe403f9eede1133b8cc561 Mon Sep 17 00:00:00 2001 From: edenkoveshi Date: Tue, 22 Feb 2022 00:31:45 +0200 Subject: [PATCH 2/2] ImagePullPolicy and ImagePullSecrets are added to JaegerCommonSpec and handled within util.Merge, and then applied to all created containers. Relevant tests updated accordingly. Signed-off-by: edenkoveshi --- apis/v1/jaeger_types.go | 19 +++-- apis/v1/zz_generated.deepcopy.go | 15 ++-- .../crd/bases/jaegertracing.io_jaegers.yaml | 83 +++++++++++++++++++ pkg/cronjob/es_index_cleaner.go | 16 ++-- pkg/cronjob/es_rollover.go | 16 ++-- pkg/cronjob/spark_dependencies.go | 10 ++- pkg/deployment/agent.go | 6 +- pkg/deployment/all_in_one.go | 14 +--- pkg/deployment/collector.go | 2 + pkg/deployment/ingester.go | 2 + pkg/deployment/query.go | 4 +- pkg/inject/sidecar.go | 2 +- pkg/inject/sidecar_test.go | 2 +- pkg/storage/elasticsearch_dependencies.go | 16 ++-- pkg/util/util.go | 27 ++++-- pkg/util/util_test.go | 73 ++++++++++++++++ 16 files changed, 239 insertions(+), 68 deletions(-) diff --git a/apis/v1/jaeger_types.go b/apis/v1/jaeger_types.go index 375ae7f50..a3f7d6a19 100644 --- a/apis/v1/jaeger_types.go +++ b/apis/v1/jaeger_types.go @@ -213,6 +213,13 @@ type JaegerCommonSpec struct { // +optional ServiceAccount string `json:"serviceAccount,omitempty"` + + // +optional + ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"` + + // +optional + // +listType=atomic + ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"` } // JaegerQuerySpec defines the options to be used when deploying the query @@ -340,12 +347,6 @@ type JaegerAllInOneSpec struct { // +optional Image string `json:"image,omitempty"` - // +optional - ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"` - - // +optional - ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"` - // +optional // +kubebuilder:pruning:PreserveUnknownFields Options Options `json:"options,omitempty"` @@ -457,9 +458,9 @@ type JaegerAgentSpec struct { // +optional Image string `json:"image,omitempty"` - // +optional - // +listType=atomic - ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"` + // // +optional + // // +listType=atomic + // ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"` // +optional // +kubebuilder:pruning:PreserveUnknownFields diff --git a/apis/v1/zz_generated.deepcopy.go b/apis/v1/zz_generated.deepcopy.go index 52fd22d5f..81a813bfc 100644 --- a/apis/v1/zz_generated.deepcopy.go +++ b/apis/v1/zz_generated.deepcopy.go @@ -144,11 +144,6 @@ func (in *Jaeger) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *JaegerAgentSpec) DeepCopyInto(out *JaegerAgentSpec) { *out = *in - if in.ImagePullSecrets != nil { - in, out := &in.ImagePullSecrets, &out.ImagePullSecrets - *out = make([]corev1.LocalObjectReference, len(*in)) - copy(*out, *in) - } in.Options.DeepCopyInto(&out.Options) in.JaegerCommonSpec.DeepCopyInto(&out.JaegerCommonSpec) in.Config.DeepCopyInto(&out.Config) @@ -177,11 +172,6 @@ func (in *JaegerAgentSpec) DeepCopy() *JaegerAgentSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *JaegerAllInOneSpec) DeepCopyInto(out *JaegerAllInOneSpec) { *out = *in - if in.ImagePullSecrets != nil { - in, out := &in.ImagePullSecrets, &out.ImagePullSecrets - *out = make([]corev1.LocalObjectReference, len(*in)) - copy(*out, *in) - } in.Options.DeepCopyInto(&out.Options) in.Config.DeepCopyInto(&out.Config) in.JaegerCommonSpec.DeepCopyInto(&out.JaegerCommonSpec) @@ -315,6 +305,11 @@ func (in *JaegerCommonSpec) DeepCopyInto(out *JaegerCommonSpec) { *out = new(corev1.PodSecurityContext) (*in).DeepCopyInto(*out) } + if in.ImagePullSecrets != nil { + in, out := &in.ImagePullSecrets, &out.ImagePullSecrets + *out = make([]corev1.LocalObjectReference, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JaegerCommonSpec. diff --git a/config/crd/bases/jaegertracing.io_jaegers.yaml b/config/crd/bases/jaegertracing.io_jaegers.yaml index 706c2fb06..8ee5d99ba 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: @@ -2035,6 +2037,7 @@ spec: type: string type: object type: array + x-kubernetes-list-type: atomic labels: additionalProperties: type: string @@ -3244,6 +3247,16 @@ spec: x-kubernetes-preserve-unknown-fields: true image: type: string + imagePullPolicy: + type: string + imagePullSecrets: + items: + properties: + name: + type: string + type: object + type: array + x-kubernetes-list-type: atomic labels: additionalProperties: type: string @@ -4091,6 +4104,16 @@ spec: type: array x-kubernetes-list-type: atomic type: object + imagePullPolicy: + type: string + imagePullSecrets: + items: + properties: + name: + type: string + type: object + type: array + x-kubernetes-list-type: atomic ingester: properties: affinity: @@ -4459,6 +4482,16 @@ spec: x-kubernetes-preserve-unknown-fields: true image: type: string + imagePullPolicy: + type: string + imagePullSecrets: + items: + properties: + name: + type: string + type: object + type: array + x-kubernetes-list-type: atomic labels: additionalProperties: type: string @@ -5670,6 +5703,16 @@ spec: type: string type: array x-kubernetes-list-type: atomic + imagePullPolicy: + type: string + imagePullSecrets: + items: + properties: + name: + type: string + type: object + type: array + x-kubernetes-list-type: atomic ingressClassName: type: string labels: @@ -6886,6 +6929,16 @@ spec: type: integer image: type: string + imagePullPolicy: + type: string + imagePullSecrets: + items: + properties: + name: + type: string + type: object + type: array + x-kubernetes-list-type: atomic labels: additionalProperties: type: string @@ -8572,6 +8625,16 @@ spec: type: boolean image: type: string + imagePullPolicy: + type: string + imagePullSecrets: + items: + properties: + name: + type: string + type: object + type: array + x-kubernetes-list-type: atomic javaOpts: type: string labels: @@ -9835,6 +9898,16 @@ spec: type: boolean image: type: string + imagePullPolicy: + type: string + imagePullSecrets: + items: + properties: + name: + type: string + type: object + type: array + x-kubernetes-list-type: atomic labels: additionalProperties: type: string @@ -11026,6 +11099,16 @@ spec: type: string image: type: string + imagePullPolicy: + type: string + imagePullSecrets: + items: + properties: + name: + type: string + type: object + type: array + x-kubernetes-list-type: atomic labels: additionalProperties: type: string diff --git a/pkg/cronjob/es_index_cleaner.go b/pkg/cronjob/es_index_cleaner.go index 389b35ec8..a94ee803b 100644 --- a/pkg/cronjob/es_index_cleaner.go +++ b/pkg/cronjob/es_index_cleaner.go @@ -73,13 +73,14 @@ func CreateEsIndexCleaner(jaeger *v1.Jaeger) *batchv1beta1.CronJob { Spec: corev1.PodSpec{ Containers: []corev1.Container{ { - Name: util.Truncate(name, 63), - Image: util.ImageName(jaeger.Spec.Storage.EsIndexCleaner.Image, "jaeger-es-index-cleaner-image"), - Args: []string{strconv.Itoa(*jaeger.Spec.Storage.EsIndexCleaner.NumberOfDays), esUrls}, - Env: util.RemoveEmptyVars(envs), - EnvFrom: envFromSource, - Resources: commonSpec.Resources, - VolumeMounts: commonSpec.VolumeMounts, + Name: util.Truncate(name, 63), + Image: util.ImageName(jaeger.Spec.Storage.EsIndexCleaner.Image, "jaeger-es-index-cleaner-image"), + Args: []string{strconv.Itoa(*jaeger.Spec.Storage.EsIndexCleaner.NumberOfDays), esUrls}, + Env: util.RemoveEmptyVars(envs), + EnvFrom: envFromSource, + Resources: commonSpec.Resources, + VolumeMounts: commonSpec.VolumeMounts, + ImagePullPolicy: commonSpec.ImagePullPolicy, }, }, RestartPolicy: corev1.RestartPolicyNever, @@ -88,6 +89,7 @@ func CreateEsIndexCleaner(jaeger *v1.Jaeger) *batchv1beta1.CronJob { SecurityContext: commonSpec.SecurityContext, ServiceAccountName: account.JaegerServiceAccountFor(jaeger, account.EsIndexCleanerComponent), Volumes: commonSpec.Volumes, + ImagePullSecrets: commonSpec.ImagePullSecrets, }, ObjectMeta: metav1.ObjectMeta{ Labels: commonSpec.Labels, diff --git a/pkg/cronjob/es_rollover.go b/pkg/cronjob/es_rollover.go index 39f464948..8bdb0eb30 100644 --- a/pkg/cronjob/es_rollover.go +++ b/pkg/cronjob/es_rollover.go @@ -88,15 +88,17 @@ func createTemplate(name, action string, jaeger *v1.Jaeger, envs []corev1.EnvVar Volumes: commonSpec.Volumes, Containers: []corev1.Container{ { - Name: name, - Image: util.ImageName(jaeger.Spec.Storage.EsRollover.Image, "jaeger-es-rollover-image"), - Args: []string{action, util.GetEsHostname(jaeger.Spec.Storage.Options.Map())}, - Env: util.RemoveEmptyVars(envs), - EnvFrom: envFromSource, - Resources: commonSpec.Resources, - VolumeMounts: commonSpec.VolumeMounts, + Name: name, + Image: util.ImageName(jaeger.Spec.Storage.EsRollover.Image, "jaeger-es-rollover-image"), + Args: []string{action, util.GetEsHostname(jaeger.Spec.Storage.Options.Map())}, + Env: util.RemoveEmptyVars(envs), + EnvFrom: envFromSource, + Resources: commonSpec.Resources, + VolumeMounts: commonSpec.VolumeMounts, + ImagePullPolicy: commonSpec.ImagePullPolicy, }, }, + ImagePullSecrets: commonSpec.ImagePullSecrets, }, } } diff --git a/pkg/cronjob/spark_dependencies.go b/pkg/cronjob/spark_dependencies.go index 804fe1ebc..1247dbd98 100644 --- a/pkg/cronjob/spark_dependencies.go +++ b/pkg/cronjob/spark_dependencies.go @@ -94,10 +94,11 @@ func CreateSparkDependencies(jaeger *v1.Jaeger) *batchv1beta1.CronJob { Image: image, Name: name, // let spark job use its default values - Env: util.RemoveEmptyVars(envVars), - EnvFrom: envFromSource, - Resources: commonSpec.Resources, - VolumeMounts: jaeger.Spec.Storage.Dependencies.JaegerCommonSpec.VolumeMounts, + Env: util.RemoveEmptyVars(envVars), + EnvFrom: envFromSource, + Resources: commonSpec.Resources, + VolumeMounts: jaeger.Spec.Storage.Dependencies.JaegerCommonSpec.VolumeMounts, + ImagePullPolicy: commonSpec.ImagePullPolicy, }, }, RestartPolicy: corev1.RestartPolicyNever, @@ -106,6 +107,7 @@ func CreateSparkDependencies(jaeger *v1.Jaeger) *batchv1beta1.CronJob { SecurityContext: commonSpec.SecurityContext, ServiceAccountName: account.JaegerServiceAccountFor(jaeger, account.DependenciesComponent), Volumes: jaeger.Spec.Storage.Dependencies.JaegerCommonSpec.Volumes, + ImagePullSecrets: commonSpec.ImagePullSecrets, }, ObjectMeta: metav1.ObjectMeta{ Labels: commonSpec.Labels, diff --git a/pkg/deployment/agent.go b/pkg/deployment/agent.go index 3eb05f9cd..1fd688abd 100644 --- a/pkg/deployment/agent.go +++ b/pkg/deployment/agent.go @@ -174,8 +174,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, @@ -186,6 +187,7 @@ func (a *Agent) Get() *appsv1.DaemonSet { SecurityContext: commonSpec.SecurityContext, ServiceAccountName: account.JaegerServiceAccountFor(a.jaeger, account.AgentComponent), EnableServiceLinks: &falseVar, + ImagePullSecrets: commonSpec.ImagePullSecrets, }, }, }, diff --git a/pkg/deployment/all_in_one.go b/pkg/deployment/all_in_one.go index 68a00b03f..3ebd7bf37 100644 --- a/pkg/deployment/all_in_one.go +++ b/pkg/deployment/all_in_one.go @@ -110,7 +110,7 @@ func (a *AllInOne) Get() *appsv1.Deployment { strategy = *a.jaeger.Spec.AllInOne.Strategy } - dep := &appsv1.Deployment{ + return &appsv1.Deployment{ TypeMeta: metav1.TypeMeta{ APIVersion: "apps/v1", Kind: "Deployment", @@ -224,7 +224,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), @@ -233,18 +234,11 @@ func (a *AllInOne) Get() *appsv1.Deployment { SecurityContext: commonSpec.SecurityContext, EnableServiceLinks: &falseVar, InitContainers: storage.GetGRPCPluginInitContainers(a.jaeger, commonSpec), + ImagePullSecrets: commonSpec.ImagePullSecrets, }, }, }, } - if a.jaeger.Spec.AllInOne.ImagePullPolicy != "" { - dep.Spec.Template.Spec.Containers[0].ImagePullPolicy = a.jaeger.Spec.AllInOne.ImagePullPolicy - } - if a.jaeger.Spec.AllInOne.ImagePullSecrets != nil { - dep.Spec.Template.Spec.ImagePullSecrets = a.jaeger.Spec.AllInOne.ImagePullSecrets - } - - return dep } // Services returns a list of services to be deployed along with the all-in-one deployment diff --git a/pkg/deployment/collector.go b/pkg/deployment/collector.go index f223790e5..093b6178e 100644 --- a/pkg/deployment/collector.go +++ b/pkg/deployment/collector.go @@ -188,6 +188,7 @@ func (c *Collector) Get() *appsv1.Deployment { InitialDelaySeconds: 1, }, Resources: commonSpec.Resources, + ImagePullPolicy: commonSpec.ImagePullPolicy, }}, PriorityClassName: priorityClassName, Volumes: commonSpec.Volumes, @@ -197,6 +198,7 @@ func (c *Collector) Get() *appsv1.Deployment { SecurityContext: commonSpec.SecurityContext, EnableServiceLinks: &falseVar, InitContainers: storage.GetGRPCPluginInitContainers(c.jaeger, commonSpec), + ImagePullSecrets: commonSpec.ImagePullSecrets, }, }, }, diff --git a/pkg/deployment/ingester.go b/pkg/deployment/ingester.go index ef03903fe..16ae818fc 100644 --- a/pkg/deployment/ingester.go +++ b/pkg/deployment/ingester.go @@ -156,6 +156,7 @@ func (i *Ingester) Get() *appsv1.Deployment { InitialDelaySeconds: 1, }, Resources: commonSpec.Resources, + ImagePullPolicy: commonSpec.ImagePullPolicy, }}, Volumes: commonSpec.Volumes, ServiceAccountName: account.JaegerServiceAccountFor(i.jaeger, account.IngesterComponent), @@ -164,6 +165,7 @@ func (i *Ingester) Get() *appsv1.Deployment { SecurityContext: commonSpec.SecurityContext, EnableServiceLinks: &falseVar, InitContainers: storage.GetGRPCPluginInitContainers(i.jaeger, commonSpec), + ImagePullSecrets: commonSpec.ImagePullSecrets, }, }, }, diff --git a/pkg/deployment/query.go b/pkg/deployment/query.go index 3eb914def..d209f4132 100644 --- a/pkg/deployment/query.go +++ b/pkg/deployment/query.go @@ -175,7 +175,8 @@ func (q *Query) Get() *appsv1.Deployment { }, InitialDelaySeconds: 1, }, - Resources: commonSpec.Resources, + Resources: commonSpec.Resources, + ImagePullPolicy: commonSpec.ImagePullPolicy, }}, PriorityClassName: priorityClassName, Volumes: commonSpec.Volumes, @@ -185,6 +186,7 @@ func (q *Query) Get() *appsv1.Deployment { SecurityContext: commonSpec.SecurityContext, EnableServiceLinks: &falseVar, InitContainers: storage.GetGRPCPluginInitContainers(q.jaeger, commonSpec), + ImagePullSecrets: commonSpec.ImagePullSecrets, }, }, }, diff --git a/pkg/inject/sidecar.go b/pkg/inject/sidecar.go index a6a210f14..4a49543f7 100644 --- a/pkg/inject/sidecar.go +++ b/pkg/inject/sidecar.go @@ -241,7 +241,7 @@ func container(jaeger *v1.Jaeger, dep *appsv1.Deployment, agentIdx int) corev1.C // see https://github.com/jaegertracing/jaeger-operator/issues/334 sort.Strings(args) - dep.Spec.Template.Spec.ImagePullSecrets = util.RemoveDuplicatedImagePullSecrets(append(dep.Spec.Template.Spec.ImagePullSecrets, jaeger.Spec.Agent.ImagePullSecrets...)) + dep.Spec.Template.Spec.ImagePullSecrets = util.RemoveDuplicatedImagePullSecrets(append(dep.Spec.Template.Spec.ImagePullSecrets, jaeger.Spec.Agent.JaegerCommonSpec.ImagePullSecrets...)) dep.Spec.Template.Spec.Volumes = util.RemoveDuplicatedVolumes(append(dep.Spec.Template.Spec.Volumes, volumesAndMountsSpec.Volumes...)) return corev1.Container{ Image: util.ImageName(jaeger.Spec.Agent.Image, "jaeger-agent-image"), diff --git a/pkg/inject/sidecar_test.go b/pkg/inject/sidecar_test.go index f3eb5c5f8..1b2df178a 100644 --- a/pkg/inject/sidecar_test.go +++ b/pkg/inject/sidecar_test.go @@ -242,7 +242,7 @@ func TestSidecarImagePullSecrets(t *testing.T) { }} jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"}) - jaeger.Spec.Agent.ImagePullSecrets = agentImagePullSecrets + jaeger.Spec.Agent.JaegerCommonSpec.ImagePullSecrets = agentImagePullSecrets dep := dep(map[string]string{}, map[string]string{}) dep.Spec.Template.Spec.ImagePullSecrets = deploymentImagePullSecrets diff --git a/pkg/storage/elasticsearch_dependencies.go b/pkg/storage/elasticsearch_dependencies.go index 05321baa1..c9afa614d 100644 --- a/pkg/storage/elasticsearch_dependencies.go +++ b/pkg/storage/elasticsearch_dependencies.go @@ -51,15 +51,17 @@ func elasticsearchDependencies(jaeger *v1.Jaeger) []batchv1.Job { SecurityContext: commonSpec.SecurityContext, ServiceAccountName: account.JaegerServiceAccountFor(jaeger, account.EsRolloverComponent), Volumes: commonSpec.Volumes, + ImagePullSecrets: commonSpec.ImagePullSecrets, Containers: []corev1.Container{ { - Name: name, - Image: util.ImageName(jaeger.Spec.Storage.EsRollover.Image, "jaeger-es-rollover-image"), - Args: []string{"init", util.GetEsHostname(jaeger.Spec.Storage.Options.Map())}, - Env: util.RemoveEmptyVars(envVars(jaeger.Spec.Storage.Options)), - EnvFrom: envFromSource, - Resources: commonSpec.Resources, - VolumeMounts: commonSpec.VolumeMounts, + Name: name, + Image: util.ImageName(jaeger.Spec.Storage.EsRollover.Image, "jaeger-es-rollover-image"), + Args: []string{"init", util.GetEsHostname(jaeger.Spec.Storage.Options.Map())}, + Env: util.RemoveEmptyVars(envVars(jaeger.Spec.Storage.Options)), + EnvFrom: envFromSource, + Resources: commonSpec.Resources, + VolumeMounts: commonSpec.VolumeMounts, + ImagePullPolicy: commonSpec.ImagePullPolicy, }, }, }, diff --git a/pkg/util/util.go b/pkg/util/util.go index 9f15ec86c..26830a8d1 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -74,6 +74,8 @@ func Merge(commonSpecs []v1.JaegerCommonSpec) *v1.JaegerCommonSpec { var tolerations []corev1.Toleration var securityContext *corev1.PodSecurityContext var serviceAccount string + var imagePullPolicy corev1.PullPolicy + var imagePullSecrets []corev1.LocalObjectReference for _, commonSpec := range commonSpecs { // Merge annotations @@ -92,6 +94,7 @@ func Merge(commonSpecs []v1.JaegerCommonSpec) *v1.JaegerCommonSpec { } volumeMounts = append(volumeMounts, commonSpec.VolumeMounts...) volumes = append(volumes, commonSpec.Volumes...) + imagePullSecrets = RemoveDuplicatedImagePullSecrets(append(imagePullSecrets, commonSpec.ImagePullSecrets...)) // Merge resources MergeResources(resources, commonSpec.Resources) @@ -110,18 +113,24 @@ func Merge(commonSpecs []v1.JaegerCommonSpec) *v1.JaegerCommonSpec { if serviceAccount == "" { serviceAccount = commonSpec.ServiceAccount } + + if imagePullPolicy == "" { + imagePullPolicy = commonSpec.ImagePullPolicy + } } return &v1.JaegerCommonSpec{ - Annotations: annotations, - Labels: labels, - VolumeMounts: RemoveDuplicatedVolumeMounts(volumeMounts), - Volumes: RemoveDuplicatedVolumes(volumes), - Resources: *resources, - Affinity: affinity, - Tolerations: tolerations, - SecurityContext: securityContext, - ServiceAccount: serviceAccount, + Annotations: annotations, + Labels: labels, + VolumeMounts: RemoveDuplicatedVolumeMounts(volumeMounts), + Volumes: RemoveDuplicatedVolumes(volumes), + Resources: *resources, + Affinity: affinity, + Tolerations: tolerations, + SecurityContext: securityContext, + ServiceAccount: serviceAccount, + ImagePullSecrets: imagePullSecrets, + ImagePullPolicy: imagePullPolicy, } } diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go index e03c789d8..93265eace 100644 --- a/pkg/util/util_test.go +++ b/pkg/util/util_test.go @@ -569,3 +569,76 @@ func TestReplaceArgument(t *testing.T) { } } + +func TestImagePullPolicyAndSecrets(t *testing.T) { + generalSpec := v1.JaegerCommonSpec{ + ImagePullPolicy: corev1.PullAlways, + ImagePullSecrets: []corev1.LocalObjectReference{ + { + Name: "secret-1", + }, + { + Name: "secret-2", + }, + }, + } + + specificSpec := v1.JaegerCommonSpec{ + ImagePullPolicy: corev1.PullNever, + ImagePullSecrets: []corev1.LocalObjectReference{ + { + Name: "secret-3", + }, + { + Name: "secret-2", + }, + }, + } + + expectedSpec := v1.JaegerCommonSpec{ + ImagePullPolicy: corev1.PullNever, + ImagePullSecrets: []corev1.LocalObjectReference{ + { + Name: "secret-3", + }, + { + Name: "secret-2", + }, + { + Name: "secret-1", + }, + }, + } + + merged := Merge([]v1.JaegerCommonSpec{specificSpec, generalSpec}) + + assert.Equal(t, expectedSpec.ImagePullPolicy, merged.ImagePullPolicy) + assert.Equal(t, expectedSpec.ImagePullSecrets, merged.ImagePullSecrets) +} + +func TestEmptyImagePullPolicy(t *testing.T) { + generalSpec := v1.JaegerCommonSpec{ + ImagePullSecrets: []corev1.LocalObjectReference{ + { + Name: "secret-1", + }, + { + Name: "secret-2", + }, + }, + } + + specificSpec := v1.JaegerCommonSpec{ + ImagePullSecrets: []corev1.LocalObjectReference{ + { + Name: "secret-3", + }, + { + Name: "secret-2", + }, + }, + } + + merged := Merge([]v1.JaegerCommonSpec{specificSpec, generalSpec}) + assert.Equal(t, corev1.PullPolicy(""), merged.ImagePullPolicy) +}