diff --git a/CHANGELOG/CHANGELOG-1.21.md b/CHANGELOG/CHANGELOG-1.21.md index dcd092818..ef7431b9f 100644 --- a/CHANGELOG/CHANGELOG-1.21.md +++ b/CHANGELOG/CHANGELOG-1.21.md @@ -18,3 +18,4 @@ When cutting a new release, update the `unreleased` heading to the tag being gen * [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` +* [FEATURE] [#1034](https://github.com/k8ssandra/k8ssandra-operator/issues/1034) Add support for priorityClassName diff --git a/apis/k8ssandra/v1alpha1/k8ssandracluster_types.go b/apis/k8ssandra/v1alpha1/k8ssandracluster_types.go index 1c52b9056..3d71c44fa 100644 --- a/apis/k8ssandra/v1alpha1/k8ssandracluster_types.go +++ b/apis/k8ssandra/v1alpha1/k8ssandracluster_types.go @@ -425,6 +425,10 @@ type DatacenterOptions struct { // +optional PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"` + // PodPriorityClassName defines the priority class name for the Cassandra pods. + // +optional + PodPriorityClassName string `json:"podPriorityClassName,omitempty"` + // ManagementApiAuth defines the authentication settings for the management API in the Cassandra pods. // +optional ManagementApiAuth *cassdcapi.ManagementApiAuthConfig `json:"managementApiAuth,omitempty"` diff --git a/charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml b/charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml index e95dada78..c9f76a440 100644 --- a/charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml +++ b/charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml @@ -9556,6 +9556,10 @@ spec: type: string type: object x-kubernetes-map-type: atomic + podPriorityClassName: + description: PodPriorityClassName defines the priority class + name for the Cassandra pods. + type: string podSecurityContext: description: PodSecurityContext defines the security context for the Cassandra pods. @@ -22018,6 +22022,10 @@ spec: configuration. This is only useful when PerNodeConfigMapRef is set. The default is "mikefarah/yq:4". type: string + podPriorityClassName: + description: PodPriorityClassName defines the priority class name + for the Cassandra pods. + type: string podSecurityContext: description: PodSecurityContext defines the security context for the Cassandra pods. diff --git a/config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml b/config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml index 3cb1f2a13..2f7151c3d 100644 --- a/config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml +++ b/config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml @@ -9494,6 +9494,10 @@ spec: type: string type: object x-kubernetes-map-type: atomic + podPriorityClassName: + description: PodPriorityClassName defines the priority class + name for the Cassandra pods. + type: string podSecurityContext: description: PodSecurityContext defines the security context for the Cassandra pods. @@ -21956,6 +21960,10 @@ spec: configuration. This is only useful when PerNodeConfigMapRef is set. The default is "mikefarah/yq:4". type: string + podPriorityClassName: + description: PodPriorityClassName defines the priority class name + for the Cassandra pods. + type: string podSecurityContext: description: PodSecurityContext defines the security context for the Cassandra pods. diff --git a/pkg/cassandra/datacenter.go b/pkg/cassandra/datacenter.go index 78d24dd6b..74cf72d4a 100644 --- a/pkg/cassandra/datacenter.go +++ b/pkg/cassandra/datacenter.go @@ -374,6 +374,7 @@ func Coalesce(clusterName string, clusterTemplate *api.CassandraClusterTemplate, dcConfig.DseWorkloads = mergedOptions.DseWorkloads dcConfig.ManagementApiAuth = mergedOptions.ManagementApiAuth dcConfig.PodTemplateSpec.Spec.SecurityContext = mergedOptions.PodSecurityContext + dcConfig.PodTemplateSpec.Spec.PriorityClassName = mergedOptions.PodPriorityClassName dcConfig.PerNodeInitContainerImage = mergedOptions.PerNodeConfigInitContainerImage dcConfig.ServiceAccount = mergedOptions.ServiceAccount dcConfig.ReadOnlyRootFilesystem = mergedOptions.ReadOnlyRootFilesystem diff --git a/pkg/cassandra/datacenter_test.go b/pkg/cassandra/datacenter_test.go index 3dea22812..2cdf18be3 100644 --- a/pkg/cassandra/datacenter_test.go +++ b/pkg/cassandra/datacenter_test.go @@ -1281,6 +1281,46 @@ func TestCoalesce(t *testing.T) { }, }, }, + { + name: "Set priority class name at cluster level", + clusterTemplate: &api.CassandraClusterTemplate{ + DatacenterOptions: api.DatacenterOptions{ + PodPriorityClassName: "mock-priority", + }, + }, + dcTemplate: &api.CassandraDatacenterTemplate{}, + want: &DatacenterConfig{ + McacEnabled: true, + PodTemplateSpec: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{{Name: "cassandra"}}, + PriorityClassName: "mock-priority", + }, + }, + }, + }, + { + name: "Override priority class name", + clusterTemplate: &api.CassandraClusterTemplate{ + DatacenterOptions: api.DatacenterOptions{ + PodPriorityClassName: "ignored-priority", + }, + }, + dcTemplate: &api.CassandraDatacenterTemplate{ + DatacenterOptions: api.DatacenterOptions{ + PodPriorityClassName: "mock-priority", + }, + }, + want: &DatacenterConfig{ + McacEnabled: true, + PodTemplateSpec: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{{Name: "cassandra"}}, + PriorityClassName: "mock-priority", + }, + }, + }, + }, } for _, tc := range tests { @@ -1376,6 +1416,17 @@ func TestNewDatacenter_ServiceAccount(t *testing.T) { assert.Equal(t, template.ServiceAccount, dc.Spec.ServiceAccountName) } +func TestNewDatacenter_PodPriorityClassName(t *testing.T) { + template := GetDatacenterConfig() + template.PodTemplateSpec.Spec.PriorityClassName = "mock-priority" + dc, err := NewDatacenter( + types.NamespacedName{Name: "testdc", Namespace: "test-namespace"}, + &template, + ) + assert.NoError(t, err) + assert.Equal(t, "mock-priority", dc.Spec.PodTemplateSpec.Spec.PriorityClassName) +} + // TestValidateCoalesced_Fail_NoStorageConfig tests that NewDatacenter fails when no storage config is provided. func TestValidateDatacenterConfig_Fail_NoStorageConfig(t *testing.T) { template := GetDatacenterConfig()