本文整理汇总了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
}
示例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
}
示例3: isValidLabelValue
func isValidLabelValue(label string) bool {
errs := validation.IsValidLabelValue(label)
if len(errs) > 0 {
return false
}
return true
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例9: validateLabelValue
func validateLabelValue(v string) error {
if len(kvalidation.IsValidLabelValue(v)) != 0 {
return field.Invalid(field.NewPath("label value"), v, qualifiedNameErrorMsg)
}
return nil
}
示例10: validateLabelValue
func validateLabelValue(v string) error {
if !kvalidation.IsValidLabelValue(v) {
return fielderrors.NewFieldInvalid("label value", v, qualifiedNameErrorMsg)
}
return nil
}
示例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
}
示例12: validateLabelValue
func validateLabelValue(v string) error {
if !validation.IsValidLabelValue(v) {
return fmt.Errorf("invalid label value: %s", labelValueErrorMsg)
}
return nil
}