slimtoolkit/slim · error

no containers

Error message

no containers

What it means

When no explicit target container is given, HandleKubernetesRuntime falls back to the first container in pod.Spec.Containers. If the pod spec has zero containers, there is nothing to attach to and it fails with 'no containers'.

Source

Thrown at pkg/app/master/command/debug/handle_kubernetes_runtime.go:218

				}
				if info.ExitMessage != "" {
					outParams["exit.message"] = info.ExitMessage
				}
			}

			xc.Out.Info("debug.session", outParams)
		}

		return
	}

	if commandParams.TargetRef == "" {
		logger.Debug("no explicit target container... pick one")
		//TODO: improve this logic (to also check for the default container)
		if len(pod.Spec.Containers) > 0 {
			commandParams.TargetRef = pod.Spec.Containers[0].Name
		} else {
			xc.FailOn(fmt.Errorf("no containers"))
		}
	}

	if commandParams.ActionShowSessionLogs {
		//list sessions before we pick a target container,
		//so we can list all debug session for the selected pod
		xc.Out.State("action.show_session_logs",
			ovars{
				"namespace": nsName,
				"pod":       podName,
				"target":    commandParams.TargetRef,
				"session":   commandParams.Session})

		if commandParams.Session == "" {
			result, err := listK8sDebugContainers(ctx, api, nsName, podName, commandParams.TargetRef, false)
			if err != nil {
				logger.WithError(err).Error("listK8sDebugContainers")
				xc.FailOn(err)

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Specify the target container explicitly via the target ref instead of relying on auto-pick
  2. Verify the pod manifest actually defines spec.containers entries (kubectl get pod -o jsonpath='{.spec.containers[*].name}')
  3. If only initContainers/ephemeral containers exist, recreate the pod with at least one regular container

Example fix

// before
debug --target pod/my-pod                // auto-pick fails: no containers
// after
debug --target pod/my-pod --container my-container
Defensive patterns

Strategy: type-guard

Validate before calling

pod, _ := clientset.CoreV1().Pods(ns).Get(ctx, name, metav1.GetOptions{})
if len(pod.Spec.Containers) == 0 {
    return fmt.Errorf("pod %s/%s has no containers; pass an explicit target", ns, name)
}

Type guard

func hasContainers(p *corev1.Pod) bool { return p != nil && len(p.Spec.Containers) > 0 }

Try / catch

err := HandleKubernetesRuntime(...)
if err != nil && strings.Contains(err.Error(), "no containers") {
    return fmt.Errorf("pod has no regular containers; specify a target container or fix the pod spec: %w", err)
}

Prevention

When it happens

Trigger: Running the kubernetes runtime debug command without a --target container while the resolved pod's spec.containers array is empty — e.g. ephemeral/sidecar-only specs, truncated or bogus pod manifests, or a pod created with only initContainers.

Common situations: Targeting a pod whose normal containers were removed by a controller mutation, custom/edge-case workloads with only ephemeral or init containers, or stale/corrupted manifests from an operator.

Related errors


AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31). Data as JSON: /api/errors/41dbe528468aacea. Report an issue: GitHub.