// validateRange checks that the allocated range and the alias range
// match.
189415
func (op *updateOp) validateRange(ctx context.Context, sync *NodeSync, node *v1.Node, aliasRange *net.IPNet) error {
	if node.Spec.PodCIDR != aliasRange.String() {
		klog.Errorf("Inconsistency detected between node PodCIDR and node alias (%v != %v)",
			node.Spec.PodCIDR, aliasRange)
		sync.kubeAPI.EmitNodeWarningEvent(node.Name, MismatchEvent,
			"Node.Spec.PodCIDR != cloud alias (%v != %v)", node.Spec.PodCIDR, aliasRange)
		// User intervention is required in this case, as this is most likely due
		// to the user mucking around with their VM aliases on the side.
	} else {
		klog.V(4).Infof("Node %q CIDR range %v is matches cloud assignment", node.Name, node.Spec.PodCIDR)
	}
	return nil
}
877021
func (m *RedisProxy_ConnPoolSettings) Validate() error {
	if m == nil {
		return nil
	}

	if m.GetOpTimeout() == nil {
		return RedisProxy_ConnPoolSettingsValidationError{
			field:  "OpTimeout",
			reason: "value is required",
		}
	}

	// no validation rules for EnableHashtagging

	// no validation rules for EnableRedirection

	// no validation rules for MaxBufferSizeBeforeFlush

	{
		tmp := m.GetBufferFlushTimeout()

		if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

			if err := v.Validate(); err != nil {
				return RedisProxy_ConnPoolSettingsValidationError{
					field:  "BufferFlushTimeout",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	}

	return nil
}
142887
func ValidateRule(obj *Rule) error {
	collections.ruleMutex.Lock()
	defer collections.ruleMutex.Unlock()

	// Validate key is correct
	keyStr := obj.TenantName + ":" + obj.PolicyName + ":" + obj.RuleID
	if obj.Key != keyStr {
		log.Errorf("Expecting Rule Key: %s. Got: %s", keyStr, obj.Key)
		return errors.New("Invalid Key")
	}

	// Validate each field

	actionMatch := regexp.MustCompile("^(allow|deny)$")
	if actionMatch.MatchString(obj.Action) == false {
		return errors.New("action string invalid format")
	}

	directionMatch := regexp.MustCompile("^(in|out)$")
	if directionMatch.MatchString(obj.Direction) == false {
		return errors.New("direction string invalid format")
	}

	if len(obj.FromEndpointGroup) > 64 {
		return errors.New("fromEndpointGroup string too long")
	}

	fromEndpointGroupMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])?$")
	if fromEndpointGroupMatch.MatchString(obj.FromEndpointGroup) == false {
		return errors.New("fromEndpointGroup string invalid format")
	}

	fromIpAddressMatch := regexp.MustCompile("^(((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})(\\-(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]))?(/(3[0-1]|2[0-9]|1[0-9]|[1-9]))?)?$")
	if fromIpAddressMatch.MatchString(obj.FromIpAddress) == false {
		return errors.New("fromIpAddress string invalid format")
	}

	if len(obj.FromNetwork) > 64 {
		return errors.New("fromNetwork string too long")
	}

	fromNetworkMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])?$")
	if fromNetworkMatch.MatchString(obj.FromNetwork) == false {
		return errors.New("fromNetwork string invalid format")
	}

	if len(obj.PolicyName) > 64 {
		return errors.New("policyName string too long")
	}

	policyNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$")
	if policyNameMatch.MatchString(obj.PolicyName) == false {
		return errors.New("policyName string invalid format")
	}

	if obj.Port > 65535 {
		return errors.New("port Value Out of bound")
	}

	if obj.Priority == 0 {
		obj.Priority = 1
	}

	if obj.Priority < 1 {
		return errors.New("priority Value Out of bound")
	}

	if obj.Priority > 100 {
		return errors.New("priority Value Out of bound")
	}

	protocolMatch := regexp.MustCompile("^(tcp|udp|icmp||[0-9]{1,3}?)$")
	if protocolMatch.MatchString(obj.Protocol) == false {
		return errors.New("protocol string invalid format")
	}

	if len(obj.RuleID) > 64 {
		return errors.New("ruleId string too long")
	}

	ruleIdMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$")
	if ruleIdMatch.MatchString(obj.RuleID) == false {
		return errors.New("ruleId string invalid format")
	}

	if len(obj.TenantName) > 64 {
		return errors.New("tenantName string too long")
	}

	tenantNameMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$")
	if tenantNameMatch.MatchString(obj.TenantName) == false {
		return errors.New("tenantName string invalid format")
	}

	if len(obj.ToEndpointGroup) > 64 {
		return errors.New("toEndpointGroup string too long")
	}

	toEndpointGroupMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])?$")
	if toEndpointGroupMatch.MatchString(obj.ToEndpointGroup) == false {
		return errors.New("toEndpointGroup string invalid format")
	}

	toIpAddressMatch := regexp.MustCompile("^(((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})(\\-(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]))?(/(3[0-1]|2[0-9]|1[0-9]|[1-9]))?)?$")
	if toIpAddressMatch.MatchString(obj.ToIpAddress) == false {
		return errors.New("toIpAddress string invalid format")
	}

	if len(obj.ToNetwork) > 64 {
		return errors.New("toNetwork string too long")
	}

	toNetworkMatch := regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])?$")
	if toNetworkMatch.MatchString(obj.ToNetwork) == false {
		return errors.New("toNetwork string invalid format")
	}

	return nil
}
940258
func (m *EndpointNetworking) Validate(formats strfmt.Registry) error {
	var res []error

	if err := m.validateAddressing(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validateHostAddressing(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}
1123934
func ValidateAddress(addr string) error {
	for _, chr := range invalidAddressRunes {
		if strings.ContainsRune(addr, chr) {
			return ErrInvalidAddress
		}
	}
	return nil
}
996822
func (p PortRange) Validate() error {
	proto := strings.ToLower(p.Protocol)
	if proto != "tcp" && proto != "udp" && proto != "icmp" {
		return errors.Errorf(`invalid protocol %q, expected "tcp", "udp", or "icmp"`, proto)
	}
	if proto == "icmp" {
		if p.FromPort == p.ToPort && p.FromPort == -1 {
			return nil
		}
		return errors.Errorf(`protocol "icmp" doesn't support any ports; got "%v"`, p.FromPort)
	}
	err := errors.Errorf(
		"invalid port range %d-%d/%s",
		p.FromPort,
		p.ToPort,
		p.Protocol,
	)
	switch {
	case p.FromPort > p.ToPort:
		return err
	case p.FromPort < 1 || p.FromPort > 65535:
		return err
	case p.ToPort < 1 || p.ToPort > 65535:
		return err
	}
	return nil
}
961971
func (s PrefixSecret) Validate() error {
	if len(s) != PrefixSecretLength {
		return fmt.Errorf("invalid prefix secret length (%d != %d)", len(s), PrefixSecretLength)
	}
	return nil
}
166031
func validateRegex(v string) error {
	_, err := regexp.Compile(v)
	return err
}
171348
func (m *FaultRateLimit_FixedLimit) Validate() error {
	if m == nil {
		return nil
	}

	if m.GetLimitKbps() < 1 {
		return FaultRateLimit_FixedLimitValidationError{
			field:  "LimitKbps",
			reason: "value must be greater than or equal to 1",
		}
	}

	return nil
}
1252420
func validateRef(ctx *validation.Context, configSet, path string, content []byte) error {
	ctx.SetFile(path)
	// cq.cfg has been disallowed since Feb 1, 2019.
	// keep this error in place till Apr 1, 2019, to encourage clients remove this
	// config file from their repo.
	ctx.Errorf("cq.cfg is no longer used and has no effect. Please, delete cq.cfg in your repo.")
	ctx.Errorf("cq.cfg is replaced by commit-queue.cfg")
	return nil
}
1047675
func (sd *ServiceDefinition) validate(context *validationContext) error {
	//TODO: check name, description, config files.

	//Check MinMax settings
	if err := sd.Instances.Validate(); err != nil {
		return fmt.Errorf("service Definition %v: %v", sd.Name, err)
	}

	if err := validation.StringIn(sd.Launch, commons.AUTO, commons.MANUAL); err != nil {
		return fmt.Errorf("service definition %v: invalid launch setting %v", sd.Name, err)
	}

	//validate endpoint config
	names := make(map[string]struct{})
	for _, se := range sd.Endpoints {
		if err := se.ValidEntity(); err != nil {
			return fmt.Errorf("service definition %v: %v", sd.Name, err)
		}
		if err := context.validateVHost(se); err != nil {
			return fmt.Errorf("service definition %v: %v", sd.Name, err)
		}
		//enable unique endpoint name validation
		trimName := strings.Trim(se.Name, " ")
		if _, found := names[trimName]; found {
			return fmt.Errorf("service definition %v: Endpoint name %s not unique in service definition", sd.Name, trimName)
		}
		names[trimName] = struct{}{}
	}
	//TODO: validate LogConfigs

	// validate Monitoring Profile
	if err := sd.MonitoringProfile.ValidEntity(); err != nil {
		return fmt.Errorf("service definition %v: invalid monitoring profile %s", sd.Name, err)
	}

	return validServiceDefinitions(&sd.Services, context)
}
792961
func (m *Matcher) Validate() error {
	var errs []error
	if m.NamespaceLister == nil {
		errs = append(errs, fmt.Errorf("the namespace matcher requires a namespaceLister"))
	}
	if m.Client == nil {
		errs = append(errs, fmt.Errorf("the namespace matcher requires a namespaceLister"))
	}
	return utilerrors.NewAggregate(errs)
}
1072989
func ValidateRoute(route *routeapi.Route) field.ErrorList {
	//ensure meta is set properly
	result := validation.ValidateObjectMeta(&route.ObjectMeta, true, ValidateRouteName, field.NewPath("metadata"))

	specPath := field.NewPath("spec")

	//host is not required but if it is set ensure it meets DNS requirements
	if len(route.Spec.Host) > 0 {
		// TODO: Add a better check that the host name matches up to
		//       DNS requirements. Change to use:
		//         ValidateHostName(route)
		//       Need to check the implications of doing it here in
		//       ValidateRoute - probably needs to be done only on
		//       creation time for new routes.
		if len(kvalidation.IsDNS1123Subdomain(route.Spec.Host)) != 0 {
			result = append(result, field.Invalid(specPath.Child("host"), route.Spec.Host, "host must conform to DNS 952 subdomain conventions"))
		}
	}

	if err := validateWildcardPolicy(route.Spec.Host, route.Spec.WildcardPolicy, specPath.Child("wildcardPolicy")); err != nil {
		result = append(result, err)
	}

	if len(route.Spec.Path) > 0 && !strings.HasPrefix(route.Spec.Path, "/") {
		result = append(result, field.Invalid(specPath.Child("path"), route.Spec.Path, "path must begin with /"))
	}

	if len(route.Spec.Path) > 0 && route.Spec.TLS != nil &&
		route.Spec.TLS.Termination == routeapi.TLSTerminationPassthrough {
		result = append(result, field.Invalid(specPath.Child("path"), route.Spec.Path, "passthrough termination does not support paths"))
	}

	if len(route.Spec.To.Name) == 0 {
		result = append(result, field.Required(specPath.Child("to", "name"), ""))
	}
	if route.Spec.To.Kind != "Service" {
		result = append(result, field.Invalid(specPath.Child("to", "kind"), route.Spec.To.Kind, "must reference a Service"))
	}
	if route.Spec.To.Weight != nil && (*route.Spec.To.Weight < 0 || *route.Spec.To.Weight > 256) {
		result = append(result, field.Invalid(specPath.Child("to", "weight"), route.Spec.To.Weight, "weight must be an integer between 0 and 256"))
	}

	backendPath := specPath.Child("alternateBackends")
	if len(route.Spec.AlternateBackends) > 3 {
		result = append(result, field.Required(backendPath, "cannot specify more than 3 alternate backends"))
	}
	for i, svc := range route.Spec.AlternateBackends {
		if len(svc.Name) == 0 {
			result = append(result, field.Required(backendPath.Index(i).Child("name"), ""))
		}
		if svc.Kind != "Service" {
			result = append(result, field.Invalid(backendPath.Index(i).Child("kind"), svc.Kind, "must reference a Service"))
		}
		if svc.Weight != nil && (*svc.Weight < 0 || *svc.Weight > 256) {
			result = append(result, field.Invalid(backendPath.Index(i).Child("weight"), svc.Weight, "weight must be an integer between 0 and 256"))
		}
	}

	if route.Spec.Port != nil {
		switch target := route.Spec.Port.TargetPort; {
		case target.Type == intstr.Int && target.IntVal == 0,
			target.Type == intstr.String && len(target.StrVal) == 0:
			result = append(result, field.Required(specPath.Child("port", "targetPort"), ""))
		}
	}

	if errs := validateTLS(route, specPath.Child("tls")); len(errs) != 0 {
		result = append(result, errs...)
	}

	return result
}
912422
func (e Email) Validate(_ interface{}) error {
	if govalidator.IsEmail(string(e)) {
		return nil
	}

	return errInvalidEmail
}
1339620
func ValidateRemote(remote string) error {
	remotes, err := RemoteList()
	if err != nil {
		return err
	}
	for _, r := range remotes {
		if r == remote {
			return nil
		}
	}

	if err = ValidateRemoteURL(remote); err == nil {
		return nil
	}

	return fmt.Errorf("Invalid remote name: %q", remote)
}
899583
func ValidAlias(alias string) bool {
	for _, i := range DateTimeAliases {
		if i == alias {
			return true
		}
	}
	return false
}
1092669
func (a *AliasAddAction) Validate() error {
	var invalid []string
	if len(a.alias) == 0 {
		invalid = append(invalid, "Alias")
	}
	if len(a.index) == 0 {
		invalid = append(invalid, "Index")
	}
	if len(invalid) > 0 {
		return fmt.Errorf("missing required fields: %v", invalid)
	}
	if a.isWriteIndex != nil && len(a.index) > 1 {
		return fmt.Errorf("more than 1 target index specified in operation with 'is_write_index' flag present")
	}
	return nil
}