Commit 81894608 authored by k8s-merge-robot's avatar k8s-merge-robot

Merge pull request #13844 from tummychow/label-deps-2

Auto commit by PR queue bot
parents 653e5def a21c52a7
...@@ -18,8 +18,8 @@ package validation ...@@ -18,8 +18,8 @@ package validation
import ( import (
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util"
errs "k8s.io/kubernetes/pkg/util/fielderrors" errs "k8s.io/kubernetes/pkg/util/fielderrors"
"k8s.io/kubernetes/pkg/util/validation"
) )
// ValidateEvent makes sure that the event makes sense. // ValidateEvent makes sure that the event makes sense.
...@@ -30,7 +30,7 @@ func ValidateEvent(event *api.Event) errs.ValidationErrorList { ...@@ -30,7 +30,7 @@ func ValidateEvent(event *api.Event) errs.ValidationErrorList {
event.Namespace != event.InvolvedObject.Namespace { event.Namespace != event.InvolvedObject.Namespace {
allErrs = append(allErrs, errs.NewFieldInvalid("involvedObject.namespace", event.InvolvedObject.Namespace, "namespace does not match involvedObject")) allErrs = append(allErrs, errs.NewFieldInvalid("involvedObject.namespace", event.InvolvedObject.Namespace, "namespace does not match involvedObject"))
} }
if !util.IsDNS1123Subdomain(event.Namespace) { if !validation.IsDNS1123Subdomain(event.Namespace) {
allErrs = append(allErrs, errs.NewFieldInvalid("namespace", event.Namespace, "")) allErrs = append(allErrs, errs.NewFieldInvalid("namespace", event.Namespace, ""))
} }
return allErrs return allErrs
......
...@@ -26,6 +26,7 @@ import ( ...@@ -26,6 +26,7 @@ import (
"k8s.io/kubernetes/pkg/util" "k8s.io/kubernetes/pkg/util"
errs "k8s.io/kubernetes/pkg/util/fielderrors" errs "k8s.io/kubernetes/pkg/util/fielderrors"
"k8s.io/kubernetes/pkg/util/sets" "k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/validation"
) )
const isNegativeErrorMsg string = `must be non-negative` const isNegativeErrorMsg string = `must be non-negative`
...@@ -170,7 +171,7 @@ func ValidateDeploymentName(name string, prefix bool) (bool, string) { ...@@ -170,7 +171,7 @@ func ValidateDeploymentName(name string, prefix bool) (bool, string) {
func ValidatePositiveIntOrPercent(intOrPercent util.IntOrString, fieldName string) errs.ValidationErrorList { func ValidatePositiveIntOrPercent(intOrPercent util.IntOrString, fieldName string) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{} allErrs := errs.ValidationErrorList{}
if intOrPercent.Kind == util.IntstrString { if intOrPercent.Kind == util.IntstrString {
if !util.IsValidPercent(intOrPercent.StrVal) { if !validation.IsValidPercent(intOrPercent.StrVal) {
allErrs = append(allErrs, errs.NewFieldInvalid(fieldName, intOrPercent, "value should be int(5) or percentage(5%)")) allErrs = append(allErrs, errs.NewFieldInvalid(fieldName, intOrPercent, "value should be int(5) or percentage(5%)"))
} }
...@@ -181,7 +182,7 @@ func ValidatePositiveIntOrPercent(intOrPercent util.IntOrString, fieldName strin ...@@ -181,7 +182,7 @@ func ValidatePositiveIntOrPercent(intOrPercent util.IntOrString, fieldName strin
} }
func getPercentValue(intOrStringValue util.IntOrString) (int, bool) { func getPercentValue(intOrStringValue util.IntOrString) (int, bool) {
if intOrStringValue.Kind != util.IntstrString || !util.IsValidPercent(intOrStringValue.StrVal) { if intOrStringValue.Kind != util.IntstrString || !validation.IsValidPercent(intOrStringValue.StrVal) {
return 0, false return 0, false
} }
value, _ := strconv.Atoi(intOrStringValue.StrVal[:len(intOrStringValue.StrVal)-1]) value, _ := strconv.Atoi(intOrStringValue.StrVal[:len(intOrStringValue.StrVal)-1])
......
...@@ -23,8 +23,8 @@ import ( ...@@ -23,8 +23,8 @@ import (
"strings" "strings"
clientcmdapi "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api" clientcmdapi "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
"k8s.io/kubernetes/pkg/util"
utilerrors "k8s.io/kubernetes/pkg/util/errors" utilerrors "k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/validation"
) )
var ErrNoContext = errors.New("no context chosen") var ErrNoContext = errors.New("no context chosen")
...@@ -232,7 +232,7 @@ func validateContext(contextName string, context clientcmdapi.Context, config cl ...@@ -232,7 +232,7 @@ func validateContext(contextName string, context clientcmdapi.Context, config cl
validationErrors = append(validationErrors, fmt.Errorf("cluster %q was not found for context %q", context.Cluster, contextName)) validationErrors = append(validationErrors, fmt.Errorf("cluster %q was not found for context %q", context.Cluster, contextName))
} }
if (len(context.Namespace) != 0) && !util.IsDNS952Label(context.Namespace) { if (len(context.Namespace) != 0) && !validation.IsDNS952Label(context.Namespace) {
validationErrors = append(validationErrors, fmt.Errorf("namespace %q for context %q does not conform to the kubernetes DNS952 rules", context.Namespace, contextName)) validationErrors = append(validationErrors, fmt.Errorf("namespace %q for context %q does not conform to the kubernetes DNS952 rules", context.Namespace, contextName))
} }
......
...@@ -27,8 +27,8 @@ import ( ...@@ -27,8 +27,8 @@ import (
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource" "k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/errors" "k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/validation"
) )
// LabelOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of // LabelOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
...@@ -77,7 +77,7 @@ func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command { ...@@ -77,7 +77,7 @@ func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]", Use: "label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]",
Short: "Update the labels on a resource", Short: "Update the labels on a resource",
Long: fmt.Sprintf(label_long, util.LabelValueMaxLength), Long: fmt.Sprintf(label_long, validation.LabelValueMaxLength),
Example: label_example, Example: label_example,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
err := RunLabel(f, out, cmd, args, options) err := RunLabel(f, out, cmd, args, options)
...@@ -113,7 +113,7 @@ func parseLabels(spec []string) (map[string]string, []string, error) { ...@@ -113,7 +113,7 @@ func parseLabels(spec []string) (map[string]string, []string, error) {
for _, labelSpec := range spec { for _, labelSpec := range spec {
if strings.Index(labelSpec, "=") != -1 { if strings.Index(labelSpec, "=") != -1 {
parts := strings.Split(labelSpec, "=") parts := strings.Split(labelSpec, "=")
if len(parts) != 2 || len(parts[1]) == 0 || !util.IsValidLabelValue(parts[1]) { if len(parts) != 2 || len(parts[1]) == 0 || !validation.IsValidLabelValue(parts[1]) {
return nil, nil, fmt.Errorf("invalid label spec: %v", labelSpec) return nil, nil, fmt.Errorf("invalid label spec: %v", labelSpec)
} }
labels[parts[0]] = parts[1] labels[parts[0]] = parts[1]
......
...@@ -24,7 +24,7 @@ import ( ...@@ -24,7 +24,7 @@ import (
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource" "k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util" "k8s.io/kubernetes/pkg/util/validation"
) )
type BasicReplicationController struct{} type BasicReplicationController struct{}
...@@ -394,7 +394,7 @@ func parseEnvs(envArray []string) ([]api.EnvVar, error) { ...@@ -394,7 +394,7 @@ func parseEnvs(envArray []string) ([]api.EnvVar, error) {
envs := []api.EnvVar{} envs := []api.EnvVar{}
for _, env := range envArray { for _, env := range envArray {
parts := strings.Split(env, "=") parts := strings.Split(env, "=")
if len(parts) != 2 || !util.IsCIdentifier(parts[0]) || len(parts[1]) == 0 { if len(parts) != 2 || !validation.IsCIdentifier(parts[0]) || len(parts[1]) == 0 {
return nil, fmt.Errorf("invalid env: %v", env) return nil, fmt.Errorf("invalid env: %v", env)
} }
envVar := api.EnvVar{Name: parts[0], Value: parts[1]} envVar := api.EnvVar{Name: parts[0], Value: parts[1]}
......
...@@ -25,8 +25,8 @@ import ( ...@@ -25,8 +25,8 @@ import (
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
client "k8s.io/kubernetes/pkg/client/unversioned" client "k8s.io/kubernetes/pkg/client/unversioned"
kubeletTypes "k8s.io/kubernetes/pkg/kubelet/types" kubeletTypes "k8s.io/kubernetes/pkg/kubelet/types"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/errors" "k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/validation"
) )
const DefaultPluginName = "kubernetes.io/no-op" const DefaultPluginName = "kubernetes.io/no-op"
...@@ -87,7 +87,7 @@ func InitNetworkPlugin(plugins []NetworkPlugin, networkPluginName string, host H ...@@ -87,7 +87,7 @@ func InitNetworkPlugin(plugins []NetworkPlugin, networkPluginName string, host H
allErrs := []error{} allErrs := []error{}
for _, plugin := range plugins { for _, plugin := range plugins {
name := plugin.Name() name := plugin.Name()
if !util.IsQualifiedName(name) { if !validation.IsQualifiedName(name) {
allErrs = append(allErrs, fmt.Errorf("network plugin has invalid name: %#v", plugin)) allErrs = append(allErrs, fmt.Errorf("network plugin has invalid name: %#v", plugin))
continue continue
} }
......
...@@ -22,9 +22,9 @@ import ( ...@@ -22,9 +22,9 @@ import (
"sort" "sort"
"strings" "strings"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/fielderrors" "k8s.io/kubernetes/pkg/util/fielderrors"
"k8s.io/kubernetes/pkg/util/sets" "k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/validation"
) )
// Selector represents a label selector. // Selector represents a label selector.
...@@ -647,17 +647,17 @@ func Parse(selector string) (Selector, error) { ...@@ -647,17 +647,17 @@ func Parse(selector string) (Selector, error) {
return nil, error return nil, error
} }
const qualifiedNameErrorMsg string = "must match regex [" + util.DNS1123SubdomainFmt + " / ] " + util.DNS1123LabelFmt const qualifiedNameErrorMsg string = "must match regex [" + validation.DNS1123SubdomainFmt + " / ] " + validation.DNS1123LabelFmt
func validateLabelKey(k string) error { func validateLabelKey(k string) error {
if !util.IsQualifiedName(k) { if !validation.IsQualifiedName(k) {
return fielderrors.NewFieldInvalid("label key", k, qualifiedNameErrorMsg) return fielderrors.NewFieldInvalid("label key", k, qualifiedNameErrorMsg)
} }
return nil return nil
} }
func validateLabelValue(v string) error { func validateLabelValue(v string) error {
if !util.IsValidLabelValue(v) { if !validation.IsValidLabelValue(v) {
return fielderrors.NewFieldInvalid("label value", v, qualifiedNameErrorMsg) return fielderrors.NewFieldInvalid("label value", v, qualifiedNameErrorMsg)
} }
return nil return nil
......
...@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and ...@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package util package validation
import ( import (
"net" "net"
......
...@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and ...@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package util package validation
import ( import (
"strings" "strings"
......
...@@ -26,9 +26,9 @@ import ( ...@@ -26,9 +26,9 @@ import (
client "k8s.io/kubernetes/pkg/client/unversioned" client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/cloudprovider" "k8s.io/kubernetes/pkg/cloudprovider"
"k8s.io/kubernetes/pkg/types" "k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/errors" "k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/validation"
) )
// VolumeOptions contains option information about a volume. // VolumeOptions contains option information about a volume.
...@@ -203,7 +203,7 @@ func (pm *VolumePluginMgr) InitPlugins(plugins []VolumePlugin, host VolumeHost) ...@@ -203,7 +203,7 @@ func (pm *VolumePluginMgr) InitPlugins(plugins []VolumePlugin, host VolumeHost)
allErrs := []error{} allErrs := []error{}
for _, plugin := range plugins { for _, plugin := range plugins {
name := plugin.Name() name := plugin.Name()
if !util.IsQualifiedName(name) { if !validation.IsQualifiedName(name) {
allErrs = append(allErrs, fmt.Errorf("volume plugin has invalid name: %#v", plugin)) allErrs = append(allErrs, fmt.Errorf("volume plugin has invalid name: %#v", plugin))
continue continue
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment