Skip to content

Commit

Permalink
Add PriorityQueue feature gate
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer [email protected]
  • Loading branch information
sbueringer committed Jan 17, 2025
1 parent 99e9a26 commit 5e5909d
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bootstrap/kubeadm/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
- "--leader-elect"
- "--diagnostics-address=${CAPI_DIAGNOSTICS_ADDRESS:=:8443}"
- "--insecure-diagnostics=${CAPI_INSECURE_DIAGNOSTICS:=false}"
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=true},KubeadmBootstrapFormatIgnition=${EXP_KUBEADM_BOOTSTRAP_FORMAT_IGNITION:=false}"
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=true},KubeadmBootstrapFormatIgnition=${EXP_KUBEADM_BOOTSTRAP_FORMAT_IGNITION:=false},PriorityQueue=${EXP_PRIORITY_QUEUE:=false}"
- "--bootstrap-token-ttl=${KUBEADM_BOOTSTRAP_TOKEN_TTL:=15m}"
image: controller:latest
name: manager
Expand Down
5 changes: 5 additions & 0 deletions bootstrap/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ import (
logsv1 "k8s.io/component-base/logs/api/v1"
_ "k8s.io/component-base/logs/json/register"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/webhook"

Expand Down Expand Up @@ -226,6 +228,9 @@ func main() {
clusterSecretCacheSelector := labels.NewSelector().Add(*req)

ctrlOptions := ctrl.Options{
Controller: config.Controller{
UsePriorityQueue: ptr.To[bool](feature.Gates.Enabled(feature.PriorityQueue)),
},
Scheme: scheme,
LeaderElection: enableLeaderElection,
LeaderElectionID: "kubeadm-bootstrap-manager-leader-election-capi",
Expand Down
2 changes: 1 addition & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
- "--diagnostics-address=${CAPI_DIAGNOSTICS_ADDRESS:=:8443}"
- "--insecure-diagnostics=${CAPI_INSECURE_DIAGNOSTICS:=false}"
- "--use-deprecated-infra-machine-naming=${CAPI_USE_DEPRECATED_INFRA_MACHINE_NAMING:=false}"
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=true},ClusterResourceSet=${EXP_CLUSTER_RESOURCE_SET:=true},ClusterTopology=${CLUSTER_TOPOLOGY:=false},RuntimeSDK=${EXP_RUNTIME_SDK:=false},MachineSetPreflightChecks=${EXP_MACHINE_SET_PREFLIGHT_CHECKS:=true},MachineWaitForVolumeDetachConsiderVolumeAttachments=${EXP_MACHINE_WAITFORVOLUMEDETACH_CONSIDER_VOLUMEATTACHMENTS:=true}"
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=true},ClusterResourceSet=${EXP_CLUSTER_RESOURCE_SET:=true},ClusterTopology=${CLUSTER_TOPOLOGY:=false},RuntimeSDK=${EXP_RUNTIME_SDK:=false},MachineSetPreflightChecks=${EXP_MACHINE_SET_PREFLIGHT_CHECKS:=true},MachineWaitForVolumeDetachConsiderVolumeAttachments=${EXP_MACHINE_WAITFORVOLUMEDETACH_CONSIDER_VOLUMEATTACHMENTS:=true},PriorityQueue=${EXP_PRIORITY_QUEUE:=false}"
image: controller:latest
name: manager
env:
Expand Down
2 changes: 1 addition & 1 deletion controlplane/kubeadm/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
- "--diagnostics-address=${CAPI_DIAGNOSTICS_ADDRESS:=:8443}"
- "--insecure-diagnostics=${CAPI_INSECURE_DIAGNOSTICS:=false}"
- "--use-deprecated-infra-machine-naming=${CAPI_USE_DEPRECATED_INFRA_MACHINE_NAMING:=false}"
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=true},ClusterTopology=${CLUSTER_TOPOLOGY:=false},KubeadmBootstrapFormatIgnition=${EXP_KUBEADM_BOOTSTRAP_FORMAT_IGNITION:=false}"
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=true},ClusterTopology=${CLUSTER_TOPOLOGY:=false},KubeadmBootstrapFormatIgnition=${EXP_KUBEADM_BOOTSTRAP_FORMAT_IGNITION:=false},PriorityQueue=${EXP_PRIORITY_QUEUE:=false}"
image: controller:latest
name: manager
env:
Expand Down
5 changes: 5 additions & 0 deletions controlplane/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ import (
logsv1 "k8s.io/component-base/logs/api/v1"
_ "k8s.io/component-base/logs/json/register"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/webhook"

Expand Down Expand Up @@ -252,6 +254,9 @@ func main() {
clusterSecretCacheSelector := labels.NewSelector().Add(*req)

ctrlOptions := ctrl.Options{
Controller: config.Controller{
UsePriorityQueue: ptr.To[bool](feature.Gates.Enabled(feature.PriorityQueue)),
},
Scheme: scheme,
LeaderElection: enableLeaderElection,
LeaderElectionID: "kubeadm-control-plane-manager-leader-election-capi",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Currently Cluster API has the following experimental features:
* `ClusterResourceSet` (env var: `EXP_CLUSTER_RESOURCE_SET`): [ClusterResourceSet](./cluster-resource-set.md)
* `MachinePool` (env var: `EXP_MACHINE_POOL`): [MachinePools](./machine-pools.md)
* `MachineSetPreflightChecks` (env var: `EXP_MACHINE_SET_PREFLIGHT_CHECKS`): [MachineSetPreflightChecks](./machineset-preflight-checks.md)
* `PriorityQueue` (env var: `EXP_PRIORITY_QUEUE`): Enables the usage of the controller-runtime PriorityQueue: https://github.com/kubernetes-sigs/controller-runtime/issues/2374
* `MachineWaitForVolumeDetachConsiderVolumeAttachments` (env var: `EXP_MACHINE_WAITFORVOLUMEDETACH_CONSIDER_VOLUMEATTACHMENTS`):
* During Machine drain the Machine controller waits for volumes to be detached. Per default, the controller considers
`Nodes.status.volumesAttached` and `VolumesAttachments`. This feature flag allows to opt-out from considering `VolumeAttachments`.
Expand Down
7 changes: 7 additions & 0 deletions feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ const (
//
// beta: v1.9
MachineWaitForVolumeDetachConsiderVolumeAttachments featuregate.Feature = "MachineWaitForVolumeDetachConsiderVolumeAttachments"

// PriorityQueue is a feature gate that controls if the controller uses the controller-runtime PriorityQueue
// instead of the default queue implementation.
//
// alpha: v1.10
PriorityQueue featuregate.Feature = "PriorityQueue"
)

func init() {
Expand All @@ -82,6 +88,7 @@ var defaultClusterAPIFeatureGates = map[featuregate.Feature]featuregate.FeatureS
MachinePool: {Default: true, PreRelease: featuregate.Beta},
MachineSetPreflightChecks: {Default: true, PreRelease: featuregate.Beta},
MachineWaitForVolumeDetachConsiderVolumeAttachments: {Default: true, PreRelease: featuregate.Beta},
PriorityQueue: {Default: false, PreRelease: featuregate.Alpha},
ClusterTopology: {Default: false, PreRelease: featuregate.Alpha},
KubeadmBootstrapFormatIgnition: {Default: false, PreRelease: featuregate.Alpha},
RuntimeSDK: {Default: false, PreRelease: featuregate.Alpha},
Expand Down
6 changes: 6 additions & 0 deletions internal/test/envtest/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ import (
"k8s.io/component-base/logs"
logsv1 "k8s.io/component-base/logs/api/v1"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/metrics"
Expand All @@ -65,6 +67,7 @@ import (
expipamwebhooks "sigs.k8s.io/cluster-api/exp/ipam/webhooks"
runtimev1 "sigs.k8s.io/cluster-api/exp/runtime/api/v1alpha1"
expapiwebhooks "sigs.k8s.io/cluster-api/exp/webhooks"
"sigs.k8s.io/cluster-api/feature"
internalwebhooks "sigs.k8s.io/cluster-api/internal/webhooks"
runtimewebhooks "sigs.k8s.io/cluster-api/internal/webhooks/runtime"
"sigs.k8s.io/cluster-api/util/kubeconfig"
Expand Down Expand Up @@ -286,6 +289,9 @@ func newEnvironment(uncachedObjs ...client.Object) *Environment {
}

options := manager.Options{
Controller: config.Controller{
UsePriorityQueue: ptr.To[bool](feature.Gates.Enabled(feature.PriorityQueue)),
},
Scheme: scheme.Scheme,
Metrics: metricsserver.Options{
BindAddress: "0",
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ import (
logsv1 "k8s.io/component-base/logs/api/v1"
_ "k8s.io/component-base/logs/json/register"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/webhook"

Expand Down Expand Up @@ -332,6 +334,9 @@ func main() {
clusterSecretCacheSelector := labels.NewSelector().Add(*req)

ctrlOptions := ctrl.Options{
Controller: config.Controller{
UsePriorityQueue: ptr.To[bool](feature.Gates.Enabled(feature.PriorityQueue)),
},
Scheme: scheme,
LeaderElection: enableLeaderElection,
LeaderElectionID: "controller-leader-election-capi",
Expand Down
1 change: 1 addition & 0 deletions test/e2e/config/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ variables:
CLUSTER_TOPOLOGY: "true"
EXP_RUNTIME_SDK: "true"
EXP_MACHINE_SET_PREFLIGHT_CHECKS: "true"
EXP_PRIORITY_QUEUE: "false"
CAPI_DIAGNOSTICS_ADDRESS: ":8080"
CAPI_INSECURE_DIAGNOSTICS: "true"

Expand Down
1 change: 1 addition & 0 deletions test/extension/config/default/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spec:
- "--leader-elect"
- "--diagnostics-address=${CAPI_DIAGNOSTICS_ADDRESS:=:8443}"
- "--insecure-diagnostics=${CAPI_INSECURE_DIAGNOSTICS:=false}"
- "--feature-gates=PriorityQueue=${EXP_PRIORITY_QUEUE:=false}"
image: controller:latest
name: manager
ports:
Expand Down
8 changes: 8 additions & 0 deletions test/extension/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ import (
logsv1 "k8s.io/component-base/logs/api/v1"
_ "k8s.io/component-base/logs/json/register"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/config"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
Expand All @@ -49,6 +51,7 @@ import (
runtimecatalog "sigs.k8s.io/cluster-api/exp/runtime/catalog"
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
"sigs.k8s.io/cluster-api/exp/runtime/server"
"sigs.k8s.io/cluster-api/feature"
"sigs.k8s.io/cluster-api/test/extension/handlers/lifecycle"
"sigs.k8s.io/cluster-api/test/extension/handlers/topologymutation"
infrav1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/api/v1beta1"
Expand Down Expand Up @@ -154,6 +157,8 @@ func InitFlags(fs *pflag.FlagSet) {

flags.AddManagerOptions(fs, &managerOptions)

feature.MutableGates.AddFlag(fs)

// Add test-extension specific flags
// NOTE: it is not mandatory to use the same flag names in all RuntimeExtension, but it is recommended when
// addressing common concerns like profiler-address, webhook-port, webhook-cert-dir etc. because it helps in ensuring
Expand Down Expand Up @@ -220,6 +225,9 @@ func main() {
}

ctrlOptions := ctrl.Options{
Controller: config.Controller{
UsePriorityQueue: ptr.To[bool](feature.Gates.Enabled(feature.PriorityQueue)),
},
Scheme: scheme,
LeaderElection: enableLeaderElection,
LeaderElectionID: "controller-leader-election-capv-test-extension",
Expand Down
2 changes: 1 addition & 1 deletion test/infrastructure/docker/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ spec:
- "--leader-elect"
- "--diagnostics-address=${CAPI_DIAGNOSTICS_ADDRESS:=:8443}"
- "--insecure-diagnostics=${CAPI_INSECURE_DIAGNOSTICS:=false}"
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=true},ClusterTopology=${CLUSTER_TOPOLOGY:=false}"
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=true},ClusterTopology=${CLUSTER_TOPOLOGY:=false},PriorityQueue=${EXP_PRIORITY_QUEUE:=false}"
image: controller:latest
name: manager
env:
Expand Down
5 changes: 5 additions & 0 deletions test/infrastructure/docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ import (
logsv1 "k8s.io/component-base/logs/api/v1"
_ "k8s.io/component-base/logs/json/register"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/webhook"

Expand Down Expand Up @@ -230,6 +232,9 @@ func main() {
clusterSecretCacheSelector := labels.NewSelector().Add(*req)

ctrlOptions := ctrl.Options{
Controller: config.Controller{
UsePriorityQueue: ptr.To[bool](feature.Gates.Enabled(feature.PriorityQueue)),
},
Scheme: scheme,
LeaderElection: enableLeaderElection,
LeaderElectionID: "controller-leader-election-capd",
Expand Down
1 change: 1 addition & 0 deletions test/infrastructure/inmemory/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ spec:
- "--leader-elect"
- "--diagnostics-address=${CAPI_DIAGNOSTICS_ADDRESS:=:8443}"
- "--insecure-diagnostics=${CAPI_INSECURE_DIAGNOSTICS:=false}"
- "--feature-gates=PriorityQueue=${EXP_PRIORITY_QUEUE:=false}"
image: controller:latest
name: manager
env:
Expand Down
5 changes: 5 additions & 0 deletions test/infrastructure/inmemory/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ import (
logsv1 "k8s.io/component-base/logs/api/v1"
_ "k8s.io/component-base/logs/json/register"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/webhook"

Expand Down Expand Up @@ -208,6 +210,9 @@ func main() {
}

ctrlOptions := ctrl.Options{
Controller: config.Controller{
UsePriorityQueue: ptr.To[bool](feature.Gates.Enabled(feature.PriorityQueue)),
},
Scheme: scheme,
LeaderElection: enableLeaderElection,
LeaderElectionID: "inmemory-controller-leader-election-capi",
Expand Down

0 comments on commit 5e5909d

Please sign in to comment.