當前位置: 首頁>>代碼示例>>Golang>>正文


Golang validation.IsValidLabelValue函數代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/util/validation.IsValidLabelValue函數的典型用法代碼示例。如果您正苦於以下問題:Golang IsValidLabelValue函數的具體用法?Golang IsValidLabelValue怎麽用?Golang IsValidLabelValue使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了IsValidLabelValue函數的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: parseLabels

func parseLabels(spec []string) (map[string]string, []string, error) {
	labels := map[string]string{}
	var remove []string
	for _, labelSpec := range spec {
		if strings.Index(labelSpec, "=") != -1 {
			parts := strings.Split(labelSpec, "=")
			if len(parts) != 2 || len(parts[1]) == 0 {
				return nil, nil, fmt.Errorf("invalid label spec: %v", labelSpec)
			}
			if errs := validation.IsValidLabelValue(parts[1]); len(errs) != 0 {
				return nil, nil, fmt.Errorf("invalid label value: %q: %s", labelSpec, strings.Join(errs, ";"))
			}
			labels[parts[0]] = parts[1]
		} else if strings.HasSuffix(labelSpec, "-") {
			remove = append(remove, labelSpec[:len(labelSpec)-1])
		} else {
			return nil, nil, fmt.Errorf("unknown label spec: %v", labelSpec)
		}
	}
	for _, removeLabel := range remove {
		if _, found := labels[removeLabel]; found {
			return nil, nil, fmt.Errorf("can not both modify and remove a label in the same command")
		}
	}
	return labels, remove, nil
}
開發者ID:odacremolbap,項目名稱:kubernetes,代碼行數:26,代碼來源:label.go

示例2: SlaveAttributesToLabels

// SlaveAttributesToLabels converts slave attributes into string key/value labels
func SlaveAttributesToLabels(attrs []*mesos.Attribute) map[string]string {
	l := map[string]string{}
	for _, a := range attrs {
		if a == nil {
			continue
		}

		var v string
		k := labelPrefix + a.GetName()

		switch a.GetType() {
		case mesos.Value_TEXT:
			v = a.GetText().GetValue()
		case mesos.Value_SCALAR:
			v = strconv.FormatFloat(a.GetScalar().GetValue(), 'G', -1, 64)
		}

		if !validation.IsQualifiedName(k) {
			log.V(3).Infof("ignoring invalid node label name %q", k)
			continue
		}

		if !validation.IsValidLabelValue(v) {
			log.V(3).Infof("ignoring invalid node label %s value: %q", k, v)
			continue
		}

		l[k] = v
	}
	return l
}
開發者ID:Clarifai,項目名稱:kubernetes,代碼行數:32,代碼來源:node.go

示例3: isValidLabelValue

func isValidLabelValue(label string) bool {
	errs := validation.IsValidLabelValue(label)
	if len(errs) > 0 {
		return false
	}
	return true
}
開發者ID:rancher,項目名稱:kubernetes-agent,代碼行數:7,代碼來源:syncer.go

示例4: validateLabelValue

func validateLabelValue(v string) error {
	if !validation.IsValidLabelValue(v) {
		//FIXME: this is not the right regex!
		return fmt.Errorf("invalid label value: %s", qualifiedNameErrorMsg)
	}
	return nil
}
開發者ID:erinboyd,項目名稱:origin,代碼行數:7,代碼來源:selector.go

示例5: ParseTaint

// ParseTaint parses a taint from a string. Taint must be off the format '<key>=<value>:<effect>'.
func ParseTaint(st string) (api.Taint, error) {
	var taint api.Taint
	parts := strings.Split(st, "=")
	if len(parts) != 2 || len(parts[1]) == 0 || len(validation.IsQualifiedName(parts[0])) > 0 {
		return taint, fmt.Errorf("invalid taint spec: %v", st)
	}

	parts2 := strings.Split(parts[1], ":")

	effect := api.TaintEffect(parts2[1])

	errs := validation.IsValidLabelValue(parts2[0])
	if len(parts2) != 2 || len(errs) != 0 {
		return taint, fmt.Errorf("invalid taint spec: %v, %s", st, strings.Join(errs, "; "))
	}

	if effect != api.TaintEffectNoSchedule && effect != api.TaintEffectPreferNoSchedule {
		return taint, fmt.Errorf("invalid taint spec: %v, unsupported taint effect", st)
	}

	taint.Key = parts[0]
	taint.Value = parts2[0]
	taint.Effect = effect

	return taint, nil
}
開發者ID:alex-mohr,項目名稱:kubernetes,代碼行數:27,代碼來源:taints.go

示例6: ValidateLabels

// ValidateLabels validates that a set of labels are correctly defined.
func ValidateLabels(labels map[string]string, fldPath *field.Path) field.ErrorList {
	allErrs := field.ErrorList{}
	for k, v := range labels {
		allErrs = append(allErrs, ValidateLabelName(k, fldPath)...)
		for _, msg := range validation.IsValidLabelValue(v) {
			allErrs = append(allErrs, field.Invalid(fldPath, v, msg))
		}
	}
	return allErrs
}
開發者ID:alex-mohr,項目名稱:kubernetes,代碼行數:11,代碼來源:validation.go

示例7: parseTaints

