With k8s correctly handle disabled auto-scale up case (#495)
This commit is contained in:
+3
-6
@@ -277,17 +277,14 @@ func (w *K8sWatcher) buildDetails(service *core.Service, externalServiceName str
|
||||
rs := &routableService{
|
||||
externalServiceName: externalServiceName,
|
||||
containerEndpoint: endpoint,
|
||||
autoScaleUp: func(ctx context.Context) (string, error) {
|
||||
if err := wakerFunc(ctx); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return endpoint, nil
|
||||
},
|
||||
autoScaleUp: buildWakerFromSleeper(endpoint, wakerFunc),
|
||||
autoScaleDown: w.buildScaleFunction(service, 1, 0),
|
||||
}
|
||||
return rs
|
||||
}
|
||||
|
||||
// buildScaleFunction generates a SleeperFunc to scale StatefulSets based on specified criteria and service annotations.
|
||||
// Will return nil if the service should not be auto-scaled due config or annotation.
|
||||
func (w *K8sWatcher) buildScaleFunction(service *core.Service, from int32, to int32) SleeperFunc {
|
||||
// Currently, annotations can only be used to opt-out of auto-scaling.
|
||||
// However, this logic is prepared also for opt-in, as it returns a `SleeperFunc` when flags are false but annotations are set to `enabled`.
|
||||
|
||||
@@ -15,6 +15,18 @@ type WakerFunc func(ctx context.Context) (string, error)
|
||||
// SleeperFunc is a function that puts a server to sleep.
|
||||
type SleeperFunc func(ctx context.Context) error
|
||||
|
||||
func buildWakerFromSleeper(endpoint string, sleeper SleeperFunc) WakerFunc {
|
||||
if sleeper == nil {
|
||||
return nil
|
||||
}
|
||||
return func(ctx context.Context) (string, error) {
|
||||
if err := sleeper(ctx); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return endpoint, nil
|
||||
}
|
||||
}
|
||||
|
||||
var tcpShieldPattern = regexp.MustCompile("///.*")
|
||||
|
||||
// RouteFinder implementations find new routes in the system that can be tracked by a RoutesHandler
|
||||
|
||||
Reference in New Issue
Block a user