feat: opt-out of auto-scaling per server (k8s) (#454)
This commit is contained in:
@@ -366,6 +366,22 @@ spec:
|
|||||||
- name: mc
|
- name: mc
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can also opt-out of auto-scaling per server by setting the following annotations on the `Service` object:
|
||||||
|
- `mc-router.itzg.me/autoScaleUp=false`
|
||||||
|
- `mc-router.itzg.me/autoScaleDown=false`
|
||||||
|
|
||||||
|
Example server with auto-scaling disabled explicitly:
|
||||||
|
```yaml
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: mc-forge
|
||||||
|
annotations:
|
||||||
|
"mc-router.itzg.me/externalServerName": "external.host.name"
|
||||||
|
"mc-router.itzg.me/autoScaleUp": "false"
|
||||||
|
"mc-router.itzg.me/autoScaleDown": "false"
|
||||||
|
```
|
||||||
|
|
||||||
## REST API
|
## REST API
|
||||||
|
|
||||||
* `GET /routes` (with `Accept: application/json`)
|
* `GET /routes` (with `Accept: application/json`)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ require (
|
|||||||
github.com/prometheus/client_golang v1.23.2
|
github.com/prometheus/client_golang v1.23.2
|
||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/sirupsen/logrus v1.9.3
|
||||||
github.com/stretchr/testify v1.11.1
|
github.com/stretchr/testify v1.11.1
|
||||||
golang.ngrok.com/ngrok v1.13.0
|
golang.ngrok.com/ngrok v1.12.1
|
||||||
golang.org/x/text v0.28.0
|
golang.org/x/text v0.28.0
|
||||||
k8s.io/api v0.33.4
|
k8s.io/api v0.33.4
|
||||||
k8s.io/apimachinery v0.33.4
|
k8s.io/apimachinery v0.33.4
|
||||||
|
|||||||
@@ -200,8 +200,8 @@ go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
|
|||||||
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
|
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
|
||||||
golang.ngrok.com/muxado/v2 v2.0.1 h1:jM9i6Pom6GGmnPrHKNR6OJRrUoHFkSZlJ3/S0zqdVpY=
|
golang.ngrok.com/muxado/v2 v2.0.1 h1:jM9i6Pom6GGmnPrHKNR6OJRrUoHFkSZlJ3/S0zqdVpY=
|
||||||
golang.ngrok.com/muxado/v2 v2.0.1/go.mod h1:wzxJYX4xiAtmwumzL+QsukVwFRXmPNv86vB8RPpOxyM=
|
golang.ngrok.com/muxado/v2 v2.0.1/go.mod h1:wzxJYX4xiAtmwumzL+QsukVwFRXmPNv86vB8RPpOxyM=
|
||||||
golang.ngrok.com/ngrok v1.13.0 h1:6SeOS+DAeIaHlkDmNH5waFHv0xjlavOV3wml0Z59/8k=
|
golang.ngrok.com/ngrok v1.12.1 h1:fjPyPr/R5/Et02x52iIJD2XqukwYeafsHNvM1ndJDAI=
|
||||||
golang.ngrok.com/ngrok v1.13.0/go.mod h1:BKOMdoZXfD4w6o3EtE7Cu9TVbaUWBqptrZRWnVcAuI4=
|
golang.ngrok.com/ngrok v1.12.1/go.mod h1:BKOMdoZXfD4w6o3EtE7Cu9TVbaUWBqptrZRWnVcAuI4=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
|||||||
+27
-4
@@ -23,6 +23,8 @@ import (
|
|||||||
const (
|
const (
|
||||||
AnnotationExternalServerName = "mc-router.itzg.me/externalServerName"
|
AnnotationExternalServerName = "mc-router.itzg.me/externalServerName"
|
||||||
AnnotationDefaultServer = "mc-router.itzg.me/defaultServer"
|
AnnotationDefaultServer = "mc-router.itzg.me/defaultServer"
|
||||||
|
AnnotationAutoScaleUp = "mc-router.itzg.me/autoScaleUp"
|
||||||
|
AnnotationAutoScaleDown = "mc-router.itzg.me/autoScaleDown"
|
||||||
)
|
)
|
||||||
|
|
||||||
// K8sWatcher is a RouteFinder that can find routes from kubernetes services.
|
// K8sWatcher is a RouteFinder that can find routes from kubernetes services.
|
||||||
@@ -279,11 +281,32 @@ func (w *K8sWatcher) buildDetails(service *core.Service, externalServiceName str
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *K8sWatcher) buildScaleFunction(service *core.Service, from int32, to int32) ScalerFunc {
|
func (w *K8sWatcher) buildScaleFunction(service *core.Service, from int32, to int32) ScalerFunc {
|
||||||
if from <= to && !w.autoScaleUp {
|
// Currently, annotations can only be used to opt-out of auto-scaling.
|
||||||
return nil
|
// However, this logic is prepared also for opt-in, as it returns a `ScalerFunc` when flags are false but annotations are set to `enabled`.
|
||||||
|
if from <= to {
|
||||||
|
enabled, exists := service.Annotations[AnnotationAutoScaleUp]
|
||||||
|
if exists {
|
||||||
|
if enabled == "false" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if !w.autoScaleUp {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if from >= to && !w.autoScaleDown {
|
if from >= to {
|
||||||
return nil
|
enabled, exists := service.Annotations[AnnotationAutoScaleDown]
|
||||||
|
if exists {
|
||||||
|
if enabled == "false" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if !w.autoScaleDown {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return func(ctx context.Context) error {
|
return func(ctx context.Context) error {
|
||||||
serviceName := service.Name
|
serviceName := service.Name
|
||||||
|
|||||||
Reference in New Issue
Block a user