@@ -24,6 +24,7 @@ import (
24
24
25
25
apierrors "k8s.io/apimachinery/pkg/api/errors"
26
26
"k8s.io/apimachinery/pkg/util/validation/field"
27
+ "k8s.io/utils/pointer"
27
28
28
29
"github.com/pkg/errors"
29
30
"k8s.io/apimachinery/pkg/runtime"
@@ -123,6 +124,15 @@ func (r *GCPManagedControlPlane) ValidateUpdate(oldRaw runtime.Object) (admissio
123
124
)
124
125
}
125
126
127
+ // Add IPAllocationPolicy for CIDR support (PLT-1246)
128
+
129
+ if ! cmp .Equal (r .Spec .ClusterIpv4Cidr , old .Spec .ClusterIpv4Cidr ) {
130
+ allErrs = append (allErrs ,
131
+ field .Invalid (field .NewPath ("spec" , "ClusterIpv4Cidr" ),
132
+ pointer .StringDeref (r .Spec .ClusterIpv4Cidr , "" ), "field is immutable" ),
133
+ )
134
+ }
135
+
126
136
if ! cmp .Equal (r .Spec .EnableAutopilot , old .Spec .EnableAutopilot ) {
127
137
allErrs = append (allErrs ,
128
138
field .Invalid (field .NewPath ("spec" , "EnableAutopilot" ),
@@ -167,3 +177,54 @@ func generateGKEName(resourceName, namespace string, maxLength int) (string, err
167
177
168
178
return fmt .Sprintf ("%s%s" , resourcePrefix , hashedName ), nil
169
179
}
180
+
181
+ // Add IPAllocationPolicy for CIDR support (PLT-1246)
182
+
183
+ func validateIPAllocationPolicy (spec GCPManagedControlPlaneSpec ) field.ErrorList {
184
+ var allErrs field.ErrorList
185
+
186
+ if spec .IPAllocationPolicy == nil {
187
+ return allErrs
188
+ }
189
+
190
+ path := field .NewPath ("spec" , "IPAllocationPolicy" )
191
+
192
+ isUseIPAliases := pointer .BoolDeref (spec .IPAllocationPolicy .UseIPAliases , false )
193
+ if spec .IPAllocationPolicy .ClusterSecondaryRangeName != nil && ! isUseIPAliases {
194
+ allErrs = append (allErrs ,
195
+ field .Invalid (path .Child ("ClusterSecondaryRangeName" ),
196
+ spec .IPAllocationPolicy .ClusterSecondaryRangeName ,
197
+ "field cannot be set unless UseIPAliases is set to true" ),
198
+ )
199
+ }
200
+ if spec .IPAllocationPolicy .ServicesSecondaryRangeName != nil && ! isUseIPAliases {
201
+ allErrs = append (allErrs ,
202
+ field .Invalid (path .Child ("ServicesSecondaryRangeName" ),
203
+ spec .IPAllocationPolicy .ServicesSecondaryRangeName ,
204
+ "field cannot be set unless UseIPAliases is set to true" ),
205
+ )
206
+ }
207
+ if spec .IPAllocationPolicy .ServicesIpv4CidrBlock != nil && ! isUseIPAliases {
208
+ allErrs = append (allErrs ,
209
+ field .Invalid (path .Child ("ServicesIpv4CidrBlock" ),
210
+ spec .IPAllocationPolicy .ServicesIpv4CidrBlock ,
211
+ "field cannot be set unless UseIPAliases is set to true" ),
212
+ )
213
+ }
214
+ if spec .IPAllocationPolicy .ClusterIpv4CidrBlock != nil && ! isUseIPAliases {
215
+ allErrs = append (allErrs ,
216
+ field .Invalid (path .Child ("ClusterIpv4CidrBlock" ),
217
+ spec .IPAllocationPolicy .ClusterIpv4CidrBlock ,
218
+ "field cannot be set unless UseIPAliases is set to true" ),
219
+ )
220
+ }
221
+ if spec .IPAllocationPolicy .ClusterIpv4CidrBlock != nil && spec .ClusterIpv4Cidr != nil {
222
+ allErrs = append (allErrs ,
223
+ field .Invalid (path .Child ("ClusterIpv4CidrBlock" ),
224
+ spec .IPAllocationPolicy .ClusterIpv4CidrBlock ,
225
+ "only one of spec.ClusterIpv4Cidr and spec.IPAllocationPolicy.ClusterIpv4CidrBlock can be set" ),
226
+ )
227
+ }
228
+
229
+ return allErrs
230
+ }
0 commit comments