Skip to content

Commit

Permalink
Merge pull request #720 from fluxcd/fix-ssa-ns-error
Browse files Browse the repository at this point in the history
ssa: Restore `namespace not specified` error handing
  • Loading branch information
stefanprodan authored Jan 18, 2024
2 parents 6f62989 + 2635630 commit c2c9efe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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

0 comments on commit c2c9efe

Please sign in to comment.