slimtoolkit/slim · error

couldn't find workload in cluster

Error message

couldn't find workload in cluster

What it means

findInCluster collects workload infos (pod/deployment/etc.) matching the given target in the cluster. If the query returns zero infos, nothing matching the workload spec exists, so it fails with this error.

Source

Thrown at pkg/app/master/kubernetes/workload.go:180

func (f *WorkloadFinder) findInCluster(target config.KubernetesTarget) (*resource.Info, error) {
	namespace := target.Namespace
	if namespace == "" {
		namespace = namespaceDefault
	}

	infos, err := f.resourceBuilderFn().
		WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
		NamespaceParam(namespace).
		SingleResourceType().
		ResourceTypeOrNameArgs(true, target.Workload).
		Do().
		Infos()
	if err != nil {
		return nil, err
	}

	if len(infos) == 0 {
		return nil, errors.New("couldn't find workload in cluster")
	}
	if len(infos) > 1 {
		return nil, errors.New("couldn't unambiguously identify workload in cluster")
	}

	return infos[0], nil
}

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Verify namespace and workload name are correct (kubectl get all -n <ns>)
  2. Check the kubeconfig context points at the intended cluster
  3. Deploy/start the target workload before running the tool

Example fix

// before
client.FindInCluster(ctx, "my-app", "default")
// after
client.FindInCluster(ctx, "my-app", "staging") // correct namespace
Defensive patterns

Strategy: validation

Validate before calling

deps, _ := clientset.AppsV1().Deployments(ns).List(ctx, metav1.ListOptions{})
found := false
for _, d := range deps.Items { if d.Name == workload { found = true } }
if !found { return fmt.Errorf("workload %s not found in namespace %s", workload, ns) }

Try / catch

info, err := findInCluster(ctx, target)
if err != nil && strings.Contains(err.Error(), "couldn't find workload") {
  return fmt.Errorf("check namespace/name and cluster context: %w", err)
}

Prevention

When it happens

Trigger: Calling findInCluster when no resource in the cluster matches the given workload name/namespace/selector — e.g. wrong namespace or typo'd workload name.

Common situations: Targeting a namespace that doesn't contain the workload; the workload was deleted or never deployed; kubeconfig pointing at the wrong cluster/context.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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