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
b5a26614
Unverified
Commit
b5a26614
authored
Jul 03, 2018
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove generic conversion function
parent
ba95744b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
1 addition
and
142 deletions
+1
-142
conversion.go
pkg/apis/core/v1/conversion.go
+0
-99
register.go
pkg/apis/core/v1/register.go
+1
-1
converter.go
staging/src/k8s.io/apimachinery/pkg/conversion/converter.go
+0
-22
scheme.go
staging/src/k8s.io/apimachinery/pkg/runtime/scheme.go
+0
-20
No files found.
pkg/apis/core/v1/conversion.go
View file @
b5a26614
...
@@ -30,105 +30,6 @@ import (
...
@@ -30,105 +30,6 @@ import (
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/extensions"
)
)
// This is a "fast-path" that avoids reflection for common types. It focuses on the objects that are
// converted the most in the cluster.
// TODO: generate one of these for every external API group - this is to prove the impact
func
addFastPathConversionFuncs
(
scheme
*
runtime
.
Scheme
)
error
{
scheme
.
AddGenericConversionFunc
(
func
(
objA
,
objB
interface
{},
s
conversion
.
Scope
)
(
bool
,
error
)
{
switch
a
:=
objA
.
(
type
)
{
case
*
v1
.
Pod
:
switch
b
:=
objB
.
(
type
)
{
case
*
core
.
Pod
:
return
true
,
Convert_v1_Pod_To_core_Pod
(
a
,
b
,
s
)
}
case
*
core
.
Pod
:
switch
b
:=
objB
.
(
type
)
{
case
*
v1
.
Pod
:
return
true
,
Convert_core_Pod_To_v1_Pod
(
a
,
b
,
s
)
}
case
*
v1
.
Event
:
switch
b
:=
objB
.
(
type
)
{
case
*
core
.
Event
:
return
true
,
Convert_v1_Event_To_core_Event
(
a
,
b
,
s
)
}
case
*
core
.
Event
:
switch
b
:=
objB
.
(
type
)
{
case
*
v1
.
Event
:
return
true
,
Convert_core_Event_To_v1_Event
(
a
,
b
,
s
)
}
case
*
v1
.
ReplicationController
:
switch
b
:=
objB
.
(
type
)
{
case
*
core
.
ReplicationController
:
return
true
,
Convert_v1_ReplicationController_To_core_ReplicationController
(
a
,
b
,
s
)
}
case
*
core
.
ReplicationController
:
switch
b
:=
objB
.
(
type
)
{
case
*
v1
.
ReplicationController
:
return
true
,
Convert_core_ReplicationController_To_v1_ReplicationController
(
a
,
b
,
s
)
}
case
*
v1
.
Node
:
switch
b
:=
objB
.
(
type
)
{
case
*
core
.
Node
:
return
true
,
Convert_v1_Node_To_core_Node
(
a
,
b
,
s
)
}
case
*
core
.
Node
:
switch
b
:=
objB
.
(
type
)
{
case
*
v1
.
Node
:
return
true
,
Convert_core_Node_To_v1_Node
(
a
,
b
,
s
)
}
case
*
v1
.
Namespace
:
switch
b
:=
objB
.
(
type
)
{
case
*
core
.
Namespace
:
return
true
,
Convert_v1_Namespace_To_core_Namespace
(
a
,
b
,
s
)
}
case
*
core
.
Namespace
:
switch
b
:=
objB
.
(
type
)
{
case
*
v1
.
Namespace
:
return
true
,
Convert_core_Namespace_To_v1_Namespace
(
a
,
b
,
s
)
}
case
*
v1
.
Service
:
switch
b
:=
objB
.
(
type
)
{
case
*
core
.
Service
:
return
true
,
Convert_v1_Service_To_core_Service
(
a
,
b
,
s
)
}
case
*
core
.
Service
:
switch
b
:=
objB
.
(
type
)
{
case
*
v1
.
Service
:
return
true
,
Convert_core_Service_To_v1_Service
(
a
,
b
,
s
)
}
case
*
v1
.
Endpoints
:
switch
b
:=
objB
.
(
type
)
{
case
*
core
.
Endpoints
:
return
true
,
Convert_v1_Endpoints_To_core_Endpoints
(
a
,
b
,
s
)
}
case
*
core
.
Endpoints
:
switch
b
:=
objB
.
(
type
)
{
case
*
v1
.
Endpoints
:
return
true
,
Convert_core_Endpoints_To_v1_Endpoints
(
a
,
b
,
s
)
}
case
*
metav1
.
WatchEvent
:
switch
b
:=
objB
.
(
type
)
{
case
*
metav1
.
InternalEvent
:
return
true
,
metav1
.
Convert_versioned_Event_to_versioned_InternalEvent
(
a
,
b
,
s
)
}
case
*
metav1
.
InternalEvent
:
switch
b
:=
objB
.
(
type
)
{
case
*
metav1
.
WatchEvent
:
return
true
,
metav1
.
Convert_versioned_InternalEvent_to_versioned_Event
(
a
,
b
,
s
)
}
}
return
false
,
nil
})
return
nil
}
func
addConversionFuncs
(
scheme
*
runtime
.
Scheme
)
error
{
func
addConversionFuncs
(
scheme
*
runtime
.
Scheme
)
error
{
// Add non-generated conversion functions
// Add non-generated conversion functions
err
:=
scheme
.
AddConversionFuncs
(
err
:=
scheme
.
AddConversionFuncs
(
...
...
pkg/apis/core/v1/register.go
View file @
b5a26614
...
@@ -30,7 +30,7 @@ func init() {
...
@@ -30,7 +30,7 @@ func init() {
// We only register manually written functions here. The registration of the
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
// makes the code compile even when the generated files are missing.
localSchemeBuilder
.
Register
(
addDefaultingFuncs
,
addConversionFuncs
,
addFastPathConversionFuncs
)
localSchemeBuilder
.
Register
(
addDefaultingFuncs
,
addConversionFuncs
)
}
}
// TODO: remove these global varialbes
// TODO: remove these global varialbes
...
...
staging/src/k8s.io/apimachinery/pkg/conversion/converter.go
View file @
b5a26614
...
@@ -53,11 +53,6 @@ type Converter struct {
...
@@ -53,11 +53,6 @@ type Converter struct {
conversionFuncs
ConversionFuncs
conversionFuncs
ConversionFuncs
generatedConversionFuncs
ConversionFuncs
generatedConversionFuncs
ConversionFuncs
// genericConversions are called during normal conversion to offer a "fast-path"
// that avoids all reflection. These methods are not called outside of the .Convert()
// method.
genericConversions
[]
GenericConversionFunc
// Set of conversions that should be treated as a no-op
// Set of conversions that should be treated as a no-op
ignoredConversions
map
[
typePair
]
struct
{}
ignoredConversions
map
[
typePair
]
struct
{}
...
@@ -102,14 +97,6 @@ func NewConverter(nameFn NameFunc) *Converter {
...
@@ -102,14 +97,6 @@ func NewConverter(nameFn NameFunc) *Converter {
return
c
return
c
}
}
// AddGenericConversionFunc adds a function that accepts the ConversionFunc call pattern
// (for two conversion types) to the converter. These functions are checked first during
// a normal conversion, but are otherwise not called. Use AddConversionFuncs when registering
// typed conversions.
func
(
c
*
Converter
)
AddGenericConversionFunc
(
fn
GenericConversionFunc
)
{
c
.
genericConversions
=
append
(
c
.
genericConversions
,
fn
)
}
// WithConversions returns a Converter that is a copy of c but with the additional
// WithConversions returns a Converter that is a copy of c but with the additional
// fns merged on top.
// fns merged on top.
func
(
c
*
Converter
)
WithConversions
(
fns
ConversionFuncs
)
*
Converter
{
func
(
c
*
Converter
)
WithConversions
(
fns
ConversionFuncs
)
*
Converter
{
...
@@ -480,15 +467,6 @@ func (f FieldMatchingFlags) IsSet(flag FieldMatchingFlags) bool {
...
@@ -480,15 +467,6 @@ func (f FieldMatchingFlags) IsSet(flag FieldMatchingFlags) bool {
// it is not used by Convert() other than storing it in the scope.
// it is not used by Convert() other than storing it in the scope.
// Not safe for objects with cyclic references!
// Not safe for objects with cyclic references!
func
(
c
*
Converter
)
Convert
(
src
,
dest
interface
{},
flags
FieldMatchingFlags
,
meta
*
Meta
)
error
{
func
(
c
*
Converter
)
Convert
(
src
,
dest
interface
{},
flags
FieldMatchingFlags
,
meta
*
Meta
)
error
{
// TODO: deprecated, will be removed in favor of untyped conversion
if
len
(
c
.
genericConversions
)
>
0
{
s
:=
&
scope
{
converter
:
c
,
flags
:
flags
,
meta
:
meta
}
for
_
,
fn
:=
range
c
.
genericConversions
{
if
ok
,
err
:=
fn
(
src
,
dest
,
s
);
ok
{
return
err
}
}
}
return
c
.
doConversion
(
src
,
dest
,
flags
,
meta
,
c
.
convert
)
return
c
.
doConversion
(
src
,
dest
,
flags
,
meta
,
c
.
convert
)
}
}
...
...
staging/src/k8s.io/apimachinery/pkg/runtime/scheme.go
View file @
b5a26614
...
@@ -296,15 +296,6 @@ func (s *Scheme) New(kind schema.GroupVersionKind) (Object, error) {
...
@@ -296,15 +296,6 @@ func (s *Scheme) New(kind schema.GroupVersionKind) (Object, error) {
return
nil
,
NewNotRegisteredErrForKind
(
s
.
schemeName
,
kind
)
return
nil
,
NewNotRegisteredErrForKind
(
s
.
schemeName
,
kind
)
}
}
// AddGenericConversionFunc adds a function that accepts the ConversionFunc call pattern
// (for two conversion types) to the converter. These functions are checked first during
// a normal conversion, but are otherwise not called. Use AddConversionFuncs when registering
// typed conversions.
// DEPRECATED: Use AddConversionFunc
func
(
s
*
Scheme
)
AddGenericConversionFunc
(
fn
conversion
.
GenericConversionFunc
)
{
s
.
converter
.
AddGenericConversionFunc
(
fn
)
}
// Log sets a logger on the scheme. For test purposes only
// Log sets a logger on the scheme. For test purposes only
func
(
s
*
Scheme
)
Log
(
l
conversion
.
DebugLogger
)
{
func
(
s
*
Scheme
)
Log
(
l
conversion
.
DebugLogger
)
{
s
.
converter
.
Debug
=
l
s
.
converter
.
Debug
=
l
...
@@ -356,17 +347,6 @@ func (s *Scheme) AddConversionFuncs(conversionFuncs ...interface{}) error {
...
@@ -356,17 +347,6 @@ func (s *Scheme) AddConversionFuncs(conversionFuncs ...interface{}) error {
return
nil
return
nil
}
}
// AddGeneratedConversionFuncs registers conversion functions that were
// automatically generated.
func
(
s
*
Scheme
)
AddGeneratedConversionFuncs
(
conversionFuncs
...
interface
{})
error
{
for
_
,
f
:=
range
conversionFuncs
{
if
err
:=
s
.
converter
.
RegisterGeneratedConversionFunc
(
f
);
err
!=
nil
{
return
err
}
}
return
nil
}
// AddConversionFunc registers a function that converts between a and b by passing objects of those
// AddConversionFunc registers a function that converts between a and b by passing objects of those
// types to the provided function. The function *must* accept objects of a and b - this machinery will not enforce
// types to the provided function. The function *must* accept objects of a and b - this machinery will not enforce
// any other guarantee.
// any other guarantee.
...
...
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