Skip to content

Commit cac0443

Browse files
committed
[K8S-534] redpanda: remove deprecated securityContext field(s)
Prior to this commit `securityContext` was an amalgam of both pod and container level security contexts that was haphazardly cherry-picked apart and applied to all pods and containers. This commit removes such fields in favor of using `podTemplate` and Kubernetes' default behavior of inheriting the Pod's SecurityContext when not specified on the individual container.
1 parent de4f039 commit cac0443

39 files changed

+5671
-1964
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
project: charts/redpanda
2+
kind: Added
3+
body: |-
4+
Added a chart wide `podTemplate` field which may be used to control Pod attributes chart wide.
5+
6+
This field has a lower precedence than `statefulset.podTemplate` and
7+
`post_install_job.podTemplate` but will still be merged with them.
8+
time: 2025-03-28T15:34:10.945119-04:00
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
project: charts/redpanda
2+
kind: Changed
3+
body: The name of the container running redpanda is now always set to `redpanda`.
4+
time: 2025-03-28T15:57:56.677782-04:00
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
project: charts/redpanda
2+
kind: Removed
3+
body: |-
4+
`statefulset.securityContext`, `statefulset.sideCars.configWatcher.securityContext` have been removed.
5+
6+
These fields previously served as both PodSecurityContext and SecurityContext
7+
across the entire chart which led to confusing semantics that couldn't be
8+
fixed without breaking backwards compatiblity.
9+
10+
The top level `podTemplate` field may be used to control
11+
PodSecurityContexts and SecurityContexts across the chart.
12+
time: 2025-03-28T15:37:46.85088-04:00