func parseTaints(spec []string) ([]api.Taint, []api.Taint, error) {
	var taints, taintsToRemove []api.Taint
	uniqueTaints := map[api.TaintEffect]sets.String{}

	for _, taintSpec := range spec {
		if strings.Index(taintSpec, "=") != -1 && strings.Index(taintSpec, ":") != -1 {
			parts := strings.Split(taintSpec, "=")
			if len(parts) != 2 || len(parts[1]) == 0 || len(validation.IsQualifiedName(parts[0])) > 0 {
				return nil, nil, fmt.Errorf("invalid taint spec: %v", taintSpec)
			}

			parts2 := strings.Split(parts[1], ":")
			errs := validation.IsValidLabelValue(parts2[0])
			if len(parts2) != 2 || len(errs) != 0 {
				return nil, nil, fmt.Errorf("invalid taint spec: %v, %s", taintSpec, strings.Join(errs, "; "))
			}

			if parts2[1] != string(api.TaintEffectNoSchedule) && parts2[1] != string(api.TaintEffectPreferNoSchedule) {
				return nil, nil, fmt.Errorf("invalid taint spec: %v, unsupported taint effect", taintSpec)
			}

			effect := api.TaintEffect(parts2[1])
			newTaint := api.Taint{
				Key:    parts[0],
				Value:  parts2[0],
				Effect: effect,
			}

			// validate if taint is unique by <key, effect>
			if len(uniqueTaints[newTaint.Effect]) > 0 && uniqueTaints[newTaint.Effect].Has(newTaint.Key) {
				return nil, nil, fmt.Errorf("duplicated taints with the same key and effect: %v", newTaint)
			}
			// add taint to existingTaints for uniqueness check
			if len(uniqueTaints[newTaint.Effect]) == 0 {
				uniqueTaints[newTaint.Effect] = sets.String{}
			}
			uniqueTaints[newTaint.Effect].Insert(newTaint.Key)

			taints = append(taints, newTaint)
		} else if strings.HasSuffix(taintSpec, "-") {
			taintKey := taintSpec[:len(taintSpec)-1]
			var effect api.TaintEffect
			if strings.Index(taintKey, ":") != -1 {
				parts := strings.Split(taintKey, ":")
				taintKey = parts[0]
				effect = api.TaintEffect(parts[1])
			}
			taintsToRemove = append(taintsToRemove, api.Taint{Key: taintKey, Effect: effect})
		} else {
			return nil, nil, fmt.Errorf("unknown taint spec: %v", taintSpec)
		}
	}
	return taints, taintsToRemove, nil
}
開發者ID:Q-Lee,項目名稱:kubernetes,代碼行數:54,代碼來源:taint.go

示例8: parseTaints

func parseTaints(spec []string) ([]api.Taint, []string, error) {
	var taints []api.Taint
	var remove []string
	for _, taintSpec := range spec {
		if strings.Index(taintSpec, "=") != -1 && strings.Index(taintSpec, ":") != -1 {
			parts := strings.Split(taintSpec, "=")
			if len(parts) != 2 || len(parts[1]) == 0 || len(validation.IsQualifiedName(parts[0])) > 0 {
				return nil, nil, fmt.Errorf("invalid taint spec: %v", taintSpec)
			}

			parts2 := strings.Split(parts[1], ":")
			errs := validation.IsValidLabelValue(parts2[0])
			if len(parts2) != 2 || len(errs) != 0 {
				return nil, nil, fmt.Errorf("invalid taint spec: %v, %s", taintSpec, strings.Join(errs, "; "))
			}

			if parts2[1] != string(api.TaintEffectNoSchedule) && parts2[1] != string(api.TaintEffectPreferNoSchedule) {
				return nil, nil, fmt.Errorf("invalid taint spec: %v, unsupported taint effect", taintSpec)
			}

			effect := api.TaintEffect(parts2[1])
			newTaint := api.Taint{
				Key:    parts[0],
				Value:  parts2[0],
				Effect: effect,
			}

			taints = append(taints, newTaint)
		} else if strings.HasSuffix(taintSpec, "-") {
			remove = append(remove, taintSpec[:len(taintSpec)-1])
		} else {
			return nil, nil, fmt.Errorf("unknown taint spec: %v", taintSpec)
		}
	}
	return taints, remove, nil
}
開發者ID:Xmagicer,項目名稱:origin,代碼行數:36,代碼來源:taint.go

示例9: validateLabelValue

func validateLabelValue(v string) error {
	if len(kvalidation.IsValidLabelValue(v)) != 0 {
		return field.Invalid(field.NewPath("label value"), v, qualifiedNameErrorMsg)
	}
	return nil
}
開發者ID:Xmagicer,項目名稱:origin,代碼行數:6,代碼來源:labelselector.go

示例10: validateLabelValue

func validateLabelValue(v string) error {
	if !kvalidation.IsValidLabelValue(v) {
		return fielderrors.NewFieldInvalid("label value", v, qualifiedNameErrorMsg)
	}
	return nil
}
開發者ID:johnmccawley,項目名稱:origin,代碼行數:6,代碼來源:labelselector.go

示例11: validateLabelValue

func validateLabelValue(v string) error {
	if errs := validation.IsValidLabelValue(v); len(errs) != 0 {
		return fmt.Errorf("invalid label value: %q: %s", v, strings.Join(errs, "; "))
	}
	return nil
}
開發者ID:RyanBinfeng,項目名稱:kubernetes,代碼行數:6,代碼來源:selector.go

示例12: validateLabelValue

func validateLabelValue(v string) error {
	if !validation.IsValidLabelValue(v) {
		return fmt.Errorf("invalid label value: %s", labelValueErrorMsg)
	}
	return nil
}
開發者ID:MISingularity,項目名稱:kubernetes,代碼行數:6,代碼來源:selector.go


注:本文中的k8s/io/kubernetes/pkg/util/validation.IsValidLabelValue函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。