Skip to content

Commit

Permalink
feat(AzureVpcPeering): allows VpcPeering to be deleted if local Netwo…
Browse files Browse the repository at this point in the history
…rk is missing
  • Loading branch information
vandjelk authored Nov 14, 2024
1 parent a8cb074 commit 16f5048
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 14 additions & 1 deletion internal/controller/cloud-control/vpcpeering_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ var _ = Describe("Feature: KCP VpcPeering", func() {
})
})

It("Scenario: KCP AWS VpcPeering is deleted when remote network is missing", func() {
It("Scenario: KCP AWS VpcPeering is deleted when local and remote networks are missing", func() {
const (
kymaName = "76f1dec7-c7d3-4129-9730-478f4cba241a"
kcpPeeringName = "f658c189-0f09-4c4b-8da6-49b3db61546d"
Expand Down Expand Up @@ -570,6 +570,19 @@ var _ = Describe("Feature: KCP VpcPeering", func() {
localRouteTable, kcpPeering.Status.Id, remoteVpcCidr))
})

// Deleting KCP remote Network before VpcPeering deletion
By("When KCP local Network is deleted", func() {
Eventually(Delete).
WithArguments(infra.Ctx(), infra.KCP().Client(), localKcpNet).
Should(Succeed(), "failed deleting local KCP Network")
})

By("Then KCP local Network does not exist", func() {
Eventually(IsDeleted).
WithArguments(infra.Ctx(), infra.KCP().Client(), localKcpNet).
Should(Succeed(), "expected KCP local Network not to exist (be deleted), but it still exists")
})

// Deleting KCP remote Network before VpcPeering deletion
By("When KCP remote Network is deleted", func() {
Eventually(Delete).
Expand Down
3 changes: 3 additions & 0 deletions pkg/kcp/provider/aws/vpcpeering/kcpNetworkLocalLoad.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func kcpNetworkLocalLoad(ctx context.Context, st composed.State) (error, context
}

if apierrors.IsNotFound(err) {
if composed.IsMarkedForDeletion(state.Obj()) {
return composed.LogErrorAndReturn(err, "KCP VpcPeering marked for deletion but, local KCP Network not found", nil, ctx)
}
state.ObjAsVpcPeering().Status.State = string(cloudcontrolv1beta1.ErrorState)
return composed.PatchStatus(state.ObjAsVpcPeering()).
SetExclusiveConditions(metav1.Condition{
Expand Down

0 comments on commit 16f5048

Please sign in to comment.