Skip to content

Commit 5e848fb

Browse files
authored
Merge pull request #2066 from alvaroaleman/inboundnatrules
🐛 Skip InboundNatRule reconciliation if no LB is configured
2 parents 0a254d8 + a3c28ef commit 5e848fb

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

azure/services/inboundnatrules/inboundnatrules.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,19 @@ func New(scope InboundNatScope) *Service {
5656

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

62+
// Externally managed clusters might not have an LB
63+
if s.Scope.APIServerLBName() == "" {
64+
log.V(4).Info("Skipping InboundNatRule reconciliation as the cluster has no LB configured")
65+
// Until https://github.com/kubernetes-sigs/cluster-api-provider-azure/issues/1868 is
66+
// resolved, this needs to be set for the machine to be able to reach the ready condition:
67+
// https://github.com/kubernetes-sigs/cluster-api-provider-azure/pull/2066#discussion_r806150004
68+
s.Scope.UpdatePutStatus(infrav1.InboundNATRulesReadyCondition, serviceName, nil)
69+
return nil
70+
}
71+
6272
ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultAzureServiceReconcileTimeout)
6373
defer cancel()
6474

azure/services/inboundnatrules/inboundnatrules_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ func TestReconcileInboundNATRule(t *testing.T) {
124124
)
125125
},
126126
},
127+
{
128+
name: "No LB, Nat rule reconciliation is skipped",
129+
expectedError: "",
130+
expect: func(s *mock_inboundnatrules.MockInboundNatScopeMockRecorder,
131+
m *mock_inboundnatrules.MockclientMockRecorder,
132+
r *mock_async.MockReconcilerMockRecorder) {
133+
s.APIServerLBName().AnyTimes().Return("")
134+
s.UpdatePutStatus(infrav1.InboundNATRulesReadyCondition, serviceName, nil)
135+
},
136+
},
127137
{
128138
name: "fail to get existing rules",
129139
expectedError: "failed to get existing NAT rules: #: Internal Server Error: StatusCode=500",

0 commit comments

Comments
 (0)