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
cd2de7d4
Commit
cd2de7d4
authored
Apr 10, 2016
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #23741 from wojtek-t/conversions_with_framework_5
Small improvements in conversion generator
parents
6d954a14
49d3c396
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
36 additions
and
45 deletions
+36
-45
main.go
cmd/libs/go2idl/conversion-gen/main.go
+1
-0
conversion.go
pkg/api/conversion.go
+11
-11
conversion_generated.go
pkg/api/v1/conversion_generated.go
+6
-16
conversion_generated.go
pkg/apis/componentconfig/v1alpha1/conversion_generated.go
+4
-4
conversion_generated.go
pkg/apis/extensions/v1beta1/conversion_generated.go
+2
-2
converter.go
pkg/conversion/converter.go
+3
-3
conversion.go
pkg/runtime/conversion.go
+9
-9
No files found.
cmd/libs/go2idl/conversion-gen/main.go
View file @
cd2de7d4
...
...
@@ -35,6 +35,7 @@ func main() {
arguments
.
InputDirs
=
[]
string
{
"k8s.io/kubernetes/pkg/api/v1"
,
"k8s.io/kubernetes/pkg/api"
,
"k8s.io/kubernetes/pkg/conversion"
,
"k8s.io/kubernetes/pkg/runtime"
,
}
...
...
pkg/api/conversion.go
View file @
cd2de7d4
...
...
@@ -41,20 +41,20 @@ func init() {
Convert_unversioned_ListMeta_To_unversioned_ListMeta
,
Convert_intstr_IntOrString_To_intstr_IntOrString
,
Convert_unversioned_Time_To_unversioned_Time
,
Convert_
string_slice
_To_unversioned_Time
,
Convert_
Slice_string
_To_unversioned_Time
,
Convert_string_To_labels_Selector
,
Convert_string_To_fields_Selector
,
Convert_
bool_ref
_To_bool
,
Convert_bool_To_
bool_ref
,
Convert_
string_ref
_To_string
,
Convert_string_To_
string_ref
,
Convert_
Pointer_bool
_To_bool
,
Convert_bool_To_
Pointer_bool
,
Convert_
Pointer_string
_To_string
,
Convert_string_To_
Pointer_string
,
Convert_labels_Selector_To_string
,
Convert_fields_Selector_To_string
,
Convert_resource_Quantity_To_resource_Quantity
,
)
}
func
Convert_
string_ref
_To_string
(
in
**
string
,
out
*
string
,
s
conversion
.
Scope
)
error
{
func
Convert_
Pointer_string
_To_string
(
in
**
string
,
out
*
string
,
s
conversion
.
Scope
)
error
{
if
*
in
==
nil
{
*
out
=
""
return
nil
...
...
@@ -63,7 +63,7 @@ func Convert_string_ref_To_string(in **string, out *string, s conversion.Scope)
return
nil
}
func
Convert_string_To_
string_ref
(
in
*
string
,
out
**
string
,
s
conversion
.
Scope
)
error
{
func
Convert_string_To_
Pointer_string
(
in
*
string
,
out
**
string
,
s
conversion
.
Scope
)
error
{
if
in
==
nil
{
stringVar
:=
""
*
out
=
&
stringVar
...
...
@@ -73,7 +73,7 @@ func Convert_string_To_string_ref(in *string, out **string, s conversion.Scope)
return
nil
}
func
Convert_
bool_ref
_To_bool
(
in
**
bool
,
out
*
bool
,
s
conversion
.
Scope
)
error
{
func
Convert_
Pointer_bool
_To_bool
(
in
**
bool
,
out
*
bool
,
s
conversion
.
Scope
)
error
{
if
*
in
==
nil
{
*
out
=
false
return
nil
...
...
@@ -82,7 +82,7 @@ func Convert_bool_ref_To_bool(in **bool, out *bool, s conversion.Scope) error {
return
nil
}
func
Convert_bool_To_
bool_ref
(
in
*
bool
,
out
**
bool
,
s
conversion
.
Scope
)
error
{
func
Convert_bool_To_
Pointer_bool
(
in
*
bool
,
out
**
bool
,
s
conversion
.
Scope
)
error
{
if
in
==
nil
{
boolVar
:=
false
*
out
=
&
boolVar
...
...
@@ -118,8 +118,8 @@ func Convert_unversioned_Time_To_unversioned_Time(in *unversioned.Time, out *unv
return
nil
}
// Convert_
string_slice
_To_unversioned_Time allows converting a URL query parameter value
func
Convert_
string_slice
_To_unversioned_Time
(
input
*
[]
string
,
out
*
unversioned
.
Time
,
s
conversion
.
Scope
)
error
{
// Convert_
Slice_string
_To_unversioned_Time allows converting a URL query parameter value
func
Convert_
Slice_string
_To_unversioned_Time
(
input
*
[]
string
,
out
*
unversioned
.
Time
,
s
conversion
.
Scope
)
error
{
str
:=
""
if
len
(
*
input
)
>
0
{
str
=
(
*
input
)[
0
]
...
...
pkg/api/v1/conversion_generated.go
View file @
cd2de7d4
...
...
@@ -5805,12 +5805,8 @@ func autoConvert_v1_RangeAllocation_To_api_RangeAllocation(in *RangeAllocation,
return
err
}
out
.
Range
=
in
.
Range
if
in
.
Data
!=
nil
{
in
,
out
:=
&
in
.
Data
,
&
out
.
Data
*
out
=
make
([]
byte
,
len
(
*
in
))
copy
(
*
out
,
*
in
)
}
else
{
out
.
Data
=
nil
if
err
:=
conversion
.
Convert_Slice_byte_To_Slice_byte
(
&
in
.
Data
,
&
out
.
Data
,
s
);
err
!=
nil
{
return
err
}
return
nil
}
...
...
@@ -5830,12 +5826,8 @@ func autoConvert_api_RangeAllocation_To_v1_RangeAllocation(in *api.RangeAllocati
return
err
}
out
.
Range
=
in
.
Range
if
in
.
Data
!=
nil
{
in
,
out
:=
&
in
.
Data
,
&
out
.
Data
*
out
=
make
([]
byte
,
len
(
*
in
))
copy
(
*
out
,
*
in
)
}
else
{
out
.
Data
=
nil
if
err
:=
conversion
.
Convert_Slice_byte_To_Slice_byte
(
&
in
.
Data
,
&
out
.
Data
,
s
);
err
!=
nil
{
return
err
}
return
nil
}
...
...
@@ -6285,8 +6277,7 @@ func autoConvert_v1_Secret_To_api_Secret(in *Secret, out *api.Secret, s conversi
*
out
=
make
(
map
[
string
][]
byte
,
len
(
*
in
))
for
key
,
val
:=
range
*
in
{
newVal
:=
new
([]
byte
)
// TODO: Inefficient conversion - can we improve it?
if
err
:=
s
.
Convert
(
&
val
,
newVal
,
0
);
err
!=
nil
{
if
err
:=
conversion
.
Convert_Slice_byte_To_Slice_byte
(
&
val
,
newVal
,
s
);
err
!=
nil
{
return
err
}
(
*
out
)[
key
]
=
*
newVal
...
...
@@ -6317,8 +6308,7 @@ func autoConvert_api_Secret_To_v1_Secret(in *api.Secret, out *Secret, s conversi
*
out
=
make
(
map
[
string
][]
byte
,
len
(
*
in
))
for
key
,
val
:=
range
*
in
{
newVal
:=
new
([]
byte
)
// TODO: Inefficient conversion - can we improve it?
if
err
:=
s
.
Convert
(
&
val
,
newVal
,
0
);
err
!=
nil
{
if
err
:=
conversion
.
Convert_Slice_byte_To_Slice_byte
(
&
val
,
newVal
,
s
);
err
!=
nil
{
return
err
}
(
*
out
)[
key
]
=
*
newVal
...
...
pkg/apis/componentconfig/v1alpha1/conversion_generated.go
View file @
cd2de7d4
...
...
@@ -83,7 +83,7 @@ func autoConvert_componentconfig_KubeSchedulerConfiguration_To_v1alpha1_KubeSche
out
.
Address
=
in
.
Address
out
.
AlgorithmProvider
=
in
.
AlgorithmProvider
out
.
PolicyConfigFile
=
in
.
PolicyConfigFile
if
err
:=
api
.
Convert_bool_To_
bool_ref
(
&
in
.
EnableProfiling
,
&
out
.
EnableProfiling
,
s
);
err
!=
nil
{
if
err
:=
api
.
Convert_bool_To_
Pointer_bool
(
&
in
.
EnableProfiling
,
&
out
.
EnableProfiling
,
s
);
err
!=
nil
{
return
err
}
out
.
KubeAPIQPS
=
in
.
KubeAPIQPS
...
...
@@ -103,7 +103,7 @@ func autoConvert_componentconfig_LeaderElectionConfiguration_To_v1alpha1_LeaderE
if
defaulting
,
found
:=
s
.
DefaultingInterface
(
reflect
.
TypeOf
(
*
in
));
found
{
defaulting
.
(
func
(
*
componentconfig
.
LeaderElectionConfiguration
))(
in
)
}
if
err
:=
api
.
Convert_bool_To_
bool_ref
(
&
in
.
LeaderElect
,
&
out
.
LeaderElect
,
s
);
err
!=
nil
{
if
err
:=
api
.
Convert_bool_To_
Pointer_bool
(
&
in
.
LeaderElect
,
&
out
.
LeaderElect
,
s
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
LeaseDuration
,
&
out
.
LeaseDuration
,
0
);
err
!=
nil
{
...
...
@@ -179,7 +179,7 @@ func autoConvert_v1alpha1_KubeSchedulerConfiguration_To_componentconfig_KubeSche
out
.
Address
=
in
.
Address
out
.
AlgorithmProvider
=
in
.
AlgorithmProvider
out
.
PolicyConfigFile
=
in
.
PolicyConfigFile
if
err
:=
api
.
Convert_
bool_ref
_To_bool
(
&
in
.
EnableProfiling
,
&
out
.
EnableProfiling
,
s
);
err
!=
nil
{
if
err
:=
api
.
Convert_
Pointer_bool
_To_bool
(
&
in
.
EnableProfiling
,
&
out
.
EnableProfiling
,
s
);
err
!=
nil
{
return
err
}
out
.
KubeAPIQPS
=
in
.
KubeAPIQPS
...
...
@@ -199,7 +199,7 @@ func autoConvert_v1alpha1_LeaderElectionConfiguration_To_componentconfig_LeaderE
if
defaulting
,
found
:=
s
.
DefaultingInterface
(
reflect
.
TypeOf
(
*
in
));
found
{
defaulting
.
(
func
(
*
LeaderElectionConfiguration
))(
in
)
}
if
err
:=
api
.
Convert_
bool_ref
_To_bool
(
&
in
.
LeaderElect
,
&
out
.
LeaderElect
,
s
);
err
!=
nil
{
if
err
:=
api
.
Convert_
Pointer_bool
_To_bool
(
&
in
.
LeaderElect
,
&
out
.
LeaderElect
,
s
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
LeaseDuration
,
&
out
.
LeaseDuration
,
0
);
err
!=
nil
{
...
...
pkg/apis/extensions/v1beta1/conversion_generated.go
View file @
cd2de7d4
...
...
@@ -3797,7 +3797,7 @@ func autoConvert_extensions_ThirdPartyResourceData_To_v1beta1_ThirdPartyResource
if
err
:=
Convert_api_ObjectMeta_To_v1_ObjectMeta
(
&
in
.
ObjectMeta
,
&
out
.
ObjectMeta
,
s
);
err
!=
nil
{
return
err
}
if
err
:=
conversion
.
ByteSliceCopy
(
&
in
.
Data
,
&
out
.
Data
,
s
);
err
!=
nil
{
if
err
:=
conversion
.
Convert_Slice_byte_To_Slice_byte
(
&
in
.
Data
,
&
out
.
Data
,
s
);
err
!=
nil
{
return
err
}
return
nil
...
...
@@ -5037,7 +5037,7 @@ func autoConvert_v1beta1_ThirdPartyResourceData_To_extensions_ThirdPartyResource
if
err
:=
Convert_v1_ObjectMeta_To_api_ObjectMeta
(
&
in
.
ObjectMeta
,
&
out
.
ObjectMeta
,
s
);
err
!=
nil
{
return
err
}
if
err
:=
conversion
.
ByteSliceCopy
(
&
in
.
Data
,
&
out
.
Data
,
s
);
err
!=
nil
{
if
err
:=
conversion
.
Convert_Slice_byte_To_Slice_byte
(
&
in
.
Data
,
&
out
.
Data
,
s
);
err
!=
nil
{
return
err
}
return
nil
...
...
pkg/conversion/converter.go
View file @
cd2de7d4
...
...
@@ -95,7 +95,7 @@ func NewConverter(nameFn NameFunc) *Converter {
inputFieldMappingFuncs
:
make
(
map
[
reflect
.
Type
]
FieldMappingFunc
),
inputDefaultFlags
:
make
(
map
[
reflect
.
Type
]
FieldMatchingFlags
),
}
c
.
RegisterConversionFunc
(
ByteSliceCopy
)
c
.
RegisterConversionFunc
(
Convert_Slice_byte_To_Slice_byte
)
return
c
}
...
...
@@ -114,8 +114,8 @@ func (c *Converter) DefaultMeta(t reflect.Type) (FieldMatchingFlags, *Meta) {
}
}
//
ByteSliceCopy
prevents recursing into every byte
func
ByteSliceCopy
(
in
*
[]
byte
,
out
*
[]
byte
,
s
Scope
)
error
{
//
Convert_Slice_byte_To_Slice_byte
prevents recursing into every byte
func
Convert_Slice_byte_To_Slice_byte
(
in
*
[]
byte
,
out
*
[]
byte
,
s
Scope
)
error
{
*
out
=
make
([]
byte
,
len
(
*
in
))
copy
(
*
out
,
*
in
)
return
nil
...
...
pkg/runtime/conversion.go
View file @
cd2de7d4
...
...
@@ -40,13 +40,13 @@ func JSONKeyMapper(key string, sourceTag, destTag reflect.StructTag) (string, st
// DefaultStringConversions are helpers for converting []string and string to real values.
var
DefaultStringConversions
=
[]
interface
{}{
convertStringSliceToS
tring
,
convertStringSliceToI
nt
,
convertStringSliceToB
ool
,
convertStringSliceToI
nt64
,
Convert_Slice_string_To_s
tring
,
Convert_Slice_string_To_i
nt
,
Convert_Slice_string_To_b
ool
,
Convert_Slice_string_To_i
nt64
,
}
func
convertStringSliceToS
tring
(
input
*
[]
string
,
out
*
string
,
s
conversion
.
Scope
)
error
{
func
Convert_Slice_string_To_s
tring
(
input
*
[]
string
,
out
*
string
,
s
conversion
.
Scope
)
error
{
if
len
(
*
input
)
==
0
{
*
out
=
""
}
...
...
@@ -54,7 +54,7 @@ func convertStringSliceToString(input *[]string, out *string, s conversion.Scope
return
nil
}
func
convertStringSliceToI
nt
(
input
*
[]
string
,
out
*
int
,
s
conversion
.
Scope
)
error
{
func
Convert_Slice_string_To_i
nt
(
input
*
[]
string
,
out
*
int
,
s
conversion
.
Scope
)
error
{
if
len
(
*
input
)
==
0
{
*
out
=
0
}
...
...
@@ -67,10 +67,10 @@ func convertStringSliceToInt(input *[]string, out *int, s conversion.Scope) erro
return
nil
}
//
converStringSliceToB
ool will convert a string parameter to boolean.
//
Conver_Slice_string_To_b
ool will convert a string parameter to boolean.
// Only the absence of a value, a value of "false", or a value of "0" resolve to false.
// Any other value (including empty string) resolves to true.
func
convertStringSliceToB
ool
(
input
*
[]
string
,
out
*
bool
,
s
conversion
.
Scope
)
error
{
func
Convert_Slice_string_To_b
ool
(
input
*
[]
string
,
out
*
bool
,
s
conversion
.
Scope
)
error
{
if
len
(
*
input
)
==
0
{
*
out
=
false
return
nil
...
...
@@ -84,7 +84,7 @@ func convertStringSliceToBool(input *[]string, out *bool, s conversion.Scope) er
return
nil
}
func
convertStringSliceToI
nt64
(
input
*
[]
string
,
out
*
int64
,
s
conversion
.
Scope
)
error
{
func
Convert_Slice_string_To_i
nt64
(
input
*
[]
string
,
out
*
int64
,
s
conversion
.
Scope
)
error
{
if
len
(
*
input
)
==
0
{
*
out
=
0
}
...
...
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