Open source
Contributing security contexts and namespace scoping to the Apache Doris operator
Two merged pull requests to apache/doris-operator in Go: per-component pod and container security contexts, and scoping the operator to one namespace.
- 2pull requests merged into Apache
- 4Doris components covered: FE, BE, CN, Broker
The problem
The Doris operator turns a DorisCluster resource into the StatefulSets for each Doris component: FE, BE, CN and Broker. On a locked-down cluster like OpenShift, those pods need real security contexts, and the operator only offered a single fsGroup setting. It also watched every namespace in the cluster, with no way to keep it to one.
What I built
- Two new optional fields on each component’s
BaseSpec:securityContextfor the pod andcontainerSecurityContextfor its containers, replacing the oldfsGroupoption - Pod templates that take the right component’s context, and an
ApplySecurityContexthelper that fills it in on every container that doesn’t already set one - Regenerated deepcopy code, CRDs, the Helm chart’s CRDs and the API docs to match
- A
--namespaceflag, passed into the controller-runtime manager, so the operator can reconcile a single namespace. It still defaults to the whole cluster
Both were merged in April 2024.
- DorisClustersecurityContext per component
- Codegendeepcopy, CRDs, Helm
- Pod templatepod-level context
- ContainersApplySecurityContext
- Manager--namespace scope
The change in pseudocode
for component in [FE, BE, CN, Broker]:
pod.SecurityContext = cluster.Spec[component].SecurityContext
containers = build_containers(component)
containers = ApplySecurityContext(containers, cluster.Spec[component].ContainerSecurityContext)
func ApplySecurityContext(containers, sc):
if sc == nil: return containers
for c in containers:
if c.SecurityContext == nil: c.SecurityContext = sc
else: log("container already has a security context, not overwriting it")
return containers
main():
namespace = flag("namespace", default = NamespaceAll)
manager = NewManager(Options{Namespace: namespace})
Why it matters
We run Doris on OpenShift, which won’t schedule pods that don’t meet its security policies. Fixing it upstream meant everyone running the operator on a stricter cluster got the same options, and we didn’t have to carry the change in a fork.