{"record":{"id":"64eed14e7261555a","repo":"slimtoolkit/slim","slug":"couldn-t-find-workload-in-cluster","errorCode":null,"errorMessage":"couldn't find workload in cluster","messagePattern":"couldn't find workload in cluster","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/master/kubernetes/workload.go","lineNumber":180,"sourceCode":"func (f *WorkloadFinder) findInCluster(target config.KubernetesTarget) (*resource.Info, error) {\n\tnamespace := target.Namespace\n\tif namespace == \"\" {\n\t\tnamespace = namespaceDefault\n\t}\n\n\tinfos, err := f.resourceBuilderFn().\n\t\tWithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).\n\t\tNamespaceParam(namespace).\n\t\tSingleResourceType().\n\t\tResourceTypeOrNameArgs(true, target.Workload).\n\t\tDo().\n\t\tInfos()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif len(infos) == 0 {\n\t\treturn nil, errors.New(\"couldn't find workload in cluster\")\n\t}\n\tif len(infos) > 1 {\n\t\treturn nil, errors.New(\"couldn't unambiguously identify workload in cluster\")\n\t}\n\n\treturn infos[0], nil\n}\n","sourceCodeStart":162,"sourceCodeEnd":188,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/master/kubernetes/workload.go#L162-L188","documentation":"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.","triggerScenarios":"Calling findInCluster when no resource in the cluster matches the given workload name/namespace/selector — e.g. wrong namespace or typo'd workload name.","commonSituations":"Targeting a namespace that doesn't contain the workload; the workload was deleted or never deployed; kubeconfig pointing at the wrong cluster/context.","solutions":["Verify namespace and workload name are correct (kubectl get all -n <ns>)","Check the kubeconfig context points at the intended cluster","Deploy/start the target workload before running the tool"],"exampleFix":"// before\nclient.FindInCluster(ctx, \"my-app\", \"default\")\n// after\nclient.FindInCluster(ctx, \"my-app\", \"staging\") // correct namespace","handlingStrategy":"validation","validationCode":"deps, _ := clientset.AppsV1().Deployments(ns).List(ctx, metav1.ListOptions{})\nfound := false\nfor _, d := range deps.Items { if d.Name == workload { found = true } }\nif !found { return fmt.Errorf(\"workload %s not found in namespace %s\", workload, ns) }","typeGuard":null,"tryCatchPattern":"info, err := findInCluster(ctx, target)\nif err != nil && strings.Contains(err.Error(), \"couldn't find workload\") {\n  return fmt.Errorf(\"check namespace/name and cluster context: %w\", err)\n}","preventionTips":["Verify with kubectl get -n <ns> before running","Confirm the kubeconfig context targets the right cluster","Ensure the workload is deployed before attaching"],"tags":["kubernetes","workload","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}