Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ResourceScaler] Fix app resource scaler #31

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 21 additions & 28 deletions pkg/resourcescaler/resourcescaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
roei3000b marked this conversation as resolved.
Show resolved Hide resolved
"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 {
Expand Down
Loading