Skip to content

Commit 122ed4b

Browse files
committed
VPA: Introduce VPA feature gates; add InPlaceOrRecreate feature gate
Signed-off-by: Max Cao <[email protected]>
1 parent 5098865 commit 122ed4b

File tree

6 files changed

+108
-0
lines changed

6 files changed

+108
-0
lines changed

vertical-pod-autoscaler/docs/flags.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This document is auto-generated from the flag definitions in the VPA admission-c
1212
| `--address` | ":8944" | The address to expose Prometheus metrics. |
1313
| `--alsologtostderr` | | log to standard error as well as files (no effect when -logtostderr=true) |
1414
| `--client-ca-file` | "/etc/tls-certs/caCert.pem" | Path to CA PEM file. |
15+
| `--feature-gates` | | A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: |
1516
| `--ignored-vpa-object-namespaces` | | A comma-separated list of namespaces to ignore when searching for VPA objects. Leave empty to avoid ignoring any namespaces. These namespaces will not be cleaned by the garbage collector. |
1617
| `--kube-api-burst` | 10 | QPS burst limit when making requests to Kubernetes apiserver |
1718
| `--kube-api-qps` | 5 | QPS limit when making requests to Kubernetes apiserver |
@@ -65,6 +66,7 @@ This document is auto-generated from the flag definitions in the VPA recommender
6566
| `--cpu-integer-post-processor-enabled` | | Enable the cpu-integer recommendation post processor. The post processor will round up CPU recommendations to a whole CPU for pods which were opted in by setting an appropriate label on VPA object (experimental) |
6667
| `--external-metrics-cpu-metric` | | ALPHA. Metric to use with external metrics provider for CPU usage. |
6768
| `--external-metrics-memory-metric` | | ALPHA. Metric to use with external metrics provider for memory usage. |
69+
| `--feature-gates` | | A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: |
6870
| `--history-length` | "8d" | How much time back prometheus have to be queried to get historical metrics |
6971
| `--history-resolution` | "1h" | Resolution at which Prometheus is queried for historical metrics |
7072
| `--humanize-memory` | | Convert memory values in recommendations to the highest appropriate SI unit with up to 2 decimal places for better readability. |
@@ -135,6 +137,7 @@ This document is auto-generated from the flag definitions in the VPA updater cod
135137
| `--eviction-rate-burst` | 1 | Burst of pods that can be evicted. |
136138
| `--eviction-rate-limit` | | Number of pods that can be evicted per seconds. A rate limit set to 0 or -1 will disable |
137139
| `--eviction-tolerance` | 0.5 | Fraction of replica count that can be evicted for update, if more than one pod can be evicted. |
140+
| `--feature-gates` | | A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: |
138141
| `--ignored-vpa-object-namespaces` | | A comma-separated list of namespaces to ignore when searching for VPA objects. Leave empty to avoid ignoring any namespaces. These namespaces will not be cleaned by the garbage collector. |
139142
| `--in-recommendation-bounds-eviction-lifetime-threshold` | 12h0m0s | Pods that live for at least that long can be evicted even if their request is within the [MinRecommended...MaxRecommended] range |
140143
| `--kube-api-burst` | 10 | QPS burst limit when making requests to Kubernetes apiserver |

vertical-pod-autoscaler/pkg/admission-controller/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"strings"
2525
"time"
2626

