Skip to content

Commit

Permalink
chore(AzureVpcPeering): skip status update while waiting local peerin…
Browse files Browse the repository at this point in the history
…g ready
  • Loading branch information
vandjelk committed Dec 19, 2024
1 parent 844f630 commit 28f528a
Showing 1 changed file with 5 additions and 34 deletions.
39 changes: 5 additions & 34 deletions pkg/kcp/provider/azure/vpcpeering/peeringLocalWaitReady.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,21 @@ package vpcpeering
import (
"context"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v5"
cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
"github.com/kyma-project/cloud-manager/pkg/composed"
"github.com/kyma-project/cloud-manager/pkg/util"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/utils/ptr"
)

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

if state.localPeering == nil {
return composed.StopWithRequeue, nil
if state.localPeering != nil &&
ptr.Deref(state.localPeering.Properties.PeeringState, "") == armnetwork.VirtualNetworkPeeringStateConnected {
return nil, nil
}

if ptr.Deref(state.localPeering.Properties.PeeringState, "") != armnetwork.VirtualNetworkPeeringStateConnected {
logger.Info("Waiting for peering Connected state",
"azureLocalPeeringId", ptr.Deref(state.localPeering.ID, ""),
"azurePeeringState", ptr.Deref(state.localPeering.Properties.PeeringState, ""))
logger.Info("Waiting for peering Connected state")

changed := false

if state.ObjAsVpcPeering().Status.State != cloudcontrolv1beta1.VirtualNetworkPeeringStateInitiated {
state.ObjAsVpcPeering().Status.State = cloudcontrolv1beta1.VirtualNetworkPeeringStateInitiated
changed = true
}

if meta.RemoveStatusCondition(state.ObjAsVpcPeering().Conditions(), cloudcontrolv1beta1.ConditionTypeError) {
changed = true
}
if meta.RemoveStatusCondition(state.ObjAsVpcPeering().Conditions(), cloudcontrolv1beta1.ConditionTypeReady) {
changed = true
}

if changed {
return composed.PatchStatus(state.ObjAsVpcPeering()).
ErrorLogMessage("Error patching KCP VpcPeering status when state initiated on wait peering connected").
SuccessError(composed.StopWithRequeueDelay(util.Timing.T1000ms())).
Run(ctx, state)
}

// azure peering connects quickly so we're aggressive and requeue with small delay
return composed.StopWithRequeueDelay(util.Timing.T1000ms()), nil
}

return nil, nil
return composed.StopWithRequeueDelay(util.Timing.T1000ms()), nil
}

0 comments on commit 28f528a

Please sign in to comment.