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
3e4236d5
Commit
3e4236d5
authored
Mar 27, 2017
by
Maru Newby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fed: Add type adapter registration to simplify maintenance
parent
dee81ed5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
9 deletions
+43
-9
adapter.go
federation/pkg/typeadapters/adapter.go
+34
-2
secret.go
federation/pkg/typeadapters/secret.go
+8
-6
secret.go
test/integration/federation/framework/secret.go
+1
-1
No files found.
federation/pkg/typeadapters/adapter.go
View file @
3e4236d5
...
@@ -17,6 +17,8 @@ limitations under the License.
...
@@ -17,6 +17,8 @@ limitations under the License.
package
typeadapters
package
typeadapters
import
(
import
(
"fmt"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
pkgruntime
"k8s.io/apimachinery/pkg/runtime"
pkgruntime
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
...
@@ -29,8 +31,6 @@ import (
...
@@ -29,8 +31,6 @@ import (
// federated type. Code written to this interface can then target any
// federated type. Code written to this interface can then target any
// type for which an implementation of this interface exists.
// type for which an implementation of this interface exists.
type
FederatedTypeAdapter
interface
{
type
FederatedTypeAdapter
interface
{
SetClient
(
client
federationclientset
.
Interface
)
Kind
()
string
Kind
()
string
ObjectType
()
pkgruntime
.
Object
ObjectType
()
pkgruntime
.
Object
IsExpectedType
(
obj
interface
{})
bool
IsExpectedType
(
obj
interface
{})
bool
...
@@ -57,3 +57,35 @@ type FederatedTypeAdapter interface {
...
@@ -57,3 +57,35 @@ type FederatedTypeAdapter interface {
NewTestObject
(
namespace
string
)
pkgruntime
.
Object
NewTestObject
(
namespace
string
)
pkgruntime
.
Object
}
}
// AdapterFactory defines the function signature for factory methods
// that create FederatedTypeAdapters. Such methods should be
// registered with RegisterAdapterFactory to ensure the type adapter
// is discoverable.
type
AdapterFactory
func
(
client
federationclientset
.
Interface
)
FederatedTypeAdapter
var
typeAdapterRegistry
=
make
(
map
[
string
]
AdapterFactory
)
// RegisterAdapterFactory ensures that the given kind and adapter
// factory will be returned in the results of the AdapterFactories
// method.
func
RegisterAdapterFactory
(
kind
string
,
factory
AdapterFactory
)
{
_
,
ok
:=
typeAdapterRegistry
[
kind
]
if
ok
{
// TODO Is panicking ok given that this is part of a type-registration mechanism
panic
(
fmt
.
Sprintf
(
"An adapter has already been registered for federated type %q"
,
kind
))
}
typeAdapterRegistry
[
kind
]
=
factory
}
// AdapterFactories returns a mapping of federated kind
// (e.g. "secret") to the factory method that will create an adapter
// for that type.
func
AdapterFactories
()
map
[
string
]
AdapterFactory
{
// Return a copy to avoid accidental mutation
result
:=
make
(
map
[
string
]
AdapterFactory
)
for
key
,
value
:=
range
typeAdapterRegistry
{
result
[
key
]
=
value
}
return
result
}
federation/pkg/typeadapters/secret.go
View file @
3e4236d5
...
@@ -27,20 +27,22 @@ import (
...
@@ -27,20 +27,22 @@ import (
kubeclientset
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
kubeclientset
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
)
)
const
secretKind
=
"secret"
func
init
()
{
RegisterAdapterFactory
(
secretKind
,
NewSecretAdapter
)
}
type
SecretAdapter
struct
{
type
SecretAdapter
struct
{
client
federationclientset
.
Interface
client
federationclientset
.
Interface
}
}
func
NewSecretAdapter
(
client
federationclientset
.
Interface
)
*
Secret
Adapter
{
func
NewSecretAdapter
(
client
federationclientset
.
Interface
)
FederatedType
Adapter
{
return
&
SecretAdapter
{
client
:
client
}
return
&
SecretAdapter
{
client
:
client
}
}
}
func
(
a
*
SecretAdapter
)
SetClient
(
client
federationclientset
.
Interface
)
{
a
.
client
=
client
}
func
(
a
*
SecretAdapter
)
Kind
()
string
{
func
(
a
*
SecretAdapter
)
Kind
()
string
{
return
"secret"
return
secretKind
}
}
func
(
a
*
SecretAdapter
)
ObjectType
()
pkgruntime
.
Object
{
func
(
a
*
SecretAdapter
)
ObjectType
()
pkgruntime
.
Object
{
...
...
test/integration/federation/framework/secret.go
View file @
3e4236d5
...
@@ -26,7 +26,7 @@ import (
...
@@ -26,7 +26,7 @@ import (
)
)
type
SecretFixture
struct
{
type
SecretFixture
struct
{
adapter
*
typeadapters
.
Secret
Adapter
adapter
typeadapters
.
FederatedType
Adapter
stopChan
chan
struct
{}
stopChan
chan
struct
{}
}
}
...
...
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