From 364276163c0fba981691c4a26b2bfd61132d7dc7 Mon Sep 17 00:00:00 2001 From: Thomas Krampl Date: Tue, 2 Jul 2024 11:44:20 +0200 Subject: [PATCH] azure/group: when deleting group, consider 404 success Co-authored-by: Christer Edvartsen --- internal/azureclient/azureclient.go | 4 ++++ internal/azureclient/azureclient_test.go | 14 ++++++++++++++ internal/reconcilers/manager.go | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/internal/azureclient/azureclient.go b/internal/azureclient/azureclient.go index 7e8cc8b..cb54519 100644 --- a/internal/azureclient/azureclient.go +++ b/internal/azureclient/azureclient.go @@ -283,6 +283,10 @@ func (s *client) DeleteGroup(ctx context.Context, grpID uuid.UUID) error { } defer resp.Body.Close() + if resp.StatusCode == http.StatusNotFound { + return nil + } + if resp.StatusCode != http.StatusNoContent { body, _ := io.ReadAll(resp.Body) return fmt.Errorf("remove azure group with ID: %q: %q: %q", grpID, resp.Status, string(body)) diff --git a/internal/azureclient/azureclient_test.go b/internal/azureclient/azureclient_test.go index a4fcdc7..d16da35 100644 --- a/internal/azureclient/azureclient_test.go +++ b/internal/azureclient/azureclient_test.go @@ -706,4 +706,18 @@ func Test_DeleteGroup(t *testing.T) { t.Errorf("Expected error to contain %q, got %q", contains, err) } }) + + t.Run("404 is considered OK", func(t *testing.T) { + httpClient := test.NewTestHttpClient( + func(req *http.Request) *http.Response { + return test.Response("404 Not Found", "{}") + }, + ) + + client := azureclient.New(httpClient) + err := client.DeleteGroup(ctx, grpID) + if err != nil { + t.Fatalf("Expected no error, got %v", err) + } + }) } diff --git a/internal/reconcilers/manager.go b/internal/reconcilers/manager.go index af1d0b3..cd1ca88 100644 --- a/internal/reconcilers/manager.go +++ b/internal/reconcilers/manager.go @@ -171,7 +171,7 @@ func (m *Manager) ListenForEvents(ctx context.Context) { if err == nil || errors.Is(err, context.Canceled) { // Receive will return nil error when canceled return - } else if err != nil { + } else { m.log.WithError(err).Error("error while receiving pubsub message") }