From b27efb246d0af960a1373a529220aeee4b13f250 Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Tue, 3 Oct 2023 17:20:40 +1300 Subject: [PATCH] Improve logging --- .../customizations/vault_extensions.go | 24 ++++++++++--------- .../testcommon/kube_per_test_context.go | 3 +++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/v2/api/keyvault/customizations/vault_extensions.go b/v2/api/keyvault/customizations/vault_extensions.go index c08449c74c2..e160c0d9f62 100644 --- a/v2/api/keyvault/customizations/vault_extensions.go +++ b/v2/api/keyvault/customizations/vault_extensions.go @@ -7,9 +7,9 @@ package customizations import ( "context" + "strings" keyvault "github.com/Azure/azure-service-operator/v2/api/keyvault/v1api20210401previewstorage" - resources "github.com/Azure/azure-service-operator/v2/api/resources/v1api20200601storage" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" @@ -66,12 +66,12 @@ func (ex *VaultExtension) ModifyARMResource( var createMode *string - switch *kv.Spec.Properties.CreateMode { - case CreateMode_CreateOrRecover: + if strings.EqualFold(*kv.Spec.Properties.CreateMode, CreateMode_CreateOrRecover) { mode := ex.handleCreateOrRecover(ctx, kv, armClient, kubeClient, resolver, log) createMode = &mode + } - case CreateMode_PurgeThenCreate: + if strings.EqualFold(*kv.Spec.Properties.CreateMode, CreateMode_PurgeThenCreate) { err := ex.handlePurgeThenCreate(ctx, kv, armClient, kubeClient, resolver, log) if err != nil { return nil, errors.Wrapf(err, "error purging soft-deleted KeyVault") @@ -108,16 +108,18 @@ func (ex *VaultExtension) handleCreateOrRecover( return CreateMode_Default } - log.Info( - "KeyVault reconciliation requested CreateOrRecover, setting CreateMode", - "KeyVault", kv.Name, - "Deleted KeyVault exists", exists) - + result := CreateMode_Default if exists { - return CreateMode_Recover + result = CreateMode_Recover } - return CreateMode_Default + log.Info( + "KeyVault reconciliation requested CreateOrRecover", + "KeyVault", kv.Name, + "Soft-deleted-KeyVault-exists", exists, + "createMode", result) + + return result } func (ex *VaultExtension) handlePurgeThenCreate( diff --git a/v2/internal/testcommon/kube_per_test_context.go b/v2/internal/testcommon/kube_per_test_context.go index 18111a0e401..4911c9dc3fc 100644 --- a/v2/internal/testcommon/kube_per_test_context.go +++ b/v2/internal/testcommon/kube_per_test_context.go @@ -518,6 +518,9 @@ func (tc *KubePerTestContext) PatchAndExpectError(old client.Object, new client. // DeleteResourceAndWait deletes the given resource in K8s and waits for // it to update to the Deleted state. func (tc *KubePerTestContext) DeleteResourceAndWait(obj client.Object) { + tc.LogSubsectionf( + "Deleting resource %s", + obj.GetName()) tc.DeleteResource(obj) tc.Eventually(obj).Should(tc.Match.BeDeleted()) }