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

cass-operator v1.23.0 #1461

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion CHANGELOG/CHANGELOG-1.21.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ When cutting a new release, update the `unreleased` heading to the tag being gen

## unreleased

* [CHANGE] [#1450](https://github.com/k8ssandra/k8ssandra-operator/issues/1450) Update datacenter labels to use Kubernetes resource names for CassandraDatacenter, not the cleaned override name. Update to cass-operator 1.23.0
* [CHANGE] [#1441](https://github.com/k8ssandra/k8ssandra-operator/issues/1441) Use k8ssandra-client instead of k8ssandra-tools for CRD upgrades
* [BUGFIX] [#1383](https://github.com/k8ssandra/k8ssandra-operator/issues/1383) Do not create MedusaBackup if MedusaBakupJob did not fully succeed
* [ENHANCEMENT] [#1667](https://github.com/k8ssahttps://github.com/k8ssandra/k8ssandra/issues/1667) Add `skipSchemaMigration` option to `K8ssandraCluster.spec.reaper`
* [BUGFIX] [#1383](https://github.com/k8ssandra/k8ssandra-operator/issues/1383) Do not create MedusaBackup if MedusaBakupJob did not fully succeed
* [BUGFIX] [#1460](https://github.com/k8ssandra/k8ssandra-operator/issues/1460) Fix podName calculations in medusa's hostmap.go to account for unbalanced racks also
* [BUGFIX] [#1466](https://github.com/k8ssandra/k8ssandra-operator/issues/1466) Do not overwrite existing status fields or forget to write the changes. Also, add new ContextName for the Datacenter to know where it used to be.
4 changes: 2 additions & 2 deletions apis/k8ssandra/v1alpha1/k8ssandracluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ type K8ssandraClusterCondition struct {

// K8ssandraStatus defines the observed of a k8ssandra instance
type K8ssandraStatus struct {
ContextName string `json:"contextName,omitempty"`
DecommissionProgress DecommissionProgress `json:"decommissionProgress,omitempty"`
Cassandra *cassdcapi.CassandraDatacenterStatus `json:"cassandra,omitempty"`
Stargate *stargateapi.StargateStatus `json:"stargate,omitempty"`
Expand Down Expand Up @@ -439,8 +440,7 @@ type DatacenterOptions struct {
// The k8s service account to use for the Cassandra pods
ServiceAccount string `json:"serviceAccount,omitempty"`

// DatacenterName allows to override the name of the Cassandra datacenter. Kubernetes objects will be named after a sanitized version of it if set, and if not metadata.name. In Cassandra the DC name will be overridden by this value.
// It may generate some confusion as objects created for the DC will have a different name than the CasandraDatacenter object itself.
// DatacenterName allows to override the name of the Cassandra datacenter. In Cassandra the DC name will be overridden by this value.
// This setting can create conflicts if multiple DCs coexist in the same namespace if metadata.name for a DC with no override is set to the same value as the override name of another DC.
// Use cautiously.
// +optional
Expand Down
22 changes: 20 additions & 2 deletions apis/k8ssandra/v1alpha1/k8ssandracluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"strings"

"github.com/Masterminds/semver/v3"
cassdcapi "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
"github.com/k8ssandra/cass-operator/pkg/reconciliation"
reaperapi "github.com/k8ssandra/k8ssandra-operator/apis/reaper/v1alpha1"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -132,15 +134,31 @@ func (r *K8ssandraCluster) validateK8ssandraCluster() error {
}

func (r *K8ssandraCluster) validateStatefulsetNameSize() error {
clusterName := r.ObjectMeta.Name
if r.Spec.Cassandra.ClusterName != "" {
clusterName = r.Spec.Cassandra.ClusterName
}

for _, dc := range r.Spec.Cassandra.Datacenters {
realDc := &cassdcapi.CassandraDatacenter{
ObjectMeta: metav1.ObjectMeta{
Name: dc.Meta.Name,
},
Spec: cassdcapi.CassandraDatacenterSpec{
ClusterName: clusterName,
},
}

if len(dc.Racks) > 0 {
for _, rack := range dc.Racks {
if len(r.SanitizedName()+"-"+dc.CassDcName()+"-"+rack.Name+"-sts-") > 60 {
stsName := reconciliation.NewNamespacedNameForStatefulSet(realDc, rack.Name)
if len(stsName.Name) > 60 {
return fmt.Errorf("the name of the statefulset for rack %s in DC %s is too long", rack.Name, dc.CassDcName())
}
}
} else {
if len(r.SanitizedName()+"-"+dc.CassDcName()+"-default-sts-") > 60 {
stsName := reconciliation.NewNamespacedNameForStatefulSet(realDc, "default")
if len(stsName.Name) > 60 {
return fmt.Errorf("the name of the statefulset for DC %s is too long", dc.CassDcName())
}
}
Expand Down
11 changes: 7 additions & 4 deletions charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2222,8 +2222,7 @@ spec:
type: array
datacenterName:
description: |-
DatacenterName allows to override the name of the Cassandra datacenter. Kubernetes objects will be named after a sanitized version of it if set, and if not metadata.name. In Cassandra the DC name will be overridden by this value.
It may generate some confusion as objects created for the DC will have a different name than the CasandraDatacenter object itself.
DatacenterName allows to override the name of the Cassandra datacenter. In Cassandra the DC name will be overridden by this value.
This setting can create conflicts if multiple DCs coexist in the same namespace if metadata.name for a DC with no override is set to the same value as the override name of another DC.
Use cautiously.
type: string
Expand Down Expand Up @@ -4251,8 +4250,7 @@ spec:
type: array
datacenterName:
description: |-
DatacenterName allows to override the name of the Cassandra datacenter. Kubernetes objects will be named after a sanitized version of it if set, and if not metadata.name. In Cassandra the DC name will be overridden by this value.
It may generate some confusion as objects created for the DC will have a different name than the CasandraDatacenter object itself.
DatacenterName allows to override the name of the Cassandra datacenter. In Cassandra the DC name will be overridden by this value.
This setting can create conflicts if multiple DCs coexist in the same namespace if metadata.name for a DC with no override is set to the same value as the override name of another DC.
Use cautiously.
type: string
Expand Down Expand Up @@ -31075,6 +31073,9 @@ spec:
with the management API
format: date-time
type: string
metadataVersion:
format: int64
type: integer
nodeReplacements:
items:
type: string
Expand Down Expand Up @@ -31175,6 +31176,8 @@ spec:
format: date-time
type: string
type: object
contextName:
type: string
decommissionProgress:
type: string
reaper:
Expand Down
2 changes: 1 addition & 1 deletion config/cass-operator/cluster-scoped/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- github.com/k8ssandra/cass-operator/config/deployments/cluster?ref=v1.22.4
- github.com/k8ssandra/cass-operator/config/deployments/cluster?ref=v1.23.0
2 changes: 1 addition & 1 deletion config/cass-operator/ns-scoped/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- github.com/k8ssandra/cass-operator/config/deployments/default?ref=v1.22.4
- github.com/k8ssandra/cass-operator/config/deployments/default?ref=v1.23.0
11 changes: 7 additions & 4 deletions config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2160,8 +2160,7 @@ spec:
type: array
datacenterName:
description: |-
DatacenterName allows to override the name of the Cassandra datacenter. Kubernetes objects will be named after a sanitized version of it if set, and if not metadata.name. In Cassandra the DC name will be overridden by this value.
It may generate some confusion as objects created for the DC will have a different name than the CasandraDatacenter object itself.
DatacenterName allows to override the name of the Cassandra datacenter. In Cassandra the DC name will be overridden by this value.
This setting can create conflicts if multiple DCs coexist in the same namespace if metadata.name for a DC with no override is set to the same value as the override name of another DC.
Use cautiously.
type: string
Expand Down Expand Up @@ -4189,8 +4188,7 @@ spec:
type: array
datacenterName:
description: |-
DatacenterName allows to override the name of the Cassandra datacenter. Kubernetes objects will be named after a sanitized version of it if set, and if not metadata.name. In Cassandra the DC name will be overridden by this value.
It may generate some confusion as objects created for the DC will have a different name than the CasandraDatacenter object itself.
DatacenterName allows to override the name of the Cassandra datacenter. In Cassandra the DC name will be overridden by this value.
This setting can create conflicts if multiple DCs coexist in the same namespace if metadata.name for a DC with no override is set to the same value as the override name of another DC.
Use cautiously.
type: string
Expand Down Expand Up @@ -31013,6 +31011,9 @@ spec:
with the management API
format: date-time
type: string
metadataVersion:
format: int64
type: integer
nodeReplacements:
items:
type: string
Expand Down Expand Up @@ -31113,6 +31114,8 @@ spec:
format: date-time
type: string
type: object
contextName:
type: string
decommissionProgress:
type: string
reaper:
Expand Down
4 changes: 2 additions & 2 deletions controllers/k8ssandra/cassandra_telemetry_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func (r *K8ssandraClusterReconciler) reconcileCassandraDCTelemetry(
cfg := telemetry.PrometheusResourcer{
MonitoringTargetNS: actualDc.Namespace,
MonitoringTargetName: actualDc.Name,
ServiceMonitorName: cassdcapi.CleanupForKubernetes(kc.CassClusterName() + "-" + actualDc.DatacenterName() + "-" + "cass-servicemonitor"),
ServiceMonitorName: cassdcapi.CleanupForKubernetes(kc.CassClusterName() + "-" + actualDc.LabelResourceName() + "-" + "cass-servicemonitor"),
Logger: logger,
CommonLabels: mustLabels(kc.Name, kc.Namespace, actualDc.DatacenterName(), commonLabels),
CommonLabels: mustLabels(kc.Name, kc.Namespace, actualDc.LabelResourceName(), commonLabels),
}
logger.Info("merged TelemetrySpec constructed", "mergedSpec", mergedSpec, "cluster", kc.Name)
// Confirm telemetry config is valid (e.g. Prometheus is installed if it is requested.)
Expand Down
80 changes: 41 additions & 39 deletions controllers/k8ssandra/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (r *K8ssandraClusterReconciler) checkFinalizer(ctx context.Context, kc *api
}

func (r *K8ssandraClusterReconciler) checkDcDeletion(ctx context.Context, kc *api.K8ssandraCluster, logger logr.Logger) result.ReconcileResult {
dcName, dcNameOverride := k8ssandra.GetDatacenterForDecommission(kc)
dcName := k8ssandra.GetDatacenterForDecommission(kc)
if dcName == "" {
return result.Continue()
}
Expand All @@ -163,76 +163,78 @@ func (r *K8ssandraClusterReconciler) checkDcDeletion(ctx context.Context, kc *ap
default:
logger.Info("Proceeding with DC deletion", "DC", dcName)

cassDcName := dcName
if dcNameOverride != "" {
cassDcName = dcNameOverride
}
return r.deleteDc(ctx, kc, dcName, cassDcName, logger)
return r.deleteDc(ctx, kc, dcName, logger)
}
}

func (r *K8ssandraClusterReconciler) deleteDc(ctx context.Context, kc *api.K8ssandraCluster, dcName string, cassDcName string, logger logr.Logger) result.ReconcileResult {
func (r *K8ssandraClusterReconciler) deleteDc(ctx context.Context, kc *api.K8ssandraCluster, dcName string, logger logr.Logger) result.ReconcileResult {
kcKey := utils.GetKey(kc)

stargate, remoteClient, err := r.findStargateForDeletion(ctx, kcKey, cassDcName, nil)
dcRemoteClient, err := r.ClientCache.GetRemoteClient(kc.Status.Datacenters[dcName].ContextName)
if err != nil {
return result.Error(err)
}

dc, _, err := r.findDcForDeletion(ctx, kcKey, dcName, dcRemoteClient)
if err != nil {
return result.Error(err)
}

if dc == nil {
// Deletion was already done
delete(kc.Status.Datacenters, dcName)
logger.Info("DC deletion finished", "DC", dcName)
return result.Continue()
}

stargate, remoteClient, err := r.findStargateForDeletion(ctx, kcKey, dc.DatacenterName(), nil)
if err != nil {
return result.Error(err)
}

if stargate != nil {
if err = remoteClient.Delete(ctx, stargate); err != nil && !errors.IsNotFound(err) {
return result.Error(fmt.Errorf("failed to delete Stargate for dc (%s): %v", cassDcName, err))
return result.Error(fmt.Errorf("failed to delete Stargate for dc (%s): %v", dc.DatacenterName(), err))
}
logger.Info("Deleted Stargate", "Stargate", utils.GetKey(stargate))
}

reaper, remoteClient, err := r.findReaperForDeletion(ctx, kcKey, cassDcName, remoteClient)
reaper, remoteClient, err := r.findReaperForDeletion(ctx, kcKey, dc.DatacenterName(), remoteClient)
if err != nil {
return result.Error(err)
}

if reaper != nil {
if err = remoteClient.Delete(ctx, reaper); err != nil && !errors.IsNotFound(err) {
return result.Error(fmt.Errorf("failed to delete Reaper for dc (%s): %v", cassDcName, err))
return result.Error(fmt.Errorf("failed to delete Reaper for dc (%s): %v", dc.DatacenterName(), err))
}
logger.Info("Deleted Reaper", "Reaper", utils.GetKey(reaper))
}

dc, remoteClient, err := r.findDcForDeletion(ctx, kcKey, dcName, remoteClient)
if err != nil {
if err := r.deleteContactPointsService(ctx, kc, dc, logger); err != nil {
return result.Error(err)
}

if dc != nil {
if err := r.deleteContactPointsService(ctx, kc, dc, logger); err != nil {
return result.Error(err)
}

if dc.GetConditionStatus(cassdcapi.DatacenterDecommission) == corev1.ConditionTrue {
logger.Info("CassandraDatacenter decommissioning in progress", "CassandraDatacenter", utils.GetKey(dc))
// There is no need to requeue here. Reconciliation will be trigger by updates made by cass-operator.
return result.Done()
}

if !annotations.HasAnnotationWithValue(dc, cassdcapi.DecommissionOnDeleteAnnotation, "true") {
patch := client.MergeFrom(dc.DeepCopy())
annotations.AddAnnotation(dc, cassdcapi.DecommissionOnDeleteAnnotation, "true")
if err = remoteClient.Patch(ctx, dc, patch); err != nil {
return result.Error(fmt.Errorf("failed to add %s annotation to dc: %v", cassdcapi.DecommissionOnDeleteAnnotation, err))
}
}

if err = remoteClient.Delete(ctx, dc); err != nil && !errors.IsNotFound(err) {
return result.Error(fmt.Errorf("failed to delete CassandraDatacenter (%s): %v", dcName, err))
}
logger.Info("Deleted CassandraDatacenter", "CassandraDatacenter", utils.GetKey(dc))
if dc.GetConditionStatus(cassdcapi.DatacenterDecommission) == corev1.ConditionTrue {
logger.Info("CassandraDatacenter decommissioning in progress", "CassandraDatacenter", utils.GetKey(dc))
// There is no need to requeue here. Reconciliation will be trigger by updates made by cass-operator.
return result.Done()
}

delete(kc.Status.Datacenters, dcName)
logger.Info("DC deletion finished", "DC", dcName)
return result.Continue()
if !annotations.HasAnnotationWithValue(dc, cassdcapi.DecommissionOnDeleteAnnotation, "true") {
patch := client.MergeFrom(dc.DeepCopy())
annotations.AddAnnotation(dc, cassdcapi.DecommissionOnDeleteAnnotation, "true")
if err = dcRemoteClient.Patch(ctx, dc, patch); err != nil {
return result.Error(fmt.Errorf("failed to add %s annotation to dc: %v", cassdcapi.DecommissionOnDeleteAnnotation, err))
}
}

if err = dcRemoteClient.Delete(ctx, dc); err != nil && !errors.IsNotFound(err) {
return result.Error(fmt.Errorf("failed to delete CassandraDatacenter (%s): %v", dcName, err))
}
logger.Info("Deleted CassandraDatacenter", "CassandraDatacenter", utils.GetKey(dc))
// There is no need to requeue here. Reconciliation will be trigger by updates made by cass-operator.
return result.Done()
}

func (r *K8ssandraClusterReconciler) findStargateForDeletion(
Expand Down
3 changes: 2 additions & 1 deletion controllers/k8ssandra/contact_points_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package k8ssandra

import (
"context"

"github.com/go-logr/logr"
cassdcapi "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
api "github.com/k8ssandra/k8ssandra-operator/apis/k8ssandra/v1alpha1"
Expand Down Expand Up @@ -82,7 +83,7 @@ func (r *K8ssandraClusterReconciler) loadAllPodsEndpoints(
func contactPointsServiceKey(kc *api.K8ssandraCluster, dc *cassdcapi.CassandraDatacenter) client.ObjectKey {
return types.NamespacedName{
Namespace: kc.Namespace,
Name: kc.SanitizedName() + "-" + dc.SanitizedName() + "-contact-points-service",
Name: kc.SanitizedName() + "-" + dc.LabelResourceName() + "-contact-points-service",
}
}

Expand Down
12 changes: 9 additions & 3 deletions controllers/k8ssandra/datacenters.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (r *K8ssandraClusterReconciler) reconcileDatacenters(ctx context.Context, k
return result.Error(fmt.Errorf("CassandraDatacenter %s has cluster name %s, but expected %s. Cluster name cannot be changed in an existing cluster", dcKey, actualDc.Spec.ClusterName, cassClusterName)), actualDcs
}

r.setStatusForDatacenter(kc, actualDc)
r.setStatusForDatacenter(kc, actualDc, dcConfig.K8sContext)

r.reconcileContactPointsService(ctx, kc, actualDc, remoteClient, dcLogger)

Expand Down Expand Up @@ -309,7 +309,7 @@ func (r *K8ssandraClusterReconciler) reconcileDatacenters(ctx context.Context, k
return result.Continue(), actualDcs
}

func (r *K8ssandraClusterReconciler) setStatusForDatacenter(kc *api.K8ssandraCluster, dc *cassdcapi.CassandraDatacenter) {
func (r *K8ssandraClusterReconciler) setStatusForDatacenter(kc *api.K8ssandraCluster, dc *cassdcapi.CassandraDatacenter, targetContext string) {
if len(kc.Status.Datacenters) == 0 {
kc.Status.Datacenters = make(map[string]api.K8ssandraStatus, 0)
}
Expand All @@ -318,9 +318,15 @@ func (r *K8ssandraClusterReconciler) setStatusForDatacenter(kc *api.K8ssandraClu

if found {
dc.Status.DeepCopyInto(kdcStatus.Cassandra)
if kdcStatus.ContextName != targetContext {
// This is pretty fatal situation if it happens to actually change the context, but for updates from previous versions we need it
kdcStatus.ContextName = targetContext
}
kc.Status.Datacenters[dc.Name] = kdcStatus
} else {
kc.Status.Datacenters[dc.Name] = api.K8ssandraStatus{
Cassandra: dc.Status.DeepCopy(),
ContextName: targetContext,
Cassandra: dc.Status.DeepCopy(),
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions controllers/k8ssandra/reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package k8ssandra
import (
"context"
"fmt"

"github.com/go-logr/logr"
cassdcapi "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
api "github.com/k8ssandra/k8ssandra-operator/apis/k8ssandra/v1alpha1"
Expand Down Expand Up @@ -242,11 +243,8 @@ func (r *K8ssandraClusterReconciler) setStatusForReaper(kc *api.K8ssandraCluster

func (r *K8ssandraClusterReconciler) removeReaperStatus(kc *api.K8ssandraCluster, dcName string) {
if kdcStatus, found := kc.Status.Datacenters[dcName]; found {
kc.Status.Datacenters[dcName] = api.K8ssandraStatus{
Reaper: nil,
Cassandra: kdcStatus.Cassandra.DeepCopy(),
Stargate: kdcStatus.Stargate.DeepCopy(),
}
kdcStatus.Reaper = nil
kc.Status.Datacenters[dcName] = kdcStatus
}
}

Expand Down
Loading
Loading