Skip to content

Commit

Permalink
Added ImagePullPolicy to JaegerCommonSpec, it is handled within the C…
Browse files Browse the repository at this point in the history
…ommonSpec Merge function and then simply added to the containers created by the Jaeger Custom Resource

Signed-off-by: edenkoveshi <[email protected]>
  • Loading branch information
edenkoveshi committed Feb 26, 2022
1 parent 50fa9e9 commit 8278d9f
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 6 deletions.
3 changes: 3 additions & 0 deletions apis/v1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pkg/deployment/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions pkg/deployment/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion pkg/deployment/all_in_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,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),
Expand Down
11 changes: 11 additions & 0 deletions pkg/deployment/all_in_one_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,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"

Expand Down
3 changes: 2 additions & 1 deletion pkg/deployment/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions pkg/deployment/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 2 additions & 1 deletion pkg/deployment/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 11 additions & 0 deletions pkg/deployment/ingester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 2 additions & 1 deletion pkg/deployment/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ func (q *Query) Get() *appsv1.Deployment {
},
InitialDelaySeconds: 1,
},
Resources: commonSpec.Resources,
Resources: commonSpec.Resources,
ImagePullPolicy: commonSpec.ImagePullPolicy,
}},
PriorityClassName: priorityClassName,
Volumes: commonSpec.Volumes,
Expand Down
11 changes: 11 additions & 0 deletions pkg/deployment/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}))
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand All @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 8278d9f

Please sign in to comment.