From 6154acb45881739ada860c45675e3b861a49da9b Mon Sep 17 00:00:00 2001 From: roei3000b Date: Wed, 6 Mar 2024 11:15:09 +0200 Subject: [PATCH 1/2] Fix app resource scaler --- pkg/resourcescaler/resourcescaler.go | 49 ++++++++++++---------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/pkg/resourcescaler/resourcescaler.go b/pkg/resourcescaler/resourcescaler.go index d1411d5..3614877 100644 --- a/pkg/resourcescaler/resourcescaler.go +++ b/pkg/resourcescaler/resourcescaler.go @@ -67,7 +67,10 @@ func New(logger logger.Logger, // SetScale scales a service // Deprecated: use SetScaleCtx instead func (s *AppResourceScaler) SetScale(resources []scalertypes.Resource, scale int) error { - return s.SetScaleCtx(context.Background(), resources, scale) + setScaleContext, cancelFunc := context.WithTimeout(context.Background(), 15*time.Minute) + defer cancelFunc() + + return s.SetScaleCtx(setScaleContext, resources, scale) } // SetScaleCtx scales a service @@ -306,48 +309,38 @@ func (s *AppResourceScaler) patchIguazioTenantAppServiceSets(ctx context.Context func (s *AppResourceScaler) waitForNoProvisioningInProcess(ctx context.Context) error { s.logger.DebugWithCtx(ctx, "Waiting for IguazioTenantAppServiceSet to finish provisioning") - timeout := time.After(5 * time.Minute) - tick := time.NewTimer(10 * time.Second) - defer tick.Stop() for { - _, _, state, err := s.getIguazioTenantAppServiceSets(ctx) - if err != nil { - return errors.Wrap(err, "Failed to get iguazio tenant app service sets") - } + select { + case <-ctx.Done(): + return ctx.Err() - if state == "ready" || state == "error" { - s.logger.DebugWithCtx(ctx, "IguazioTenantAppServiceSet finished provisioning") - return nil - } + case <-time.After(10 * time.Second): + _, _, state, err := s.getIguazioTenantAppServiceSets(ctx) + if err != nil { + return errors.Wrap(err, "Failed to get iguazio tenant app service sets") + } - s.logger.DebugWithCtx(ctx, "IguazioTenantAppServiceSet is still provisioning", "state", state) + if state == "ready" || state == "error" { + s.logger.DebugWithCtx(ctx, "IguazioTenantAppServiceSet finished provisioning") + return nil + } - select { - case <-ctx.Done(): - return errors.New("Context was cancelled") - case <-timeout: - return errors.New("Timed out waiting for IguazioTenantAppServiceSet to finish provisioning") - case <-tick.C: - continue + s.logger.DebugWithCtx(ctx, "IguazioTenantAppServiceSet is still provisioning", "state", state) } + } } func (s *AppResourceScaler) waitForServicesState(ctx context.Context, serviceNames []string, desiredState string) error { s.logger.DebugWithCtx(ctx, - "Waiting for services to reach desired state", + "Waiting for services to reach desired state - Roei", "serviceNames", serviceNames, "desiredState", desiredState) - timeout := time.After(10 * time.Minute) - tick := time.NewTicker(5 * time.Second) - defer tick.Stop() for { select { case <-ctx.Done(): - return errors.New("Context was cancelled") - case <-timeout: - return errors.New("Timed out waiting for services to reach desired state") - case <-tick.C: + return ctx.Err() + case <-time.After(5 * time.Second): servicesToCheck := append([]string(nil), serviceNames...) _, statusServicesMap, _, err := s.getIguazioTenantAppServiceSets(ctx) if err != nil { From 72cc5c0832cf62b0f513706b8e5a58115cc2f9b2 Mon Sep 17 00:00:00 2001 From: roei3000b Date: Wed, 6 Mar 2024 12:21:57 +0200 Subject: [PATCH 2/2] Fix cr --- pkg/resourcescaler/resourcescaler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/resourcescaler/resourcescaler.go b/pkg/resourcescaler/resourcescaler.go index 3614877..0ee99b0 100644 --- a/pkg/resourcescaler/resourcescaler.go +++ b/pkg/resourcescaler/resourcescaler.go @@ -333,7 +333,7 @@ func (s *AppResourceScaler) waitForNoProvisioningInProcess(ctx context.Context) func (s *AppResourceScaler) waitForServicesState(ctx context.Context, serviceNames []string, desiredState string) error { s.logger.DebugWithCtx(ctx, - "Waiting for services to reach desired state - Roei", + "Waiting for services to reach desired state", "serviceNames", serviceNames, "desiredState", desiredState) for {