Skip to content

Commit

Permalink
Add support for priorityClassName (fixes #1034) (#1432)
Browse files Browse the repository at this point in the history
  • Loading branch information
olim7t authored Dec 17, 2024
1 parent 75c9f23 commit d00a94b
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG/CHANGELOG-1.21.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions apis/k8ssandra/v1alpha1/k8ssandracluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
8 changes: 8 additions & 0 deletions charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions pkg/cassandra/datacenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions pkg/cassandra/datacenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d00a94b

Please sign in to comment.