Skip to content

Commit 2be0669

Browse files
feat(failuredomains): add failure domain rollout controller
Adds a new controller that monitors cluster.status.failureDomains and triggers rollouts on KubeAdmControlPlane when failure domains currently in use by control plane machines are disabled or removed. The controller is enabled by default and can be disabled with --failure-domain-rollout-enabled=false.
1 parent 9c71eb0 commit 2be0669

File tree

6 files changed

+1521
-0
lines changed

6 files changed

+1521
-0
lines changed

charts/cluster-api-runtime-extensions-nutanix/templates/role.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,17 @@ rules:
7575
- cluster.x-k8s.io
7676
resources:
7777
- clusters
78+
- machines
7879
verbs:
7980
- get
8081
- list
8182
- watch
83+
- apiGroups:
84+
- cluster.x-k8s.io
85+
resources:
86+
- clusters/status
87+
verbs:
88+
- get
8289
- apiGroups:
8390
- cluster.x-k8s.io
8491
resources:
@@ -89,6 +96,16 @@ rules:
8996
- patch
9097
- update
9198
- watch
99+
- apiGroups:
100+
- controlplane.cluster.x-k8s.io
101+
resources:
102+
- kubeadmcontrolplanes
103+
verbs:
104+
- get
105+
- list
106+
- patch
107+
- update
108+
- watch
92109
- apiGroups:
93110
- storage.k8s.io
94111
resources:

cmd/main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"k8s.io/klog/v2"
2020
crsv1 "sigs.k8s.io/cluster-api/api/addons/v1beta1"
2121
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
22+
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
2223
ctrl "sigs.k8s.io/controller-runtime"
2324
"sigs.k8s.io/controller-runtime/pkg/client"
2425
"sigs.k8s.io/controller-runtime/pkg/controller"
@@ -32,6 +33,7 @@ import (
3233
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers"
3334
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/server"
3435
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/controllers/enforceclusterautoscalerlimits"
36+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/controllers/failuredomainrollout"
3537
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/controllers/namespacesync"
3638
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/feature"
3739
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws"
@@ -55,6 +57,7 @@ func main() {
5557
utilruntime.Must(clientgoscheme.AddToScheme(clientScheme))
5658
utilruntime.Must(crsv1.AddToScheme(clientScheme))
5759
utilruntime.Must(clusterv1.AddToScheme(clientScheme))
60+
utilruntime.Must(controlplanev1.AddToScheme(clientScheme))
5861
utilruntime.Must(caaphv1.AddToScheme(clientScheme))
5962

6063
webhookOptions := webhook.Options{
@@ -121,6 +124,7 @@ func main() {
121124

122125
namespacesyncOptions := namespacesync.Options{}
123126
enforceClusterAutoscalerLimitsOptions := enforceclusterautoscalerlimits.Options{}
127+
failureDomainRolloutOptions := failuredomainrollout.Options{}
124128

125129
// Initialize and parse command line flags.
126130
logs.AddFlags(pflag.CommandLine, logs.SkipLoggingConfigurationFlags())
@@ -133,6 +137,7 @@ func main() {
133137
nutanixMetaHandlers.AddFlags(pflag.CommandLine)
134138
namespacesyncOptions.AddFlags(pflag.CommandLine)
135139
enforceClusterAutoscalerLimitsOptions.AddFlags(pflag.CommandLine)
140+
failureDomainRolloutOptions.AddFlags(pflag.CommandLine)
136141
pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
137142
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
138143

@@ -232,6 +237,23 @@ func main() {
232237
}
233238
}
234239

240+
if failureDomainRolloutOptions.Enabled {
241+
if err := (&failuredomainrollout.Reconciler{
242+
Client: mgr.GetClient(),
243+
}).SetupWithManager(
244+
mgr,
245+
&controller.Options{MaxConcurrentReconciles: failureDomainRolloutOptions.Concurrency},
246+
); err != nil {
247+
setupLog.Error(
248+
err,
249+
"unable to create controller",
250+
"controller",
251+
"failuredomainrollout.Reconciler",
252+
)
253+
os.Exit(1)
254+
}
255+
}
256+
235257
mgr.GetWebhookServer().Register("/mutate-v1beta1-cluster", &webhook.Admission{
236258
Handler: cluster.NewDefaulter(mgr.GetClient(), admission.NewDecoder(mgr.GetScheme())),
237259
})

0 commit comments

Comments
 (0)