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:
R.B. Boyer 2021-01-04 11:27:00 -06:00 committed by GitHub
parent 7a21bd7720
commit 42dea6f01e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 8 deletions

3
.changelog/9278.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
server: deletions of intentions by name using the intention API is now idempotent
```

View File

@ -413,9 +413,7 @@ func (s *Intention) computeApplyChangesDelete(
return nil, fmt.Errorf("Intention lookup failed: %v", err)
}
if ixn == nil {
src := structs.NewServiceName(exactIxn.SourceName, exactIxn.SourceEnterpriseMeta())
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 nil, nil // by-name deletions are idempotent
}
return &structs.IntentionMutation{

View File

@ -653,14 +653,14 @@ func TestIntentionApply_WithoutIDs(t *testing.T) {
require.Equal(t, expect, entry)
}
// Delete a non existent intention should return an error
testutil.RequireErrorContains(t, opApply(&structs.IntentionRequest{
// Delete a non existent intention should act like it did work
require.NoError(t, opApply(&structs.IntentionRequest{
Op: structs.IntentionOpDelete,
Intention: &structs.Intention{
SourceName: "ghost",
DestinationName: "phantom",
},
}), "Cannot delete non-existent intention")
}))
// Delete the original
require.NoError(t, opApply(&structs.IntentionRequest{

View File

@ -554,8 +554,8 @@ func TestIntentionDeleteExact(t *testing.T) {
resp := httptest.NewRecorder()
obj, err := a.srv.IntentionExact(resp, req)
require.Nil(t, obj)
testutil.RequireErrorContains(t, err, "Cannot delete non-existent intention")
require.NoError(t, err) // by-name deletions are idempotent
require.Equal(t, true, obj)
})
exact := ixn.ToExact()
@ -643,6 +643,18 @@ func TestIntentionSpecificDelete(t *testing.T) {
ixn := structs.TestIntention(t)
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
var reply string
{