charts/redpanda/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and is generated by [Changie](https://github.com/miniscruff/changie).
66

77

88
## Unreleased
9+
### Added
10+
* Added a chart wide `podTemplate` field which may be used to control Pod attributes chart wide.
11+
12+
This field has a lower precedence than `statefulset.podTemplate` and
13+
`post_install_job.podTemplate` but will still be merged with them.
914
### Changed
1015
* Promoted the config-watcher sidecar into a real go binary that handles user management and simplifies cluster health checks so they no longer fail when the sole issue is that other nodes in the cluster are unavailable. Additionally the new sidecar subsumes the behavior of the `statefulset.sideCars.controllers` stanza which should now be specified via their own `enabled` flags.
1116
* `clusterDomain` now defaults to `cluster.local.` (A trialing `.` has been added) and the chart no longer adds trailing `.`'s to internal domains.
@@ -25,12 +30,21 @@ and is generated by [Changie](https://github.com/miniscruff/changie).
2530
Any unexpected values will result in a validation error,previously they would
2631
have been ignored.
2732
* Update Console depedency to latest version with breaking change. Please visit Console change-log.
33+
* The name of the container running redpanda is now always set to `redpanda`.
2834
### Removed
2935
* Connectors sub-chart integration.
3036

3137
The connectors chart may still be deployed separately, though it is not
3238
officially support. If possible, it is recommended to migrate to redpanda
3339
connect.
40+
* `statefulset.securityContext`, `statefulset.sideCars.configWatcher.securityContext` have been removed.
41+
42+
These fields previously served as both PodSecurityContext and SecurityContext
43+
across the entire chart which led to confusing semantics that couldn't be
44+
fixed without breaking backwards compatiblity.
45+
46+
The top level `podTemplate` field may be used to control
47+
PodSecurityContexts and SecurityContexts across the chart.
3448
### Fixed
3549
* Reverse order of applying resources to first create ClusterRole and then ClusterRoleBinding.
3650
When Redpanda custom resource has enabled RBAC the reconciliation was blocked due

charts/redpanda/README.md

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,28 @@ Node selection constraints for scheduling Pods, can override this for StatefulSe
530530

531531
**Default:** `{}`
532532

533+
### [podTemplate.annotations](https://artifacthub.io/packages/helm/redpanda-data/redpanda?modal=values&path=podTemplate.annotations)
534+
535+
Annotations to apply (or overwrite the default) to all Pods of this Chart.
536+
537+
**Default:** `{}`
538+
539+
### [podTemplate.labels](https://artifacthub.io/packages/helm/redpanda-data/redpanda?modal=values&path=podTemplate.labels)
540+
541+
Labels to apply (or overwrite the default) to all Pods of this Chart.
542+
543+
**Default:** `{}`
544+
545+
### [podTemplate.spec](https://artifacthub.io/packages/helm/redpanda-data/redpanda?modal=values&path=podTemplate.spec)
546+
547+
A subset of Kubernetes' PodSpec type that will be merged into the PodSpec of all Pods for this Chart. See [Merge Semantics](#merging-semantics) for details.
548+
549+
**Default:**
550+
551+
```
552+
{"securityContext":{"fsGroup":101,"fsGroupChangePolicy":"OnRootMismatch","runAsUser":101}}
553+
```
554+
533555
### [post_install_job.affinity](https://artifacthub.io/packages/helm/redpanda-data/redpanda?modal=values&path=post_install_job.affinity)
534556

535557
**Default:** `{}`
@@ -935,16 +957,6 @@ Number of Redpanda brokers (Redpanda Data recommends setting this to the number
935957

936958
**Default:** `3`
937959

938-
### [statefulset.securityContext](https://artifacthub.io/packages/helm/redpanda-data/redpanda?modal=values&path=statefulset.securityContext)
939-
940-
DEPRECATED: Prefer to use podTemplate.spec.securityContext or podTemplate.spec.containers[0].securityContext.
941-
942-
**Default:**
943-
944-
```
945-
{"fsGroup":101,"fsGroupChangePolicy":"OnRootMismatch","runAsUser":101}
946-
```
947-
948960
### [statefulset.sideCars.brokerDecommissioner.decommissionAfter](https://artifacthub.io/packages/helm/redpanda-data/redpanda?modal=values&path=statefulset.sideCars.brokerDecommissioner.decommissionAfter)
949961

950962
**Default:** `"60s"`
@@ -973,12 +985,6 @@ DEPRECATED: Please use statefulset.sideCars.resources
973985

974986
**Default:** `{}`
975987

976-
### [statefulset.sideCars.configWatcher.securityContext](https://artifacthub.io/packages/helm/redpanda-data/redpanda?modal=values&path=statefulset.sideCars.configWatcher.securityContext)
977-
978-
DEPRECATED: Please use statefulset.sideCars.securityContext
979-
980-
**Default:** `{}`
981-
982988
### [statefulset.sideCars.controllers](https://artifacthub.io/packages/helm/redpanda-data/redpanda?modal=values&path=statefulset.sideCars.controllers)
983989

984990
DEPRECATED: Please use statefulset.sideCars.brokerDecommissioner and statefulset.sideCars.pvcUnbinder

charts/redpanda/ci/34-security-contexts-novalues.yaml

Lines changed: 0 additions & 35 deletions
This file was deleted.

charts/redpanda/ci/38-post-install-upgrade-merges-novalues.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
# limitations under the License.
1515
---
1616
statefulset:
17-
securityContext:
18-
runAsUser: 1000
19-
runAsGroup: 1000
17+
podTemplate:
18+
spec:
19+
securityContext:
20+
runAsUser: 1000
21+
runAsGroup: 1000
2022

2123
tolerations:
2224
- key: "example-key"
@@ -40,9 +42,11 @@ affinity:
4042

4143

4244
post_install_job:
43-
securityContext:
44-
# This should override the default above
45-
runAsUser: 2000
45+
podTemplate:
46+
spec:
47+
securityContext:
48+
# This should override the default above
49+
runAsUser: 2000
4650

4751
resources:
4852
limits:

charts/redpanda/ci/38-post-install-upgrade-no-overrides-novalues.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
# limitations under the License.
1515
---
1616
statefulset:
17-
securityContext:
18-
runAsUser: 1000
19-
runAsGroup: 1000
17+
podTemplate:
18+
spec:
19+
securityContext:
20+
runAsUser: 1000
21+
runAsGroup: 1000
2022

2123
tolerations:
2224
- key: "example-key"

charts/redpanda/helpers.go

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -324,35 +324,6 @@ func CertSecretName(dot *helmette.Dot, certName string, cert *TLSCert) string {
324324
return fmt.Sprintf("%s-%s-cert", Fullname(dot), certName)
325325
}
326326

327-
// PodSecurityContext returns a subset of [corev1.PodSecurityContext] for the
328-
// redpanda Statefulset. It is also used as the default PodSecurityContext.
329-
func PodSecurityContext(dot *helmette.Dot) *corev1.PodSecurityContext {
330-
values := helmette.Unwrap[Values](dot.Values)
331-
332-
sc := ptr.Deref(values.Statefulset.PodSecurityContext, values.Statefulset.SecurityContext)
333-
334-
return &corev1.PodSecurityContext{
335-
FSGroup: sc.FSGroup,
336-
FSGroupChangePolicy: sc.FSGroupChangePolicy,
337-
}
338-
}
339-
340-
// ContainerSecurityContext returns a subset of [corev1.SecurityContext] for
341-
// the redpanda Statefulset. It is also used as the default
342-
// ContainerSecurityContext.
343-
func ContainerSecurityContext(dot *helmette.Dot) corev1.SecurityContext {
344-
values := helmette.Unwrap[Values](dot.Values)
345-
346-
sc := ptr.Deref(values.Statefulset.PodSecurityContext, values.Statefulset.SecurityContext)
347-
348-
return corev1.SecurityContext{
349-
RunAsUser: sc.RunAsUser,
350-
RunAsGroup: coalesce([]*int64{sc.RunAsGroup, sc.FSGroup}),
351-
AllowPrivilegeEscalation: coalesce([]*bool{sc.AllowPrivilegeEscalation, sc.AllowPriviledgeEscalation}),
352-
RunAsNonRoot: sc.RunAsNonRoot,
353-
}
354-
}
355-
356327
//nolint:stylecheck
357328
func RedpandaAtLeast_22_2_0(dot *helmette.Dot) bool {
358329
return redpandaAtLeast(dot, redpanda_22_2_0)
@@ -407,19 +378,6 @@ func cleanForK8s(in string) string {
407378
return strings.TrimSuffix(helmette.Trunc(63, in), "-")
408379
}
409380

410-
// coalesce returns the first non-nil pointer. This is distinct from helmette's
411-
// Coalesce which returns the first non-EMPTY pointer.
412-
// It accepts a slice as variadic methods are not currently supported in
413-
// gotohelm.
414-
func coalesce[T any](values []*T) *T {
415-
for _, v := range values {
416-
if v != nil {
417-
return v
418-
}
419-
}
420-
return nil
421-
}
422-
423381
// StrategicMergePatch is a half-baked implementation of Kubernetes' strategic
424382
// merge patch. It's closer to a merge patch with smart handling of lists
425383
// that's tailored to the values permitted by [PodTemplate].
@@ -428,7 +386,13 @@ func StrategicMergePatch(overrides PodTemplate, original corev1.PodTemplateSpec)
428386
// - No support for Directives
429387
// - List merging by key is handled on a case by case basis.
430388
// - Can't "unset" optional values in the original due to there being no
431-
// difference between *T being explicitly nil or not yet.
389+
// difference between *T being explicitly nil or not set.
390+
391+
// Nasty hack to work around mutability issues when using MergeTo on a
392+
// deeply nested object. gotohelm doesn't currently have a deepCopy method,
393+
// so we marshal to JSON and then unmarshal back into the same type.
394+
overridesClone := helmette.FromJSON(helmette.ToJSON(overrides))
395+
overrides = helmette.MergeTo[PodTemplate](overridesClone)
432396

433397
overrideSpec := overrides.Spec
434398
if overrideSpec == nil {

0 commit comments

Comments
 (0)