Skip to content

Commit 91941d9

Browse files
authored
Merge pull request #4828 from prometherion/fixup-cluster-cp
🌱 Making ControlPlane LoadBalancer immutable for disabled type
2 parents 0b59c11 + 772417e commit 91941d9

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

api/v1beta2/awscluster_webhook.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ func (r *AWSCluster) validateControlPlaneLoadBalancerUpdate(oldlb, newlb *AWSLoa
153153
)
154154
}
155155
} else {
156+
// A disabled Load Balancer has many implications that must be treated as immutable/
157+
// this is mostly used by externally managed Control Plane, and there's no need to support type changes.
158+
// More info: https://kubernetes.slack.com/archives/CD6U2V71N/p1708983246100859?thread_ts=1708973478.410979&cid=CD6U2V71N
159+
if (oldlb.LoadBalancerType == LoadBalancerTypeDisabled && newlb.LoadBalancerType != LoadBalancerTypeDisabled) ||
160+
(newlb.LoadBalancerType == LoadBalancerTypeDisabled && oldlb.LoadBalancerType != LoadBalancerTypeDisabled) {
161+
allErrs = append(allErrs,
162+
field.Invalid(field.NewPath("spec", "controlPlaneLoadBalancer", "type"),
163+
newlb.Scheme, "field is immutable when created of disabled type"),
164+
)
165+
}
156166
// If old scheme was not nil, the new scheme should be the same.
157167
if !cmp.Equal(oldlb.Scheme, newlb.Scheme) {
158168
allErrs = append(allErrs,

api/v1beta2/awscluster_webhook_test.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,48 @@ func TestAWSClusterValidateCreate(t *testing.T) {
607607
}
608608

609609
func TestAWSClusterValidateUpdate(t *testing.T) {
610-
tests := []struct {
610+
var tests = []struct {
611611
name string
612612
oldCluster *AWSCluster
613613
newCluster *AWSCluster
614614
wantErr bool
615615
}{
616+
{
617+
name: "Control Plane LB type is immutable when switching from disabled to any",
618+
oldCluster: &AWSCluster{
619+
Spec: AWSClusterSpec{
620+
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
621+
LoadBalancerType: LoadBalancerTypeDisabled,
622+
},
623+
},
624+
},
625+
newCluster: &AWSCluster{
626+
Spec: AWSClusterSpec{
627+
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
628+
LoadBalancerType: LoadBalancerTypeClassic,
629+
},
630+
},
631+
},
632+
wantErr: true,
633+
},
634+
{
635+
name: "Control Plane LB type is immutable when switching from any to disabled",
636+
oldCluster: &AWSCluster{
637+
Spec: AWSClusterSpec{
638+
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
639+
LoadBalancerType: LoadBalancerTypeClassic,
640+
},
641+
},
642+
},
643+
newCluster: &AWSCluster{
644+
Spec: AWSClusterSpec{
645+
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
646+
LoadBalancerType: LoadBalancerTypeDisabled,
647+
},
648+
},
649+
},
650+
wantErr: true,
651+
},
616652
{
617653
name: "region is immutable",
618654
oldCluster: &AWSCluster{

0 commit comments

Comments
 (0)