apache/pulsar · critical · RuntimeException

Failed to create statefulset for function %s

Error message

Failed to create statefulset for function %s

What it means

KubernetesRuntime.submitStatefulSet() runs a retry Action to create the function's StatefulSet; if it does not succeed after retries, it throws RuntimeException naming the function. The function's pods cannot be scheduled without the StatefulSet.

Source

Thrown at pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/kubernetes/KubernetesRuntime.java:595

                                .success(false)
                                .errorMsg(errorMsg)
                                .build();
                    }

                    return Actions.ActionResult.builder().success(true).build();
                })
                .build();


        AtomicBoolean success = new AtomicBoolean(false);
        Actions.newBuilder()
                .addAction(createStatefulSet.toBuilder()
                        .onSuccess(ignored -> success.set(true))
                        .build())
                .run();

        if (!success.get()) {
            throw new RuntimeException(String.format("Failed to create statefulset for function %s", fqfn));
        }
    }


    public void deleteStatefulSet() throws InterruptedException {
        String statefulSetName = createJobName(instanceConfig.getFunctionDetails(), this.jobName);

        String fqfn = FunctionCommon.getFullyQualifiedName(instanceConfig.getFunctionDetails());
        Actions.Action deleteStatefulSet = Actions.Action.builder()
                .actionName(String.format("Deleting statefulset for function %s", fqfn))
                .numRetries(KubernetesRuntimeFactory.numRetries)
                .sleepBetweenInvocationsMs(KubernetesRuntimeFactory.sleepBetweenRetriesMs)
                .supplier(() -> {
                    try {
                        appsClient.deleteNamespacedStatefulSet(
                                statefulSetName,
                                jobNamespace)
                                .gracePeriodSeconds(gracePeriodSeconds)

View on GitHub (pinned to 820761864e)

Solutions

  1. Inspect the logged cause from the k8s client (connection, 403, 422 validation, quota).
  2. Verify RBAC allows creating statefulsets in the target namespace.
  3. Check namespace ResourceQuota and pod limits.
  4. Validate the function's image name, pull policy and secrets referenced in the statefulset spec.

Example fix

// before: quota exceeded
kubectl describe resourcequota -n <ns>
// after: raise quota or reduce requested cpu/memory in function config
Defensive patterns

Strategy: retry

Validate before calling

// before starting: check quota and RBAC
kubectl auth can-i create statefulsets.apps -n <ns> --as=system:serviceaccount:<ns>:<worker-sa>
kubectl describe resourcequota -n <ns>

Try / catch

try {
    kubernetesRuntime.start();
} catch (RuntimeException e) {
    if (e.getMessage().startsWith("Failed to create statefulset for function")) {
        log.error("StatefulSet creation failed; check quota, image validity, and RBAC", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: submitStatefulSet() called from start() when creating the StatefulSet via the k8s client fails on every attempt — API errors, invalid spec, quota exceeded, or RBAC denial.

Common situations: Resource quota exceeded in the namespace; invalid image name or pull secret; worker ServiceAccount lacking StatefulSet create permissions; API server connectivity problems.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/ed4f479ba6faaf1e. Report an issue: GitHub.