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
608f4cde
Commit
608f4cde
authored
Aug 16, 2016
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor out InterfacesFor
parent
5981aa8b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
1 deletion
+76
-1
types.go
pkg/apimachinery/types.go
+33
-1
types_test.go
pkg/apimachinery/types_test.go
+43
-0
No files found.
pkg/apimachinery/types.go
View file @
608f4cde
...
@@ -17,6 +17,8 @@ limitations under the License.
...
@@ -17,6 +17,8 @@ limitations under the License.
package
apimachinery
package
apimachinery
import
(
import
(
"fmt"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
...
@@ -47,6 +49,36 @@ type GroupMeta struct {
...
@@ -47,6 +49,36 @@ type GroupMeta struct {
RESTMapper
meta
.
RESTMapper
RESTMapper
meta
.
RESTMapper
// InterfacesFor returns the default Codec and ResourceVersioner for a given version
// InterfacesFor returns the default Codec and ResourceVersioner for a given version
// or an error if the version is not known.
// string, or an error if the version is not known.
// TODO: make this stop being a func pointer and always use the default
// function provided below once every place that populates this field has been changed.
InterfacesFor
func
(
version
unversioned
.
GroupVersion
)
(
*
meta
.
VersionInterfaces
,
error
)
InterfacesFor
func
(
version
unversioned
.
GroupVersion
)
(
*
meta
.
VersionInterfaces
,
error
)
// InterfacesByVersion stores the per-version interfaces.
InterfacesByVersion
map
[
unversioned
.
GroupVersion
]
*
meta
.
VersionInterfaces
}
// InterfacesFor returns the default Codec and ResourceVersioner for a given version
// string, or an error if the version is not known.
// TODO: Remove the "Default" prefix.
func
(
gm
*
GroupMeta
)
DefaultInterfacesFor
(
version
unversioned
.
GroupVersion
)
(
*
meta
.
VersionInterfaces
,
error
)
{
if
v
,
ok
:=
gm
.
InterfacesByVersion
[
version
];
ok
{
return
v
,
nil
}
return
nil
,
fmt
.
Errorf
(
"unsupported storage version: %s (valid: %v)"
,
version
,
gm
.
GroupVersions
)
}
// Adds the given version to the group. Only call during init, after that
// GroupMeta objects should be immutable. Not thread safe.
// (If you use this, be sure to set .InterfacesFor = .DefaultInterfacesFor)
func
(
gm
*
GroupMeta
)
AddVersion
(
version
unversioned
.
GroupVersion
,
interfaces
*
meta
.
VersionInterfaces
)
error
{
if
e
,
a
:=
gm
.
GroupVersion
.
Group
,
version
.
Group
;
a
!=
e
{
return
fmt
.
Errorf
(
"got a version in group %v, but am in group %v"
,
a
,
e
)
}
if
gm
.
InterfacesByVersion
==
nil
{
gm
.
InterfacesByVersion
=
make
(
map
[
unversioned
.
GroupVersion
]
*
meta
.
VersionInterfaces
)
}
gm
.
InterfacesByVersion
[
version
]
=
interfaces
gm
.
GroupVersions
=
append
(
gm
.
GroupVersions
,
version
)
return
nil
}
}
pkg/apimachinery/types_test.go
0 → 100644
View file @
608f4cde
/*
Copyright 2016 The Kubernetes Authors 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
apimachinery
import
(
"testing"
"k8s.io/kubernetes/pkg/api/unversioned"
)
func
TestAdd
(
t
*
testing
.
T
)
{
gm
:=
GroupMeta
{
GroupVersion
:
unversioned
.
GroupVersion
{
Group
:
"test"
,
Version
:
"v1"
,
},
GroupVersions
:
[]
unversioned
.
GroupVersion
{{
"test"
,
"v1"
}},
}
gm
.
AddVersion
(
unversioned
.
GroupVersion
{
"test"
,
"v1"
},
nil
)
if
e
,
a
:=
1
,
len
(
gm
.
InterfacesByVersion
);
e
!=
a
{
t
.
Errorf
(
"expected %v, got %v"
)
}
// GroupVersions is unchanged
if
e
,
a
:=
1
,
len
(
gm
.
GroupVersions
);
e
!=
a
{
t
.
Errorf
(
"expected %v, got %v"
,
e
,
a
)
}
}
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