diff --git a/ssa/errors/errors.go b/ssa/errors/errors.go index 18c8de74..dfbb528d 100644 --- a/ssa/errors/errors.go +++ b/ssa/errors/errors.go @@ -52,7 +52,7 @@ func (e *DryRunErr) Error() string { } if apierrors.IsNotFound(e.Unwrap()) { - if e.involvedObject.GetNamespace() != "" { + if e.involvedObject.GetNamespace() == "" { return fmt.Sprintf("%s namespace not specified: %s", utils.FmtUnstructured(e.involvedObject), e.Unwrap().Error()) } return fmt.Sprintf("%s not found: %s", utils.FmtUnstructured(e.involvedObject), e.Unwrap().Error()) diff --git a/ssa/manager_apply_test.go b/ssa/manager_apply_test.go index ffa95dec..b7c49ed4 100644 --- a/ssa/manager_apply_test.go +++ b/ssa/manager_apply_test.go @@ -949,6 +949,26 @@ func TestApply_Cleanup_Exclusions(t *testing.T) { }) } +func TestApply_MissingNamespaceErr(t *testing.T) { + timeout := 10 * time.Second + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + id := generateName("err") + objects, err := readManifest("testdata/test1.yaml", id) + if err != nil { + t.Fatal(err) + } + + _, configMap := getFirstObject(objects, "ConfigMap", id) + unstructured.RemoveNestedField(configMap.Object, "metadata", "namespace") + + _, err = manager.ApplyAllStaged(ctx, []*unstructured.Unstructured{configMap}, DefaultApplyOptions()) + if !strings.Contains(err.Error(), "namespace not specified") { + t.Fatal("Expected namespace not specified error") + } +} + func containsItemString(s []string, e string) bool { for _, a := range s { if a == e {