Skip to content

Commit 0199374

Browse files
feat(failuredomains): add failure domain rollout controller (#1207)
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. **How has this been tested?** * Create 4 failure domains: fd-1, fd-2, fd-3, fd-4 * Create a cluster with control plane on 3 failure domains fd-1, fd-2, fd-3 * Remove fd-3 from the control plane configuration and observe a rollout to fd-1 & fd-2 only * Add fd-3 again and observe a rollout to fd-1, fd-2, and fd-3 * Add fd-4 to control plane configuration and observe no rollout takes place
1 parent dd7e338 commit 0199374

File tree

6 files changed

+2417
-0
lines changed

6 files changed

+2417
-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"
@@ -33,6 +34,7 @@ import (
3334
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers"
3435
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/server"
3536
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/controllers/enforceclusterautoscalerlimits"
37+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/controllers/failuredomainrollout"
3638
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/controllers/namespacesync"
3739
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/feature"
3840
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws"
@@ -56,6 +58,7 @@ func main() {
5658
utilruntime.Must(clientgoscheme.AddToScheme(clientScheme))
5759
utilruntime.Must(crsv1.AddToScheme(clientScheme))
5860
utilruntime.Must(clusterv1.AddToScheme(clientScheme))
61+
utilruntime.Must(controlplanev1.AddToScheme(clientScheme))
5962
utilruntime.Must(caaphv1.AddToScheme(clientScheme))
6063
utilruntime.Must(capxv1.AddToScheme(clientScheme))
6164

@@ -123,6 +126,7 @@ func main() {
123126

124127
namespacesyncOptions := namespacesync.Options{}
125128
enforceClusterAutoscalerLimitsOptions := enforceclusterautoscalerlimits.Options{}
129+
failureDomainRolloutOptions := failuredomainrollout.Options{}
126130

127131
// Initialize and parse command line flags.
128132
logs.AddFlags(pflag.CommandLine, logs.SkipLoggingConfigurationFlags())
@@ -135,6 +139,7 @@ func main() {
135139
nutanixMetaHandlers.AddFlags(pflag.CommandLine)
136140
namespacesyncOptions.AddFlags(pflag.CommandLine)
137141
enforceClusterAutoscalerLimitsOptions.AddFlags(pflag.CommandLine)
142+
failureDomainRolloutOptions.AddFlags(pflag.CommandLine)
138143
pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
139144
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
140145

@@ -234,6 +239,23 @@ func main() {
234239
}
235240
}
236241

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

0 commit comments

Comments
 (0)