Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssa: Restore namespace not specified error handing #720

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ssa/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
20 changes: 20 additions & 0 deletions ssa/manager_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading