Repository: k8ssandra/k8ssandra-operator
Pull request #784 (2022-11-29 14:22:25)

Simplify pod template spec handling
<!--  Thanks for sending a pull request!  Before submitting:

1. Read our CONTRIBUTING.md guide
2. Rebase your PR if it gets out of sync with main
-->

**What this PR does**:

Simplifies handling of pod template spec.

**Which issue(s) this PR fixes**:
None, and that's fine.

**Checklist**
- [ ] Changes manually tested
- [ ] Automated Tests added/updated
- [ ] Documentation added/updated
- [ ] CHANGELOG.md updated (not required for documentation PRs)
- [ ] CLA Signed:  [DataStax CLA](https://cla.datastax.com/)


github-actions[bot]: No linked issues found. Please add the corresponding issues in the pull request description. <br/> [Use GitHub automation to close the issue when a PR is merged](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) <!-- metadata = {"action":"linked_issue"} -->

Patch:
diff --git a/controllers/k8ssandra/dcconfigs.go b/controllers/k8ssandra/dcconfigs.go
index 7ce4436a..a6d85716 100644
--- a/controllers/k8ssandra/dcconfigs.go
+++ b/controllers/k8ssandra/dcconfigs.go
@@ -48,7 +48,7 @@ func (r *K8ssandraClusterReconciler) createDatacenterConfigs(
 			return nil, err
 		}
 
-		_ = cassandra.ApplyAuth(dcConfig, kc.Spec.IsAuthEnabled(), kc.Spec.UseExternalSecrets())
+		cassandra.ApplyAuth(dcConfig, kc.Spec.IsAuthEnabled(), kc.Spec.UseExternalSecrets())
 
 		// This is only really required when auth is enabled, but it doesn't hurt to apply system replication on
 		// unauthenticated clusters.
@@ -72,9 +72,7 @@ func (r *K8ssandraClusterReconciler) createDatacenterConfigs(
 		}
 
 		// Inject MCAC metrics filters
-		if err = telemetry.InjectCassandraTelemetryFilters(kc.Spec.Cassandra.Telemetry, dcConfig); err != nil {
-			return nil, err
-		}
+		telemetry.InjectCassandraTelemetryFilters(kc.Spec.Cassandra.Telemetry, dcConfig)
 
 		cassandra.AddNumTokens(dcConfig)
 		cassandra.AddStartRpc(dcConfig)
diff --git a/controllers/k8ssandra/medusa_reconciler.go b/controllers/k8ssandra/medusa_reconciler.go
index b1011870..1035ceb0 100644
--- a/controllers/k8ssandra/medusa_reconciler.go
+++ b/controllers/k8ssandra/medusa_reconciler.go
@@ -30,14 +30,6 @@ func (r *K8ssandraClusterReconciler) reconcileMedusa(
 	medusaSpec := kc.Spec.Medusa
 	if medusaSpec != nil {
 		logger.Info("Medusa is enabled")
-		if dcConfig.PodTemplateSpec == nil {
-			dcConfig.PodTemplateSpec = &corev1.PodTemplateSpec{
-				Spec: corev1.PodSpec{
-					Containers:     []corev1.Container{},
-					InitContainers: []corev1.Container{},
-				},
-			}
-		}
 
 		// Check that certificates are provided if client encryption is enabled
 		if cassandra.ClientEncryptionEnabled(dcConfig) {
@@ -56,7 +48,7 @@ func (r *K8ssandraClusterReconciler) reconcileMedusa(
 
 		medusa.UpdateMedusaInitContainer(dcConfig, medusaSpec, kc.Spec.UseExternalSecrets(), kc.SanitizedName(), logger)
 		medusa.UpdateMedusaMainContainer(dcConfig, medusaSpec, kc.Spec.UseExternalSecrets(), kc.SanitizedName(), logger)
-		medusa.UpdateMedusaVolumes(dcConfig, medusaSpec, kc.SanitizedName(), logger)
+		medusa.UpdateMedusaVolumes(dcConfig, medusaSpec, kc.SanitizedName())
 		if !kc.Spec.UseExternalSecrets() {
 			cassandra.AddCqlUser(medusaSpec.CassandraUserSecretRef, dcConfig, medusa.CassandraUserSecretName(medusaSpec, kc.SanitizedName()))
 		}
diff --git a/controllers/k8ssandra/per_node_config.go b/controllers/k8ssandra/per_node_config.go
index 0bee1d1c..3615bcd2 100644
--- a/controllers/k8ssandra/per_node_config.go
+++ b/controllers/k8ssandra/per_node_config.go
@@ -114,7 +114,7 @@ func (r *K8ssandraClusterReconciler) reconcileDefaultPerNodeConfiguration(
 	if desiredPerNodeConfig != nil {
 		dcConfig.PerNodeConfigMapRef.Name = desiredPerNodeConfig.Name
 		perNodeConfigMapHash := annotations.GetAnnotation(desiredPerNodeConfig, k8ssandraapi.ResourceHashAnnotation)
-		annotations.AddAnnotation(dcConfig.PodTemplateSpec, k8ssandraapi.PerNodeConfigHashAnnotation, perNodeConfigMapHash)
+		annotations.AddAnnotation(&dcConfig.PodTemplateSpec, k8ssandraapi.PerNodeConfigHashAnnotation, perNodeConfigMapHash)
 		nodeconfig.MountPerNodeConfig(dcConfig)
 		dcLogger.Info("Mounted per-node configuration")
 	}
@@ -160,7 +160,7 @@ func (r *K8ssandraClusterReconciler) reconcileUserProvidedPerNodeConfiguration(
 		// mount it as is. Also, we don't manage its full lifecycle.
 
 		perNodeConfigMapHash := utils.DeepHashString(actualPerNodeConfig)
-		annotations.AddAnnotation(dcConfig.PodTemplateSpec, k8ssandraapi.PerNodeConfigHashAnnotation, perNodeConfigMapHash)
+		annotations.AddAnnotation(&dcConfig.PodTemplateSpec, k8ssandraapi.PerNodeConfigHashAnnotation, perNodeConfigMapHash)
 		nodeconfig.MountPerNodeConfig(dcConfig)
 		dcLogger.Info("Mounted per-node configuration")
 
diff --git a/pkg/cassandra/auth.go b/pkg/cassandra/auth.go
index c776ad97..a30b9724 100644
--- a/pkg/cassandra/auth.go
+++ b/pkg/cassandra/auth.go
@@ -1,7 +1,6 @@
 package cassandra
 
 import (
-	"errors"
 	"fmt"
 
 	cassdcapi "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
@@ -10,11 +9,7 @@ import (
 )
 
 // ApplyAuth modifies the dc config depending on whether auth is enabled in the cluster or not.
-func ApplyAuth(dcConfig *DatacenterConfig, authEnabled bool, useExternalSecrets bool) error {
-
-	if dcConfig.PodTemplateSpec == nil {
-		return errors.New("PodTemplateSpec was nil, cannot add auth settings")
-	}
+func ApplyAuth(dcConfig *DatacenterConfig, authEnabled bool, useExternalSecrets bool) {
 
 	dcConfig.CassandraConfig = ApplyAuthSettings(dcConfig.CassandraConfig, authEnabled, dcConfig.ServerType)
 
@@ -38,7 +33,6 @@ func ApplyAuth(dcConfig *DatacenterConfig, authEnabled bool, useExternalSecrets
 		addOptionIfMissing(dcConfig, "-Djava.security.auth.login.config=$CASSANDRA_HOME/conf/cassandra-jaas.config")
 		addOptionIfMissing(dcConfig, "-Dcassandra.jmx.authorizer=org.apache.cassandra.auth.jmx.AuthorizationProxy")
 	}
-	return nil
 }
 
 // ApplyAuthSettings modifies the given config and applies defaults for authenticator, authorizer and role manager,
diff --git a/pkg/cassandra/datacenter.go b/pkg/cassandra/datacenter.go
index d820d074..a9aa8eb0 100644
--- a/pkg/cassandra/datacenter.go
+++ b/pkg/cassandra/datacenter.go
@@ -1,7 +1,6 @@
 package cassandra
 
 import (
-	"errors"
 	"fmt"
 
 	"github.com/Masterminds/semver/v3"
@@ -95,7 +94,7 @@ type DatacenterConfig struct {
 	AdditionalSeeds           []string
 	Networking                *cassdcapi.NetworkingConfig
 	Users                     []cassdcapi.CassandraUser
-	PodTemplateSpec           *corev1.PodTemplateSpec
+	PodTemplateSpec           corev1.PodTemplateSpec
 	MgmtAPIHeap               *resource.Quantity
 	SoftPodAntiAffinity       *bool
 	Tolerations               []corev1.Toleration
@@ -107,9 +106,8 @@ type DatacenterConfig struct {
 	ServerTruststorePassword  string
 	CDC                       *cassdcapi.CDCConfiguration
 	DseWorkloads              *cassdcapi.DseWorkloads
-	ConfigBuilderResources    *corev1.ResourceRequirements
-	ManagementApiAuth         *cassdcapi.ManagementApiAuthConfig
-	PerNodeConfigMapRef       corev1.LocalObjectReference
+	ManagementApiAuth        *cassdcapi.ManagementApiAuthConfig
+	PerNodeConfigMapRef      corev1.LocalObjectReference
 	PerNodeInitContainerImage string
 	ExternalSecrets           bool
 
@@ -165,7 +163,7 @@ func NewDatacenter(klusterKey types.NamespacedName, template *DatacenterConfig)
 			SuperuserSecretName: superUserSecretName,
 			Users:               template.Users,
 			Networking:          template.Networking,
-			PodTemplateSpec:     template.PodTemplateSpec,
+			PodTemplateSpec:     &template.PodTemplateSpec,
 			CDC:                 template.CDC,
 			DseWorkloads:        template.DseWorkloads,
 		},
@@ -183,8 +181,11 @@ func NewDatacenter(klusterKey types.NamespacedName, template *DatacenterConfig)
 		dc.Spec.AllowMultipleNodesPerWorker = *template.SoftPodAntiAffinity
 	}
 
-	if template.ConfigBuilderResources != nil {
-		dc.Spec.ConfigBuilderResources = *template.ConfigBuilderResources
+	if position, found := FindInitContainer(&template.PodTemplateSpec, reconciliation.ServerConfigContainerName); found {
+		configBuilderResources := template.PodTemplateSpec.Spec.InitContainers[position].Resources
+		if configBuilderResources.Limits != nil || configBuilderResources.Requests != nil {
+			dc.Spec.ConfigBuilderResources = configBuilderResources
+		}
 	}
 
 	if template.ManagementApiAuth != nil {
@@ -286,10 +287,6 @@ func Coalesce(clusterName string, clusterTemplate *api.CassandraClusterTemplate,
 	dcConfig.PerNodeConfigMapRef = dcTemplate.PerNodeConfigMapRef
 	dcConfig.CDC = dcTemplate.CDC
 
-	// Ensure we have a valid PodTemplateSpec before proceeding to modify it.
-	// FIXME if we are doing this, then we should remove the pointer
-	dcConfig.PodTemplateSpec = &corev1.PodTemplateSpec{}
-
 	mergedOptions := goalesceutils.MergeCRs(clusterTemplate.DatacenterOptions, dcTemplate.DatacenterOptions)
 
 	if len(mergedOptions.ServerVersion) > 0 {
@@ -313,11 +310,11 @@ func Coalesce(clusterName string, clusterTemplate *api.CassandraClusterTemplate,
 	dcConfig.PerNodeInitContainerImage = mergedOptions.PerNodeConfigInitContainerImage
 
 	if len(mergedOptions.Containers) > 0 {
-		_ = AddContainersToPodTemplateSpec(dcConfig, mergedOptions.Containers...)
+		AddContainersToPodTemplateSpec(dcConfig, mergedOptions.Containers...)
 	}
 
 	if len(mergedOptions.InitContainers) > 0 {
-		_ = AddInitContainersToPodTemplateSpec(dcConfig, mergedOptions.InitContainers...)
+		AddInitContainersToPodTemplateSpec(dcConfig, mergedOptions.InitContainers...)
 	}
 
 	if mergedOptions.ExtraVolumes != nil {
@@ -325,7 +322,7 @@ func Coalesce(clusterName string, clusterTemplate *api.CassandraClusterTemplate,
 	}
 
 	// we need to declare at least one container, otherwise the PodTemplateSpec struct will be invalid
-	UpdateCassandraContainer(dcConfig.PodTemplateSpec, func(c *corev1.Container) {})
+	UpdateCassandraContainer(&dcConfig.PodTemplateSpec, func(c *corev1.Container) {})
 
 	return dcConfig
 }
@@ -348,26 +345,12 @@ func ValidateDatacenterConfig(dcConfig *DatacenterConfig) error {
 	return nil
 }
 
-func AddContainersToPodTemplateSpec(dcConfig *DatacenterConfig, containers ...corev1.Container) error {
-	if dcConfig.PodTemplateSpec == nil {
-		return errors.New("PodTemplateSpec was nil, cannot add containers")
-	} else {
-		dcConfig.PodTemplateSpec.Spec.Containers = append(dcConfig.PodTemplateSpec.Spec.Containers, containers...)
-		return nil
-	}
+func AddContainersToPodTemplateSpec(dcConfig *DatacenterConfig, containers ...corev1.Container) {
+	dcConfig.PodTemplateSpec.Spec.Containers = append(dcConfig.PodTemplateSpec.Spec.Containers, containers...)
 }
 
-func AddInitContainersToPodTemplateSpec(dcConfig *DatacenterConfig, initContainers ...corev1.Container) error {
-	if dcConfig.PodTemplateSpec == nil {
-		return errors.New("PodTemplateSpec was nil, cannot add init containers")
-	} else {
-		dcConfig.PodTemplateSpec.Spec.InitContainers = append(dcConfig.PodTemplateSpec.Spec.InitContainers, initContainers...)
-		position, found := FindInitContainer(dcConfig.PodTemplateSpec, reconciliation.ServerConfigContainerName)
-		if found && (dcConfig.PodTemplateSpec.Spec.InitContainers[position].Resources.Limits != nil || dcConfig.PodTemplateSpec.Spec.InitContainers[position].Resources.Requests != nil) {
-			dcConfig.ConfigBuilderResources = &dcConfig.PodTemplateSpec.Spec.InitContainers[position].Resources
-		}
-		return nil
-	}
+func AddInitContainersToPodTemplateSpec(dcConfig *DatacenterConfig, initContainers ...corev1.Container) {
+	dcConfig.PodTemplateSpec.Spec.InitContainers = append(dcConfig.PodTemplateSpec.Spec.InitContainers, initContainers...)
 }
 
 func AddK8ssandraVolumesToPodTemplateSpec(dcConfig *DatacenterConfig, extraVolumes api.K8ssandraVolumes) {
@@ -389,26 +372,17 @@ func AddK8ssandraVolumesToPodTemplateSpec(dcConfig *DatacenterConfig, extraVolum
 }
 
 func AddVolumesToPodTemplateSpec(dcConfig *DatacenterConfig, volume corev1.Volume) {
-	if dcConfig.PodTemplateSpec == nil {
-		dcConfig.PodTemplateSpec = &corev1.PodTemplateSpec{
-			Spec: corev1.PodSpec{
-				Volumes: []corev1.Volume{volume},
-			},
-		}
-	} else {
-		dcConfig.PodTemplateSpec.Spec.Volumes = append(dcConfig.PodTemplateSpec.Spec.Volumes, volume)
-	}
+	dcConfig.PodTemplateSpec.Spec.Volumes = append(dcConfig.PodTemplateSpec.Spec.Volumes, volume)
 }
 
 func FindContainer(dcPodTemplateSpec *corev1.PodTemplateSpec, containerName string) (int, bool) {
-	if dcPodTemplateSpec != nil && dcPodTemplateSpec.Spec.Containers != nil {
+	if dcPodTemplateSpec != nil {
 		for i, container := range dcPodTemplateSpec.Spec.Containers {
 			if container.Name == containerName {
 				return i, true
 			}
 		}
 	}
-
 	return -1, false
 }
 
@@ -420,7 +394,6 @@ func FindInitContainer(dcPodTemplateSpec *corev1.PodTemplateSpec, containerName
 			}
 		}
 	}
-
 	return -1, false
 }
 
@@ -432,19 +405,15 @@ func FindVolume(dcPodTemplateSpec *corev1.PodTemplateSpec, volumeName string) (i
 			}
 		}
 	}
-
 	return -1, false
 }
 
 func FindAdditionalVolume(dcConfig *DatacenterConfig, volumeName string) (int, bool) {
-	if dcConfig.StorageConfig.AdditionalVolumes != nil {
-		for i, volume := range dcConfig.StorageConfig.AdditionalVolumes {
-			if volume.Name == volumeName {
-				return i, true
-			}
+	for i, volume := range dcConfig.StorageConfig.AdditionalVolumes {
+		if volume.Name == volumeName {
+			return i, true
 		}
 	}
-
 	return -1, false
 }
 
diff --git a/pkg/cassandra/encryption.go b/pkg/cassandra/encryption.go
index 235a1a18..fa7b66f5 100644
--- a/pkg/cassandra/encryption.go
+++ b/pkg/cassandra/encryption.go
@@ -72,7 +72,7 @@ func addVolumesForEncryption(template *DatacenterConfig, storeType encryption.St
 
 	for _, volume := range []*corev1.Volume{keystoreVolume, truststoreVolume} {
 		if volume != nil {
-			indexKey, foundKey := FindVolume(template.PodTemplateSpec, volume.Name)
+			indexKey, foundKey := FindVolume(&template.PodTemplateSpec, volume.Name)
 			AddOrUpdateVolume(template, volume, indexKey, foundKey)
 		}
 	}
@@ -125,7 +125,7 @@ func addEncryptionMountToCassandra(template *DatacenterConfig, keystoreVolume, t
 		Name: "cassandra",
 	}
 
-	cassandraContainerIdx, foundCassandra := FindContainer(template.PodTemplateSpec, "cassandra")
+	cassandraContainerIdx, foundCassandra := FindContainer(&template.PodTemplateSpec, "cassandra")
 	if foundCassandra {
 		cassandraContainer = template.PodTemplateSpec.Spec.Containers[cassandraContainerIdx].DeepCopy()
 	}
diff --git a/pkg/medusa/reconcile.go b/pkg/medusa/reconcile.go
index 67a0adc5..cd6322ac 100644
--- a/pkg/medusa/reconcile.go
+++ b/pkg/medusa/reconcile.go
@@ -12,7 +12,7 @@ import (
 	corev1 "k8s.io/api/core/v1"
 
 	"github.com/go-logr/logr"
-	cassandra "github.com/k8ssandra/k8ssandra-operator/pkg/cassandra"
+	"github.com/k8ssandra/k8ssandra-operator/pkg/cassandra"
 	"k8s.io/apimachinery/pkg/api/resource"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 )
@@ -132,7 +132,8 @@ func CreateMedusaConfigMap(namespace, k8cName, medusaIni string) *corev1.ConfigM
 	}
 }
 
-// Get the cassandra user secret name from the medusa spec or generate one based on the cluster name
+// CassandraUserSecretName gets the cassandra user secret name from the medusa spec or generate one
+// based on the cluster name.
 func CassandraUserSecretName(medusaSpec *api.MedusaClusterTemplate, k8cName string) string {
 	if medusaSpec.CassandraUserSecretRef.Name == "" {
 		return fmt.Sprintf("%s-medusa", k8cName)
@@ -141,7 +142,7 @@ func CassandraUserSecretName(medusaSpec *api.MedusaClusterTemplate, k8cName stri
 }
 
 func UpdateMedusaInitContainer(dcConfig *cassandra.DatacenterConfig, medusaSpec *api.MedusaClusterTemplate, useExternalSecrets bool, k8cName string, logger logr.Logger) {
-	restoreContainerIndex, found := cassandra.FindInitContainer(dcConfig.PodTemplateSpec, "medusa-restore")
+	restoreContainerIndex, found := cassandra.FindInitContainer(&dcConfig.PodTemplateSpec, "medusa-restore")
 	restoreContainer := &corev1.Container{Name: "medusa-restore"}
 	if found {
 		logger.Info("Found medusa-restore init container")
@@ -150,8 +151,8 @@ func UpdateMedusaInitContainer(dcConfig *cassandra.DatacenterConfig, medusaSpec
 	}
 	setImage(medusaSpec.ContainerImage, restoreContainer)
 	restoreContainer.SecurityContext = medusaSpec.SecurityContext
-	restoreContainer.Env = medusaEnvVars(medusaSpec, k8cName, useExternalSecrets, logger, "RESTORE")
-	restoreContainer.VolumeMounts = medusaVolumeMounts(medusaSpec, k8cName, logger)
+	restoreContainer.Env = medusaEnvVars(medusaSpec, k8cName, useExternalSecrets, "RESTORE")
+	restoreContainer.VolumeMounts = medusaVolumeMounts(medusaSpec, k8cName)
 	restoreContainer.Resources = medusaInitContainerResources(medusaSpec)
 
 	if !found {
@@ -159,7 +160,7 @@ func UpdateMedusaInitContainer(dcConfig *cassandra.DatacenterConfig, medusaSpec
 		// medusa-restore init container doesn't exist, we need to add it
 		// We'll add the server-config-init init container in first position so it initializes cassandra.yaml for Medusa to use, if it doesn't exist already.
 		// The definition of that container will be completed later by cass-operator.
-		_, serverConfigInitContainerFound := cassandra.FindInitContainer(dcConfig.PodTemplateSpec, "server-config-init")
+		_, serverConfigInitContainerFound := cassandra.FindInitContainer(&dcConfig.PodTemplateSpec, "server-config-init")
 		if !serverConfigInitContainerFound {
 			serverConfigContainer := &corev1.Container{Name: "server-config-init"}
 			dcConfig.PodTemplateSpec.Spec.InitContainers = append(dcConfig.PodTemplateSpec.Spec.InitContainers, *serverConfigContainer)
@@ -188,7 +189,7 @@ func medusaInitContainerResources(medusaSpec *api.MedusaClusterTemplate) corev1.
 }
 
 func UpdateMedusaMainContainer(dcConfig *cassandra.DatacenterConfig, medusaSpec *api.MedusaClusterTemplate, useExternalSecrets bool, k8cName string, logger logr.Logger) {
-	medusaContainerIndex, found := cassandra.FindContainer(dcConfig.PodTemplateSpec, "medusa")
+	medusaContainerIndex, found := cassandra.FindContainer(&dcConfig.PodTemplateSpec, "medusa")
 	medusaContainer := &corev1.Container{Name: "medusa"}
 	if found {
 		logger.Info("Found medusa container")
@@ -197,12 +198,12 @@ func UpdateMedusaMainContainer(dcConfig *cassandra.DatacenterConfig, medusaSpec
 	}
 	setImage(medusaSpec.ContainerImage, medusaContainer)
 	medusaContainer.SecurityContext = medusaSpec.SecurityContext
-	medusaContainer.Env = medusaEnvVars(medusaSpec, k8cName, useExternalSecrets, logger, "GRPC")
+	medusaContainer.Env = medusaEnvVars(medusaSpec, k8cName, useExternalSecrets, "GRPC")
 	medusaContainer.Ports = []corev1.ContainerPort{
 		{ContainerPort: 50051, Name: "grpc"},
 	}
 
-	medusaContainer.VolumeMounts = medusaVolumeMounts(medusaSpec, k8cName, logger)
+	medusaContainer.VolumeMounts = medusaVolumeMounts(medusaSpec, k8cName)
 	medusaContainer.Resources = medusaMainContainerResources(medusaSpec)
 
 	if !found {
@@ -238,7 +239,7 @@ func setImage(containerImage *images.Image, container *corev1.Container) {
 	container.ImagePullPolicy = image.PullPolicy
 }
 
-func medusaVolumeMounts(medusaSpec *api.MedusaClusterTemplate, k8cName string, logger logr.Logger) []corev1.VolumeMount {
+func medusaVolumeMounts(medusaSpec *api.MedusaClusterTemplate, k8cName string) []corev1.VolumeMount {
 	volumeMounts := []corev1.VolumeMount{
 		{ // Cassandra config volume
 			Name:      "server-config",
@@ -284,7 +285,7 @@ func medusaVolumeMounts(medusaSpec *api.MedusaClusterTemplate, k8cName string, l
 	return volumeMounts
 }
 
-func medusaEnvVars(medusaSpec *api.MedusaClusterTemplate, k8cName string, useExternalSecrets bool, logger logr.Logger, mode string) []corev1.EnvVar {
+func medusaEnvVars(medusaSpec *api.MedusaClusterTemplate, k8cName string, useExternalSecrets bool, mode string) []corev1.EnvVar {
 	envVars := []corev1.EnvVar{
 		{
 			Name:  "MEDUSA_MODE",
@@ -329,9 +330,9 @@ func medusaEnvVars(medusaSpec *api.MedusaClusterTemplate, k8cName string, useExt
 }
 
 // Create or update volumes for medusa
-func UpdateMedusaVolumes(dcConfig *cassandra.DatacenterConfig, medusaSpec *api.MedusaClusterTemplate, k8cName string, logger logr.Logger) {
+func UpdateMedusaVolumes(dcConfig *cassandra.DatacenterConfig, medusaSpec *api.MedusaClusterTemplate, k8cName string) {
 	// Medusa config volume, containing medusa.ini
-	configVolumeIndex, found := cassandra.FindVolume(dcConfig.PodTemplateSpec, fmt.Sprintf("%s-medusa", k8cName))
+	configVolumeIndex, found := cassandra.FindVolume(&dcConfig.PodTemplateSpec, fmt.Sprintf("%s-medusa", k8cName))
 	configVolume := &corev1.Volume{
 		Name: fmt.Sprintf("%s-medusa", k8cName),
 		VolumeSource: corev1.VolumeSource{
@@ -348,7 +349,7 @@ func UpdateMedusaVolumes(dcConfig *cassandra.DatacenterConfig, medusaSpec *api.M
 	// Medusa credentials volume using the referenced secret
 	if medusaSpec.StorageProperties.StorageProvider != "local" {
 		// We're not using local storage for backups, which requires a secret with backend credentials
-		secretVolumeIndex, found := cassandra.FindVolume(dcConfig.PodTemplateSpec, 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{
@@ -361,7 +362,7 @@ func UpdateMedusaVolumes(dcConfig *cassandra.DatacenterConfig, medusaSpec *api.M
 		cassandra.AddOrUpdateVolume(dcConfig, secretVolume, secretVolumeIndex, found)
 	} else {
 		// We're using local storage for backups, which requires a volume for the local backup storage
-		backupVolumeIndex, found := cassandra.FindVolume(dcConfig.PodTemplateSpec, "medusa-backups")
+		backupVolumeIndex, found := cassandra.FindVolume(&dcConfig.PodTemplateSpec, "medusa-backups")
 		accessModes := []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
 		storageClassName := "standard"
 		storageSize := resource.MustParse("10Gi")
@@ -395,7 +396,7 @@ func UpdateMedusaVolumes(dcConfig *cassandra.DatacenterConfig, medusaSpec *api.M
 	}
 
 	// Pod info volume
-	podInfoVolumeIndex, found := cassandra.FindVolume(dcConfig.PodTemplateSpec, "podinfo")
+	podInfoVolumeIndex, found := cassandra.FindVolume(&dcConfig.PodTemplateSpec, "podinfo")
 	podInfoVolume := &corev1.Volume{
 		Name: "podinfo",
 		VolumeSource: corev1.VolumeSource{
@@ -416,7 +417,7 @@ func UpdateMedusaVolumes(dcConfig *cassandra.DatacenterConfig, medusaSpec *api.M
 
 	// Encryption client certificates
 	if medusaSpec.CertificatesSecretRef.Name != "" {
-		encryptionClientVolumeIndex, found := cassandra.FindVolume(dcConfig.PodTemplateSpec, "certificates")
+		encryptionClientVolumeIndex, found := cassandra.FindVolume(&dcConfig.PodTemplateSpec, "certificates")
 		encryptionClientVolume := &corev1.Volume{
 			Name: "certificates",
 			VolumeSource: corev1.VolumeSource{
diff --git a/pkg/nodeconfig/mount.go b/pkg/nodeconfig/mount.go
index 2eb51446..a9841e1c 100644
--- a/pkg/nodeconfig/mount.go
+++ b/pkg/nodeconfig/mount.go
@@ -17,9 +17,9 @@ const (
 // should only be called for DCs having a per-node ConfigMap reference.
 func MountPerNodeConfig(dcConfig *cassandra.DatacenterConfig) {
 	// if the config-builder init container isn't found, declare a placeholder now to guarantee order of execution
-	cassandra.UpdateInitContainer(dcConfig.PodTemplateSpec, reconciliation.ServerConfigContainerName, func(container *v1.Container) {})
+	cassandra.UpdateInitContainer(&dcConfig.PodTemplateSpec, reconciliation.ServerConfigContainerName, func(container *v1.Container) {})
 	// add per-node-config init container
-	_ = cassandra.AddInitContainersToPodTemplateSpec(dcConfig, newPerNodeConfigInitContainer(dcConfig.PerNodeInitContainerImage))
+	cassandra.AddInitContainersToPodTemplateSpec(dcConfig, newPerNodeConfigInitContainer(dcConfig.PerNodeInitContainerImage))
 	// add per-node config volume to pod spec
 	cassandra.AddVolumesToPodTemplateSpec(dcConfig, newPerNodeConfigVolume(dcConfig.PerNodeConfigMapRef.Name))
 }
diff --git a/pkg/reaper/datacenter.go b/pkg/reaper/datacenter.go
index 1bd7e549..c99bd4e1 100644
--- a/pkg/reaper/datacenter.go
+++ b/pkg/reaper/datacenter.go
@@ -7,9 +7,6 @@ import (
 )
 
 func AddReaperSettingsToDcConfig(reaperTemplate *reaperapi.ReaperClusterTemplate, dcConfig *cassandra.DatacenterConfig, authEnabled bool) {
-	if dcConfig.PodTemplateSpec == nil {
-		dcConfig.PodTemplateSpec = &corev1.PodTemplateSpec{}
-	}
 	enableRemoteJmxAccess(dcConfig)
 	if authEnabled && !dcConfig.ExternalSecrets {
 		cassandra.AddCqlUser(reaperTemplate.CassandraUserSecretRef, dcConfig, DefaultUserSecretName(dcConfig.Cluster))
@@ -21,7 +18,7 @@ func AddReaperSettingsToDcConfig(reaperTemplate *reaperapi.ReaperClusterTemplate
 // need to change that to LOCAL_JMX=no here. Note that this change has implications on authentication that were handled
 // already in pkg/cassandra/auth.go.
 func enableRemoteJmxAccess(dcConfig *cassandra.DatacenterConfig) {
-	cassandra.UpdateCassandraContainer(dcConfig.PodTemplateSpec, func(c *corev1.Container) {
+	cassandra.UpdateCassandraContainer(&dcConfig.PodTemplateSpec, func(c *corev1.Container) {
 		c.Env = append(c.Env, corev1.EnvVar{Name: "LOCAL_JMX", Value: "no"})
 	})
 }
diff --git a/pkg/telemetry/cassandra_metrics_filters.go b/pkg/telemetry/cassandra_metrics_filters.go
index 8c78879e..9b3e8f10 100644
--- a/pkg/telemetry/cassandra_metrics_filters.go
+++ b/pkg/telemetry/cassandra_metrics_filters.go
@@ -1,7 +1,6 @@
 package telemetry
 
 import (
-	"errors"
 	"strings"
 
 	telemetry "github.com/k8ssandra/k8ssandra-operator/apis/telemetry/v1alpha1"
@@ -28,7 +27,7 @@ var (
 
 // InjectCassandraTelemetryFilters adds MCAC filters to the cassandra container as an env variable.
 // If filter list is set to nil, the default filters are used, otherwise the provided filters are used.
-func InjectCassandraTelemetryFilters(telemetrySpec *telemetry.TelemetrySpec, dcConfig *cassandra.DatacenterConfig) error {
+func InjectCassandraTelemetryFilters(telemetrySpec *telemetry.TelemetrySpec, dcConfig *cassandra.DatacenterConfig) {
 	filtersEnvVar := v1.EnvVar{}
 	if telemetrySpec == nil || telemetrySpec.Mcac == nil || telemetrySpec.Mcac.MetricFilters == nil {
 		// Default filters are applied
@@ -37,11 +36,7 @@ func InjectCassandraTelemetryFilters(telemetrySpec *telemetry.TelemetrySpec, dcC
 		// Custom filters are applied
 		filtersEnvVar = v1.EnvVar{Name: "METRIC_FILTERS", Value: strings.Join(*telemetrySpec.Mcac.MetricFilters, " ")}
 	}
-	if dcConfig.PodTemplateSpec == nil {
-		return errors.New("no PodTemplateSpec in dcConfig to inject telemetry filtering env vars into")
-	}
-	cassandra.UpdateCassandraContainer(dcConfig.PodTemplateSpec, func(container *v1.Container) {
+	cassandra.UpdateCassandraContainer(&dcConfig.PodTemplateSpec, func(container *v1.Container) {
 		container.Env = append(container.Env, filtersEnvVar)
 	})
-	return nil
 }


Test patch:
diff --git a/controllers/k8ssandra/per_node_config_test.go b/controllers/k8ssandra/per_node_config_test.go
index d20404a8..68fd5d8c 100644
--- a/controllers/k8ssandra/per_node_config_test.go
+++ b/controllers/k8ssandra/per_node_config_test.go
@@ -40,7 +40,6 @@ func TestK8ssandraClusterReconciler_reconcilePerNodeConfiguration(t *testing.T)
 					Meta: api.EmbeddedObjectMeta{
 						Name: "dc1",
 					},
-					PodTemplateSpec: &corev1.PodTemplateSpec{},
 				},
 				remoteClient: func() client.Client {
 					fakeClient, _ := test.NewFakeClient()
@@ -60,7 +59,6 @@ func TestK8ssandraClusterReconciler_reconcilePerNodeConfiguration(t *testing.T)
 					Meta: api.EmbeddedObjectMeta{
 						Name: "dc1",
 					},
-					PodTemplateSpec: &corev1.PodTemplateSpec{},
 					InitialTokensByPodName: map[string][]string{
 						"pod1": {"token1", "token2"},
 						"pod2": {"token3", "token4"},
@@ -74,11 +72,11 @@ func TestK8ssandraClusterReconciler_reconcilePerNodeConfiguration(t *testing.T)
 			wantResult: result.Continue(),
 			configAssert: func(t *testing.T, gotConfig *cassandra.DatacenterConfig) {
 				assert.Equal(t, "test-dc1-per-node-config", gotConfig.PerNodeConfigMapRef.Name)
-				hash := annotations.GetAnnotation(gotConfig.PodTemplateSpec, api.PerNodeConfigHashAnnotation)
+				hash := annotations.GetAnnotation(&gotConfig.PodTemplateSpec, api.PerNodeConfigHashAnnotation)
 				assert.NotEmpty(t, hash)
-				_, found := cassandra.FindInitContainer(gotConfig.PodTemplateSpec, nodeconfig.PerNodeConfigInitContainerName)
+				_, found := cassandra.FindInitContainer(&gotConfig.PodTemplateSpec, nodeconfig.PerNodeConfigInitContainerName)
 				assert.True(t, found)
-				_, found = cassandra.FindVolume(gotConfig.PodTemplateSpec, nodeconfig.PerNodeConfigVolumeName)
+				_, found = cassandra.FindVolume(&gotConfig.PodTemplateSpec, nodeconfig.PerNodeConfigVolumeName)
 				assert.True(t, found)
 			},
 		},
@@ -90,7 +88,6 @@ func TestK8ssandraClusterReconciler_reconcilePerNodeConfiguration(t *testing.T)
 						Name:      "dc1",
 						Namespace: "dc1-ns",
 					},
-					PodTemplateSpec: &corev1.PodTemplateSpec{},
 					PerNodeConfigMapRef: corev1.LocalObjectReference{
 						Name: "user-provided-per-node-config",
 					},
@@ -114,11 +111,11 @@ func TestK8ssandraClusterReconciler_reconcilePerNodeConfiguration(t *testing.T)
 			wantResult: result.Continue(),
 			configAssert: func(t *testing.T, gotConfig *cassandra.DatacenterConfig) {
 				assert.Equal(t, "user-provided-per-node-config", gotConfig.PerNodeConfigMapRef.Name)
-				hash := annotations.GetAnnotation(gotConfig.PodTemplateSpec, api.PerNodeConfigHashAnnotation)
+				hash := annotations.GetAnnotation(&gotConfig.PodTemplateSpec, api.PerNodeConfigHashAnnotation)
 				assert.NotEmpty(t, hash)
-				_, found := cassandra.FindInitContainer(gotConfig.PodTemplateSpec, nodeconfig.PerNodeConfigInitContainerName)
+				_, found := cassandra.FindInitContainer(&gotConfig.PodTemplateSpec, nodeconfig.PerNodeConfigInitContainerName)
 				assert.True(t, found)
-				_, found = cassandra.FindVolume(gotConfig.PodTemplateSpec, nodeconfig.PerNodeConfigVolumeName)
+				_, found = cassandra.FindVolume(&gotConfig.PodTemplateSpec, nodeconfig.PerNodeConfigVolumeName)
 				assert.True(t, found)
 			},
 		},
diff --git a/pkg/cassandra/datacenter_test.go b/pkg/cassandra/datacenter_test.go
index bd018e9f..5cebdf79 100644
--- a/pkg/cassandra/datacenter_test.go
+++ b/pkg/cassandra/datacenter_test.go
@@ -66,7 +66,7 @@ func TestCoalesce(t *testing.T) {
 				Size:               3,
 				AdditionalSeeds:    []string{"172.18.0.8", "172.18.0.14"},
 				ServerType:         "dse",
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{Name: "cassandra"}},
 					},
@@ -87,7 +87,7 @@ func TestCoalesce(t *testing.T) {
 			},
 			want: &DatacenterConfig{
 				ServerVersion: semver.MustParse("4.0.1"),
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{Name: "cassandra"}},
 					},
@@ -108,7 +108,7 @@ func TestCoalesce(t *testing.T) {
 			},
 			want: &DatacenterConfig{
 				ServerImage: "k8ssandra/cass-operator:dev",
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{Name: "cassandra"}},
 					},
@@ -144,7 +144,7 @@ func TestCoalesce(t *testing.T) {
 						corev1.ResourceMemory: resource.MustParse("2048Mi"),
 					},
 				},
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{Name: "cassandra"}},
 					},
@@ -192,7 +192,7 @@ func TestCoalesce(t *testing.T) {
 						},
 					},
 				},
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{Name: "cassandra"}},
 					},
@@ -219,7 +219,7 @@ func TestCoalesce(t *testing.T) {
 				Networking: &cassdcapi.NetworkingConfig{
 					HostNetwork: true,
 				},
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{Name: "cassandra"}},
 					},
@@ -262,7 +262,7 @@ func TestCoalesce(t *testing.T) {
 						MaxHeapSize: parseQuantity("1024Mi"),
 					},
 				},
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{Name: "cassandra"}},
 					},
@@ -307,7 +307,7 @@ func TestCoalesce(t *testing.T) {
 						Name: "rack3",
 					},
 				},
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{Name: "cassandra"}},
 					},
@@ -345,7 +345,7 @@ func TestCoalesce(t *testing.T) {
 				SuperuserSecretRef: corev1.LocalObjectReference{Name: "test-superuser"},
 				Size:               3,
 				MgmtAPIHeap:        &mgmtAPIHeap,
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{Name: "cassandra"}},
 					},
@@ -383,7 +383,7 @@ func TestCoalesce(t *testing.T) {
 				SuperuserSecretRef: corev1.LocalObjectReference{Name: "test-superuser"},
 				Size:               3,
 				MgmtAPIHeap:        &mgmtAPIHeap,
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{Name: "cassandra"}},
 					},
@@ -404,7 +404,7 @@ func TestCoalesce(t *testing.T) {
 			},
 			want: &DatacenterConfig{
 				JmxInitContainerImage: &images.Image{Name: "dc-image"},
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{Name: "cassandra"}},
 					},
@@ -419,7 +419,7 @@ func TestCoalesce(t *testing.T) {
 			},
 			want: &DatacenterConfig{
 				Stopped: true,
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{Name: "cassandra"}},
 					},
@@ -440,7 +440,7 @@ func TestCoalesce(t *testing.T) {
 			},
 			dcTemplate: &api.CassandraDatacenterTemplate{},
 			want: &DatacenterConfig{
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{
 							{
@@ -481,7 +481,7 @@ func TestCoalesce(t *testing.T) {
 			},
 			dcTemplate: &api.CassandraDatacenterTemplate{},
 			want: &DatacenterConfig{
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						InitContainers: []corev1.Container{
 							{
@@ -532,7 +532,7 @@ func TestCoalesce(t *testing.T) {
 						},
 					},
 				},
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{Name: "cassandra"}},
 					},
@@ -616,7 +616,7 @@ func TestCoalesce(t *testing.T) {
 						},
 					},
 				},
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Volumes: []corev1.Volume{
 							{
@@ -655,7 +655,7 @@ func TestCoalesce(t *testing.T) {
 			},
 			want: &DatacenterConfig{
 				DseWorkloads: &cassdcapi.DseWorkloads{AnalyticsEnabled: true, GraphEnabled: true},
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{Name: "cassandra"}},
 					},
@@ -738,7 +738,7 @@ func TestCoalesce(t *testing.T) {
 				},
 			},
 			want: &DatacenterConfig{
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{
 							{
@@ -829,7 +829,7 @@ func TestCoalesce(t *testing.T) {
 				},
 			},
 			want: &DatacenterConfig{
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{Name: "cassandra"}},
 						InitContainers: []corev1.Container{
@@ -871,7 +871,7 @@ func TestCoalesce(t *testing.T) {
 			},
 			want: &DatacenterConfig{
 				PerNodeInitContainerImage: "dc-level:latest",
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{Name: "cassandra"}},
 					},
@@ -910,7 +910,7 @@ func TestNewDatacenter_MgmtAPIHeapSize_Unset(t *testing.T) {
 		&template,
 	)
 	assert.Equal(t, err, nil)
-	assert.Equal(t, (*corev1.PodTemplateSpec)(nil), dc.Spec.PodTemplateSpec)
+	assert.Equal(t, &corev1.PodTemplateSpec{}, dc.Spec.PodTemplateSpec)
 }
 
 func TestNewDatacenter_AllowMultipleCassPerNodeSet(t *testing.T) {
diff --git a/pkg/cassandra/encryption_test.go b/pkg/cassandra/encryption_test.go
index a3c674a5..f769f8a2 100644
--- a/pkg/cassandra/encryption_test.go
+++ b/pkg/cassandra/encryption_test.go
@@ -52,9 +52,6 @@ func TestCheckMandatoryEncryptionFields(t *testing.T) {
 
 func TestAddEncryptionMountToCassandra(t *testing.T) {
 	dcConfig := &DatacenterConfig{
-		PodTemplateSpec: &corev1.PodTemplateSpec{
-			Spec: corev1.PodSpec{},
-		},
 		CassandraConfig: api.CassandraConfig{
 			CassandraYaml: unstructured.Unstructured{
 				"client_encryption_options": map[string]interface{}{
@@ -142,9 +139,6 @@ func TestAddEncryptionMountToCassandra(t *testing.T) {
 
 func TestAddVolumesForEncryption(t *testing.T) {
 	dcConfig := &DatacenterConfig{
-		PodTemplateSpec: &corev1.PodTemplateSpec{
-			Spec: corev1.PodSpec{},
-		},
 		CassandraConfig: api.CassandraConfig{
 			CassandraYaml: unstructured.Unstructured{
 				"client_encryption_options": map[string]interface{}{
@@ -196,9 +190,6 @@ func TestAddVolumesForEncryption(t *testing.T) {
 func TestHandleEncryptionOptions(t *testing.T) {
 	// Test a succeeding case with both client and server encryption turned on
 	dcConfig := &DatacenterConfig{
-		PodTemplateSpec: &corev1.PodTemplateSpec{
-			Spec: corev1.PodSpec{},
-		},
 		CassandraConfig: api.CassandraConfig{
 			CassandraYaml: unstructured.Unstructured{
 				"client_encryption_options": map[string]interface{}{
@@ -279,7 +270,7 @@ func TestHandleEncryptionOptions(t *testing.T) {
 func TestHandleEncryptionOptionsWithExistingContainers(t *testing.T) {
 	// Test a succeeding case with both client and server encryption turned on
 	dcConfig := &DatacenterConfig{
-		PodTemplateSpec: &corev1.PodTemplateSpec{
+		PodTemplateSpec: corev1.PodTemplateSpec{
 			Spec: corev1.PodSpec{
 				Containers: []corev1.Container{
 					{
@@ -345,9 +336,6 @@ func TestHandleEncryptionOptionsWithExistingContainers(t *testing.T) {
 func TestHandleNoEncryptionOptions(t *testing.T) {
 	// Test a succeeding case with disabled encryption
 	dcConfig := &DatacenterConfig{
-		PodTemplateSpec: &corev1.PodTemplateSpec{
-			Spec: corev1.PodSpec{},
-		},
 		CassandraConfig: api.CassandraConfig{
 			CassandraYaml: unstructured.Unstructured{
 				"client_encryption_options": map[string]interface{}{
@@ -380,9 +368,6 @@ func TestHandleNoEncryptionOptions(t *testing.T) {
 func TestHandleFailedEncryptionOptions(t *testing.T) {
 	// Test a succeeding case with missing encryption options
 	dcConfig := &DatacenterConfig{
-		PodTemplateSpec: &corev1.PodTemplateSpec{
-			Spec: corev1.PodSpec{},
-		},
 		CassandraConfig: api.CassandraConfig{
 			CassandraYaml: unstructured.Unstructured{
 				"client_encryption_options": map[string]interface{}{
diff --git a/pkg/medusa/reconcile_test.go b/pkg/medusa/reconcile_test.go
index 4b2a2d7d..d3c74a6c 100644
--- a/pkg/medusa/reconcile_test.go
+++ b/pkg/medusa/reconcile_test.go
@@ -6,7 +6,7 @@ import (
 	"github.com/go-logr/logr"
 	api "github.com/k8ssandra/k8ssandra-operator/apis/k8ssandra/v1alpha1"
 	medusaapi "github.com/k8ssandra/k8ssandra-operator/apis/medusa/v1alpha1"
-	cassandra "github.com/k8ssandra/k8ssandra-operator/pkg/cassandra"
+	"github.com/k8ssandra/k8ssandra-operator/pkg/cassandra"
 	"github.com/stretchr/testify/assert"
 	corev1 "k8s.io/api/core/v1"
 	"k8s.io/apimachinery/pkg/api/resource"
@@ -346,14 +346,7 @@ func TestInitContainerDefaultResources(t *testing.T) {
 		},
 	}
 
-	dcConfig := cassandra.DatacenterConfig{
-		PodTemplateSpec: &corev1.PodTemplateSpec{
-			Spec: corev1.PodSpec{
-				Containers:     []corev1.Container{},
-				InitContainers: []corev1.Container{},
-			},
-		},
-	}
+	dcConfig := cassandra.DatacenterConfig{}
 
 	logger := logr.New(logr.Discard().GetSink())
 
@@ -363,7 +356,7 @@ func TestInitContainerDefaultResources(t *testing.T) {
 	assert.Equal(t, 1, len(dcConfig.PodTemplateSpec.Spec.Containers))
 	assert.Equal(t, 2, len(dcConfig.PodTemplateSpec.Spec.InitContainers))
 	// Init container resources
-	medusaInitContainerIndex, found := cassandra.FindInitContainer(dcConfig.PodTemplateSpec, "medusa-restore")
+	medusaInitContainerIndex, found := cassandra.FindInitContainer(&dcConfig.PodTemplateSpec, "medusa-restore")
 	assert.True(t, found, "Couldn't find medusa-restore init container")
 
 	assert.Equal(t, resource.MustParse(InitContainerMemRequest), *dcConfig.PodTemplateSpec.Spec.InitContainers[medusaInitContainerIndex].Resources.Requests.Memory(), "expected init container memory request to be set")
@@ -411,14 +404,7 @@ func TestInitContainerCustomResources(t *testing.T) {
 		},
 	}
 
-	dcConfig := cassandra.DatacenterConfig{
-		PodTemplateSpec: &corev1.PodTemplateSpec{
-			Spec: corev1.PodSpec{
-				Containers:     []corev1.Container{},
-				InitContainers: []corev1.Container{},
-			},
-		},
-	}
+	dcConfig := cassandra.DatacenterConfig{}
 
 	logger := logr.New(logr.Discard().GetSink())
 
@@ -428,7 +414,7 @@ func TestInitContainerCustomResources(t *testing.T) {
 	assert.Equal(t, 1, len(dcConfig.PodTemplateSpec.Spec.Containers))
 	assert.Equal(t, 2, len(dcConfig.PodTemplateSpec.Spec.InitContainers))
 	// Init container resources
-	medusaInitContainerIndex, found := cassandra.FindInitContainer(dcConfig.PodTemplateSpec, "medusa-restore")
+	medusaInitContainerIndex, found := cassandra.FindInitContainer(&dcConfig.PodTemplateSpec, "medusa-restore")
 	assert.True(t, found, "Couldn't find medusa-restore init container")
 
 	assert.Equal(t, resource.MustParse("10Gi"), *dcConfig.PodTemplateSpec.Spec.InitContainers[medusaInitContainerIndex].Resources.Requests.Memory(), "expected init container memory request to be set")
@@ -458,21 +444,14 @@ func TestExternalSecretsFlag(t *testing.T) {
 		},
 	}
 
-	dcConfig := cassandra.DatacenterConfig{
-		PodTemplateSpec: &corev1.PodTemplateSpec{
-			Spec: corev1.PodSpec{
-				Containers:     []corev1.Container{},
-				InitContainers: []corev1.Container{},
-			},
-		},
-	}
+	dcConfig := cassandra.DatacenterConfig{}
 
 	logger := logr.New(logr.Discard().GetSink())
 
 	UpdateMedusaInitContainer(&dcConfig, medusaSpec, true, "test", logger)
 	UpdateMedusaMainContainer(&dcConfig, medusaSpec, true, "test", logger)
 
-	medusaInitContainerIndex, found := cassandra.FindInitContainer(dcConfig.PodTemplateSpec, "medusa-restore")
+	medusaInitContainerIndex, found := cassandra.FindInitContainer(&dcConfig.PodTemplateSpec, "medusa-restore")
 	assert.True(t, found, "Couldn't find medusa-restore init container")
 
 	assert.Equal(t, 2, len(dcConfig.PodTemplateSpec.Spec.Containers[0].Env))
diff --git a/pkg/nodeconfig/mount_test.go b/pkg/nodeconfig/mount_test.go
index bf966ea7..b3407b30 100644
--- a/pkg/nodeconfig/mount_test.go
+++ b/pkg/nodeconfig/mount_test.go
@@ -23,7 +23,6 @@ func TestMountPerNodeConfig(t *testing.T) {
 					Name:      "dc1",
 					Namespace: "dc1-ns",
 				},
-				PodTemplateSpec: &corev1.PodTemplateSpec{},
 				PerNodeConfigMapRef: corev1.LocalObjectReference{
 					Name: "test-dc1-per-node-config",
 				},
@@ -33,7 +32,7 @@ func TestMountPerNodeConfig(t *testing.T) {
 					Name:      "dc1",
 					Namespace: "dc1-ns",
 				},
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						InitContainers: []corev1.Container{
 							{Name: reconciliation.ServerConfigContainerName},
@@ -56,7 +55,6 @@ func TestMountPerNodeConfig(t *testing.T) {
 					Name:      "dc1",
 					Namespace: "dc1-ns",
 				},
-				PodTemplateSpec: &corev1.PodTemplateSpec{},
 				PerNodeConfigMapRef: corev1.LocalObjectReference{
 					Name: "test-dc1-per-node-config",
 				},
@@ -67,7 +65,7 @@ func TestMountPerNodeConfig(t *testing.T) {
 					Name:      "dc1",
 					Namespace: "dc1-ns",
 				},
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						InitContainers: []corev1.Container{
 							{Name: reconciliation.ServerConfigContainerName},
diff --git a/pkg/reaper/datacenter_test.go b/pkg/reaper/datacenter_test.go
index 023ed484..fed133da 100644
--- a/pkg/reaper/datacenter_test.go
+++ b/pkg/reaper/datacenter_test.go
@@ -27,7 +27,7 @@ func TestAddReaperSettingsToDcConfig(t *testing.T) {
 			&cassandra.DatacenterConfig{
 				Meta:    api.EmbeddedObjectMeta{Name: "dc1"},
 				Cluster: "cluster1",
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{
 							Name: reconciliation.CassandraContainerName,
@@ -39,7 +39,7 @@ func TestAddReaperSettingsToDcConfig(t *testing.T) {
 				Meta:    api.EmbeddedObjectMeta{Name: "dc1"},
 				Cluster: "cluster1",
 				Users:   []cassdcapi.CassandraUser{{SecretName: "cluster1-reaper", Superuser: true}},
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{
 							Name: reconciliation.CassandraContainerName,
@@ -61,7 +61,7 @@ func TestAddReaperSettingsToDcConfig(t *testing.T) {
 			&cassandra.DatacenterConfig{
 				Meta:    api.EmbeddedObjectMeta{Name: "dc1"},
 				Cluster: "cluster1",
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{
 							Name: reconciliation.CassandraContainerName,
@@ -85,7 +85,7 @@ func TestAddReaperSettingsToDcConfig(t *testing.T) {
 				Cluster:            "cluster1",
 				SuperuserSecretRef: corev1.LocalObjectReference{Name: "cassandra-superuser"},
 				Users:              []cassdcapi.CassandraUser{{SecretName: "another-user", Superuser: true}},
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{
 							{
@@ -109,7 +109,7 @@ func TestAddReaperSettingsToDcConfig(t *testing.T) {
 					{SecretName: "another-user", Superuser: true},
 					{SecretName: "cass-user", Superuser: true},
 				},
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{
 							{
@@ -141,7 +141,7 @@ func TestAddReaperSettingsToDcConfig(t *testing.T) {
 				Meta:    api.EmbeddedObjectMeta{Name: "dc1"},
 				Cluster: "cluster1",
 				Users:   []cassdcapi.CassandraUser{{SecretName: "another-user", Superuser: true}},
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{
 							{
@@ -159,7 +159,7 @@ func TestAddReaperSettingsToDcConfig(t *testing.T) {
 				Meta:    api.EmbeddedObjectMeta{Name: "dc1"},
 				Cluster: "cluster1",
 				Users:   []cassdcapi.CassandraUser{{SecretName: "another-user", Superuser: true}},
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{
 							{
@@ -193,7 +193,7 @@ func TestAddReaperSettingsToDcConfig(t *testing.T) {
 				Meta:            api.EmbeddedObjectMeta{Name: "dc1"},
 				Cluster:         "cluster1",
 				ExternalSecrets: true,
-				PodTemplateSpec: &corev1.PodTemplateSpec{
+				PodTemplateSpec: corev1.PodTemplateSpec{
 					Spec: corev1.PodSpec{
 						Containers: []corev1.Container{{
 							Name: reconciliation.CassandraContainerName,
diff --git a/pkg/telemetry/cassandra_metrics_filters_test.go b/pkg/telemetry/cassandra_metrics_filters_test.go
index ea976e4f..d32082ca 100644
--- a/pkg/telemetry/cassandra_metrics_filters_test.go
+++ b/pkg/telemetry/cassandra_metrics_filters_test.go
@@ -8,18 +8,18 @@ import (
 	telemetry "github.com/k8ssandra/k8ssandra-operator/apis/telemetry/v1alpha1"
 	"github.com/k8ssandra/k8ssandra-operator/pkg/cassandra"
 	"github.com/stretchr/testify/assert"
-	v1 "k8s.io/api/core/v1"
+	corev1 "k8s.io/api/core/v1"
 )
 
 // Test_InjectCassandraTelemetryFilters tests that metrics filters from the CRD are correctly injected.
 func Test_InjectCassandraTelemetryFilters(t *testing.T) {
 	dcConfig := &cassandra.DatacenterConfig{
-		PodTemplateSpec: &v1.PodTemplateSpec{
-			Spec: v1.PodSpec{
-				Containers: []v1.Container{
+		PodTemplateSpec: corev1.PodTemplateSpec{
+			Spec: corev1.PodSpec{
+				Containers: []corev1.Container{
 					{
 						Name: "cassandra",
-						Env:  []v1.EnvVar{},
+						Env:  []corev1.EnvVar{},
 					},
 				},
 			},
@@ -47,12 +47,12 @@ func Test_InjectCassandraTelemetryFilters(t *testing.T) {
 // Test_InjectCassandraTelemetryFiltersDefaults tests that default metrics filters are injected when no custom ones are defined.
 func Test_InjectCassandraTelemetryFiltersDefaults(t *testing.T) {
 	dcConfig := &cassandra.DatacenterConfig{
-		PodTemplateSpec: &v1.PodTemplateSpec{
-			Spec: v1.PodSpec{
-				Containers: []v1.Container{
+		PodTemplateSpec: corev1.PodTemplateSpec{
+			Spec: corev1.PodSpec{
+				Containers: []corev1.Container{
 					{
 						Name: "cassandra",
-						Env:  []v1.EnvVar{},
+						Env:  []corev1.EnvVar{},
 					},
 				},
 			},
@@ -73,12 +73,12 @@ func Test_InjectCassandraTelemetryFiltersDefaults(t *testing.T) {
 
 func Test_InjectCassandraTelemetryFilters_Empty(t *testing.T) {
 	dcConfig := &cassandra.DatacenterConfig{
-		PodTemplateSpec: &v1.PodTemplateSpec{
-			Spec: v1.PodSpec{
-				Containers: []v1.Container{
+		PodTemplateSpec: corev1.PodTemplateSpec{
+			Spec: corev1.PodSpec{
+				Containers: []corev1.Container{
 					{
 						Name: "cassandra",
-						Env:  []v1.EnvVar{},
+						Env:  []corev1.EnvVar{},
 					},
 				},
 			},