Commit a21c52a7 authored by tummychow's avatar tummychow

Move util/validation files to their own package

parent c8f92192
......@@ -18,8 +18,8 @@ package validation
import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util"
errs "k8s.io/kubernetes/pkg/util/fielderrors"
"k8s.io/kubernetes/pkg/util/validation"
)
// ValidateEvent makes sure that the event makes sense.
......@@ -30,7 +30,7 @@ func ValidateEvent(event *api.Event) errs.ValidationErrorList {
event.Namespace != event.InvolvedObject.Namespace {
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, ""))
}
return allErrs
......
......@@ -26,6 +26,7 @@ import (
"k8s.io/kubernetes/pkg/util"
errs "k8s.io/kubernetes/pkg/util/fielderrors"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/validation"
)
const isNegativeErrorMsg string = `must be non-negative`
......@@ -170,7 +171,7 @@ func ValidateDeploymentName(name string, prefix bool) (bool, string) {
func ValidatePositiveIntOrPercent(intOrPercent util.IntOrString, fieldName string) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
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%)"))
}
......@@ -181,7 +182,7 @@ func ValidatePositiveIntOrPercent(intOrPercent util.IntOrString, fieldName strin
}
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
}
value, _ := strconv.Atoi(intOrStringValue.StrVal[:len(intOrStringValue.StrVal)-1])
......
......@@ -23,8 +23,8 @@ import (
"strings"
clientcmdapi "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
"k8s.io/kubernetes/pkg/util"
utilerrors "k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/validation"
)
var ErrNoContext = errors.New("no context chosen")
......@@ -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))
}
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))
}
......
......@@ -27,8 +27,8 @@ import (
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"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
......@@ -77,7 +77,7 @@ func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command {
cmd := &cobra.Command{
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",
Long: fmt.Sprintf(label_long, util.LabelValueMaxLength),
Long: fmt.Sprintf(label_long, validation.LabelValueMaxLength),
Example: label_example,
Run: func(cmd *cobra.Command, args []string) {
err := RunLabel(f, out, cmd, args, options)
......@@ -113,7 +113,7 @@ func parseLabels(spec []string) (map[string]string, []string, error) {
for _, labelSpec := range spec {
if strings.Index(labelSpec, "=") != -1 {
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)
}
labels[parts[0]] = parts[1]
......
......@@ -24,7 +24,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/validation"
)
type BasicReplicationController struct{}
......@@ -394,7 +394,7 @@ func parseEnvs(envArray []string) ([]api.EnvVar, error) {
envs := []api.EnvVar{}
for _, env := range envArray {
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)
}
envVar := api.EnvVar{Name: parts[0], Value: parts[1]}
......
......@@ -25,8 +25,8 @@ import (
"k8s.io/kubernetes/pkg/api"
client "k8s.io/kubernetes/pkg/client/unversioned"
kubeletTypes "k8s.io/kubernetes/pkg/kubelet/types"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/validation"
)
const DefaultPluginName = "kubernetes.io/no-op"
......@@ -87,7 +87,7 @@ func InitNetworkPlugin(plugins []NetworkPlugin, networkPluginName string, host H
allErrs := []error{}
for _, plugin := range plugins {
name := plugin.Name()
if !util.IsQualifiedName(name) {
if !validation.IsQualifiedName(name) {
allErrs = append(allErrs, fmt.Errorf("network plugin has invalid name: %#v", plugin))
continue
}
......
......@@ -22,9 +22,9 @@ import (
"sort"
"strings"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/fielderrors"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/validation"
)
// Selector represents a label selector.
......@@ -647,17 +647,17 @@ func Parse(selector string) (Selector, 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 {
if !util.IsQualifiedName(k) {
if !validation.IsQualifiedName(k) {
return fielderrors.NewFieldInvalid("label key", k, qualifiedNameErrorMsg)
}
return nil
}
func validateLabelValue(v string) error {
if !util.IsValidLabelValue(v) {
if !validation.IsValidLabelValue(v) {
return fielderrors.NewFieldInvalid("label value", v, qualifiedNameErrorMsg)
}
return nil
......
......@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package util
package validation
import (
"net"
......
......@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package util
package validation
import (
"strings"
......
......@@ -26,9 +26,9 @@ import (
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/cloudprovider"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/validation"
)
// VolumeOptions contains option information about a volume.
......@@ -203,7 +203,7 @@ func (pm *VolumePluginMgr) InitPlugins(plugins []VolumePlugin, host VolumeHost)
allErrs := []error{}
for _, plugin := range plugins {
name := plugin.Name()
if !util.IsQualifiedName(name) {
if !validation.IsQualifiedName(name) {
allErrs = append(allErrs, fmt.Errorf("volume plugin has invalid name: %#v", plugin))
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