in controllers/manager/staticgatewayconfiguration_controller.go [255:301]
func validate(gwConfig *egressgatewayv1alpha1.StaticGatewayConfiguration) error {
// need to validate either GatewayNodepoolName or GatewayVmssProfile is provided, but not both
var allErrs field.ErrorList
if gwConfig.Spec.GatewayNodepoolName == "" && vmssProfileIsEmpty(gwConfig) {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec").Child("gatewaynodepoolname"),
fmt.Sprintf("GatewayNodepoolName: %s, GatewayVmssProfile: %#v", gwConfig.Spec.GatewayNodepoolName, gwConfig.Spec.GatewayVmssProfile),
"Either GatewayNodepoolName or GatewayVmssProfile must be provided"))
}
if gwConfig.Spec.GatewayNodepoolName != "" && !vmssProfileIsEmpty(gwConfig) {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec").Child("gatewaynodepoolname"),
fmt.Sprintf("GatewayNodepoolName: %s, GatewayVmssProfile: %#v", gwConfig.Spec.GatewayNodepoolName, gwConfig.Spec.GatewayVmssProfile),
"Only one of GatewayNodepoolName and GatewayVmssProfile should be provided"))
}
if !vmssProfileIsEmpty(gwConfig) {
if gwConfig.Spec.GatewayVmssProfile.VmssResourceGroup == "" {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec").Child("gatewayvmssprofile").Child("vmssresourcegroup"),
gwConfig.Spec.GatewayVmssProfile.VmssResourceGroup,
"Gateway vmss resource group is empty"))
}
if gwConfig.Spec.GatewayVmssProfile.VmssName == "" {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec").Child("gatewayvmssprofile").Child("vmssname"),
gwConfig.Spec.GatewayVmssProfile.VmssName,
"Gateway vmss name is empty"))
}
if gwConfig.Spec.GatewayVmssProfile.PublicIpPrefixSize < 0 || gwConfig.Spec.GatewayVmssProfile.PublicIpPrefixSize > 31 {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec").Child("gatewayvmssprofile").Child("publicipprefixsize"),
gwConfig.Spec.GatewayVmssProfile.PublicIpPrefixSize,
"Gateway vmss public ip prefix size should be between 0 and 31 inclusively"))
}
}
if !gwConfig.Spec.ProvisionPublicIps && gwConfig.Spec.PublicIpPrefixId != "" {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec").Child("publicipprefixid"),
gwConfig.Spec.PublicIpPrefixId,
"PublicIpPrefixId should be empty when ProvisionPublicIps is false"))
}
if len(allErrs) == 0 {
return nil
}
return apierrors.NewInvalid(
schema.GroupKind{Group: "egressgateway.kubernetes.azure.com", Kind: "StaticGatewayConfiguration"},
gwConfig.Name, allErrs)
}