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
650aead4
Commit
650aead4
authored
Dec 07, 2014
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support Node/NodeList as a valid name in all versions
Also refactor v1beta1/conversion_test.go `v1beta` -> `current` to allow easier cut and paste of tests.
parent
5447e741
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
133 additions
and
28 deletions
+133
-28
register.go
pkg/api/register.go
+3
-0
conversion_test.go
pkg/api/v1beta1/conversion_test.go
+48
-25
register.go
pkg/api/v1beta1/register.go
+3
-0
conversion_test.go
pkg/api/v1beta2/conversion_test.go
+26
-3
register.go
pkg/api/v1beta2/register.go
+3
-0
conversion_test.go
pkg/api/v1beta3/conversion_test.go
+47
-0
register.go
pkg/api/v1beta3/register.go
+3
-0
No files found.
pkg/api/register.go
View file @
650aead4
...
...
@@ -46,6 +46,9 @@ func init() {
&
BoundPod
{},
&
BoundPods
{},
)
// Legacy names are supported
Scheme
.
AddKnownTypeWithName
(
""
,
"Node"
,
&
Minion
{})
Scheme
.
AddKnownTypeWithName
(
""
,
"NodeList"
,
&
MinionList
{})
}
func
(
*
Pod
)
IsAnAPIObject
()
{}
...
...
pkg/api/v1beta1/conversion_test.go
View file @
650aead4
...
...
@@ -21,13 +21,36 @@ import (
"testing"
newer
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
current
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
)
var
Convert
=
newer
.
Scheme
.
Convert
func
TestNodeConversion
(
t
*
testing
.
T
)
{
obj
,
err
:=
current
.
Codec
.
Decode
([]
byte
(
`{"kind":"Node","apiVersion":"v1beta1"}`
))
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
_
,
ok
:=
obj
.
(
*
newer
.
Minion
);
!
ok
{
t
.
Errorf
(
"unexpected type: %#v"
,
obj
)
}
obj
,
err
=
current
.
Codec
.
Decode
([]
byte
(
`{"kind":"NodeList","apiVersion":"v1beta1"}`
))
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
_
,
ok
:=
obj
.
(
*
newer
.
MinionList
);
!
ok
{
t
.
Errorf
(
"unexpected type: %#v"
,
obj
)
}
obj
=
&
newer
.
Node
{}
if
err
:=
current
.
Codec
.
DecodeInto
([]
byte
(
`{"kind":"Node","apiVersion":"v1beta1"}`
),
obj
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
func
TestEnvConversion
(
t
*
testing
.
T
)
{
nonCanonical
:=
[]
v1beta1
.
EnvVar
{
nonCanonical
:=
[]
current
.
EnvVar
{
{
Key
:
"EV"
},
{
Key
:
"EV"
,
Name
:
"EX"
},
}
...
...
@@ -48,7 +71,7 @@ func TestEnvConversion(t *testing.T) {
// Test conversion the other way, too.
for
i
:=
range
canonical
{
var
got
v1beta1
.
EnvVar
var
got
current
.
EnvVar
err
:=
Convert
(
&
canonical
[
i
],
&
got
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
...
...
@@ -65,15 +88,15 @@ func TestEnvConversion(t *testing.T) {
func
TestVolumeMountConversionToOld
(
t
*
testing
.
T
)
{
table
:=
[]
struct
{
in
newer
.
VolumeMount
out
v1beta1
.
VolumeMount
out
current
.
VolumeMount
}{
{
in
:
newer
.
VolumeMount
{
Name
:
"foo"
,
MountPath
:
"/dev/foo"
,
ReadOnly
:
true
},
out
:
v1beta1
.
VolumeMount
{
Name
:
"foo"
,
MountPath
:
"/dev/foo"
,
Path
:
"/dev/foo"
,
ReadOnly
:
true
},
out
:
current
.
VolumeMount
{
Name
:
"foo"
,
MountPath
:
"/dev/foo"
,
Path
:
"/dev/foo"
,
ReadOnly
:
true
},
},
}
for
_
,
item
:=
range
table
{
got
:=
v1beta1
.
VolumeMount
{}
got
:=
current
.
VolumeMount
{}
err
:=
Convert
(
&
item
.
in
,
&
got
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
...
...
@@ -87,17 +110,17 @@ func TestVolumeMountConversionToOld(t *testing.T) {
func
TestVolumeMountConversionToNew
(
t
*
testing
.
T
)
{
table
:=
[]
struct
{
in
v1beta1
.
VolumeMount
in
current
.
VolumeMount
out
newer
.
VolumeMount
}{
{
in
:
v1beta1
.
VolumeMount
{
Name
:
"foo"
,
MountPath
:
"/dev/foo"
,
ReadOnly
:
true
},
in
:
current
.
VolumeMount
{
Name
:
"foo"
,
MountPath
:
"/dev/foo"
,
ReadOnly
:
true
},
out
:
newer
.
VolumeMount
{
Name
:
"foo"
,
MountPath
:
"/dev/foo"
,
ReadOnly
:
true
},
},
{
in
:
v1beta1
.
VolumeMount
{
Name
:
"foo"
,
MountPath
:
"/dev/foo"
,
Path
:
"/dev/bar"
,
ReadOnly
:
true
},
in
:
current
.
VolumeMount
{
Name
:
"foo"
,
MountPath
:
"/dev/foo"
,
Path
:
"/dev/bar"
,
ReadOnly
:
true
},
out
:
newer
.
VolumeMount
{
Name
:
"foo"
,
MountPath
:
"/dev/foo"
,
ReadOnly
:
true
},
},
{
in
:
v1beta1
.
VolumeMount
{
Name
:
"foo"
,
Path
:
"/dev/bar"
,
ReadOnly
:
true
},
in
:
current
.
VolumeMount
{
Name
:
"foo"
,
Path
:
"/dev/bar"
,
ReadOnly
:
true
},
out
:
newer
.
VolumeMount
{
Name
:
"foo"
,
MountPath
:
"/dev/bar"
,
ReadOnly
:
true
},
},
}
...
...
@@ -115,13 +138,13 @@ func TestVolumeMountConversionToNew(t *testing.T) {
}
func
TestMinionListConversionToNew
(
t
*
testing
.
T
)
{
oldMinion
:=
func
(
id
string
)
v1beta1
.
Minion
{
return
v1beta1
.
Minion
{
TypeMeta
:
v1beta1
.
TypeMeta
{
ID
:
id
}}
oldMinion
:=
func
(
id
string
)
current
.
Minion
{
return
current
.
Minion
{
TypeMeta
:
current
.
TypeMeta
{
ID
:
id
}}
}
newMinion
:=
func
(
id
string
)
newer
.
Minion
{
return
newer
.
Minion
{
ObjectMeta
:
newer
.
ObjectMeta
{
Name
:
id
}}
}
oldMinions
:=
[]
v1beta1
.
Minion
{
oldMinions
:=
[]
current
.
Minion
{
oldMinion
(
"foo"
),
oldMinion
(
"bar"
),
}
...
...
@@ -131,19 +154,19 @@ func TestMinionListConversionToNew(t *testing.T) {
}
table
:=
[]
struct
{
oldML
*
v1beta1
.
MinionList
oldML
*
current
.
MinionList
newML
*
newer
.
MinionList
}{
{
oldML
:
&
v1beta1
.
MinionList
{
Items
:
oldMinions
},
oldML
:
&
current
.
MinionList
{
Items
:
oldMinions
},
newML
:
&
newer
.
MinionList
{
Items
:
newMinions
},
},
{
oldML
:
&
v1beta1
.
MinionList
{
Minions
:
oldMinions
},
oldML
:
&
current
.
MinionList
{
Minions
:
oldMinions
},
newML
:
&
newer
.
MinionList
{
Items
:
newMinions
},
},
{
oldML
:
&
v1beta1
.
MinionList
{
oldML
:
&
current
.
MinionList
{
Items
:
oldMinions
,
Minions
:
[]
v1beta1
.
Minion
{
oldMinion
(
"baz"
)},
Minions
:
[]
current
.
Minion
{
oldMinion
(
"baz"
)},
},
newML
:
&
newer
.
MinionList
{
Items
:
newMinions
},
},
...
...
@@ -162,13 +185,13 @@ func TestMinionListConversionToNew(t *testing.T) {
}
func
TestMinionListConversionToOld
(
t
*
testing
.
T
)
{
oldMinion
:=
func
(
id
string
)
v1beta1
.
Minion
{
return
v1beta1
.
Minion
{
TypeMeta
:
v1beta1
.
TypeMeta
{
ID
:
id
}}
oldMinion
:=
func
(
id
string
)
current
.
Minion
{
return
current
.
Minion
{
TypeMeta
:
current
.
TypeMeta
{
ID
:
id
}}
}
newMinion
:=
func
(
id
string
)
newer
.
Minion
{
return
newer
.
Minion
{
ObjectMeta
:
newer
.
ObjectMeta
{
Name
:
id
}}
}
oldMinions
:=
[]
v1beta1
.
Minion
{
oldMinions
:=
[]
current
.
Minion
{
oldMinion
(
"foo"
),
oldMinion
(
"bar"
),
}
...
...
@@ -178,12 +201,12 @@ func TestMinionListConversionToOld(t *testing.T) {
}
newML
:=
&
newer
.
MinionList
{
Items
:
newMinions
}
oldML
:=
&
v1beta1
.
MinionList
{
oldML
:=
&
current
.
MinionList
{
Items
:
oldMinions
,
Minions
:
oldMinions
,
}
got
:=
&
v1beta1
.
MinionList
{}
got
:=
&
current
.
MinionList
{}
err
:=
Convert
(
newML
,
got
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
...
...
@@ -195,7 +218,7 @@ func TestMinionListConversionToOld(t *testing.T) {
func
TestServiceEmptySelector
(
t
*
testing
.
T
)
{
// Nil map should be preserved
svc
:=
&
v1beta1
.
Service
{
Selector
:
nil
}
svc
:=
&
current
.
Service
{
Selector
:
nil
}
data
,
err
:=
newer
.
Scheme
.
EncodeToVersion
(
svc
,
"v1beta1"
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
...
...
@@ -210,7 +233,7 @@ func TestServiceEmptySelector(t *testing.T) {
}
// Empty map should be preserved
svc2
:=
&
v1beta1
.
Service
{
Selector
:
map
[
string
]
string
{}}
svc2
:=
&
current
.
Service
{
Selector
:
map
[
string
]
string
{}}
data
,
err
=
newer
.
Scheme
.
EncodeToVersion
(
svc2
,
"v1beta1"
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
...
...
pkg/api/v1beta1/register.go
View file @
650aead4
...
...
@@ -51,6 +51,9 @@ func init() {
&
BoundPod
{},
&
BoundPods
{},
)
// Future names are supported
api
.
Scheme
.
AddKnownTypeWithName
(
"v1beta1"
,
"Node"
,
&
Minion
{})
api
.
Scheme
.
AddKnownTypeWithName
(
"v1beta1"
,
"NodeList"
,
&
MinionList
{})
}
func
(
*
Pod
)
IsAnAPIObject
()
{}
...
...
pkg/api/v1beta2/conversion_test.go
View file @
650aead4
...
...
@@ -20,12 +20,12 @@ import (
"testing"
newer
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2
"
current
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1
"
)
func
TestServiceEmptySelector
(
t
*
testing
.
T
)
{
// Nil map should be preserved
svc
:=
&
v1beta2
.
Service
{
Selector
:
nil
}
svc
:=
&
current
.
Service
{
Selector
:
nil
}
data
,
err
:=
newer
.
Scheme
.
EncodeToVersion
(
svc
,
"v1beta2"
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
...
...
@@ -40,7 +40,7 @@ func TestServiceEmptySelector(t *testing.T) {
}
// Empty map should be preserved
svc2
:=
&
v1beta2
.
Service
{
Selector
:
map
[
string
]
string
{}}
svc2
:=
&
current
.
Service
{
Selector
:
map
[
string
]
string
{}}
data
,
err
=
newer
.
Scheme
.
EncodeToVersion
(
svc2
,
"v1beta2"
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
...
...
@@ -54,3 +54,26 @@ func TestServiceEmptySelector(t *testing.T) {
t
.
Errorf
(
"unexpected selector: %#v"
,
obj
)
}
}
func
TestNodeConversion
(
t
*
testing
.
T
)
{
obj
,
err
:=
current
.
Codec
.
Decode
([]
byte
(
`{"kind":"Node","apiVersion":"v1beta2"}`
))
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
_
,
ok
:=
obj
.
(
*
newer
.
Minion
);
!
ok
{
t
.
Errorf
(
"unexpected type: %#v"
,
obj
)
}
obj
,
err
=
current
.
Codec
.
Decode
([]
byte
(
`{"kind":"NodeList","apiVersion":"v1beta2"}`
))
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
_
,
ok
:=
obj
.
(
*
newer
.
MinionList
);
!
ok
{
t
.
Errorf
(
"unexpected type: %#v"
,
obj
)
}
obj
=
&
newer
.
Node
{}
if
err
:=
current
.
Codec
.
DecodeInto
([]
byte
(
`{"kind":"Node","apiVersion":"v1beta2"}`
),
obj
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
pkg/api/v1beta2/register.go
View file @
650aead4
...
...
@@ -51,6 +51,9 @@ func init() {
&
BoundPod
{},
&
BoundPods
{},
)
// Future names are supported
api
.
Scheme
.
AddKnownTypeWithName
(
"v1beta2"
,
"Node"
,
&
Minion
{})
api
.
Scheme
.
AddKnownTypeWithName
(
"v1beta2"
,
"NodeList"
,
&
MinionList
{})
}
func
(
*
Pod
)
IsAnAPIObject
()
{}
...
...
pkg/api/v1beta3/conversion_test.go
0 → 100644
View file @
650aead4
/*
Copyright 2014 Google Inc. All rights reserved.
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
v1beta3_test
import
(
"testing"
newer
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
current
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
)
func
TestNodeConversion
(
t
*
testing
.
T
)
{
obj
,
err
:=
current
.
Codec
.
Decode
([]
byte
(
`{"kind":"Minion","apiVersion":"v1beta3"}`
))
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
_
,
ok
:=
obj
.
(
*
newer
.
Minion
);
!
ok
{
t
.
Errorf
(
"unexpected type: %#v"
,
obj
)
}
obj
,
err
=
current
.
Codec
.
Decode
([]
byte
(
`{"kind":"MinionList","apiVersion":"v1beta3"}`
))
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
_
,
ok
:=
obj
.
(
*
newer
.
MinionList
);
!
ok
{
t
.
Errorf
(
"unexpected type: %#v"
,
obj
)
}
obj
=
&
newer
.
Node
{}
if
err
:=
current
.
Codec
.
DecodeInto
([]
byte
(
`{"kind":"Minion","apiVersion":"v1beta3"}`
),
obj
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
pkg/api/v1beta3/register.go
View file @
650aead4
...
...
@@ -47,6 +47,9 @@ func init() {
&
Event
{},
&
EventList
{},
)
// Legacy names are supported
api
.
Scheme
.
AddKnownTypeWithName
(
"v1beta3"
,
"Minion"
,
&
Node
{})
api
.
Scheme
.
AddKnownTypeWithName
(
"v1beta3"
,
"MinionList"
,
&
NodeList
{})
}
func
(
*
Pod
)
IsAnAPIObject
()
{}
...
...
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