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

Use a single image for the container and the init-container of Reaper #1287

Merged
merged 1 commit into from
Apr 17, 2024
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
3 changes: 2 additions & 1 deletion CHANGELOG/CHANGELOG-1.15.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ When cutting a new release, update the `unreleased` heading to the tag being gen
* [BUGFIX] [#1266](https://github.com/k8ssandra/k8ssandra-operator/issues/1266) MedusaConfigurations must now be namespace local to the K8ssandraCluster they are attached to, a webhook error will be thrown otherwise (for new clusters only). Additionally, ReplicatedSecrets should only pick up secrets from their local namespace to replicate.
* [BUGFIX] [#1217](https://github.com/k8ssandra/k8ssandra-operator/issues/1217) Medusa storage secrets now use a ReplicatedSecret for synchronization, fixing an issue where changes to the secrets were not propagating. Additionally, fix a number of issues with local testing on ARM Macs.
* [BUGFIX] [#1253](https://github.com/k8ssandra/k8ssandra-operator/issues/1253) Medusa storage secrets are now labelled with a unique label.
* [FEATURE] [#1260](https://github.com/k8ssandra/k8ssandra-operator/issues/1260) Update controller-gen to version 0.14.0.
* [FEATURE] [#1260](https://github.com/k8ssandra/k8ssandra-operator/issues/1260) Update controller-gen to version 0.14.0.
* [BUGFIX] [1287](https://github.com/k8ssandra/k8ssandra-operator/pull/1287) Use the same image for Reaper init and main containers
7 changes: 3 additions & 4 deletions controllers/reaper/reaper_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,9 @@ func testCreateReaper(t *testing.T, ctx context.Context, k8sClient client.Client
assert.Len(t, deployment.OwnerReferences, 1, "deployment owner reference not set")
assert.Equal(t, rpr.UID, deployment.OwnerReferences[0].UID, "deployment owner reference has wrong uid")

// init container should be a default image and thus should not contain the latest tag; pull policy should be the
// default one (IfNotPresent)
assert.Equal(t, "docker.io/thelastpickle/cassandra-reaper:"+reaper.DefaultVersion, deployment.Spec.Template.Spec.InitContainers[0].Image)
assert.Equal(t, corev1.PullIfNotPresent, deployment.Spec.Template.Spec.InitContainers[0].ImagePullPolicy)
// init container should use the same image and tag as the main container.
assert.Equal(t, deployment.Spec.Template.Spec.Containers[0].Image, deployment.Spec.Template.Spec.InitContainers[0].Image)
assert.Equal(t, deployment.Spec.Template.Spec.Containers[0].ImagePullPolicy, deployment.Spec.Template.Spec.InitContainers[0].ImagePullPolicy)

// main container is a custom image where the tag isn't specified, so it should default to latest, and pull policy
// to Always.
Expand Down
19 changes: 7 additions & 12 deletions pkg/reaper/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ func NewDeployment(reaper *api.Reaper, dc *cassdcapi.CassandraDatacenter, keysto
})
}

initImage := reaper.Spec.InitContainerImage.ApplyDefaults(defaultImage)
mainImage := reaper.Spec.ContainerImage.ApplyDefaults(defaultImage)

initContainerResources := computeInitContainerResources(reaper.Spec.InitContainerResources)
Expand All @@ -236,7 +235,7 @@ func NewDeployment(reaper *api.Reaper, dc *cassdcapi.CassandraDatacenter, keysto
},
Spec: corev1.PodSpec{
Affinity: reaper.Spec.Affinity,
InitContainers: computeInitContainers(reaper, initImage, envVars, volumeMounts, initContainerResources),
InitContainers: computeInitContainers(reaper, mainImage, envVars, volumeMounts, initContainerResources),
Containers: []corev1.Container{
{
Name: "reaper",
Expand Down Expand Up @@ -265,7 +264,7 @@ func NewDeployment(reaper *api.Reaper, dc *cassdcapi.CassandraDatacenter, keysto
ServiceAccountName: reaper.Spec.ServiceAccountName,
Tolerations: reaper.Spec.Tolerations,
SecurityContext: reaper.Spec.PodSecurityContext,
ImagePullSecrets: computeImagePullSecrets(reaper, mainImage, initImage),
ImagePullSecrets: computeImagePullSecrets(reaper, mainImage),
Volumes: volumes,
},
},
Expand Down Expand Up @@ -311,7 +310,7 @@ func computeMainContainerResources(resourceRequirements *corev1.ResourceRequirem

func computeInitContainers(
reaper *api.Reaper,
initImage *images.Image,
mainImage *images.Image,
envVars []corev1.EnvVar,
volumeMounts []corev1.VolumeMount,
resourceRequirements *corev1.ResourceRequirements) []corev1.Container {
Expand All @@ -320,8 +319,8 @@ func computeInitContainers(
initContainers = append(initContainers,
corev1.Container{
Name: "reaper-schema-init",
Image: initImage.String(),
ImagePullPolicy: initImage.PullPolicy,
Image: mainImage.String(),
ImagePullPolicy: mainImage.PullPolicy,
SecurityContext: reaper.Spec.InitContainerSecurityContext,
Env: envVars,
Args: []string{"schema-migration"},
Expand All @@ -332,12 +331,8 @@ func computeInitContainers(
return initContainers
}

func computeImagePullSecrets(reaper *api.Reaper, mainImage, initImage *images.Image) []corev1.LocalObjectReference {
if reaper.Spec.SkipSchemaMigration {
return images.CollectPullSecrets(mainImage)
} else {
return images.CollectPullSecrets(mainImage, initImage)
}
func computeImagePullSecrets(reaper *api.Reaper, mainImage *images.Image) []corev1.LocalObjectReference {
return images.CollectPullSecrets(mainImage)
}

func computeProbe(probeTemplate *corev1.Probe) *corev1.Probe {
Expand Down
Loading