Skip to content

Commit

Permalink
fix(s3): support non mandatory key file
Browse files Browse the repository at this point in the history
  • Loading branch information
JBOClara committed Dec 6, 2023
1 parent acde850 commit 04b110e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
7 changes: 7 additions & 0 deletions controllers/k8ssandra/medusa_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,23 @@ func (r *K8ssandraClusterReconciler) reconcileMedusa(

// Create required volumes for the Medusa containers
volumes := medusa.GenerateMedusaVolumes(dcConfig, medusaSpec, kc.SanitizedName())
logger.Info("Starting to create volumes for Medusa containers")
for _, volume := range volumes {
logger.Info("Created volume for Medusa container", "volume", volume.Volume.Name)
cassandra.AddOrUpdateVolume(dcConfig, volume.Volume, volume.VolumeIndex, volume.Exists)
}
logger.Info("Finished creating volumes for Medusa containers")

// Create the Medusa standalone pod
desiredMedusaStandalone := medusa.StandaloneMedusaDeployment(*medusaContainer, kc.SanitizedName(), dcConfig.SanitizedName(), namespace, logger)

// Add the volumes previously computed to the Medusa standalone pod
logger.Info("Starting to add volumes to the Medusa standalone pod")
for _, volume := range volumes {
logger.Info("Adding volume to the Medusa standalone pod", "volume", volume.Volume.Name)
cassandra.AddOrUpdateVolumeToSpec(&desiredMedusaStandalone.Spec.Template, volume.Volume, volume.VolumeIndex, volume.Exists)
}
logger.Info("Finished adding volumes to the Medusa standalone pod")

if !kc.Spec.UseExternalSecrets() {
cassandraUserSecretName := medusa.CassandraUserSecretName(medusaSpec, kc.SanitizedName())
Expand All @@ -86,6 +92,7 @@ func (r *K8ssandraClusterReconciler) reconcileMedusa(
// Reconcile the Medusa standalone deployment
kcKey := utils.GetKey(kc)
desiredMedusaStandalone.SetLabels(labels.CleanedUpByLabels(kcKey))
logger.Info("Desired Medusa standalone deployment", "deployment", desiredMedusaStandalone)
recRes := reconciliation.ReconcileObject(ctx, remoteClient, r.DefaultDelay, *desiredMedusaStandalone)
switch {
case recRes.IsError():
Expand Down
39 changes: 22 additions & 17 deletions pkg/medusa/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func CreateMedusaIni(kc *k8ss.K8ssandraCluster) string {
use_sudo_for_restore = false
storage_provider = {{ .Spec.Medusa.StorageProperties.StorageProvider }}
bucket_name = {{ .Spec.Medusa.StorageProperties.BucketName }}
{{- if .Spec.Medusa.StorageProperties.StorageSecretRef }}
{{- if .Spec.Medusa.StorageProperties.StorageSecretRef.Name }}
key_file = /etc/medusa-secrets/credentials
{{- end }}
{{- if .Spec.Medusa.StorageProperties.Prefix }}
Expand Down Expand Up @@ -163,7 +163,7 @@ func UpdateMedusaInitContainer(dcConfig *cassandra.DatacenterConfig, medusaSpec
setImage(medusaSpec.ContainerImage, restoreContainer)
restoreContainer.SecurityContext = medusaSpec.SecurityContext
restoreContainer.Env = medusaEnvVars(medusaSpec, k8cName, useExternalSecrets, "RESTORE")
restoreContainer.VolumeMounts = medusaVolumeMounts(medusaSpec, k8cName)
restoreContainer.VolumeMounts = medusaVolumeMounts(medusaSpec, k8cName, logger)
restoreContainer.Resources = medusaInitContainerResources(medusaSpec)

if !found {
Expand Down Expand Up @@ -223,7 +223,7 @@ func CreateMedusaMainContainer(dcConfig *cassandra.DatacenterConfig, medusaSpec

medusaContainer.ReadinessProbe = readinessProbe
medusaContainer.LivenessProbe = livenessProbe
medusaContainer.VolumeMounts = medusaVolumeMounts(medusaSpec, k8cName)
medusaContainer.VolumeMounts = medusaVolumeMounts(medusaSpec, k8cName, logger)
medusaContainer.Resources = medusaMainContainerResources(medusaSpec)
return medusaContainer, nil
}
Expand Down Expand Up @@ -257,7 +257,7 @@ func setImage(containerImage *images.Image, container *corev1.Container) {
container.ImagePullPolicy = image.PullPolicy
}

func medusaVolumeMounts(medusaSpec *api.MedusaClusterTemplate, k8cName string) []corev1.VolumeMount {
func medusaVolumeMounts(medusaSpec *api.MedusaClusterTemplate, k8cName string, logger logr.Logger) []corev1.VolumeMount {
volumeMounts := []corev1.VolumeMount{
{ // Cassandra config volume
Name: "server-config",
Expand Down Expand Up @@ -287,10 +287,13 @@ func medusaVolumeMounts(medusaSpec *api.MedusaClusterTemplate, k8cName string) [

// Mount secret with Medusa storage backend credentials if the secret ref is provided.
if medusaSpec.StorageProperties.StorageSecretRef.Name != "" {
logger.Info("Info: Mounting secret with Medusa storage backend credentials")
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: medusaSpec.StorageProperties.StorageSecretRef.Name,
MountPath: "/etc/medusa-secrets",
})
} else {
logger.Info("Info: No secret with Medusa storage backend credentials provided")
}

Check warning on line 297 in pkg/medusa/reconcile.go

View check run for this annotation

Codecov / codecov/patch

pkg/medusa/reconcile.go#L296-L297

Added lines #L296 - L297 were not covered by tests

return volumeMounts
Expand Down Expand Up @@ -377,21 +380,23 @@ func GenerateMedusaVolumes(dcConfig *cassandra.DatacenterConfig, medusaSpec *api
})

// Medusa credentials volume using the referenced secret
secretVolumeIndex, found := cassandra.FindVolume(&dcConfig.PodTemplateSpec, medusaSpec.StorageProperties.StorageSecretRef.Name)
secretVolume := &corev1.Volume{
Name: medusaSpec.StorageProperties.StorageSecretRef.Name,
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: medusaSpec.StorageProperties.StorageSecretRef.Name,
if medusaSpec.StorageProperties.StorageSecretRef.Name != "" {
secretVolumeIndex, found := cassandra.FindVolume(&dcConfig.PodTemplateSpec, medusaSpec.StorageProperties.StorageSecretRef.Name)
secretVolume := &corev1.Volume{
Name: medusaSpec.StorageProperties.StorageSecretRef.Name,
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: medusaSpec.StorageProperties.StorageSecretRef.Name,
},

Check warning on line 390 in pkg/medusa/reconcile.go

View check run for this annotation

Codecov / codecov/patch

pkg/medusa/reconcile.go#L383-L390

Added lines #L383 - L390 were not covered by tests
},
},
}
}

Check warning on line 392 in pkg/medusa/reconcile.go

View check run for this annotation

Codecov / codecov/patch

pkg/medusa/reconcile.go#L392

Added line #L392 was not covered by tests

newVolumes = append(newVolumes, medusaVolume{
Volume: secretVolume,
VolumeIndex: secretVolumeIndex,
Exists: found,
})
newVolumes = append(newVolumes, medusaVolume{
Volume: secretVolume,
VolumeIndex: secretVolumeIndex,
Exists: found,
})
}

Check warning on line 399 in pkg/medusa/reconcile.go

View check run for this annotation

Codecov / codecov/patch

pkg/medusa/reconcile.go#L394-L399

Added lines #L394 - L399 were not covered by tests

// Pod info volume
podInfoVolumeIndex, found := cassandra.FindVolume(&dcConfig.PodTemplateSpec, "podinfo")
Expand Down

0 comments on commit 04b110e

Please sign in to comment.