With k8s correctly handle disabled auto-scale up case (#495)
This commit is contained in:
+4
-7
@@ -277,17 +277,14 @@ func (w *K8sWatcher) buildDetails(service *core.Service, externalServiceName str
|
|||||||
rs := &routableService{
|
rs := &routableService{
|
||||||
externalServiceName: externalServiceName,
|
externalServiceName: externalServiceName,
|
||||||
containerEndpoint: endpoint,
|
containerEndpoint: endpoint,
|
||||||
autoScaleUp: func(ctx context.Context) (string, error) {
|
autoScaleUp: buildWakerFromSleeper(endpoint, wakerFunc),
|
||||||
if err := wakerFunc(ctx); err != nil {
|
autoScaleDown: w.buildScaleFunction(service, 1, 0),
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return endpoint, nil
|
|
||||||
},
|
|
||||||
autoScaleDown: w.buildScaleFunction(service, 1, 0),
|
|
||||||
}
|
}
|
||||||
return rs
|
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 {
|
func (w *K8sWatcher) buildScaleFunction(service *core.Service, from int32, to int32) SleeperFunc {
|
||||||
// Currently, annotations can only be used to opt-out of auto-scaling.
|
// 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`.
|
// 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.
|
// SleeperFunc is a function that puts a server to sleep.
|
||||||
type SleeperFunc func(ctx context.Context) error
|
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("///.*")
|
var tcpShieldPattern = regexp.MustCompile("///.*")
|
||||||
|
|
||||||
// RouteFinder implementations find new routes in the system that can be tracked by a RoutesHandler
|
// RouteFinder implementations find new routes in the system that can be tracked by a RoutesHandler
|
||||||
|
|||||||
Reference in New Issue
Block a user