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

Add support for imagePullSecrets to sidecar's Deployment #1115

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions deploy/crds/jaegertracing.io_jaegers_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,13 @@ spec:
type: object
image:
type: string
imagePullSecrets:
items:
properties:
name:
type: string
type: object
type: array
labels:
additionalProperties:
type: string
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/jaegertracing/v1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ type JaegerAgentSpec struct {
// +optional
Image string `json:"image,omitempty"`

// +optional
// +listType=set
ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"`

// +optional
Options Options `json:"options,omitempty"`

Expand Down
5 changes: 5 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.

19 changes: 18 additions & 1 deletion pkg/apis/jaegertracing/v1/zz_generated.openapi.go

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

1 change: 1 addition & 0 deletions pkg/inject/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func container(jaeger *v1.Jaeger, dep *appsv1.Deployment) corev1.Container {
// 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.Volumes = util.RemoveDuplicatedVolumes(append(dep.Spec.Template.Spec.Volumes, volumesAndMountsSpec.Volumes...))
return corev1.Container{
Image: util.ImageName(jaeger.Spec.Agent.Image, "jaeger-agent-image"),
Expand Down
16 changes: 16 additions & 0 deletions pkg/inject/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,22 @@ func TestInjectSidecarWithVolumeMounts(t *testing.T) {
assert.NotContains(t, dep.Spec.Template.Spec.Containers[1].VolumeMounts, commonVolumeMount)
}

func TestSidecarImagePullSecrets(t *testing.T) {

agentImagePullSecrets := []corev1.LocalObjectReference{{
Name: "agentImagePullSecret",
}}

jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestSidecarImagePullSecrets"})
jaeger.Spec.Agent.ImagePullSecrets = agentImagePullSecrets

dep := dep(map[string]string{}, map[string]string{})
dep = Sidecar(jaeger, dep)

assert.Len(t, dep.Spec.Template.Spec.ImagePullSecrets, 1)
assert.Equal(t, dep.Spec.Template.Spec.ImagePullSecrets[0].Name, "agentImagePullSecret")
}

func TestSidecarDefaultPorts(t *testing.T) {
// prepare
jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestSidecarPorts"})
Expand Down
16 changes: 16 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ func removeDuplicatedVolumeMounts(volumeMounts []corev1.VolumeMount) []corev1.Vo
return results
}

// RemoveDuplicatedImagePullSecrets returns a unique list of ImagePullSecrets based on ImagePullSecrets names. Only the first item is kept.
func RemoveDuplicatedImagePullSecrets(imagePullSecrets []corev1.LocalObjectReference) []corev1.LocalObjectReference {
var results []corev1.LocalObjectReference
existing := map[string]bool{}

for _, imagePullSecret := range imagePullSecrets {
if existing[imagePullSecret.Name] {
continue
}
results = append(results, imagePullSecret)
existing[imagePullSecret.Name] = true
}
// Return the new slice
return results
}

// Merge returns a merged version of the list of JaegerCommonSpec instances with most specific first
func Merge(commonSpecs []v1.JaegerCommonSpec) *v1.JaegerCommonSpec {
annotations := make(map[string]string)
Expand Down
14 changes: 14 additions & 0 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ func TestRemoveDuplicatedVolumeMounts(t *testing.T) {
assert.Equal(t, "data2", volumeMounts[1].Name)
}

func TestRemoveDuplicatedImagePullSecrets(t *testing.T) {
imagePullSecrets := []corev1.LocalObjectReference{{
Name: "secret1",
}, {
Name: "secret2",
}, {
Name: "secret1",
}}

assert.Len(t, RemoveDuplicatedImagePullSecrets(imagePullSecrets), 2)
assert.Equal(t, "secret1", imagePullSecrets[0].Name)
assert.Equal(t, "secret2", imagePullSecrets[1].Name)
}

func TestMergeAnnotations(t *testing.T) {
generalSpec := v1.JaegerCommonSpec{
Annotations: map[string]string{
Expand Down