All work

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.

Open source · Apache Software Foundation · 2024

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

Both were merged in April 2024.

  1. DorisClustersecurityContext per component
  2. Codegendeepcopy, CRDs, Helm
  3. Pod templatepod-level context
  4. ContainersApplySecurityContext
  5. Manager--namespace scope

The change in pseudocode

A sketch of the idea, not the production code.

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.

Stack

Links