27+
"github.com/spf13/pflag"
2728
"k8s.io/client-go/informers"
2829
kube_client "k8s.io/client-go/kubernetes"
2930
kube_flag "k8s.io/component-base/cli/flag"
@@ -36,6 +37,7 @@ import (
3637
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource/pod/recommendation"
3738
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource/vpa"
3839
vpa_clientset "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned"
40+
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/features"
3941
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/target"
4042
controllerfetcher "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/target/controller_fetcher"
4143
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/limitrange"
@@ -81,6 +83,7 @@ func main() {
8183
commonFlags := common.InitCommonFlags()
8284
klog.InitFlags(nil)
8385
common.InitLoggingFlags()
86+
features.MutableFeatureGate.AddFlag(pflag.CommandLine)
8487
kube_flag.InitFlags()
8588
klog.V(1).InfoS("Starting Vertical Pod Autoscaler Admission Controller", "version", common.VerticalPodAutoscalerVersion())
8689

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package features
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/util/runtime"
21+
"k8s.io/apimachinery/pkg/util/version"
22+
"k8s.io/component-base/featuregate"
23+
24+
"k8s.io/autoscaler/vertical-pod-autoscaler/common"
25+
)
26+
27+
const (
28+
// Every feature gate should add method here following this template:
29+
//
30+
// // alpha: v1.X
31+
// // components: admission-controller, recommender, updater
32+
//
33+
// MyFeature featuregate.Feature = "MyFeature".
34+
//
35+
// Feature gates should be listed in alphabetical, case-sensitive
36+
// (upper before any lower case character) order. This reduces the risk
37+
// of code conflicts because changes are more likely to be scattered
38+
// across the file.
39+
//
40+
// In each feature gate description, you must specify "components".
41+
// The feature must be enabled by the --feature-gates argument on each listed component.
42+
43+
// alpha: v1.4.0
44+
// components: admission-controller, updater
45+
46+
// InPlaceOrRecreate enables the InPlaceOrRecreate update mode to be used.
47+
// Requires KEP-1287 InPlacePodVerticalScaling feature-gate to be enabled on the cluster.
48+
InPlaceOrRecreate featuregate.Feature = "InPlaceOrRecreate"
49+
)
50+
51+
// MutableFeatureGate is a mutable, versioned, global FeatureGate.
52+
var MutableFeatureGate featuregate.MutableVersionedFeatureGate = featuregate.NewFeatureGate()
53+
54+
// Enabled is a helper function for MutableFeatureGate.Enabled(f)
55+
func Enabled(f featuregate.Feature) bool {
56+
return MutableFeatureGate.Enabled(f)
57+
}
58+
59+
func init() {
60+
// set the emulation version to align with VPA versioning system
61+
runtime.Must(MutableFeatureGate.SetEmulationVersion(version.MustParse(common.VerticalPodAutoscalerVersion())))
62+
runtime.Must(MutableFeatureGate.AddVersioned(defaultVersionedFeatureGates))
63+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package features
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/util/version"
21+
"k8s.io/component-base/featuregate"
22+
)
23+
24+
// defaultVersionedFeatureGates consists of all known VPA-specific feature keys with VersionedSpecs.
25+
// To add a new feature, define a key for it in pkg/features/features.go and add it here. The features will be
26+
// available throughout Kubernetes binaries.
27+
28+
// Entries are alphabetized.
29+
var defaultVersionedFeatureGates = map[featuregate.Feature]featuregate.VersionedSpecs{
30+
InPlaceOrRecreate: {
31+
{Version: version.MustParse("1.3.0"), Default: false, PreRelease: featuregate.Alpha}, // TODO: have to downgrade to 1.3.0 for now until we bump VPA version
32+
},
33+
}

vertical-pod-autoscaler/pkg/recommender/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040

4141
"k8s.io/autoscaler/vertical-pod-autoscaler/common"
4242
vpa_clientset "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned"
43+
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/features"
4344
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/recommender/checkpoint"
4445
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/recommender/input"
4546
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/recommender/input/history"
@@ -131,6 +132,8 @@ func main() {
131132
leaderElection := defaultLeaderElectionConfiguration()
132133
componentbaseoptions.BindLeaderElectionFlags(&leaderElection, pflag.CommandLine)
133134

135+
features.MutableFeatureGate.AddFlag(pflag.CommandLine)
136+
134137
kube_flag.InitFlags()
135138
klog.V(1).InfoS("Vertical Pod Autoscaler Recommender", "version", common.VerticalPodAutoscalerVersion(), "recommenderName", *recommenderName)
136139

vertical-pod-autoscaler/pkg/updater/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737

3838
"k8s.io/autoscaler/vertical-pod-autoscaler/common"
3939
vpa_clientset "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned"
40+
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/features"
4041
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/target"
4142
controllerfetcher "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/target/controller_fetcher"
4243
updater "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/updater/logic"
@@ -88,6 +89,8 @@ func main() {
8889
leaderElection := defaultLeaderElectionConfiguration()
8990
componentbaseoptions.BindLeaderElectionFlags(&leaderElection, pflag.CommandLine)
9091

92+
features.MutableFeatureGate.AddFlag(pflag.CommandLine)
93+
9194
kube_flag.InitFlags()
9295
klog.V(1).InfoS("Vertical Pod Autoscaler Updater", "version", common.VerticalPodAutoscalerVersion())
9396

0 commit comments

Comments
 (0)