From 4343d945864e849917bb8ab26f0721ed5b3e6e73 Mon Sep 17 00:00:00 2001 From: janiskemper <63146658+janiskemper@users.noreply.github.com> Date: Wed, 19 Jun 2024 17:32:56 +0200 Subject: [PATCH] :seedling: Stop calling API when HCloudMachineTemplate status is set (#1353) :seedling: Stop calling API when hcmt status is set We call the HCloud API in every reconcile loop of the hcloudmachine_template controller. This is not necessary since the server type does not change for one template object. We can set it once when the status is empty and then don't have to set it while the status is not nil anymore. --- .../hcloud/machinetemplate/machinetemplate.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/services/hcloud/machinetemplate/machinetemplate.go b/pkg/services/hcloud/machinetemplate/machinetemplate.go index 0b51cce70..36606819c 100644 --- a/pkg/services/hcloud/machinetemplate/machinetemplate.go +++ b/pkg/services/hcloud/machinetemplate/machinetemplate.go @@ -46,12 +46,14 @@ func (s *Service) Reconcile(ctx context.Context) error { // delete the deprecated condition from existing machinetemplate objects conditions.Delete(s.scope.HCloudMachineTemplate, infrav1.DeprecatedRateLimitExceededCondition) - capacity, err := s.getCapacity(ctx) - if err != nil { - return fmt.Errorf("failed to get capacity: %w", err) - } + if s.scope.HCloudMachineTemplate.Status.Capacity == nil { + capacity, err := s.getCapacity(ctx) + if err != nil { + return fmt.Errorf("failed to get capacity: %w", err) + } - s.scope.HCloudMachineTemplate.Status.Capacity = capacity + s.scope.HCloudMachineTemplate.Status.Capacity = capacity + } return nil }