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
7be20b0d
Commit
7be20b0d
authored
Jul 12, 2016
by
jianhuiz
Committed by
jianhuiz
Aug 22, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ClusterName field to ObjectMeta
parent
25ce84b3
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
50 additions
and
3 deletions
+50
-3
validation.go
federation/apis/federation/validation/validation.go
+1
-3
meta.go
pkg/api/meta.go
+7
-0
interfaces.go
pkg/api/meta/interfaces.go
+2
-0
types.go
pkg/api/types.go
+5
-0
meta.go
pkg/api/v1/meta.go
+7
-0
types.go
pkg/api/v1/types.go
+5
-0
validation.go
pkg/api/validation/validation.go
+9
-0
types.go
pkg/runtime/types.go
+8
-0
unstructured_test.go
pkg/runtime/unstructured_test.go
+6
-0
No files found.
federation/apis/federation/validation/validation.go
View file @
7be20b0d
...
@@ -22,8 +22,6 @@ import (
...
@@ -22,8 +22,6 @@ import (
"k8s.io/kubernetes/pkg/util/validation/field"
"k8s.io/kubernetes/pkg/util/validation/field"
)
)
var
ValidateClusterName
=
validation
.
NameIsDNS1035Label
func
ValidateClusterSpec
(
spec
*
federation
.
ClusterSpec
,
fieldPath
*
field
.
Path
)
field
.
ErrorList
{
func
ValidateClusterSpec
(
spec
*
federation
.
ClusterSpec
,
fieldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
allErrs
:=
field
.
ErrorList
{}
// address is required.
// address is required.
...
@@ -34,7 +32,7 @@ func ValidateClusterSpec(spec *federation.ClusterSpec, fieldPath *field.Path) fi
...
@@ -34,7 +32,7 @@ func ValidateClusterSpec(spec *federation.ClusterSpec, fieldPath *field.Path) fi
}
}
func
ValidateCluster
(
cluster
*
federation
.
Cluster
)
field
.
ErrorList
{
func
ValidateCluster
(
cluster
*
federation
.
Cluster
)
field
.
ErrorList
{
allErrs
:=
validation
.
ValidateObjectMeta
(
&
cluster
.
ObjectMeta
,
false
,
ValidateClusterName
,
field
.
NewPath
(
"metadata"
))
allErrs
:=
validation
.
ValidateObjectMeta
(
&
cluster
.
ObjectMeta
,
false
,
validation
.
ValidateClusterName
,
field
.
NewPath
(
"metadata"
))
allErrs
=
append
(
allErrs
,
ValidateClusterSpec
(
&
cluster
.
Spec
,
field
.
NewPath
(
"spec"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateClusterSpec
(
&
cluster
.
Spec
,
field
.
NewPath
(
"spec"
))
...
)
return
allErrs
return
allErrs
}
}
...
...
pkg/api/meta.go
View file @
7be20b0d
...
@@ -131,3 +131,10 @@ func (meta *ObjectMeta) SetOwnerReferences(references []metatypes.OwnerReference
...
@@ -131,3 +131,10 @@ func (meta *ObjectMeta) SetOwnerReferences(references []metatypes.OwnerReference
}
}
meta
.
OwnerReferences
=
newReferences
meta
.
OwnerReferences
=
newReferences
}
}
func
(
meta
*
ObjectMeta
)
GetClusterName
()
string
{
return
meta
.
ClusterName
}
func
(
meta
*
ObjectMeta
)
SetClusterName
(
clusterName
string
)
{
meta
.
ClusterName
=
clusterName
}
pkg/api/meta/interfaces.go
View file @
7be20b0d
...
@@ -62,6 +62,8 @@ type Object interface {
...
@@ -62,6 +62,8 @@ type Object interface {
SetFinalizers
(
finalizers
[]
string
)
SetFinalizers
(
finalizers
[]
string
)
GetOwnerReferences
()
[]
metatypes
.
OwnerReference
GetOwnerReferences
()
[]
metatypes
.
OwnerReference
SetOwnerReferences
([]
metatypes
.
OwnerReference
)
SetOwnerReferences
([]
metatypes
.
OwnerReference
)
GetClusterName
()
string
SetClusterName
(
clusterName
string
)
}
}
var
_
Object
=
&
runtime
.
Unstructured
{}
var
_
Object
=
&
runtime
.
Unstructured
{}
...
...
pkg/api/types.go
View file @
7be20b0d
...
@@ -149,6 +149,11 @@ type ObjectMeta struct {
...
@@ -149,6 +149,11 @@ type ObjectMeta struct {
// from the list. If the deletionTimestamp of the object is non-nil, entries
// from the list. If the deletionTimestamp of the object is non-nil, entries
// in this list can only be removed.
// in this list can only be removed.
Finalizers
[]
string
`json:"finalizers,omitempty"`
Finalizers
[]
string
`json:"finalizers,omitempty"`
// The name of the cluster which the object belongs to.
// This is used to distinguish resources with same name and namespace in different clusters.
// This field is not set anywhere right now and apiserver is going to ignore it if set in create or update request.
ClusterName
string
`json:"clusterName,omitempty"`
}
}
const
(
const
(
...
...
pkg/api/v1/meta.go
View file @
7be20b0d
...
@@ -83,3 +83,10 @@ func (meta *ObjectMeta) SetOwnerReferences(references []metatypes.OwnerReference
...
@@ -83,3 +83,10 @@ func (meta *ObjectMeta) SetOwnerReferences(references []metatypes.OwnerReference
}
}
meta
.
OwnerReferences
=
newReferences
meta
.
OwnerReferences
=
newReferences
}
}
func
(
meta
*
ObjectMeta
)
GetClusterName
()
string
{
return
meta
.
ClusterName
}
func
(
meta
*
ObjectMeta
)
SetClusterName
(
clusterName
string
)
{
meta
.
ClusterName
=
clusterName
}
pkg/api/v1/types.go
View file @
7be20b0d
...
@@ -186,6 +186,11 @@ type ObjectMeta struct {
...
@@ -186,6 +186,11 @@ type ObjectMeta struct {
// from the list. If the deletionTimestamp of the object is non-nil, entries
// from the list. If the deletionTimestamp of the object is non-nil, entries
// in this list can only be removed.
// in this list can only be removed.
Finalizers
[]
string
`json:"finalizers,omitempty" patchStrategy:"merge" protobuf:"bytes,14,rep,name=finalizers"`
Finalizers
[]
string
`json:"finalizers,omitempty" patchStrategy:"merge" protobuf:"bytes,14,rep,name=finalizers"`
// The name of the cluster which the object belongs to.
// This is used to distinguish resources with same name and namespace in different clusters.
// This field is not set anywhere right now and apiserver is going to ignore it if set in create or update request.
ClusterName
string
`json:"clusterName,omitempty"`
}
}
const
(
const
(
...
...
pkg/api/validation/validation.go
View file @
7be20b0d
...
@@ -279,6 +279,9 @@ var ValidateServiceAccountName = NameIsDNSSubdomain
...
@@ -279,6 +279,9 @@ var ValidateServiceAccountName = NameIsDNSSubdomain
// trailing dashes are allowed.
// trailing dashes are allowed.
var
ValidateEndpointsName
=
NameIsDNSSubdomain
var
ValidateEndpointsName
=
NameIsDNSSubdomain
// ValidateClusterName can be used to check whether the given cluster name is valid.
var
ValidateClusterName
=
NameIsDNS1035Label
// 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
{
if
prefix
{
if
prefix
{
...
@@ -364,6 +367,11 @@ func ValidateObjectMeta(meta *api.ObjectMeta, requiresNamespace bool, nameFn Val
...
@@ -364,6 +367,11 @@ func ValidateObjectMeta(meta *api.ObjectMeta, requiresNamespace bool, nameFn Val
allErrs
=
append
(
allErrs
,
field
.
Forbidden
(
fldPath
.
Child
(
"namespace"
),
"not allowed on this type"
))
allErrs
=
append
(
allErrs
,
field
.
Forbidden
(
fldPath
.
Child
(
"namespace"
),
"not allowed on this type"
))
}
}
}
}
if
len
(
meta
.
ClusterName
)
!=
0
{
for
_
,
msg
:=
range
ValidateClusterName
(
meta
.
ClusterName
,
false
)
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
.
Child
(
"clusterName"
),
meta
.
ClusterName
,
msg
))
}
}
allErrs
=
append
(
allErrs
,
ValidateNonnegativeField
(
meta
.
Generation
,
fldPath
.
Child
(
"generation"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateNonnegativeField
(
meta
.
Generation
,
fldPath
.
Child
(
"generation"
))
...
)
allErrs
=
append
(
allErrs
,
unversionedvalidation
.
ValidateLabels
(
meta
.
Labels
,
fldPath
.
Child
(
"labels"
))
...
)
allErrs
=
append
(
allErrs
,
unversionedvalidation
.
ValidateLabels
(
meta
.
Labels
,
fldPath
.
Child
(
"labels"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateAnnotations
(
meta
.
Annotations
,
fldPath
.
Child
(
"annotations"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateAnnotations
(
meta
.
Annotations
,
fldPath
.
Child
(
"annotations"
))
...
)
...
@@ -425,6 +433,7 @@ func ValidateObjectMetaUpdate(newMeta, oldMeta *api.ObjectMeta, fldPath *field.P
...
@@ -425,6 +433,7 @@ func ValidateObjectMetaUpdate(newMeta, oldMeta *api.ObjectMeta, fldPath *field.P
allErrs
=
append
(
allErrs
,
ValidateImmutableField
(
newMeta
.
Namespace
,
oldMeta
.
Namespace
,
fldPath
.
Child
(
"namespace"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateImmutableField
(
newMeta
.
Namespace
,
oldMeta
.
Namespace
,
fldPath
.
Child
(
"namespace"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateImmutableField
(
newMeta
.
UID
,
oldMeta
.
UID
,
fldPath
.
Child
(
"uid"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateImmutableField
(
newMeta
.
UID
,
oldMeta
.
UID
,
fldPath
.
Child
(
"uid"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateImmutableField
(
newMeta
.
CreationTimestamp
,
oldMeta
.
CreationTimestamp
,
fldPath
.
Child
(
"creationTimestamp"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateImmutableField
(
newMeta
.
CreationTimestamp
,
oldMeta
.
CreationTimestamp
,
fldPath
.
Child
(
"creationTimestamp"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateImmutableField
(
newMeta
.
ClusterName
,
oldMeta
.
ClusterName
,
fldPath
.
Child
(
"clusterName"
))
...
)
allErrs
=
append
(
allErrs
,
unversionedvalidation
.
ValidateLabels
(
newMeta
.
Labels
,
fldPath
.
Child
(
"labels"
))
...
)
allErrs
=
append
(
allErrs
,
unversionedvalidation
.
ValidateLabels
(
newMeta
.
Labels
,
fldPath
.
Child
(
"labels"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateAnnotations
(
newMeta
.
Annotations
,
fldPath
.
Child
(
"annotations"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateAnnotations
(
newMeta
.
Annotations
,
fldPath
.
Child
(
"annotations"
))
...
)
...
...
pkg/runtime/types.go
View file @
7be20b0d
...
@@ -456,6 +456,14 @@ func (u *Unstructured) SetFinalizers(finalizers []string) {
...
@@ -456,6 +456,14 @@ func (u *Unstructured) SetFinalizers(finalizers []string) {
u
.
setNestedSlice
(
finalizers
,
"metadata"
,
"finalizers"
)
u
.
setNestedSlice
(
finalizers
,
"metadata"
,
"finalizers"
)
}
}
func
(
u
*
Unstructured
)
GetClusterName
()
string
{
return
getNestedString
(
u
.
Object
,
"metadata"
,
"clusterName"
)
}
func
(
u
*
Unstructured
)
SetClusterName
(
clusterName
string
)
{
u
.
setNestedField
(
clusterName
,
"metadata"
,
"clusterName"
)
}
// UnstructuredList allows lists that do not have Golang structs
// UnstructuredList allows lists that do not have Golang structs
// registered to be manipulated generically. This can be used to deal
// registered to be manipulated generically. This can be used to deal
// with the API lists from a plug-in.
// with the API lists from a plug-in.
...
...
pkg/runtime/unstructured_test.go
View file @
7be20b0d
...
@@ -160,6 +160,7 @@ func TestUnstructuredGetters(t *testing.T) {
...
@@ -160,6 +160,7 @@ func TestUnstructuredGetters(t *testing.T) {
"finalizer.1"
,
"finalizer.1"
,
"finalizer.2"
,
"finalizer.2"
,
},
},
"clusterName"
:
"cluster123"
,
},
},
},
},
}
}
...
@@ -232,6 +233,9 @@ func TestUnstructuredGetters(t *testing.T) {
...
@@ -232,6 +233,9 @@ func TestUnstructuredGetters(t *testing.T) {
if
got
,
want
:=
unstruct
.
GetFinalizers
(),
[]
string
{
"finalizer.1"
,
"finalizer.2"
};
!
reflect
.
DeepEqual
(
got
,
want
)
{
if
got
,
want
:=
unstruct
.
GetFinalizers
(),
[]
string
{
"finalizer.1"
,
"finalizer.2"
};
!
reflect
.
DeepEqual
(
got
,
want
)
{
t
.
Errorf
(
"GetFinalizers()=%v, want %v"
,
got
,
want
)
t
.
Errorf
(
"GetFinalizers()=%v, want %v"
,
got
,
want
)
}
}
if
got
,
want
:=
unstruct
.
GetClusterName
(),
"cluster123"
;
got
!=
want
{
t
.
Errorf
(
"GetClusterName()=%v, want %v"
,
got
,
want
)
}
}
}
func
TestUnstructuredSetters
(
t
*
testing
.
T
)
{
func
TestUnstructuredSetters
(
t
*
testing
.
T
)
{
...
@@ -277,6 +281,7 @@ func TestUnstructuredSetters(t *testing.T) {
...
@@ -277,6 +281,7 @@ func TestUnstructuredSetters(t *testing.T) {
"finalizer.1"
,
"finalizer.1"
,
"finalizer.2"
,
"finalizer.2"
,
},
},
"clusterName"
:
"cluster123"
,
},
},
},
},
}
}
...
@@ -311,6 +316,7 @@ func TestUnstructuredSetters(t *testing.T) {
...
@@ -311,6 +316,7 @@ func TestUnstructuredSetters(t *testing.T) {
}
}
unstruct
.
SetOwnerReferences
(
newOwnerReferences
)
unstruct
.
SetOwnerReferences
(
newOwnerReferences
)
unstruct
.
SetFinalizers
([]
string
{
"finalizer.1"
,
"finalizer.2"
})
unstruct
.
SetFinalizers
([]
string
{
"finalizer.1"
,
"finalizer.2"
})
unstruct
.
SetClusterName
(
"cluster123"
)
if
!
reflect
.
DeepEqual
(
unstruct
,
want
)
{
if
!
reflect
.
DeepEqual
(
unstruct
,
want
)
{
t
.
Errorf
(
"Wanted:
\n
%s
\n
Got:
\n
%s"
,
want
,
unstruct
)
t
.
Errorf
(
"Wanted:
\n
%s
\n
Got:
\n
%s"
,
want
,
unstruct
)
...
...
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