Skip to content

Commit

Permalink
Move from annotation to .spec.readOnlyRootFilesystem property, add ru…
Browse files Browse the repository at this point in the history
…nAsNonRoot to default securityContext
  • Loading branch information
burmanm committed May 31, 2024
1 parent f908d1e commit 29c71d0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Changelog for Cass Operator, new PRs should update the `main / unreleased` secti

## unreleased

* [ENHANCEMENT] [#199](https://github.com/k8ssandra/cass-operator/issues/199) If .spec.readOnlyRootFilesystem is set, run the cassandra container with readOnlyRootFilesystem. Also, modify the default SecurityContext to mention runAsNonRoot: true

## v1.21.0

* [FEATURE] [#659](https://github.com/k8ssandra/cass-operator/issues/659) Add support for HCD serverType with versions 1.x.x. It will be deployed like Cassandra >= 4.1 for now.
Expand Down
4 changes: 4 additions & 0 deletions apis/cassandra/v1beta1/cassandradatacenter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ type CassandraDatacenterSpec struct {
// Use cautiously.
// +optional
DatacenterName string `json:"datacenterName,omitempty"`

// ReadOnlyRootFilesystem makes the cassandra container to be run with a read-only root filesystem. Currently only functional when used with the
// new k8ssandra-client config builder (Cassandra 4.1 and newer and HCD)
ReadOnlyRootFilesystem bool `json:"readOnlyRootFilesystem,omitempty"`
}

type NetworkingConfig struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8814,6 +8814,11 @@ spec:
- name
type: object
type: array
readOnlyRootFilesystem:
description: |-
ReadOnlyRootFilesystem makes the cassandra container to be run with a read-only root filesystem. Currently only functional when used with the
new k8ssandra-client config builder (Cassandra 4.1 and newer and HCD)
type: boolean
replaceNodes:
description: Deprecated Use CassandraTask replacenode to achieve correct
node replacement. A list of pod names that need to be replaced.
Expand Down
9 changes: 5 additions & 4 deletions pkg/reconciliation/construct_podtemplatespec.go
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ func buildContainers(dc *api.CassandraDatacenter, baseTemplate *corev1.PodTempla
}

func readOnlyFs(dc *api.CassandraDatacenter) bool {
return metav1.HasAnnotation(dc.ObjectMeta, "cassandra.datastax.com/readonly-fs")
return dc.Spec.ReadOnlyRootFilesystem && dc.UseClientImage()
}

func buildPodTemplateSpec(dc *api.CassandraDatacenter, rack api.Rack, addLegacyInternodeMount bool) (*corev1.PodTemplateSpec, error) {
Expand Down Expand Up @@ -836,9 +836,10 @@ func buildPodTemplateSpec(dc *api.CassandraDatacenter, rack api.Rack, addLegacyI
if baseTemplate.Spec.SecurityContext == nil {
var userID int64 = 999
baseTemplate.Spec.SecurityContext = &corev1.PodSecurityContext{
RunAsUser: &userID,
RunAsGroup: &userID,
FSGroup: &userID,
RunAsUser: &userID,
RunAsGroup: &userID,
FSGroup: &userID,
RunAsNonRoot: ptr.To[bool](true),
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/testdata/default-two-rack-two-node-dc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ spec:
serverVersion: "4.0.10"
managementApiAuth:
insecure: {}
readOnlyRootFilesystem: true
size: 2
storageConfig:
cassandraDataVolumeClaimSpec:
Expand Down

0 comments on commit 29c71d0

Please sign in to comment.