func validateURLPathMaps()

in pkg/appgw/validators.go [56:111]


func validateURLPathMaps(eventRecorder record.EventRecorder, config *n.ApplicationGatewayPropertiesFormat, envVariables environment.EnvVariables, ingressList []*networking.Ingress, serviceList []*v1.Service) error {
	if config.URLPathMaps == nil {
		return nil
	}

	for _, pathMap := range *config.URLPathMaps {
		if len(*pathMap.PathRules) == 0 {
			// There are no paths. This is a rule of type "Basic"
			validRedirect := pathMap.DefaultRedirectConfiguration != nil
			validBackend := pathMap.DefaultBackendAddressPool != nil && pathMap.DefaultBackendHTTPSettings != nil

			if !validRedirect && !validBackend {
				// TODO(draychev): Emit an event for the appropriate object
				e := controllererrors.NewErrorf(
					controllererrors.ErrorNoDefaults,
					"URL path map '%s' needs either a default backend pool or default redirect", *pathMap.Name,
				)
				return e
			}

			if validRedirect && validBackend || !validRedirect && !validBackend {
				// TODO(draychev): Emit an event for the appropriate object
				e := controllererrors.NewErrorf(
					controllererrors.ErrorEitherDefaults,
					"URL path map '%s' needs only one of default backend pool or default redirect", *pathMap.Name,
				)
				return e
			}

		} else {
			// There are paths defined. This is a rule of type "Path-based"
			for _, rule := range *pathMap.PathRules {
				validRedirect := rule.RedirectConfiguration != nil
				validBackend := rule.BackendAddressPool != nil && rule.BackendHTTPSettings != nil

				if !validRedirect && !validBackend {
					e := controllererrors.NewErrorf(
						controllererrors.ErrorNoBackendorRedirect,
						"Path Rule '%s' needs either a default backend pool or default redirect", *rule.Name,
					)
					return e
				}

				if validRedirect && validBackend || !validRedirect && !validBackend {
					e := controllererrors.NewErrorf(
						controllererrors.ErrorEitherBackendorRedirect,
						"Path Rule '%s' needs either a default backend pool or default redirect", *rule.Name,
					)
					return e
				}
			}

		}
	}
	return nil
}