From 5e83d5bc838ab3c3aa05ebdc93976de0672143e4 Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Wed, 9 Feb 2022 14:45:56 -0500 Subject: [PATCH] :bug: Skip InboundNatRule reconciliation if no LB is configured 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. --- azure/services/inboundnatrules/inboundnatrules.go | 11 ++++++++++- .../services/inboundnatrules/inboundnatrules_test.go | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/azure/services/inboundnatrules/inboundnatrules.go b/azure/services/inboundnatrules/inboundnatrules.go index 3c6485292e7..378fb976005 100644 --- a/azure/services/inboundnatrules/inboundnatrules.go +++ b/azure/services/inboundnatrules/inboundnatrules.go @@ -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() diff --git a/azure/services/inboundnatrules/inboundnatrules_test.go b/azure/services/inboundnatrules/inboundnatrules_test.go index 111c76149e4..68c4e7bd8d0 100644 --- a/azure/services/inboundnatrules/inboundnatrules_test.go +++ b/azure/services/inboundnatrules/inboundnatrules_test.go @@ -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",