Skip to content

Commit

Permalink
backport of commit e39b39e
Browse files Browse the repository at this point in the history
  • Loading branch information
mikenomitch authored Dec 15, 2023
1 parent ca55c26 commit 2d9ece7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/19483.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
namespaces: Failed delete calls no longer return success codes
```
1 change: 1 addition & 0 deletions nomad/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,7 @@ func (n *nomadFSM) applyNamespaceDelete(buf []byte, index uint64) interface{} {

if err := n.state.DeleteNamespaces(index, req.Namespaces); err != nil {
n.logger.Error("DeleteNamespaces failed", "error", err)
return err
}

return nil
Expand Down
23 changes: 23 additions & 0 deletions nomad/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3307,6 +3307,29 @@ func TestFSM_DeleteNamespaces(t *testing.T) {
assert.Nil(out)
}

func TestFSM_DeleteNamespaces_ErrorSurfacing(t *testing.T) {
ci.Parallel(t)
fsm := testFSM(t)

ns1 := mock.Namespace()
// force a failure by making this the default
ns1.Name = "default"
must.NoError(t, fsm.State().UpsertNamespaces(1000, []*structs.Namespace{ns1}))

req := structs.NamespaceDeleteRequest{
Namespaces: []string{ns1.Name},
}

buf, err := structs.Encode(structs.NamespaceDeleteRequestType, req)
must.NoError(t, err)
resp := fsm.Apply(makeLog(buf))
must.NotNil(t, resp)

err, ok := resp.(error)
must.True(t, ok, must.Sprintf("resp not of error type: %T %v", resp, resp))
must.ErrorContains(t, err, "default namespace can not be deleted")
}

func TestFSM_SnapshotRestore_Namespaces(t *testing.T) {
ci.Parallel(t)
// Add some state
Expand Down

0 comments on commit 2d9ece7

Please sign in to comment.