Skip to content

Commit

Permalink
fix(NukeAwsBackups) - Load vault before listing the backups (#1008)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi-shankar-sap authored Feb 5, 2025
1 parent 8790d83 commit 646db33
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/kcp/provider/aws/nuke/loadNfsBackups.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ func loadNfsBackups(ctx context.Context, st composed.State) (error, context.Cont
state := st.(*State)
logger := composed.LoggerFromCtx(ctx)

if state.vault == nil {
logger.Info("No vault exists.")
return nil, ctx
}

backups, err := state.awsClient.ListRecoveryPointsForVault(ctx, state.GetAccountId(), state.GetVaultName())
if err != nil {
logger.Error(err, "Error listing Aws Recovery Points")
Expand Down
27 changes: 27 additions & 0 deletions pkg/kcp/provider/aws/nuke/loadVault.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package nuke

import (
"context"
"github.com/kyma-project/cloud-manager/pkg/composed"
"k8s.io/utils/ptr"
"time"
)

func loadVault(ctx context.Context, st composed.State) (error, context.Context) {
state := st.(*State)

//Get the vaultName and load it.
vaultName := state.GetVaultName()
vaults, err := state.awsClient.ListBackupVaults(ctx)
if err != nil {
return composed.LogErrorAndReturn(err, "Error listing AWS Backup Vaults", composed.StopWithRequeueDelay(time.Second), ctx)
}

//Match the vault by name. If found, continue...
for _, vault := range vaults {
if ptr.Deref(vault.BackupVaultName, "") == vaultName {
state.vault = &vault
}
}
return nil, nil
}
1 change: 1 addition & 0 deletions pkg/kcp/provider/aws/nuke/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func New(stateFactory StateFactory) composed.Action {
return composed.ComposeActions(
"awsNuke",
createAwsClient,
loadVault,
loadNfsBackups,
providerResourceStatusDiscovered,
deleteNfsBackup,
Expand Down
1 change: 1 addition & 0 deletions pkg/kcp/provider/aws/nuke/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type State struct {
nuketypes.State
ProviderResources []*nuketypes.ProviderResourceKindState

vault *types.BackupVaultListMember
awsClientProvider awsClient.SkrClientProvider[awsnukeclient.NukeNfsBackupClient]
env abstractions.Environment
awsClient awsnukeclient.NukeNfsBackupClient
Expand Down

0 comments on commit 646db33

Please sign in to comment.