From a43fdabbb75afe4e8ebb67de256dfa5dbaeb4968 Mon Sep 17 00:00:00 2001 From: Olivier Michallat Date: Fri, 15 Mar 2024 16:39:37 -0700 Subject: [PATCH] Don't use DC name override when naming resources --- controllers/k8ssandra/cassandra_telemetry_reconciler.go | 2 +- controllers/k8ssandra/datacenters.go | 2 +- controllers/k8ssandra/k8ssandracluster_controller.go | 2 +- controllers/k8ssandra/reaper.go | 4 ++-- controllers/reaper/vector.go | 2 +- controllers/stargate/stargate_controller.go | 2 +- controllers/stargate/vector.go | 2 +- pkg/medusa/utils.go | 2 +- pkg/reaper/resource.go | 2 +- pkg/reaper/vector.go | 4 ++-- pkg/stargate/config.go | 2 +- pkg/stargate/deployments.go | 2 +- pkg/stargate/stargate.go | 6 +++--- pkg/stargate/vector.go | 4 ++-- 14 files changed, 19 insertions(+), 19 deletions(-) diff --git a/controllers/k8ssandra/cassandra_telemetry_reconciler.go b/controllers/k8ssandra/cassandra_telemetry_reconciler.go index 7067ac5d6..66ffce61d 100644 --- a/controllers/k8ssandra/cassandra_telemetry_reconciler.go +++ b/controllers/k8ssandra/cassandra_telemetry_reconciler.go @@ -37,7 +37,7 @@ func (r *K8ssandraClusterReconciler) reconcileCassandraDCTelemetry( cfg := telemetry.PrometheusResourcer{ MonitoringTargetNS: actualDc.Namespace, MonitoringTargetName: actualDc.Name, - ServiceMonitorName: kc.SanitizedName() + "-" + actualDc.DatacenterName() + "-" + "cass-servicemonitor", + ServiceMonitorName: kc.SanitizedName() + "-" + actualDc.Name + "-" + "cass-servicemonitor", Logger: logger, CommonLabels: mustLabels(kc.Name, kc.Namespace, actualDc.DatacenterName(), commonLabels), } diff --git a/controllers/k8ssandra/datacenters.go b/controllers/k8ssandra/datacenters.go index 066679b4f..fa6f8ddc2 100644 --- a/controllers/k8ssandra/datacenters.go +++ b/controllers/k8ssandra/datacenters.go @@ -111,7 +111,7 @@ func (r *K8ssandraClusterReconciler) reconcileDatacenters(ctx context.Context, k Kluster: kc, RequeueDelay: r.DefaultDelay, DcNamespace: desiredDc.Namespace, - DcName: desiredDc.DatacenterName(), + DcName: desiredDc.Name, } agentRes := agentCfg.ReconcileTelemetryAgentConfig(desiredDc) if agentRes.IsRequeue() { diff --git a/controllers/k8ssandra/k8ssandracluster_controller.go b/controllers/k8ssandra/k8ssandracluster_controller.go index e589f1c34..082289b60 100644 --- a/controllers/k8ssandra/k8ssandracluster_controller.go +++ b/controllers/k8ssandra/k8ssandracluster_controller.go @@ -164,7 +164,7 @@ func (r *K8ssandraClusterReconciler) afterCassandraReconciled(ctx context.Contex dc := dcs[i] dcKey := utils.GetKey(dc) logger := logger.WithValues("CassandraDatacenter", dcKey) - logger.Info("Reconciling Stargate and Reaper for dc " + dc.DatacenterName()) + logger.Info("Reconciling Stargate and Reaper for dc " + dc.Name) if remoteClient, err := r.ClientCache.GetRemoteClient(dcTemplate.K8sContext); err != nil { logger.Error(err, "Failed to get remote client") return result.Error(err) diff --git a/controllers/k8ssandra/reaper.go b/controllers/k8ssandra/reaper.go index 4145de48b..054a962e1 100644 --- a/controllers/k8ssandra/reaper.go +++ b/controllers/k8ssandra/reaper.go @@ -102,7 +102,7 @@ func (r *K8ssandraClusterReconciler) reconcileReaper( if reaperTemplate != nil { reaperTemplate.SecretsProvider = kc.Spec.SecretsProvider - logger.Info("Reaper present for DC " + actualDc.DatacenterName()) + logger.Info("Reaper present for DC " + actualDc.Name) desiredReaper, err := reaper.NewReaper(reaperKey, kc, actualDc, reaperTemplate, logger) @@ -155,7 +155,7 @@ func (r *K8ssandraClusterReconciler) reconcileReaper( } else { - logger.Info("Reaper not present for DC " + actualDc.DatacenterName()) + logger.Info("Reaper not present for DC " + actualDc.Name) // Test if Reaper was removed if err := remoteClient.Get(ctx, reaperKey, actualReaper); err != nil { diff --git a/controllers/reaper/vector.go b/controllers/reaper/vector.go index 2ff935cf3..8551de2de 100644 --- a/controllers/reaper/vector.go +++ b/controllers/reaper/vector.go @@ -29,7 +29,7 @@ func (r *ReaperReconciler) reconcileVectorConfigMap( namespace := reaper.Namespace configMapKey := client.ObjectKey{ Namespace: namespace, - Name: reaperpkg.VectorAgentConfigMapName(actualDc.Spec.ClusterName, actualDc.DatacenterName()), + Name: reaperpkg.VectorAgentConfigMapName(actualDc.Spec.ClusterName, actualDc.Name), } if reaper.Spec.Telemetry.IsVectorEnabled() { // Create the vector toml config content diff --git a/controllers/stargate/stargate_controller.go b/controllers/stargate/stargate_controller.go index 6dfe7dfa8..d8681b856 100644 --- a/controllers/stargate/stargate_controller.go +++ b/controllers/stargate/stargate_controller.go @@ -435,7 +435,7 @@ func (r *StargateReconciler) reconcileStargateConfigMap( configMapKey := client.ObjectKey{ Namespace: namespace, - Name: stargate.GeneratedConfigMapName(dc.Spec.ClusterName, dc.DatacenterName()), + Name: stargate.GeneratedConfigMapName(dc.Spec.ClusterName, dc.Name), } logger = logger.WithValues("StargateConfigMap", configMapKey) diff --git a/controllers/stargate/vector.go b/controllers/stargate/vector.go index 0884c378c..7c719ac77 100644 --- a/controllers/stargate/vector.go +++ b/controllers/stargate/vector.go @@ -29,7 +29,7 @@ func (r *StargateReconciler) reconcileVectorConfigMap( namespace := stargate.Namespace configMapKey := client.ObjectKey{ Namespace: namespace, - Name: stargatepkg.VectorAgentConfigMapName(actualDc.Spec.ClusterName, actualDc.DatacenterName()), + Name: stargatepkg.VectorAgentConfigMapName(actualDc.Spec.ClusterName, actualDc.Name), } if stargate.Spec.Telemetry.IsVectorEnabled() { // Create the vector toml config content diff --git a/pkg/medusa/utils.go b/pkg/medusa/utils.go index cc04907a2..1c471459b 100644 --- a/pkg/medusa/utils.go +++ b/pkg/medusa/utils.go @@ -17,7 +17,7 @@ func GetCassandraDatacenterPods(ctx context.Context, cassdc *cassdcapi.Cassandra cassdcapi.DatacenterLabel: cassdc.DatacenterName(), } if err := r.List(ctx, podList, labels, client.InNamespace(cassdc.Namespace)); err != nil { - logger.Error(err, "failed to get pods for cassandradatacenter", "CassandraDatacenter", cassdc.DatacenterName()) + logger.Error(err, "failed to get pods for cassandradatacenter", "CassandraDatacenter", cassdc.Name) return nil, err } diff --git a/pkg/reaper/resource.go b/pkg/reaper/resource.go index d26992cf4..d45ab0a47 100644 --- a/pkg/reaper/resource.go +++ b/pkg/reaper/resource.go @@ -25,7 +25,7 @@ const ( // DefaultResourceName generates a name for a new Reaper resource that is derived from the Cassandra cluster and DC // names. func DefaultResourceName(dc *cassdcapi.CassandraDatacenter) string { - return cassdcapi.CleanupForKubernetes(dc.Spec.ClusterName + "-" + dc.DatacenterName() + "-reaper") + return cassdcapi.CleanupForKubernetes(dc.Spec.ClusterName + "-" + dc.Name + "-reaper") } func NewReaper( diff --git a/pkg/reaper/vector.go b/pkg/reaper/vector.go index f55d98afa..8af6d3e3d 100644 --- a/pkg/reaper/vector.go +++ b/pkg/reaper/vector.go @@ -33,7 +33,7 @@ func VectorAgentConfigMapName(clusterName, dcName string) string { func CreateVectorConfigMap(namespace, vectorToml string, dc cassdcapi.CassandraDatacenter) *corev1.ConfigMap { return &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: VectorAgentConfigMapName(dc.Spec.ClusterName, dc.DatacenterName()), + Name: VectorAgentConfigMapName(dc.Spec.ClusterName, dc.Name), Namespace: namespace, Labels: utils.MergeMap( map[string]string{ @@ -78,7 +78,7 @@ func configureVector(reaper *api.Reaper, deployment *appsv1.Deployment, dc *cass Name: "reaper-vector-config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - LocalObjectReference: corev1.LocalObjectReference{Name: VectorAgentConfigMapName(dc.Spec.ClusterName, dc.DatacenterName())}, + LocalObjectReference: corev1.LocalObjectReference{Name: VectorAgentConfigMapName(dc.Spec.ClusterName, dc.Name)}, }, }, } diff --git a/pkg/stargate/config.go b/pkg/stargate/config.go index 226f32fde..60fed798f 100644 --- a/pkg/stargate/config.go +++ b/pkg/stargate/config.go @@ -42,7 +42,7 @@ func FilterConfig(config map[string]interface{}, retainedSettings []string) map[ func CreateStargateConfigMap(namespace, cassandraYaml, stargateCqlYaml string, dc cassdcapi.CassandraDatacenter) *corev1.ConfigMap { return &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: GeneratedConfigMapName(dc.Spec.ClusterName, dc.DatacenterName()), + Name: GeneratedConfigMapName(dc.Spec.ClusterName, dc.Name), Namespace: namespace, Labels: utils.MergeMap( map[string]string{ diff --git a/pkg/stargate/deployments.go b/pkg/stargate/deployments.go index cf7464e40..93f3394e4 100644 --- a/pkg/stargate/deployments.go +++ b/pkg/stargate/deployments.go @@ -351,7 +351,7 @@ func computeVolumes(template *api.StargateTemplate, dc *cassdcapi.CassandraDatac VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ LocalObjectReference: corev1.LocalObjectReference{ - Name: GeneratedConfigMapName(dc.Spec.ClusterName, dc.DatacenterName()), + Name: GeneratedConfigMapName(dc.Spec.ClusterName, dc.Name), }, }, }, diff --git a/pkg/stargate/stargate.go b/pkg/stargate/stargate.go index c7eeceaa0..684992842 100644 --- a/pkg/stargate/stargate.go +++ b/pkg/stargate/stargate.go @@ -16,15 +16,15 @@ import ( ) func ResourceName(dc *cassdcapi.CassandraDatacenter) string { - return cassdcapi.CleanupForKubernetes(dc.Spec.ClusterName + "-" + dc.DatacenterName() + "-stargate") + return cassdcapi.CleanupForKubernetes(dc.Spec.ClusterName + "-" + dc.Name + "-stargate") } func ServiceName(dc *cassdcapi.CassandraDatacenter) string { - return cassdcapi.CleanupForKubernetes(dc.Spec.ClusterName + "-" + dc.DatacenterName() + "-stargate-service") + return cassdcapi.CleanupForKubernetes(dc.Spec.ClusterName + "-" + dc.Name + "-stargate-service") } func DeploymentName(dc *cassdcapi.CassandraDatacenter, rack *cassdcapi.Rack) string { - return cassdcapi.CleanupForKubernetes(dc.Spec.ClusterName + "-" + dc.DatacenterName() + "-" + rack.Name + "-stargate-deployment") + return cassdcapi.CleanupForKubernetes(dc.Spec.ClusterName + "-" + dc.Name + "-" + rack.Name + "-stargate-deployment") } func NewStargate( diff --git a/pkg/stargate/vector.go b/pkg/stargate/vector.go index f65e15332..6001f43d1 100644 --- a/pkg/stargate/vector.go +++ b/pkg/stargate/vector.go @@ -33,7 +33,7 @@ func VectorAgentConfigMapName(clusterName, dcName string) string { func CreateVectorConfigMap(namespace, vectorToml string, dc cassdcapi.CassandraDatacenter) *corev1.ConfigMap { return &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: VectorAgentConfigMapName(dc.Spec.ClusterName, dc.DatacenterName()), + Name: VectorAgentConfigMapName(dc.Spec.ClusterName, dc.Name), Namespace: namespace, Labels: utils.MergeMap( map[string]string{ @@ -78,7 +78,7 @@ func configureVector(stargate *api.Stargate, deployment *appsv1.Deployment, dc * Name: "stargate-vector-config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - LocalObjectReference: corev1.LocalObjectReference{Name: VectorAgentConfigMapName(dc.Spec.ClusterName, dc.DatacenterName())}, + LocalObjectReference: corev1.LocalObjectReference{Name: VectorAgentConfigMapName(dc.Spec.ClusterName, dc.Name)}, }, }, }