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
395be3b4
Commit
395be3b4
authored
Feb 21, 2017
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apimachinery: handle duplicated and conflicting type registration
parent
6050f59b
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
95 additions
and
28 deletions
+95
-28
eventsink.go
...ion/pkg/federation-controller/util/eventsink/eventsink.go
+6
-4
serialization_test.go
pkg/api/serialization_test.go
+2
-1
register.go
pkg/apis/autoscaling/v2alpha1/register.go
+0
-5
register.go
pkg/apis/rbac/register.go
+0
-2
metaonly.go
pkg/controller/garbagecollector/metaonly/metaonly.go
+4
-0
scheme.go
staging/src/k8s.io/apimachinery/pkg/runtime/scheme.go
+10
-0
scheme_test.go
staging/src/k8s.io/apimachinery/pkg/runtime/scheme_test.go
+73
-0
register.go
staging/src/k8s.io/apiserver/pkg/apis/apiserver/register.go
+0
-2
register.go
staging/src/k8s.io/apiserver/pkg/apis/example/register.go
+0
-2
etcd_helper_test.go
...src/k8s.io/apiserver/pkg/storage/etcd/etcd_helper_test.go
+0
-1
register.go
...s.io/kube-aggregator/pkg/apis/apiregistration/register.go
+0
-9
register.go
...g/src/k8s.io/sample-apiserver/pkg/apis/wardle/register.go
+0
-2
No files found.
federation/pkg/federation-controller/util/eventsink/eventsink.go
View file @
395be3b4
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
clientv1
"k8s.io/client-go/pkg/api/v1"
clientv1
"k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/record"
...
@@ -48,10 +49,11 @@ func NewFederatedEventSink(clientset fedclientset.Interface) *FederatedEventSink
...
@@ -48,10 +49,11 @@ func NewFederatedEventSink(clientset fedclientset.Interface) *FederatedEventSink
var
scheme
=
runtime
.
NewScheme
()
var
scheme
=
runtime
.
NewScheme
()
func
init
()
{
func
init
()
{
scheme
.
AddKnownTypes
(
clientv1
.
SchemeGroupVersion
,
// register client-go's and kube's Event type under two different GroupVersions
&
clientv1
.
Event
{},
// TODO: switch to client-go client for events
&
kubev1
.
Event
{},
scheme
.
AddKnownTypes
(
clientv1
.
SchemeGroupVersion
,
&
clientv1
.
Event
{})
)
scheme
.
AddKnownTypes
(
schema
.
GroupVersion
{
Group
:
"fake-kube-"
+
kubev1
.
SchemeGroupVersion
.
Group
,
Version
:
kubev1
.
SchemeGroupVersion
.
Version
},
&
kubev1
.
Event
{})
if
err
:=
scheme
.
AddConversionFuncs
(
if
err
:=
scheme
.
AddConversionFuncs
(
metav1
.
Convert_unversioned_Time_To_unversioned_Time
,
metav1
.
Convert_unversioned_Time_To_unversioned_Time
,
);
err
!=
nil
{
);
err
!=
nil
{
...
...
pkg/api/serialization_test.go
View file @
395be3b4
...
@@ -174,7 +174,8 @@ func TestCommonKindsRegistered(t *testing.T) {
...
@@ -174,7 +174,8 @@ func TestCommonKindsRegistered(t *testing.T) {
t
.
Error
(
err
)
t
.
Error
(
err
)
}
}
defaults
:=
gv
.
WithKind
(
""
)
defaults
:=
gv
.
WithKind
(
""
)
if
_
,
got
,
err
:=
api
.
Codecs
.
LegacyCodec
()
.
Decode
([]
byte
(
`{"kind":"`
+
kind
+
`"}`
),
&
defaults
,
nil
);
err
!=
nil
||
gvk
!=
*
got
{
var
got
*
schema
.
GroupVersionKind
if
obj
,
got
,
err
=
api
.
Codecs
.
LegacyCodec
()
.
Decode
([]
byte
(
`{"kind":"`
+
kind
+
`"}`
),
&
defaults
,
obj
);
err
!=
nil
||
gvk
!=
*
got
{
t
.
Errorf
(
"expected %v: %v %v"
,
gvk
,
got
,
err
)
t
.
Errorf
(
"expected %v: %v %v"
,
gvk
,
got
,
err
)
}
}
data
,
err
:=
runtime
.
Encode
(
api
.
Codecs
.
LegacyCodec
(
*
gv
),
obj
)
data
,
err
:=
runtime
.
Encode
(
api
.
Codecs
.
LegacyCodec
(
*
gv
),
obj
)
...
...
pkg/apis/autoscaling/v2alpha1/register.go
View file @
395be3b4
...
@@ -20,7 +20,6 @@ import (
...
@@ -20,7 +20,6 @@ import (
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/kubernetes/pkg/api/v1"
)
)
// GroupName is the group name use in this package
// GroupName is the group name use in this package
...
@@ -39,10 +38,6 @@ func addKnownTypes(scheme *runtime.Scheme) error {
...
@@ -39,10 +38,6 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme
.
AddKnownTypes
(
SchemeGroupVersion
,
scheme
.
AddKnownTypes
(
SchemeGroupVersion
,
&
HorizontalPodAutoscaler
{},
&
HorizontalPodAutoscaler
{},
&
HorizontalPodAutoscalerList
{},
&
HorizontalPodAutoscalerList
{},
&
v1
.
ListOptions
{},
&
v1
.
DeleteOptions
{},
&
metav1
.
GetOptions
{},
&
metav1
.
ExportOptions
{},
)
)
metav1
.
AddToGroupVersion
(
scheme
,
SchemeGroupVersion
)
metav1
.
AddToGroupVersion
(
scheme
,
SchemeGroupVersion
)
return
nil
return
nil
...
...
pkg/apis/rbac/register.go
View file @
395be3b4
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
rbac
package
rbac
import
(
import
(
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
)
)
...
@@ -55,6 +54,5 @@ func addKnownTypes(scheme *runtime.Scheme) error {
...
@@ -55,6 +54,5 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&
ClusterRoleBindingList
{},
&
ClusterRoleBindingList
{},
&
ClusterRoleList
{},
&
ClusterRoleList
{},
)
)
metav1
.
AddToGroupVersion
(
scheme
,
SchemeGroupVersion
)
return
nil
return
nil
}
}
pkg/controller/garbagecollector/metaonly/metaonly.go
View file @
395be3b4
...
@@ -52,6 +52,10 @@ func NewMetadataCodecFactory() serializer.CodecFactory {
...
@@ -52,6 +52,10 @@ func NewMetadataCodecFactory() serializer.CodecFactory {
if
kind
.
Version
==
runtime
.
APIVersionInternal
{
if
kind
.
Version
==
runtime
.
APIVersionInternal
{
continue
continue
}
}
if
kind
==
api
.
Unversioned
.
WithKind
(
"Status"
)
{
// this is added below as unversioned
continue
}
metaOnlyObject
:=
gvkToMetadataOnlyObject
(
kind
)
metaOnlyObject
:=
gvkToMetadataOnlyObject
(
kind
)
scheme
.
AddKnownTypeWithName
(
kind
,
metaOnlyObject
)
scheme
.
AddKnownTypeWithName
(
kind
,
metaOnlyObject
)
}
}
...
...
staging/src/k8s.io/apimachinery/pkg/runtime/scheme.go
View file @
395be3b4
...
@@ -190,7 +190,17 @@ func (s *Scheme) AddKnownTypeWithName(gvk schema.GroupVersionKind, obj Object) {
...
@@ -190,7 +190,17 @@ func (s *Scheme) AddKnownTypeWithName(gvk schema.GroupVersionKind, obj Object) {
panic
(
"All types must be pointers to structs."
)
panic
(
"All types must be pointers to structs."
)
}
}
if
oldT
,
found
:=
s
.
gvkToType
[
gvk
];
found
&&
oldT
!=
t
{
panic
(
fmt
.
Sprintf
(
"Double registration of different types for %v: old=%v.%v, new=%v.%v"
,
gvk
,
oldT
.
PkgPath
(),
oldT
.
Name
(),
t
.
PkgPath
(),
t
.
Name
()))
}
s
.
gvkToType
[
gvk
]
=
t
s
.
gvkToType
[
gvk
]
=
t
for
_
,
existingGvk
:=
range
s
.
typeToGVK
[
t
]
{
if
existingGvk
==
gvk
{
return
}
}
s
.
typeToGVK
[
t
]
=
append
(
s
.
typeToGVK
[
t
],
gvk
)
s
.
typeToGVK
[
t
]
=
append
(
s
.
typeToGVK
[
t
],
gvk
)
}
}
...
...
staging/src/k8s.io/apimachinery/pkg/runtime/scheme_test.go
View file @
395be3b4
...
@@ -548,6 +548,79 @@ func TestKnownTypes(t *testing.T) {
...
@@ -548,6 +548,79 @@ func TestKnownTypes(t *testing.T) {
}
}
}
}
func
TestAddKnownTypesIdemPotent
(
t
*
testing
.
T
)
{
s
:=
runtime
.
NewScheme
()
gv
:=
schema
.
GroupVersion
{
Group
:
"foo"
,
Version
:
"v1"
}
s
.
AddKnownTypes
(
gv
,
&
InternalSimple
{})
s
.
AddKnownTypes
(
gv
,
&
InternalSimple
{})
if
len
(
s
.
KnownTypes
(
gv
))
!=
1
{
t
.
Errorf
(
"expected only one %v type after double registration"
,
gv
)
}
if
len
(
s
.
AllKnownTypes
())
!=
1
{
t
.
Errorf
(
"expected only one type after double registration"
)
}
s
.
AddKnownTypeWithName
(
gv
.
WithKind
(
"InternalSimple"
),
&
InternalSimple
{})
s
.
AddKnownTypeWithName
(
gv
.
WithKind
(
"InternalSimple"
),
&
InternalSimple
{})
if
len
(
s
.
KnownTypes
(
gv
))
!=
1
{
t
.
Errorf
(
"expected only one %v type after double registration with custom name"
,
gv
)
}
if
len
(
s
.
AllKnownTypes
())
!=
1
{
t
.
Errorf
(
"expected only one type after double registration with custom name"
)
}
s
.
AddUnversionedTypes
(
gv
,
&
InternalSimple
{})
if
len
(
s
.
KnownTypes
(
gv
))
!=
1
{
t
.
Errorf
(
"expected only one %v type after double registration with custom name"
,
gv
)
}
if
len
(
s
.
AllKnownTypes
())
!=
1
{
t
.
Errorf
(
"expected only one type after double registration with custom name"
)
}
kinds
,
_
,
err
:=
s
.
ObjectKinds
(
&
InternalSimple
{})
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
len
(
kinds
)
!=
1
{
t
.
Errorf
(
"expected only one kind for InternalSimple after double registration"
,
gv
)
}
}
func
TestConflictingAddKnownTypes
(
t
*
testing
.
T
)
{
s
:=
runtime
.
NewScheme
()
gv
:=
schema
.
GroupVersion
{
Group
:
"foo"
,
Version
:
"v1"
}
panicked
:=
make
(
chan
bool
)
go
func
()
{
defer
func
()
{
if
recover
()
!=
nil
{
panicked
<-
true
}
}()
s
.
AddKnownTypeWithName
(
gv
.
WithKind
(
"InternalSimple"
),
&
InternalSimple
{})
s
.
AddKnownTypeWithName
(
gv
.
WithKind
(
"InternalSimple"
),
&
ExternalSimple
{})
panicked
<-
false
}()
if
!<-
panicked
{
t
.
Errorf
(
"Expected AddKnownTypesWithName to panic with conflicting type registrations"
)
}
go
func
()
{
defer
func
()
{
if
recover
()
!=
nil
{
panicked
<-
true
}
}()
s
.
AddUnversionedTypes
(
gv
,
&
InternalSimple
{})
s
.
AddUnversionedTypes
(
gv
,
&
InternalSimple
{})
panicked
<-
false
}()
if
!<-
panicked
{
t
.
Errorf
(
"Expected AddUnversionedTypes to panic with conflicting type registrations"
)
}
}
func
TestConvertToVersionBasic
(
t
*
testing
.
T
)
{
func
TestConvertToVersionBasic
(
t
*
testing
.
T
)
{
s
:=
GetTestScheme
()
s
:=
GetTestScheme
()
tt
:=
&
TestType1
{
A
:
"I'm not a pointer object"
}
tt
:=
&
TestType1
{
A
:
"I'm not a pointer object"
}
...
...
staging/src/k8s.io/apiserver/pkg/apis/apiserver/register.go
View file @
395be3b4
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
apiserver
package
apiserver
import
(
import
(
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
)
)
...
@@ -47,6 +46,5 @@ func addKnownTypes(scheme *runtime.Scheme) error {
...
@@ -47,6 +46,5 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme
.
AddKnownTypes
(
SchemeGroupVersion
,
scheme
.
AddKnownTypes
(
SchemeGroupVersion
,
&
AdmissionConfiguration
{},
&
AdmissionConfiguration
{},
)
)
metav1
.
AddToGroupVersion
(
scheme
,
SchemeGroupVersion
)
return
nil
return
nil
}
}
staging/src/k8s.io/apiserver/pkg/apis/example/register.go
View file @
395be3b4
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
example
package
example
import
(
import
(
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
)
)
...
@@ -48,6 +47,5 @@ func addKnownTypes(scheme *runtime.Scheme) error {
...
@@ -48,6 +47,5 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme
.
AddKnownTypes
(
SchemeGroupVersion
,
scheme
.
AddKnownTypes
(
SchemeGroupVersion
,
&
Pod
{},
&
Pod
{},
)
)
metav1
.
AddToGroupVersion
(
scheme
,
SchemeGroupVersion
)
return
nil
return
nil
}
}
staging/src/k8s.io/apiserver/pkg/storage/etcd/etcd_helper_test.go
View file @
395be3b4
...
@@ -77,7 +77,6 @@ func testScheme(t *testing.T) (*runtime.Scheme, serializer.CodecFactory) {
...
@@ -77,7 +77,6 @@ func testScheme(t *testing.T) (*runtime.Scheme, serializer.CodecFactory) {
scheme
:=
runtime
.
NewScheme
()
scheme
:=
runtime
.
NewScheme
()
scheme
.
Log
(
t
)
scheme
.
Log
(
t
)
scheme
.
AddKnownTypes
(
schema
.
GroupVersion
{
Version
:
runtime
.
APIVersionInternal
},
&
storagetesting
.
TestResource
{})
scheme
.
AddKnownTypes
(
schema
.
GroupVersion
{
Version
:
runtime
.
APIVersionInternal
},
&
storagetesting
.
TestResource
{})
scheme
.
AddKnownTypes
(
schema
.
GroupVersion
{
Version
:
runtime
.
APIVersionInternal
},
&
storagetesting
.
TestResource
{})
example
.
AddToScheme
(
scheme
)
example
.
AddToScheme
(
scheme
)
examplev1
.
AddToScheme
(
scheme
)
examplev1
.
AddToScheme
(
scheme
)
if
err
:=
scheme
.
AddConversionFuncs
(
if
err
:=
scheme
.
AddConversionFuncs
(
...
...
staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/register.go
View file @
395be3b4
...
@@ -17,12 +17,8 @@ limitations under the License.
...
@@ -17,12 +17,8 @@ limitations under the License.
package
apiregistration
package
apiregistration
import
(
import
(
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
// we register here until we separate our scheme, which requires updates to client gen
kapi
"k8s.io/client-go/pkg/api"
)
)
const
GroupName
=
"apiregistration.k8s.io"
const
GroupName
=
"apiregistration.k8s.io"
...
@@ -50,11 +46,6 @@ func addKnownTypes(scheme *runtime.Scheme) error {
...
@@ -50,11 +46,6 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme
.
AddKnownTypes
(
SchemeGroupVersion
,
scheme
.
AddKnownTypes
(
SchemeGroupVersion
,
&
APIService
{},
&
APIService
{},
&
APIServiceList
{},
&
APIServiceList
{},
&
kapi
.
ListOptions
{},
&
metav1
.
DeleteOptions
{},
&
metav1
.
GetOptions
{},
)
)
metav1
.
AddToGroupVersion
(
scheme
,
SchemeGroupVersion
)
return
nil
return
nil
}
}
staging/src/k8s.io/sample-apiserver/pkg/apis/wardle/register.go
View file @
395be3b4
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
wardle
package
wardle
import
(
import
(
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
)
)
...
@@ -48,6 +47,5 @@ func addKnownTypes(scheme *runtime.Scheme) error {
...
@@ -48,6 +47,5 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&
Flunder
{},
&
Flunder
{},
&
FlunderList
{},
&
FlunderList
{},
)
)
metav1
.
AddToGroupVersion
(
scheme
,
SchemeGroupVersion
)
return
nil
return
nil
}
}
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