server: deletions of intentions by name using the intention API is now idempotent (#9278)
Restoring a behavior inadvertently changed while fixing #9254
This commit is contained in:
parent
7a21bd7720
commit
42dea6f01e
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:improvement
|
||||||
|
server: deletions of intentions by name using the intention API is now idempotent
|
||||||
|
```
|
|
@ -413,9 +413,7 @@ func (s *Intention) computeApplyChangesDelete(
|
||||||
return nil, fmt.Errorf("Intention lookup failed: %v", err)
|
return nil, fmt.Errorf("Intention lookup failed: %v", err)
|
||||||
}
|
}
|
||||||
if ixn == nil {
|
if ixn == nil {
|
||||||
src := structs.NewServiceName(exactIxn.SourceName, exactIxn.SourceEnterpriseMeta())
|
return nil, nil // by-name deletions are idempotent
|
||||||
dst := structs.NewServiceName(exactIxn.DestinationName, exactIxn.DestinationEnterpriseMeta())
|
|
||||||
return nil, fmt.Errorf("Cannot delete non-existent intention: source=%q, destination=%q", src.String(), dst.String())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &structs.IntentionMutation{
|
return &structs.IntentionMutation{
|
||||||
|
|
|
@ -653,14 +653,14 @@ func TestIntentionApply_WithoutIDs(t *testing.T) {
|
||||||
require.Equal(t, expect, entry)
|
require.Equal(t, expect, entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete a non existent intention should return an error
|
// Delete a non existent intention should act like it did work
|
||||||
testutil.RequireErrorContains(t, opApply(&structs.IntentionRequest{
|
require.NoError(t, opApply(&structs.IntentionRequest{
|
||||||
Op: structs.IntentionOpDelete,
|
Op: structs.IntentionOpDelete,
|
||||||
Intention: &structs.Intention{
|
Intention: &structs.Intention{
|
||||||
SourceName: "ghost",
|
SourceName: "ghost",
|
||||||
DestinationName: "phantom",
|
DestinationName: "phantom",
|
||||||
},
|
},
|
||||||
}), "Cannot delete non-existent intention")
|
}))
|
||||||
|
|
||||||
// Delete the original
|
// Delete the original
|
||||||
require.NoError(t, opApply(&structs.IntentionRequest{
|
require.NoError(t, opApply(&structs.IntentionRequest{
|
||||||
|
|
|
@ -554,8 +554,8 @@ func TestIntentionDeleteExact(t *testing.T) {
|
||||||
|
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := a.srv.IntentionExact(resp, req)
|
obj, err := a.srv.IntentionExact(resp, req)
|
||||||
require.Nil(t, obj)
|
require.NoError(t, err) // by-name deletions are idempotent
|
||||||
testutil.RequireErrorContains(t, err, "Cannot delete non-existent intention")
|
require.Equal(t, true, obj)
|
||||||
})
|
})
|
||||||
|
|
||||||
exact := ixn.ToExact()
|
exact := ixn.ToExact()
|
||||||
|
@ -643,6 +643,18 @@ func TestIntentionSpecificDelete(t *testing.T) {
|
||||||
ixn := structs.TestIntention(t)
|
ixn := structs.TestIntention(t)
|
||||||
ixn.SourceName = "foo"
|
ixn.SourceName = "foo"
|
||||||
|
|
||||||
|
t.Run("cannot delete non-existent intention", func(t *testing.T) {
|
||||||
|
fakeID := generateUUID()
|
||||||
|
|
||||||
|
req, err := http.NewRequest("DELETE", "/v1/connect/intentions/"+fakeID, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
resp := httptest.NewRecorder()
|
||||||
|
obj, err := a.srv.IntentionSpecific(resp, req)
|
||||||
|
testutil.RequireErrorContains(t, err, "Cannot delete non-existent intention")
|
||||||
|
require.Nil(t, obj)
|
||||||
|
})
|
||||||
|
|
||||||
// Create an intention directly
|
// Create an intention directly
|
||||||
var reply string
|
var reply string
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue