func Validate(e *v1alpha1.EtcdCluster) field.ErrorList {
	etcd := e.DeepCopy()
	allErrs := field.ErrorList{}

	fldPath := field.NewPath("spec")

	if etcd.Spec.Size < 1 || etcd.Spec.Size > 7 {
		allErrs = append(allErrs, field.Invalid(fldPath.Child("size"), etcd.Spec.Size, "must >= 1 and <= 7"))
	}

	_, err := semver.Parse(etcd.Spec.Version)
	if err != nil {
		allErrs = append(allErrs, field.Invalid(fldPath.Child("version"), etcd.Spec.Version, "must be a semver version"))
	}

	// external and autogenerate can't exist at the same time
	if etcd.Spec.Secure != nil && etcd.Spec.Secure.TLS != nil && etcd.Spec.Secure.TLS.ExternalCerts != nil && etcd.Spec.Secure.TLS.AutoTLSCert != nil {
		tls := etcd.Spec.Secure.TLS
		if tls.AutoTLSCert.AutoGenerateServerCert && tls.ExternalCerts.ServerSecret != "" {
			allErrs = append(allErrs, field.Invalid(fldPath.Child("secure", "tls", "autoTLSCert", "autoGenerateServerCert"), tls.AutoTLSCert.AutoGenerateServerCert, "can't be specified at the same time as serverSecret"))
		}
		if tls.AutoTLSCert.AutoGeneratePeerCert && tls.ExternalCerts.PeerSecret != "" {
			allErrs = append(allErrs, field.Invalid(fldPath.Child("secure", "tls", "autoTLSCert", "autoGeneratePeerCert"), tls.AutoTLSCert.AutoGeneratePeerCert, "can't be specified at the same time as peerSecret"))
		}
		if tls.AutoTLSCert.AutoGenerateClientCert && tls.ExternalCerts.ClientSecret != "" {
			allErrs = append(allErrs, field.Invalid(fldPath.Child("secure", "tls", "autoTLSCert", "autoGenerateClientCert"), tls.AutoTLSCert.AutoGenerateClientCert, "can't be specified at the same time as clientSecret"))
		}
	}

	if len(etcd.Spec.Learners) > 1 {
		allErrs = append(allErrs, field.TooMany(fldPath.Child("learners"), len(etcd.Spec.Learners), 1))
	} else if len(etcd.Spec.Learners) == 1 {
		index, err := strconv.Atoi(etcd.Spec.Learners[0])
		if err != nil {
			allErrs = append(allErrs, field.Invalid(fldPath.Child("learners"), etcd.Spec.Learners, "must be an array of numeric strings"))
		} else if int32(index) >= etcd.Spec.Size {
			allErrs = append(allErrs, field.Invalid(fldPath.Child("learners"), etcd.Spec.Learners, "must less than etcd size"))
		}
	}

	return allErrs
}
// Validate validate an etcd cluster
Validate validate an etcd cluster
// Validate validate an etcd cluster
func Validate(e *v1alpha1.EtcdCluster) field.ErrorList {
	etcd := e.DeepCopy()
	allErrs := field.ErrorList{}
	fldPath := field.NewPath("spec")
	if etcd.Spec.Size < 1 || etcd.Spec.Size > 7 {
		allErrs = append(allErrs, field.Invalid(fldPath.Child("size"), etcd.Spec.Size, "must >= 1 and <= 7"))
	}
	_, err := semver.Parse(etcd.Spec.Version)
	if err != nil {
		allErrs = append(allErrs, field.Invalid(fldPath.Child("version"), etcd.Spec.Version, "must be a semver version"))
	}
	if etcd.Spec.Secure != nil && etcd.Spec.Secure.TLS != nil && etcd.Spec.Secure.TLS.ExternalCerts != nil && etcd.Spec.Secure.TLS.AutoTLSCert != nil {
		tls := etcd.Spec.Secure.TLS
		if tls.AutoTLSCert.AutoGenerateServerCert && tls.ExternalCerts.ServerSecret != "" {
			allErrs = append(allErrs, field.Invalid(fldPath.Child("secure", "tls", "autoTLSCert", "autoGenerateServerCert"), tls.AutoTLSCert.AutoGenerateServerCert, "can't be specified at the same time as serverSecret"))
		}
		if tls.AutoTLSCert.AutoGeneratePeerCert && tls.ExternalCerts.PeerSecret != "" {
			allErrs = append(allErrs, field.Invalid(fldPath.Child("secure", "tls", "autoTLSCert", "autoGeneratePeerCert"), tls.AutoTLSCert.AutoGeneratePeerCert, "can't be specified at the same time as peerSecret"))
		}
		if tls.AutoTLSCert.AutoGenerateClientCert && tls.ExternalCerts.ClientSecret != "" {
			allErrs = append(allErrs, field.Invalid(fldPath.Child("secure", "tls", "autoTLSCert", "autoGenerateClientCert"), tls.AutoTLSCert.AutoGenerateClientCert, "can't be specified at the same time as clientSecret"))
		}
	}
	if len(etcd.Spec.Learners) > 1 {
		allErrs = append(allErrs, field.TooMany(fldPath.Child("learners"), len(etcd.Spec.Learners), 1))
	} else if len(etcd.Spec.Learners) == 1 {
		index, err := strconv.Atoi(etcd.Spec.Learners[0])
		if err != nil {
			allErrs = append(allErrs, field.Invalid(fldPath.Child("learners"), etcd.Spec.Learners, "must be an array of numeric strings"))
		} else if int32(index) >= etcd.Spec.Size {
			allErrs = append(allErrs, field.Invalid(fldPath.Child("learners"), etcd.Spec.Learners, "must less than etcd size"))
		}
	}
	return allErrs
}
func Validate ( e * v1alpha1 . EtcdCluster ) field . ErrorList { etcd := e . DeepCopy ( ) allErrs := field . ErrorList { } fldPath := field . NewPath ( " " ) if etcd . Spec . Size < 1 || etcd . Spec . Size > 7 { allErrs = append ( allErrs , field . Invalid ( fldPath . Child ( " " ) , etcd . Spec . Size , " " ) ) } _ , err := semver . Parse ( etcd . Spec . Version ) if err != nil { allErrs = append ( allErrs , field . Invalid ( fldPath . Child ( " " ) , etcd . Spec . Version , " " ) ) } if etcd . Spec . Secure != nil && etcd . Spec . Secure . TLS != nil && etcd . Spec . Secure . TLS . ExternalCerts != nil && etcd . Spec . Secure . TLS . AutoTLSCert != nil { tls := etcd . Spec . Secure . TLS if tls . AutoTLSCert . AutoGenerateServerCert && tls . ExternalCerts . ServerSecret != " " { allErrs = append ( allErrs , field . Invalid ( fldPath . Child ( " " , " " , " " , " " ) , tls . AutoTLSCert . AutoGenerateServerCert , " " ) ) } if tls . AutoTLSCert . AutoGeneratePeerCert && tls . ExternalCerts . PeerSecret != " " { allErrs = append ( allErrs , field . Invalid ( fldPath . Child ( " " , " " , " " , " " ) , tls . AutoTLSCert . AutoGeneratePeerCert , " " ) ) } if tls . AutoTLSCert . AutoGenerateClientCert && tls . ExternalCerts . ClientSecret != " " { allErrs = append ( allErrs , field . Invalid ( fldPath . Child ( " " , " " , " " , " " ) , tls . AutoTLSCert . AutoGenerateClientCert , " " ) ) } } if len ( etcd . Spec . Learners ) > 1 { allErrs = append ( allErrs , field . TooMany ( fldPath . Child ( " " ) , len ( etcd . Spec . Learners ) , 1 ) ) } else if len ( etcd . Spec . Learners ) == 1 { index , err := strconv . Atoi ( etcd . Spec . Learners [ 0 ] ) if err != nil { allErrs = append ( allErrs , field . Invalid ( fldPath . Child ( " " ) , etcd . Spec . Learners , " " ) ) } else if int32 ( index ) >= etcd . Spec . Size { allErrs = append ( allErrs , field . Invalid ( fldPath . Child ( " " ) , etcd . Spec . Learners , " " ) ) } } return allErrs }
Validate validate an etcd cluster
Validate validate an etcd cluster
// external and autogenerate can't exist at the same time