Skip to content

Commit

Permalink
🐛 Skip InboundNatRule reconciliation if no LB is configured
Browse files Browse the repository at this point in the history
Clusters might be externally managed in which case the apiserver
endpoint might be in a different Azure account or on a different
platform altogether. In this case, there are no inboundnatrules for the
LB to reconcile, so skip doing that if the LB name is empty.
  • Loading branch information
alvaroaleman committed Feb 14, 2022
1 parent 461953a commit 5e83d5b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion azure/services/inboundnatrules/inboundnatrules.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,18 @@ func New(scope InboundNatScope) *Service {

// Reconcile gets/creates/updates an inbound NAT rule.
func (s *Service) Reconcile(ctx context.Context) error {
ctx, _, done := tele.StartSpanWithLogger(ctx, "inboundnatrules.Service.Reconcile")
ctx, log, done := tele.StartSpanWithLogger(ctx, "inboundnatrules.Service.Reconcile")
defer done()

if s.Scope.APIServerLBName() == "" {
log.V(4).Info("Skipping InboundNatRule reconciliation as the cluster has no LB configured")
// Until https://github.com/kubernetes-sigs/cluster-api-provider-azure/issues/1868 is
// resolved, this needs to be set for the machine to be able to reach the ready condition:
// https://github.com/kubernetes-sigs/cluster-api-provider-azure/pull/2066#discussion_r806150004
s.Scope.UpdatePutStatus(infrav1.InboundNATRulesReadyCondition, serviceName, nil)
return nil
}

ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultAzureServiceReconcileTimeout)
defer cancel()

Expand Down
10 changes: 10 additions & 0 deletions azure/services/inboundnatrules/inboundnatrules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ func TestReconcileInboundNATRule(t *testing.T) {
)
},
},
{
name: "No LB, Nat rule reconciliation is skipped",
expectedError: "",
expect: func(s *mock_inboundnatrules.MockInboundNatScopeMockRecorder,
m *mock_inboundnatrules.MockclientMockRecorder,
r *mock_async.MockReconcilerMockRecorder) {
s.APIServerLBName().AnyTimes().Return("")
s.UpdatePutStatus(infrav1.InboundNATRulesReadyCondition, serviceName, nil)
},
},
{
name: "fail to get existing rules",
expectedError: "failed to get existing NAT rules: #: Internal Server Error: StatusCode=500",
Expand Down

0 comments on commit 5e83d5b

Please sign in to comment.