Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
theunrepentantgeek committed Oct 3, 2023
1 parent d02b75d commit b27efb2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
24 changes: 13 additions & 11 deletions v2/api/keyvault/customizations/vault_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions v2/internal/testcommon/kube_per_test_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down

0 comments on commit b27efb2

Please sign in to comment.