Skip to content

Commit

Permalink
update downscale
Browse files Browse the repository at this point in the history
  • Loading branch information
yuchen-db committed Oct 13, 2024
1 parent 7d10753 commit 0a62d87
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pkg/controller/delay.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ import (
"github.com/grafana/rollout-operator/pkg/config"
)

func getStsSvcName(sts *v1.StatefulSet) string {
if sts.Spec.ServiceName != "" {
return sts.Spec.ServiceName
}
return sts.GetName()
}

func cancelDelayedDownscaleIfConfigured(ctx context.Context, logger log.Logger, sts *v1.StatefulSet, httpClient httpClient, replicas int32) {
delay, prepareURL, err := parseDelayedDownscaleAnnotations(sts.GetAnnotations())
if delay == 0 || prepareURL == nil {
Expand All @@ -31,7 +38,7 @@ func cancelDelayedDownscaleIfConfigured(ctx context.Context, logger log.Logger,
return
}

endpoints := createPrepareDownscaleEndpoints(sts.Namespace, sts.GetName(), 0, int(replicas), prepareURL)
endpoints := createPrepareDownscaleEndpoints(sts.Namespace, getStsSvcName(sts), 0, int(replicas), prepareURL)

callCancelDelayedDownscale(ctx, logger, httpClient, endpoints)
}
Expand All @@ -54,19 +61,19 @@ func checkScalingDelay(ctx context.Context, logger log.Logger, sts *v1.StatefulS
}

if desiredReplicas >= currentReplicas {
callCancelDelayedDownscale(ctx, logger, httpClient, createPrepareDownscaleEndpoints(sts.Namespace, sts.GetName(), 0, int(currentReplicas), prepareURL))
callCancelDelayedDownscale(ctx, logger, httpClient, createPrepareDownscaleEndpoints(sts.Namespace, getStsSvcName(sts), 0, int(currentReplicas), prepareURL))
// Proceed even if calling cancel of delayed downscale fails. We call cancellation repeatedly, so it will happen during next reconcile.
return desiredReplicas, nil
}

{
// Replicas in [0, desired) interval should cancel any delayed downscale, if they have any.
cancelEndpoints := createPrepareDownscaleEndpoints(sts.Namespace, sts.GetName(), 0, int(desiredReplicas), prepareURL)
cancelEndpoints := createPrepareDownscaleEndpoints(sts.Namespace, getStsSvcName(sts), 0, int(desiredReplicas), prepareURL)
callCancelDelayedDownscale(ctx, logger, httpClient, cancelEndpoints)
}

// Replicas in [desired, current) interval are going to be stopped.
downscaleEndpoints := createPrepareDownscaleEndpoints(sts.Namespace, sts.GetName(), int(desiredReplicas), int(currentReplicas), prepareURL)
downscaleEndpoints := createPrepareDownscaleEndpoints(sts.Namespace, getStsSvcName(sts), int(desiredReplicas), int(currentReplicas), prepareURL)
elapsedTimeSinceDownscaleInitiated, err := callPrepareDownscaleAndReturnElapsedDurationsSinceInitiatedDownscale(ctx, logger, httpClient, downscaleEndpoints)
if err != nil {
return currentReplicas, fmt.Errorf("failed prepare pods for delayed downscale: %v", err)
Expand Down Expand Up @@ -147,7 +154,8 @@ func createPrepareDownscaleEndpoints(namespace, serviceName string, from, to int
}

ep.url = *url
ep.url.Host = fmt.Sprintf("%s.%v.%v.svc.cluster.local.", ep.podName, serviceName, ep.namespace)
port := ep.url.Port()
ep.url.Host = fmt.Sprintf("%s.%v.%v.svc.cluster.local:%s", ep.podName, serviceName, ep.namespace, port)

eps = append(eps, ep)
}
Expand Down

0 comments on commit 0a62d87

Please sign in to comment.