Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
3a17d433
Commit
3a17d433
authored
Jan 16, 2017
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move first pkg/api/validation's into apimachinery
parent
bf307d99
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
142 additions
and
80 deletions
+142
-80
BUILD
pkg/api/validation/BUILD
+1
-0
BUILD
pkg/api/validation/genericvalidation/BUILD
+4
-2
objectmeta.go
pkg/api/validation/genericvalidation/objectmeta.go
+5
-64
objectmeta_test.go
pkg/api/validation/genericvalidation/objectmeta_test.go
+2
-1
validation.go
pkg/api/validation/validation.go
+10
-9
doc.go
staging/src/k8s.io/apimachinery/pkg/api/validation/doc.go
+18
-0
generic.go
...ing/src/k8s.io/apimachinery/pkg/api/validation/generic.go
+85
-0
util.go
...8s.io/apiserver/pkg/authentication/serviceaccount/util.go
+3
-3
BUILD
vendor/BUILD
+14
-1
No files found.
pkg/api/validation/BUILD
View file @
3a17d433
...
@@ -33,6 +33,7 @@ go_library(
...
@@ -33,6 +33,7 @@ go_library(
"//vendor:github.com/exponent-io/jsonpath",
"//vendor:github.com/exponent-io/jsonpath",
"//vendor:github.com/golang/glog",
"//vendor:github.com/golang/glog",
"//vendor:k8s.io/apimachinery/pkg/api/meta",
"//vendor:k8s.io/apimachinery/pkg/api/meta",
"//vendor:k8s.io/apimachinery/pkg/api/validation",
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1/unstructured",
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1/unstructured",
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1/validation",
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1/validation",
...
...
pkg/api/validation/genericvalidation/BUILD
View file @
3a17d433
...
@@ -12,12 +12,13 @@ go_library(
...
@@ -12,12 +12,13 @@ go_library(
name = "go_default_library",
name = "go_default_library",
srcs = [
srcs = [
"doc.go",
"doc.go",
"
validation
.go",
"
objectmeta
.go",
],
],
tags = ["automanaged"],
tags = ["automanaged"],
deps = [
deps = [
"//pkg/api:go_default_library",
"//pkg/api:go_default_library",
"//pkg/api/v1:go_default_library",
"//pkg/api/v1:go_default_library",
"//vendor:k8s.io/apimachinery/pkg/api/validation",
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1/validation",
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1/validation",
"//vendor:k8s.io/apimachinery/pkg/runtime/schema",
"//vendor:k8s.io/apimachinery/pkg/runtime/schema",
...
@@ -29,11 +30,12 @@ go_library(
...
@@ -29,11 +30,12 @@ go_library(
go_test(
go_test(
name = "go_default_test",
name = "go_default_test",
srcs = ["
validation
_test.go"],
srcs = ["
objectmeta
_test.go"],
library = ":go_default_library",
library = ":go_default_library",
tags = ["automanaged"],
tags = ["automanaged"],
deps = [
deps = [
"//pkg/api:go_default_library",
"//pkg/api:go_default_library",
"//vendor:k8s.io/apimachinery/pkg/api/validation",
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
"//vendor:k8s.io/apimachinery/pkg/util/validation/field",
"//vendor:k8s.io/apimachinery/pkg/util/validation/field",
],
],
...
...
pkg/api/validation/genericvalidation/
validation
.go
→
pkg/api/validation/genericvalidation/
objectmeta
.go
View file @
3a17d433
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"fmt"
"fmt"
"strings"
"strings"
apimachineyvalidation
"k8s.io/apimachinery/pkg/api/validation"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
v1validation
"k8s.io/apimachinery/pkg/apis/meta/v1/validation"
v1validation
"k8s.io/apimachinery/pkg/apis/meta/v1/validation"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
...
@@ -34,7 +35,6 @@ import (
...
@@ -34,7 +35,6 @@ import (
// fields by default.
// fields by default.
var
RepairMalformedUpdates
bool
=
true
var
RepairMalformedUpdates
bool
=
true
const
IsNegativeErrorMsg
string
=
`must be greater than or equal to 0`
const
FieldImmutableErrorMsg
string
=
`field is immutable`
const
FieldImmutableErrorMsg
string
=
`field is immutable`
const
totalAnnotationSizeLimitB
int
=
256
*
(
1
<<
10
)
// 256 kB
const
totalAnnotationSizeLimitB
int
=
256
*
(
1
<<
10
)
// 256 kB
...
@@ -44,67 +44,8 @@ var BannedOwners = map[schema.GroupVersionKind]struct{}{
...
@@ -44,67 +44,8 @@ var BannedOwners = map[schema.GroupVersionKind]struct{}{
v1
.
SchemeGroupVersion
.
WithKind
(
"Event"
)
:
{},
v1
.
SchemeGroupVersion
.
WithKind
(
"Event"
)
:
{},
}
}
// ValidateNameFunc validates that the provided name is valid for a given resource type.
// Not all resources have the same validation rules for names. Prefix is true
// if the name will have a value appended to it. If the name is not valid,
// this returns a list of descriptions of individual characteristics of the
// value that were not valid. Otherwise this returns an empty list or nil.
type
ValidateNameFunc
func
(
name
string
,
prefix
bool
)
[]
string
// NameIsDNSSubdomain is a ValidateNameFunc for names that must be a DNS subdomain.
func
NameIsDNSSubdomain
(
name
string
,
prefix
bool
)
[]
string
{
if
prefix
{
name
=
maskTrailingDash
(
name
)
}
return
validation
.
IsDNS1123Subdomain
(
name
)
}
// NameIsDNSLabel is a ValidateNameFunc for names that must be a DNS 1123 label.
func
NameIsDNSLabel
(
name
string
,
prefix
bool
)
[]
string
{
if
prefix
{
name
=
maskTrailingDash
(
name
)
}
return
validation
.
IsDNS1123Label
(
name
)
}
// NameIsDNS1035Label is a ValidateNameFunc for names that must be a DNS 952 label.
func
NameIsDNS1035Label
(
name
string
,
prefix
bool
)
[]
string
{
if
prefix
{
name
=
maskTrailingDash
(
name
)
}
return
validation
.
IsDNS1035Label
(
name
)
}
// ValidateNamespaceName can be used to check whether the given namespace name is valid.
// Prefix indicates this name will be used as part of generation, in which case
// trailing dashes are allowed.
var
ValidateNamespaceName
=
NameIsDNSLabel
// ValidateClusterName can be used to check whether the given cluster name is valid.
// ValidateClusterName can be used to check whether the given cluster name is valid.
var
ValidateClusterName
=
NameIsDNS1035Label
var
ValidateClusterName
=
apimachineyvalidation
.
NameIsDNS1035Label
// ValidateServiceAccountName can be used to check whether the given service account name is valid.
// Prefix indicates this name will be used as part of generation, in which case
// trailing dashes are allowed.
var
ValidateServiceAccountName
=
NameIsDNSSubdomain
// maskTrailingDash replaces the final character of a string with a subdomain safe
// value if is a dash.
func
maskTrailingDash
(
name
string
)
string
{
if
strings
.
HasSuffix
(
name
,
"-"
)
{
return
name
[
:
len
(
name
)
-
2
]
+
"a"
}
return
name
}
// Validates that given value is not negative.
func
ValidateNonnegativeField
(
value
int64
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
if
value
<
0
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
,
value
,
IsNegativeErrorMsg
))
}
return
allErrs
}
// ValidateAnnotations validates that a set of annotations are correctly defined.
// ValidateAnnotations validates that a set of annotations are correctly defined.
func
ValidateAnnotations
(
annotations
map
[
string
]
string
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
func
ValidateAnnotations
(
annotations
map
[
string
]
string
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
...
@@ -201,7 +142,7 @@ func ValidateImmutableField(newVal, oldVal interface{}, fldPath *field.Path) fie
...
@@ -201,7 +142,7 @@ func ValidateImmutableField(newVal, oldVal interface{}, fldPath *field.Path) fie
// ValidateObjectMeta validates an object's metadata on creation. It expects that name generation has already
// ValidateObjectMeta validates an object's metadata on creation. It expects that name generation has already
// been performed.
// been performed.
// It doesn't return an error for rootscoped resources with namespace, because namespace should already be cleared before.
// It doesn't return an error for rootscoped resources with namespace, because namespace should already be cleared before.
func
ValidateObjectMeta
(
meta
*
api
.
ObjectMeta
,
requiresNamespace
bool
,
nameFn
ValidateNameFunc
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
func
ValidateObjectMeta
(
meta
*
api
.
ObjectMeta
,
requiresNamespace
bool
,
nameFn
apimachineyvalidation
.
ValidateNameFunc
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
allErrs
:=
field
.
ErrorList
{}
if
len
(
meta
.
GenerateName
)
!=
0
{
if
len
(
meta
.
GenerateName
)
!=
0
{
...
@@ -223,7 +164,7 @@ func ValidateObjectMeta(meta *api.ObjectMeta, requiresNamespace bool, nameFn Val
...
@@ -223,7 +164,7 @@ func ValidateObjectMeta(meta *api.ObjectMeta, requiresNamespace bool, nameFn Val
if
len
(
meta
.
Namespace
)
==
0
{
if
len
(
meta
.
Namespace
)
==
0
{
allErrs
=
append
(
allErrs
,
field
.
Required
(
fldPath
.
Child
(
"namespace"
),
""
))
allErrs
=
append
(
allErrs
,
field
.
Required
(
fldPath
.
Child
(
"namespace"
),
""
))
}
else
{
}
else
{
for
_
,
msg
:=
range
ValidateNamespaceName
(
meta
.
Namespace
,
false
)
{
for
_
,
msg
:=
range
apimachineyvalidation
.
ValidateNamespaceName
(
meta
.
Namespace
,
false
)
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
.
Child
(
"namespace"
),
meta
.
Namespace
,
msg
))
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
.
Child
(
"namespace"
),
meta
.
Namespace
,
msg
))
}
}
}
}
...
@@ -237,7 +178,7 @@ func ValidateObjectMeta(meta *api.ObjectMeta, requiresNamespace bool, nameFn Val
...
@@ -237,7 +178,7 @@ func ValidateObjectMeta(meta *api.ObjectMeta, requiresNamespace bool, nameFn Val
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
.
Child
(
"clusterName"
),
meta
.
ClusterName
,
msg
))
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
.
Child
(
"clusterName"
),
meta
.
ClusterName
,
msg
))
}
}
}
}
allErrs
=
append
(
allErrs
,
ValidateNonnegativeField
(
meta
.
Generation
,
fldPath
.
Child
(
"generation"
))
...
)
allErrs
=
append
(
allErrs
,
apimachineyvalidation
.
ValidateNonnegativeField
(
meta
.
Generation
,
fldPath
.
Child
(
"generation"
))
...
)
allErrs
=
append
(
allErrs
,
v1validation
.
ValidateLabels
(
meta
.
Labels
,
fldPath
.
Child
(
"labels"
))
...
)
allErrs
=
append
(
allErrs
,
v1validation
.
ValidateLabels
(
meta
.
Labels
,
fldPath
.
Child
(
"labels"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateAnnotations
(
meta
.
Annotations
,
fldPath
.
Child
(
"annotations"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateAnnotations
(
meta
.
Annotations
,
fldPath
.
Child
(
"annotations"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateOwnerReferences
(
meta
.
OwnerReferences
,
fldPath
.
Child
(
"ownerReferences"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateOwnerReferences
(
meta
.
OwnerReferences
,
fldPath
.
Child
(
"ownerReferences"
))
...
)
...
...
pkg/api/validation/genericvalidation/
validation
_test.go
→
pkg/api/validation/genericvalidation/
objectmeta
_test.go
View file @
3a17d433
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
"testing"
"testing"
"time"
"time"
apimachineryvalidation
"k8s.io/apimachinery/pkg/api/validation"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
...
@@ -409,7 +410,7 @@ func TestValidateObjectMetaTrimsTrailingSlash(t *testing.T) {
...
@@ -409,7 +410,7 @@ func TestValidateObjectMetaTrimsTrailingSlash(t *testing.T) {
errs
:=
ValidateObjectMeta
(
errs
:=
ValidateObjectMeta
(
&
api
.
ObjectMeta
{
Name
:
"test"
,
GenerateName
:
"foo-"
},
&
api
.
ObjectMeta
{
Name
:
"test"
,
GenerateName
:
"foo-"
},
false
,
false
,
NameIsDNSSubdomain
,
apimachineryvalidation
.
NameIsDNSSubdomain
,
field
.
NewPath
(
"field"
))
field
.
NewPath
(
"field"
))
if
len
(
errs
)
!=
0
{
if
len
(
errs
)
!=
0
{
t
.
Fatalf
(
"unexpected errors: %v"
,
errs
)
t
.
Fatalf
(
"unexpected errors: %v"
,
errs
)
...
...
pkg/api/validation/validation.go
View file @
3a17d433
...
@@ -28,6 +28,7 @@ import (
...
@@ -28,6 +28,7 @@ import (
"github.com/golang/glog"
"github.com/golang/glog"
apimachineryvalidation
"k8s.io/apimachinery/pkg/api/validation"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
unversionedvalidation
"k8s.io/apimachinery/pkg/apis/meta/v1/validation"
unversionedvalidation
"k8s.io/apimachinery/pkg/apis/meta/v1/validation"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/labels"
...
@@ -50,7 +51,7 @@ import (
...
@@ -50,7 +51,7 @@ import (
// fields by default.
// fields by default.
var
RepairMalformedUpdates
bool
=
genericvalidation
.
RepairMalformedUpdates
var
RepairMalformedUpdates
bool
=
genericvalidation
.
RepairMalformedUpdates
const
isNegativeErrorMsg
string
=
generic
validation
.
IsNegativeErrorMsg
const
isNegativeErrorMsg
string
=
apimachinery
validation
.
IsNegativeErrorMsg
const
isInvalidQuotaResource
string
=
`must be a standard resource for quota`
const
isInvalidQuotaResource
string
=
`must be a standard resource for quota`
const
fieldImmutableErrorMsg
string
=
genericvalidation
.
FieldImmutableErrorMsg
const
fieldImmutableErrorMsg
string
=
genericvalidation
.
FieldImmutableErrorMsg
const
isNotIntegerErrorMsg
string
=
`must be an integer`
const
isNotIntegerErrorMsg
string
=
`must be an integer`
...
@@ -175,7 +176,7 @@ func ValidateOwnerReferences(ownerReferences []metav1.OwnerReference, fldPath *f
...
@@ -175,7 +176,7 @@ func ValidateOwnerReferences(ownerReferences []metav1.OwnerReference, fldPath *f
// if the name will have a value appended to it. If the name is not valid,
// if the name will have a value appended to it. If the name is not valid,
// this returns a list of descriptions of individual characteristics of the
// this returns a list of descriptions of individual characteristics of the
// value that were not valid. Otherwise this returns an empty list or nil.
// value that were not valid. Otherwise this returns an empty list or nil.
type
ValidateNameFunc
generic
validation
.
ValidateNameFunc
type
ValidateNameFunc
apimachinery
validation
.
ValidateNameFunc
// maskTrailingDash replaces the final character of a string with a subdomain safe
// maskTrailingDash replaces the final character of a string with a subdomain safe
// value if is a dash.
// value if is a dash.
...
@@ -210,7 +211,7 @@ var ValidateNodeName = NameIsDNSSubdomain
...
@@ -210,7 +211,7 @@ var ValidateNodeName = NameIsDNSSubdomain
// ValidateNamespaceName can be used to check whether the given namespace name is valid.
// ValidateNamespaceName can be used to check whether the given namespace name is valid.
// Prefix indicates this name will be used as part of generation, in which case
// Prefix indicates this name will be used as part of generation, in which case
// trailing dashes are allowed.
// trailing dashes are allowed.
var
ValidateNamespaceName
=
generic
validation
.
ValidateNamespaceName
var
ValidateNamespaceName
=
apimachinery
validation
.
ValidateNamespaceName
// ValidateLimitRangeName can be used to check whether the given limit range name is valid.
// ValidateLimitRangeName can be used to check whether the given limit range name is valid.
// Prefix indicates this name will be used as part of generation, in which case
// Prefix indicates this name will be used as part of generation, in which case
...
@@ -231,7 +232,7 @@ var ValidateSecretName = NameIsDNSSubdomain
...
@@ -231,7 +232,7 @@ var ValidateSecretName = NameIsDNSSubdomain
// ValidateServiceAccountName can be used to check whether the given service account name is valid.
// ValidateServiceAccountName can be used to check whether the given service account name is valid.
// Prefix indicates this name will be used as part of generation, in which case
// Prefix indicates this name will be used as part of generation, in which case
// trailing dashes are allowed.
// trailing dashes are allowed.
var
ValidateServiceAccountName
=
generic
validation
.
ValidateServiceAccountName
var
ValidateServiceAccountName
=
apimachinery
validation
.
ValidateServiceAccountName
// ValidateEndpointsName can be used to check whether the given endpoints name is valid.
// ValidateEndpointsName can be used to check whether the given endpoints name is valid.
// Prefix indicates this name will be used as part of generation, in which case
// Prefix indicates this name will be used as part of generation, in which case
...
@@ -244,22 +245,22 @@ var ValidateClusterName = genericvalidation.ValidateClusterName
...
@@ -244,22 +245,22 @@ var ValidateClusterName = genericvalidation.ValidateClusterName
// TODO update all references to these functions to point to the genericvalidation ones
// TODO update all references to these functions to point to the genericvalidation ones
// NameIsDNSSubdomain is a ValidateNameFunc for names that must be a DNS subdomain.
// NameIsDNSSubdomain is a ValidateNameFunc for names that must be a DNS subdomain.
func
NameIsDNSSubdomain
(
name
string
,
prefix
bool
)
[]
string
{
func
NameIsDNSSubdomain
(
name
string
,
prefix
bool
)
[]
string
{
return
generic
validation
.
NameIsDNSSubdomain
(
name
,
prefix
)
return
apimachinery
validation
.
NameIsDNSSubdomain
(
name
,
prefix
)
}
}
// NameIsDNSLabel is a ValidateNameFunc for names that must be a DNS 1123 label.
// NameIsDNSLabel is a ValidateNameFunc for names that must be a DNS 1123 label.
func
NameIsDNSLabel
(
name
string
,
prefix
bool
)
[]
string
{
func
NameIsDNSLabel
(
name
string
,
prefix
bool
)
[]
string
{
return
generic
validation
.
NameIsDNSLabel
(
name
,
prefix
)
return
apimachinery
validation
.
NameIsDNSLabel
(
name
,
prefix
)
}
}
// NameIsDNS1035Label is a ValidateNameFunc for names that must be a DNS 952 label.
// NameIsDNS1035Label is a ValidateNameFunc for names that must be a DNS 952 label.
func
NameIsDNS1035Label
(
name
string
,
prefix
bool
)
[]
string
{
func
NameIsDNS1035Label
(
name
string
,
prefix
bool
)
[]
string
{
return
generic
validation
.
NameIsDNS1035Label
(
name
,
prefix
)
return
apimachinery
validation
.
NameIsDNS1035Label
(
name
,
prefix
)
}
}
// Validates that given value is not negative.
// Validates that given value is not negative.
func
ValidateNonnegativeField
(
value
int64
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
func
ValidateNonnegativeField
(
value
int64
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
return
generic
validation
.
ValidateNonnegativeField
(
value
,
fldPath
)
return
apimachinery
validation
.
ValidateNonnegativeField
(
value
,
fldPath
)
}
}
// Validates that a Quantity is not negative
// Validates that a Quantity is not negative
...
@@ -289,7 +290,7 @@ func ValidateImmutableAnnotation(newVal string, oldVal string, annotation string
...
@@ -289,7 +290,7 @@ func ValidateImmutableAnnotation(newVal string, oldVal string, annotation string
// It doesn't return an error for rootscoped resources with namespace, because namespace should already be cleared before.
// It doesn't return an error for rootscoped resources with namespace, because namespace should already be cleared before.
// TODO: Remove calls to this method scattered in validations of specific resources, e.g., ValidatePodUpdate.
// TODO: Remove calls to this method scattered in validations of specific resources, e.g., ValidatePodUpdate.
func
ValidateObjectMeta
(
meta
*
api
.
ObjectMeta
,
requiresNamespace
bool
,
nameFn
ValidateNameFunc
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
func
ValidateObjectMeta
(
meta
*
api
.
ObjectMeta
,
requiresNamespace
bool
,
nameFn
ValidateNameFunc
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
return
genericvalidation
.
ValidateObjectMeta
(
meta
,
requiresNamespace
,
generic
validation
.
ValidateNameFunc
(
nameFn
),
fldPath
)
return
genericvalidation
.
ValidateObjectMeta
(
meta
,
requiresNamespace
,
apimachinery
validation
.
ValidateNameFunc
(
nameFn
),
fldPath
)
}
}
// ValidateObjectMetaUpdate validates an object's metadata when updated
// ValidateObjectMetaUpdate validates an object's metadata when updated
...
...
staging/src/k8s.io/apimachinery/pkg/api/validation/doc.go
0 → 100644
View file @
3a17d433
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package validation contains generic api type validation functions.
package
validation
// import "k8s.io/apimachinery/pkg/api/validation"
staging/src/k8s.io/apimachinery/pkg/api/validation/generic.go
0 → 100644
View file @
3a17d433
/*
Copyright 2014 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
validation
import
(
"strings"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
)
const
IsNegativeErrorMsg
string
=
`must be greater than or equal to 0`
// ValidateNameFunc validates that the provided name is valid for a given resource type.
// Not all resources have the same validation rules for names. Prefix is true
// if the name will have a value appended to it. If the name is not valid,
// this returns a list of descriptions of individual characteristics of the
// value that were not valid. Otherwise this returns an empty list or nil.
type
ValidateNameFunc
func
(
name
string
,
prefix
bool
)
[]
string
// NameIsDNSSubdomain is a ValidateNameFunc for names that must be a DNS subdomain.
func
NameIsDNSSubdomain
(
name
string
,
prefix
bool
)
[]
string
{
if
prefix
{
name
=
maskTrailingDash
(
name
)
}
return
validation
.
IsDNS1123Subdomain
(
name
)
}
// NameIsDNSLabel is a ValidateNameFunc for names that must be a DNS 1123 label.
func
NameIsDNSLabel
(
name
string
,
prefix
bool
)
[]
string
{
if
prefix
{
name
=
maskTrailingDash
(
name
)
}
return
validation
.
IsDNS1123Label
(
name
)
}
// NameIsDNS1035Label is a ValidateNameFunc for names that must be a DNS 952 label.
func
NameIsDNS1035Label
(
name
string
,
prefix
bool
)
[]
string
{
if
prefix
{
name
=
maskTrailingDash
(
name
)
}
return
validation
.
IsDNS1035Label
(
name
)
}
// ValidateNamespaceName can be used to check whether the given namespace name is valid.
// Prefix indicates this name will be used as part of generation, in which case
// trailing dashes are allowed.
var
ValidateNamespaceName
=
NameIsDNSLabel
// ValidateServiceAccountName can be used to check whether the given service account name is valid.
// Prefix indicates this name will be used as part of generation, in which case
// trailing dashes are allowed.
var
ValidateServiceAccountName
=
NameIsDNSSubdomain
// maskTrailingDash replaces the final character of a string with a subdomain safe
// value if is a dash.
func
maskTrailingDash
(
name
string
)
string
{
if
strings
.
HasSuffix
(
name
,
"-"
)
{
return
name
[
:
len
(
name
)
-
2
]
+
"a"
}
return
name
}
// Validates that given value is not negative.
func
ValidateNonnegativeField
(
value
int64
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
if
value
<
0
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
,
value
,
IsNegativeErrorMsg
))
}
return
allErrs
}
staging/src/k8s.io/apiserver/pkg/authentication/serviceaccount/util.go
View file @
3a17d433
...
@@ -20,7 +20,7 @@ import (
...
@@ -20,7 +20,7 @@ import (
"fmt"
"fmt"
"strings"
"strings"
"k8s.io/kubernetes/pkg/api/validation/generic
validation"
apimachineryvalidation
"k8s.io/apimachinery/pkg/api/
validation"
)
)
const
(
const
(
...
@@ -50,10 +50,10 @@ func SplitUsername(username string) (string, string, error) {
...
@@ -50,10 +50,10 @@ func SplitUsername(username string) (string, string, error) {
return
""
,
""
,
invalidUsernameErr
return
""
,
""
,
invalidUsernameErr
}
}
namespace
,
name
:=
parts
[
0
],
parts
[
1
]
namespace
,
name
:=
parts
[
0
],
parts
[
1
]
if
len
(
generic
validation
.
ValidateNamespaceName
(
namespace
,
false
))
!=
0
{
if
len
(
apimachinery
validation
.
ValidateNamespaceName
(
namespace
,
false
))
!=
0
{
return
""
,
""
,
invalidUsernameErr
return
""
,
""
,
invalidUsernameErr
}
}
if
len
(
generic
validation
.
ValidateServiceAccountName
(
name
,
false
))
!=
0
{
if
len
(
apimachinery
validation
.
ValidateServiceAccountName
(
name
,
false
))
!=
0
{
return
""
,
""
,
invalidUsernameErr
return
""
,
""
,
invalidUsernameErr
}
}
return
namespace
,
name
,
nil
return
namespace
,
name
,
nil
...
...
vendor/BUILD
View file @
3a17d433
...
@@ -8746,7 +8746,7 @@ go_library(
...
@@ -8746,7 +8746,7 @@ go_library(
name = "k8s.io/apiserver/pkg/authentication/serviceaccount",
name = "k8s.io/apiserver/pkg/authentication/serviceaccount",
srcs = ["k8s.io/apiserver/pkg/authentication/serviceaccount/util.go"],
srcs = ["k8s.io/apiserver/pkg/authentication/serviceaccount/util.go"],
tags = ["automanaged"],
tags = ["automanaged"],
deps = ["//
pkg/api/validation/genericvalidation:go_default_library
"],
deps = ["//
vendor:k8s.io/apimachinery/pkg/api/validation
"],
)
)
go_test(
go_test(
...
@@ -13382,3 +13382,16 @@ filegroup(
...
@@ -13382,3 +13382,16 @@ filegroup(
srcs = [":package-srcs"],
srcs = [":package-srcs"],
tags = ["automanaged"],
tags = ["automanaged"],
)
)
go_library(
name = "k8s.io/apimachinery/pkg/api/validation",
srcs = [
"k8s.io/apimachinery/pkg/api/validation/doc.go",
"k8s.io/apimachinery/pkg/api/validation/generic.go",
],
tags = ["automanaged"],
deps = [
"//vendor:k8s.io/apimachinery/pkg/util/validation",
"//vendor:k8s.io/apimachinery/pkg/util/validation/field",
],
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment