@@ -1130,10 +1130,11 @@ func TestValidateEtcd(t *testing.T) {
1130
1130
1131
1131
func TestGetClusterNodeMask (t * testing.T ) {
1132
1132
tests := []struct {
1133
- name string
1134
- cfg * kubeadmapi.ClusterConfiguration
1135
- isIPv6 bool
1136
- expectedMask int
1133
+ name string
1134
+ cfg * kubeadmapi.ClusterConfiguration
1135
+ isIPv6 bool
1136
+ expectedMask int
1137
+ expectedError bool
1137
1138
}{
1138
1139
{
1139
1140
name : "ipv4 default mask" ,
@@ -1151,6 +1152,16 @@ func TestGetClusterNodeMask(t *testing.T) {
1151
1152
isIPv6 : false ,
1152
1153
expectedMask : 23 ,
1153
1154
},
1155
+ {
1156
+ name : "ipv4 wrong mask" ,
1157
+ cfg : & kubeadmapi.ClusterConfiguration {
1158
+ ControllerManager : kubeadmapi.ControlPlaneComponent {
1159
+ ExtraArgs : map [string ]string {"node-cidr-mask-size" : "aa23" },
1160
+ },
1161
+ },
1162
+ isIPv6 : false ,
1163
+ expectedError : true ,
1164
+ },
1154
1165
{
1155
1166
name : "ipv6 default mask" ,
1156
1167
cfg : & kubeadmapi.ClusterConfiguration {},
@@ -1216,6 +1227,17 @@ func TestGetClusterNodeMask(t *testing.T) {
1216
1227
isIPv6 : false ,
1217
1228
expectedMask : 23 ,
1218
1229
},
1230
+ {
1231
+ name : "dual ipv4 wrong mask" ,
1232
+ cfg : & kubeadmapi.ClusterConfiguration {
1233
+ FeatureGates : map [string ]bool {features .IPv6DualStack : true },
1234
+ ControllerManager : kubeadmapi.ControlPlaneComponent {
1235
+ ExtraArgs : map [string ]string {"node-cidr-mask-size-ipv4" : "aa" },
1236
+ },
1237
+ },
1238
+ isIPv6 : false ,
1239
+ expectedError : true ,
1240
+ },
1219
1241
{
1220
1242
name : "dual ipv6 default mask and legacy flag" ,
1221
1243
cfg : & kubeadmapi.ClusterConfiguration {
@@ -1238,10 +1260,25 @@ func TestGetClusterNodeMask(t *testing.T) {
1238
1260
isIPv6 : true ,
1239
1261
expectedMask : 83 ,
1240
1262
},
1263
+ {
1264
+ name : "dual ipv6 custom mask and wrong flag" ,
1265
+ cfg : & kubeadmapi.ClusterConfiguration {
1266
+ FeatureGates : map [string ]bool {features .IPv6DualStack : true },
1267
+ ControllerManager : kubeadmapi.ControlPlaneComponent {
1268
+ ExtraArgs : map [string ]string {"node-cidr-mask-size" : "23" , "node-cidr-mask-size-ipv6" : "a83" },
1269
+ },
1270
+ },
1271
+ isIPv6 : true ,
1272
+ expectedError : true ,
1273
+ },
1241
1274
}
1242
1275
for _ , test := range tests {
1243
1276
t .Run (test .name , func (t * testing.T ) {
1244
- if mask := getClusterNodeMask (test .cfg , test .isIPv6 ); mask != test .expectedMask {
1277
+ mask , err := getClusterNodeMask (test .cfg , test .isIPv6 )
1278
+ if (err == nil ) == test .expectedError {
1279
+ t .Errorf ("expected error: %v, got %v" , test .expectedError , err )
1280
+ }
1281
+ if mask != test .expectedMask {
1245
1282
t .Errorf ("expected mask: %d, got %d" , test .expectedMask , mask )
1246
1283
}
1247
1284
})
0 commit comments