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
7cc1855c
Commit
7cc1855c
authored
Jul 27, 2015
by
Marek Grabowski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11806 from wojtek-t/private_etcd_helper
Make EtcdHelper private - expose only StorageInterface
parents
00cd52dd
9d943df3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
56 changed files
with
401 additions
and
421 deletions
+401
-421
integration.go
cmd/integration/integration.go
+3
-3
server.go
cmd/kube-apiserver/app/server.go
+6
-6
kubernetes.go
cmd/kubernetes/kubernetes.go
+3
-3
authn.go
pkg/apiserver/authn.go
+4
-4
master.go
pkg/master/master.go
+25
-25
master_test.go
pkg/master/master_test.go
+1
-2
etcd.go
pkg/registry/controller/etcd/etcd.go
+2
-2
etcd_test.go
pkg/registry/controller/etcd/etcd_test.go
+5
-5
etcd.go
pkg/registry/endpoint/etcd/etcd.go
+2
-2
etcd_test.go
pkg/registry/endpoint/etcd/etcd_test.go
+5
-5
etcd.go
pkg/registry/etcd/etcd.go
+5
-5
etcd_test.go
pkg/registry/etcd/etcd_test.go
+6
-6
registry.go
pkg/registry/event/registry.go
+3
-3
registry_test.go
pkg/registry/event/registry_test.go
+2
-2
etcd.go
pkg/registry/generic/etcd/etcd.go
+17
-17
etcd_test.go
pkg/registry/generic/etcd/etcd_test.go
+2
-2
registry.go
pkg/registry/generic/registry.go
+1
-1
registry.go
pkg/registry/limitrange/registry.go
+3
-3
registry_test.go
pkg/registry/limitrange/registry_test.go
+2
-2
etcd.go
pkg/registry/minion/etcd/etcd.go
+2
-2
etcd_test.go
pkg/registry/minion/etcd/etcd_test.go
+5
-5
etcd.go
pkg/registry/namespace/etcd/etcd.go
+2
-2
etcd_test.go
pkg/registry/namespace/etcd/etcd_test.go
+26
-26
etcd.go
pkg/registry/persistentvolume/etcd/etcd.go
+2
-2
etcd_test.go
pkg/registry/persistentvolume/etcd/etcd_test.go
+6
-6
etcd.go
pkg/registry/persistentvolumeclaim/etcd/etcd.go
+2
-2
etcd_test.go
pkg/registry/persistentvolumeclaim/etcd/etcd_test.go
+6
-6
etcd.go
pkg/registry/pod/etcd/etcd.go
+3
-3
etcd_test.go
pkg/registry/pod/etcd/etcd_test.go
+43
-42
etcd.go
pkg/registry/podtemplate/etcd/etcd.go
+2
-2
etcd_test.go
pkg/registry/podtemplate/etcd/etcd_test.go
+7
-7
etcd.go
pkg/registry/resourcequota/etcd/etcd.go
+2
-2
etcd_test.go
pkg/registry/resourcequota/etcd/etcd_test.go
+28
-27
etcd.go
pkg/registry/secret/etcd/etcd.go
+3
-4
etcd_test.go
pkg/registry/secret/etcd/etcd_test.go
+7
-7
etcd.go
pkg/registry/service/allocator/etcd/etcd.go
+9
-9
etcd_test.go
pkg/registry/service/allocator/etcd/etcd_test.go
+7
-7
etcd_test.go
pkg/registry/service/ipallocator/etcd/etcd_test.go
+5
-5
etcd.go
pkg/registry/serviceaccount/etcd/etcd.go
+2
-2
etcd_test.go
pkg/registry/serviceaccount/etcd/etcd_test.go
+7
-7
tokengetter.go
pkg/serviceaccount/tokengetter.go
+5
-5
etcd_helper.go
pkg/tools/etcd_helper.go
+0
-0
etcd_helper_test.go
pkg/tools/etcd_helper_test.go
+24
-20
etcd_helper_watch.go
pkg/tools/etcd_helper_watch.go
+8
-31
etcd_helper_watch_test.go
pkg/tools/etcd_helper_watch_test.go
+9
-9
etcd_object.go
pkg/tools/etcd_object.go
+5
-5
interfaces.go
pkg/tools/interfaces.go
+10
-2
auth_test.go
test/integration/auth_test.go
+16
-16
etcd_tools_test.go
test/integration/etcd_tools_test.go
+25
-34
etcd_utils.go
test/integration/framework/etcd_utils.go
+2
-2
master_utils.go
test/integration/framework/master_utils.go
+14
-14
master_benchmark_test.go
test/integration/master_benchmark_test.go
+1
-1
scheduler_test.go
test/integration/scheduler_test.go
+3
-3
secret_test.go
test/integration/secret_test.go
+2
-2
service_account_test.go
test/integration/service_account_test.go
+2
-2
utils.go
test/integration/utils.go
+2
-2
No files found.
cmd/integration/integration.go
View file @
7cc1855c
...
@@ -132,9 +132,9 @@ func startComponents(firstManifestURL, secondManifestURL, apiVersion string) (st
...
@@ -132,9 +132,9 @@ func startComponents(firstManifestURL, secondManifestURL, apiVersion string) (st
cl
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
apiServer
.
URL
,
Version
:
apiVersion
})
cl
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
apiServer
.
URL
,
Version
:
apiVersion
})
helper
,
err
:=
master
.
NewEtcdHelper
(
etcdClient
,
""
,
etcdtest
.
PathPrefix
())
etcdStorage
,
err
:=
master
.
NewEtcdStorage
(
etcdClient
,
""
,
etcdtest
.
PathPrefix
())
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"Unable to get etcd
helper
: %v"
,
err
)
glog
.
Fatalf
(
"Unable to get etcd
storage
: %v"
,
err
)
}
}
// Master
// Master
...
@@ -154,7 +154,7 @@ func startComponents(firstManifestURL, secondManifestURL, apiVersion string) (st
...
@@ -154,7 +154,7 @@ func startComponents(firstManifestURL, secondManifestURL, apiVersion string) (st
// Create a master and install handlers into mux.
// Create a master and install handlers into mux.
m
:=
master
.
New
(
&
master
.
Config
{
m
:=
master
.
New
(
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
KubeletClient
:
fakeKubeletClient
{},
KubeletClient
:
fakeKubeletClient
{},
EnableCoreControllers
:
true
,
EnableCoreControllers
:
true
,
EnableLogsSupport
:
false
,
EnableLogsSupport
:
false
,
...
...
cmd/kube-apiserver/app/server.go
View file @
7cc1855c
...
@@ -214,12 +214,12 @@ func (s *APIServer) verifyClusterIPFlags() {
...
@@ -214,12 +214,12 @@ func (s *APIServer) verifyClusterIPFlags() {
}
}
}
}
func
newEtcd
(
etcdConfigFile
string
,
etcdServerList
util
.
StringList
,
storageVersion
string
,
pathPrefix
string
)
(
helper
tools
.
EtcdHelper
,
err
error
)
{
func
newEtcd
(
etcdConfigFile
string
,
etcdServerList
util
.
StringList
,
storageVersion
string
,
pathPrefix
string
)
(
etcdStorage
tools
.
StorageInterface
,
err
error
)
{
var
client
tools
.
EtcdClient
var
client
tools
.
EtcdClient
if
etcdConfigFile
!=
""
{
if
etcdConfigFile
!=
""
{
client
,
err
=
etcd
.
NewClientFromFile
(
etcdConfigFile
)
client
,
err
=
etcd
.
NewClientFromFile
(
etcdConfigFile
)
if
err
!=
nil
{
if
err
!=
nil
{
return
helper
,
err
return
nil
,
err
}
}
}
else
{
}
else
{
etcdClient
:=
etcd
.
NewClient
(
etcdServerList
)
etcdClient
:=
etcd
.
NewClient
(
etcdServerList
)
...
@@ -234,7 +234,7 @@ func newEtcd(etcdConfigFile string, etcdServerList util.StringList, storageVersi
...
@@ -234,7 +234,7 @@ func newEtcd(etcdConfigFile string, etcdServerList util.StringList, storageVersi
client
=
etcdClient
client
=
etcdClient
}
}
return
master
.
NewEtcd
Helper
(
client
,
storageVersion
,
pathPrefix
)
return
master
.
NewEtcd
Storage
(
client
,
storageVersion
,
pathPrefix
)
}
}
// Run runs the specified APIServer. This should never exit.
// Run runs the specified APIServer. This should never exit.
...
@@ -298,7 +298,7 @@ func (s *APIServer) Run(_ []string) error {
...
@@ -298,7 +298,7 @@ func (s *APIServer) Run(_ []string) error {
glog
.
Fatalf
(
"Invalid server address: %v"
,
err
)
glog
.
Fatalf
(
"Invalid server address: %v"
,
err
)
}
}
helper
,
err
:=
newEtcd
(
s
.
EtcdConfigFile
,
s
.
EtcdServerList
,
s
.
StorageVersion
,
s
.
EtcdPathPrefix
)
etcdStorage
,
err
:=
newEtcd
(
s
.
EtcdConfigFile
,
s
.
EtcdServerList
,
s
.
StorageVersion
,
s
.
EtcdPathPrefix
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"Invalid storage version or misconfigured etcd: %v"
,
err
)
glog
.
Fatalf
(
"Invalid storage version or misconfigured etcd: %v"
,
err
)
}
}
...
@@ -313,7 +313,7 @@ func (s *APIServer) Run(_ []string) error {
...
@@ -313,7 +313,7 @@ func (s *APIServer) Run(_ []string) error {
glog
.
Warning
(
"no RSA key provided, service account token authentication disabled"
)
glog
.
Warning
(
"no RSA key provided, service account token authentication disabled"
)
}
}
}
}
authenticator
,
err
:=
apiserver
.
NewAuthenticator
(
s
.
BasicAuthFile
,
s
.
ClientCAFile
,
s
.
TokenAuthFile
,
s
.
ServiceAccountKeyFile
,
s
.
ServiceAccountLookup
,
helper
)
authenticator
,
err
:=
apiserver
.
NewAuthenticator
(
s
.
BasicAuthFile
,
s
.
ClientCAFile
,
s
.
TokenAuthFile
,
s
.
ServiceAccountKeyFile
,
s
.
ServiceAccountLookup
,
etcdStorage
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"Invalid Authentication Config: %v"
,
err
)
glog
.
Fatalf
(
"Invalid Authentication Config: %v"
,
err
)
}
}
...
@@ -356,7 +356,7 @@ func (s *APIServer) Run(_ []string) error {
...
@@ -356,7 +356,7 @@ func (s *APIServer) Run(_ []string) error {
}
}
}
}
config
:=
&
master
.
Config
{
config
:=
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
EventTTL
:
s
.
EventTTL
,
EventTTL
:
s
.
EventTTL
,
KubeletClient
:
kubeletClient
,
KubeletClient
:
kubeletClient
,
ServiceClusterIPRange
:
&
n
,
ServiceClusterIPRange
:
&
n
,
...
...
cmd/kubernetes/kubernetes.go
View file @
7cc1855c
...
@@ -78,14 +78,14 @@ func (h *delegateHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
...
@@ -78,14 +78,14 @@ func (h *delegateHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
func
runApiServer
(
etcdClient
tools
.
EtcdClient
,
addr
net
.
IP
,
port
int
,
masterServiceNamespace
string
)
{
func
runApiServer
(
etcdClient
tools
.
EtcdClient
,
addr
net
.
IP
,
port
int
,
masterServiceNamespace
string
)
{
handler
:=
delegateHandler
{}
handler
:=
delegateHandler
{}
helper
,
err
:=
master
.
NewEtcdHelper
(
etcdClient
,
""
,
master
.
DefaultEtcdPathPrefix
)
etcdStorage
,
err
:=
master
.
NewEtcdStorage
(
etcdClient
,
""
,
master
.
DefaultEtcdPathPrefix
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"Unable to get etcd
helper
: %v"
,
err
)
glog
.
Fatalf
(
"Unable to get etcd
storage
: %v"
,
err
)
}
}
// Create a master and install handlers into mux.
// Create a master and install handlers into mux.
m
:=
master
.
New
(
&
master
.
Config
{
m
:=
master
.
New
(
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
KubeletClient
:
&
client
.
HTTPKubeletClient
{
KubeletClient
:
&
client
.
HTTPKubeletClient
{
Client
:
http
.
DefaultClient
,
Client
:
http
.
DefaultClient
,
Config
:
&
client
.
KubeletConfig
{
Port
:
10250
},
Config
:
&
client
.
KubeletConfig
{
Port
:
10250
},
...
...
pkg/apiserver/authn.go
View file @
7cc1855c
...
@@ -32,7 +32,7 @@ import (
...
@@ -32,7 +32,7 @@ import (
)
)
// NewAuthenticator returns an authenticator.Request or an error
// NewAuthenticator returns an authenticator.Request or an error
func
NewAuthenticator
(
basicAuthFile
,
clientCAFile
,
tokenFile
,
serviceAccountKeyFile
string
,
serviceAccountLookup
bool
,
helper
tools
.
EtcdHelper
)
(
authenticator
.
Request
,
error
)
{
func
NewAuthenticator
(
basicAuthFile
,
clientCAFile
,
tokenFile
,
serviceAccountKeyFile
string
,
serviceAccountLookup
bool
,
storage
tools
.
StorageInterface
)
(
authenticator
.
Request
,
error
)
{
var
authenticators
[]
authenticator
.
Request
var
authenticators
[]
authenticator
.
Request
if
len
(
basicAuthFile
)
>
0
{
if
len
(
basicAuthFile
)
>
0
{
...
@@ -60,7 +60,7 @@ func NewAuthenticator(basicAuthFile, clientCAFile, tokenFile, serviceAccountKeyF
...
@@ -60,7 +60,7 @@ func NewAuthenticator(basicAuthFile, clientCAFile, tokenFile, serviceAccountKeyF
}
}
if
len
(
serviceAccountKeyFile
)
>
0
{
if
len
(
serviceAccountKeyFile
)
>
0
{
serviceAccountAuth
,
err
:=
newServiceAccountAuthenticator
(
serviceAccountKeyFile
,
serviceAccountLookup
,
helper
)
serviceAccountAuth
,
err
:=
newServiceAccountAuthenticator
(
serviceAccountKeyFile
,
serviceAccountLookup
,
storage
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -104,7 +104,7 @@ func newAuthenticatorFromTokenFile(tokenAuthFile string) (authenticator.Request,
...
@@ -104,7 +104,7 @@ func newAuthenticatorFromTokenFile(tokenAuthFile string) (authenticator.Request,
}
}
// newServiceAccountAuthenticator returns an authenticator.Request or an error
// newServiceAccountAuthenticator returns an authenticator.Request or an error
func
newServiceAccountAuthenticator
(
keyfile
string
,
lookup
bool
,
helper
tools
.
EtcdHelper
)
(
authenticator
.
Request
,
error
)
{
func
newServiceAccountAuthenticator
(
keyfile
string
,
lookup
bool
,
storage
tools
.
StorageInterface
)
(
authenticator
.
Request
,
error
)
{
publicKey
,
err
:=
serviceaccount
.
ReadPublicKey
(
keyfile
)
publicKey
,
err
:=
serviceaccount
.
ReadPublicKey
(
keyfile
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -114,7 +114,7 @@ func newServiceAccountAuthenticator(keyfile string, lookup bool, helper tools.Et
...
@@ -114,7 +114,7 @@ func newServiceAccountAuthenticator(keyfile string, lookup bool, helper tools.Et
if
lookup
{
if
lookup
{
// If we need to look up service accounts and tokens,
// If we need to look up service accounts and tokens,
// go directly to etcd to avoid recursive auth insanity
// go directly to etcd to avoid recursive auth insanity
serviceAccountGetter
=
serviceaccount
.
NewGetterFrom
EtcdHelper
(
helper
)
serviceAccountGetter
=
serviceaccount
.
NewGetterFrom
StorageInterface
(
storage
)
}
}
tokenAuthenticator
:=
serviceaccount
.
JWTTokenAuthenticator
([]
*
rsa
.
PublicKey
{
publicKey
},
lookup
,
serviceAccountGetter
)
tokenAuthenticator
:=
serviceaccount
.
JWTTokenAuthenticator
([]
*
rsa
.
PublicKey
{
publicKey
},
lookup
,
serviceAccountGetter
)
...
...
pkg/master/master.go
View file @
7cc1855c
...
@@ -87,10 +87,10 @@ const (
...
@@ -87,10 +87,10 @@ const (
// Config is a structure used to configure a Master.
// Config is a structure used to configure a Master.
type
Config
struct
{
type
Config
struct
{
EtcdHelper
tools
.
EtcdHelper
DatabaseStorage
tools
.
StorageInterface
EventTTL
time
.
Duration
EventTTL
time
.
Duration
MinionRegexp
string
MinionRegexp
string
KubeletClient
client
.
KubeletClient
KubeletClient
client
.
KubeletClient
// allow downstream consumers to disable the core controller loops
// allow downstream consumers to disable the core controller loops
EnableCoreControllers
bool
EnableCoreControllers
bool
EnableLogsSupport
bool
EnableLogsSupport
bool
...
@@ -223,17 +223,17 @@ type Master struct {
...
@@ -223,17 +223,17 @@ type Master struct {
clock
util
.
Clock
clock
util
.
Clock
}
}
// NewEtcd
Helper returns an EtcdHelper
for the provided arguments or an error if the version
// NewEtcd
Storage returns a StorageInterface
for the provided arguments or an error if the version
// is incorrect.
// is incorrect.
func
NewEtcd
Helper
(
client
tools
.
EtcdClient
,
version
string
,
prefix
string
)
(
helper
tools
.
EtcdHelper
,
err
error
)
{
func
NewEtcd
Storage
(
client
tools
.
EtcdClient
,
version
string
,
prefix
string
)
(
etcdStorage
tools
.
StorageInterface
,
err
error
)
{
if
version
==
""
{
if
version
==
""
{
version
=
latest
.
Version
version
=
latest
.
Version
}
}
versionInterfaces
,
err
:=
latest
.
InterfacesFor
(
version
)
versionInterfaces
,
err
:=
latest
.
InterfacesFor
(
version
)
if
err
!=
nil
{
if
err
!=
nil
{
return
helper
,
err
return
etcdStorage
,
err
}
}
return
tools
.
NewEtcd
Helper
(
client
,
versionInterfaces
.
Codec
,
prefix
),
nil
return
tools
.
NewEtcd
Storage
(
client
,
versionInterfaces
.
Codec
,
prefix
),
nil
}
}
// setDefaults fills in any fields not set that are required to have valid data.
// setDefaults fills in any fields not set that are required to have valid data.
...
@@ -420,37 +420,37 @@ func logStackOnRecover(panicReason interface{}, httpWriter http.ResponseWriter)
...
@@ -420,37 +420,37 @@ func logStackOnRecover(panicReason interface{}, httpWriter http.ResponseWriter)
func
(
m
*
Master
)
init
(
c
*
Config
)
{
func
(
m
*
Master
)
init
(
c
*
Config
)
{
healthzChecks
:=
[]
healthz
.
HealthzChecker
{}
healthzChecks
:=
[]
healthz
.
HealthzChecker
{}
m
.
clock
=
util
.
RealClock
{}
m
.
clock
=
util
.
RealClock
{}
podStorage
:=
podetcd
.
NewStorage
(
c
.
EtcdHelper
,
c
.
KubeletClient
)
podStorage
:=
podetcd
.
NewStorage
(
c
.
DatabaseStorage
,
c
.
KubeletClient
)
podRegistry
:=
pod
.
NewRegistry
(
podStorage
.
Pod
)
podRegistry
:=
pod
.
NewRegistry
(
podStorage
.
Pod
)
podTemplateStorage
:=
podtemplateetcd
.
NewREST
(
c
.
EtcdHelper
)
podTemplateStorage
:=
podtemplateetcd
.
NewREST
(
c
.
DatabaseStorage
)
eventRegistry
:=
event
.
NewEtcdRegistry
(
c
.
EtcdHelper
,
uint64
(
c
.
EventTTL
.
Seconds
()))
eventRegistry
:=
event
.
NewEtcdRegistry
(
c
.
DatabaseStorage
,
uint64
(
c
.
EventTTL
.
Seconds
()))
limitRangeRegistry
:=
limitrange
.
NewEtcdRegistry
(
c
.
EtcdHelper
)
limitRangeRegistry
:=
limitrange
.
NewEtcdRegistry
(
c
.
DatabaseStorage
)
resourceQuotaStorage
,
resourceQuotaStatusStorage
:=
resourcequotaetcd
.
NewStorage
(
c
.
EtcdHelper
)
resourceQuotaStorage
,
resourceQuotaStatusStorage
:=
resourcequotaetcd
.
NewStorage
(
c
.
DatabaseStorage
)
secretStorage
:=
secretetcd
.
NewStorage
(
c
.
EtcdHelper
)
secretStorage
:=
secretetcd
.
NewStorage
(
c
.
DatabaseStorage
)
serviceAccountStorage
:=
serviceaccountetcd
.
NewStorage
(
c
.
EtcdHelper
)
serviceAccountStorage
:=
serviceaccountetcd
.
NewStorage
(
c
.
DatabaseStorage
)
persistentVolumeStorage
,
persistentVolumeStatusStorage
:=
pvetcd
.
NewStorage
(
c
.
EtcdHelper
)
persistentVolumeStorage
,
persistentVolumeStatusStorage
:=
pvetcd
.
NewStorage
(
c
.
DatabaseStorage
)
persistentVolumeClaimStorage
,
persistentVolumeClaimStatusStorage
:=
pvcetcd
.
NewStorage
(
c
.
EtcdHelper
)
persistentVolumeClaimStorage
,
persistentVolumeClaimStatusStorage
:=
pvcetcd
.
NewStorage
(
c
.
DatabaseStorage
)
namespaceStorage
,
namespaceStatusStorage
,
namespaceFinalizeStorage
:=
namespaceetcd
.
NewStorage
(
c
.
EtcdHelper
)
namespaceStorage
,
namespaceStatusStorage
,
namespaceFinalizeStorage
:=
namespaceetcd
.
NewStorage
(
c
.
DatabaseStorage
)
m
.
namespaceRegistry
=
namespace
.
NewRegistry
(
namespaceStorage
)
m
.
namespaceRegistry
=
namespace
.
NewRegistry
(
namespaceStorage
)
endpointsStorage
:=
endpointsetcd
.
NewStorage
(
c
.
EtcdHelper
)
endpointsStorage
:=
endpointsetcd
.
NewStorage
(
c
.
DatabaseStorage
)
m
.
endpointRegistry
=
endpoint
.
NewRegistry
(
endpointsStorage
)
m
.
endpointRegistry
=
endpoint
.
NewRegistry
(
endpointsStorage
)
nodeStorage
,
nodeStatusStorage
:=
nodeetcd
.
NewStorage
(
c
.
EtcdHelper
,
c
.
KubeletClient
)
nodeStorage
,
nodeStatusStorage
:=
nodeetcd
.
NewStorage
(
c
.
DatabaseStorage
,
c
.
KubeletClient
)
m
.
nodeRegistry
=
minion
.
NewRegistry
(
nodeStorage
)
m
.
nodeRegistry
=
minion
.
NewRegistry
(
nodeStorage
)
// TODO: split me up into distinct storage registries
// TODO: split me up into distinct storage registries
registry
:=
etcd
.
NewRegistry
(
c
.
EtcdHelper
,
podRegistry
,
m
.
endpointRegistry
)
registry
:=
etcd
.
NewRegistry
(
c
.
DatabaseStorage
,
podRegistry
,
m
.
endpointRegistry
)
m
.
serviceRegistry
=
registry
m
.
serviceRegistry
=
registry
var
serviceClusterIPRegistry
service
.
RangeRegistry
var
serviceClusterIPRegistry
service
.
RangeRegistry
serviceClusterIPAllocator
:=
ipallocator
.
NewAllocatorCIDRRange
(
m
.
serviceClusterIPRange
,
func
(
max
int
,
rangeSpec
string
)
allocator
.
Interface
{
serviceClusterIPAllocator
:=
ipallocator
.
NewAllocatorCIDRRange
(
m
.
serviceClusterIPRange
,
func
(
max
int
,
rangeSpec
string
)
allocator
.
Interface
{
mem
:=
allocator
.
NewAllocationMap
(
max
,
rangeSpec
)
mem
:=
allocator
.
NewAllocationMap
(
max
,
rangeSpec
)
etcd
:=
etcdallocator
.
NewEtcd
(
mem
,
"/ranges/serviceips"
,
"serviceipallocation"
,
c
.
EtcdHelper
)
etcd
:=
etcdallocator
.
NewEtcd
(
mem
,
"/ranges/serviceips"
,
"serviceipallocation"
,
c
.
DatabaseStorage
)
serviceClusterIPRegistry
=
etcd
serviceClusterIPRegistry
=
etcd
return
etcd
return
etcd
})
})
...
@@ -459,13 +459,13 @@ func (m *Master) init(c *Config) {
...
@@ -459,13 +459,13 @@ func (m *Master) init(c *Config) {
var
serviceNodePortRegistry
service
.
RangeRegistry
var
serviceNodePortRegistry
service
.
RangeRegistry
serviceNodePortAllocator
:=
portallocator
.
NewPortAllocatorCustom
(
m
.
serviceNodePortRange
,
func
(
max
int
,
rangeSpec
string
)
allocator
.
Interface
{
serviceNodePortAllocator
:=
portallocator
.
NewPortAllocatorCustom
(
m
.
serviceNodePortRange
,
func
(
max
int
,
rangeSpec
string
)
allocator
.
Interface
{
mem
:=
allocator
.
NewAllocationMap
(
max
,
rangeSpec
)
mem
:=
allocator
.
NewAllocationMap
(
max
,
rangeSpec
)
etcd
:=
etcdallocator
.
NewEtcd
(
mem
,
"/ranges/servicenodeports"
,
"servicenodeportallocation"
,
c
.
EtcdHelper
)
etcd
:=
etcdallocator
.
NewEtcd
(
mem
,
"/ranges/servicenodeports"
,
"servicenodeportallocation"
,
c
.
DatabaseStorage
)
serviceNodePortRegistry
=
etcd
serviceNodePortRegistry
=
etcd
return
etcd
return
etcd
})
})
m
.
serviceNodePortAllocator
=
serviceNodePortRegistry
m
.
serviceNodePortAllocator
=
serviceNodePortRegistry
controllerStorage
:=
controlleretcd
.
NewREST
(
c
.
EtcdHelper
)
controllerStorage
:=
controlleretcd
.
NewREST
(
c
.
DatabaseStorage
)
// TODO: Factor out the core API registration
// TODO: Factor out the core API registration
m
.
storage
=
map
[
string
]
rest
.
Storage
{
m
.
storage
=
map
[
string
]
rest
.
Storage
{
...
@@ -701,7 +701,7 @@ func (m *Master) getServersToValidate(c *Config) map[string]apiserver.Server {
...
@@ -701,7 +701,7 @@ func (m *Master) getServersToValidate(c *Config) map[string]apiserver.Server {
"controller-manager"
:
{
Addr
:
"127.0.0.1"
,
Port
:
ports
.
ControllerManagerPort
,
Path
:
"/healthz"
},
"controller-manager"
:
{
Addr
:
"127.0.0.1"
,
Port
:
ports
.
ControllerManagerPort
,
Path
:
"/healthz"
},
"scheduler"
:
{
Addr
:
"127.0.0.1"
,
Port
:
ports
.
SchedulerPort
,
Path
:
"/healthz"
},
"scheduler"
:
{
Addr
:
"127.0.0.1"
,
Port
:
ports
.
SchedulerPort
,
Path
:
"/healthz"
},
}
}
for
ix
,
machine
:=
range
c
.
EtcdHelper
.
Client
.
GetCluster
()
{
for
ix
,
machine
:=
range
c
.
DatabaseStorage
.
Backends
()
{
etcdUrl
,
err
:=
url
.
Parse
(
machine
)
etcdUrl
,
err
:=
url
.
Parse
(
machine
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to parse etcd url for validation: %v"
,
err
)
glog
.
Errorf
(
"Failed to parse etcd url for validation: %v"
,
err
)
...
...
pkg/master/master_test.go
View file @
7cc1855c
...
@@ -31,8 +31,7 @@ func TestGetServersToValidate(t *testing.T) {
...
@@ -31,8 +31,7 @@ func TestGetServersToValidate(t *testing.T) {
config
:=
Config
{}
config
:=
Config
{}
fakeClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeClient
.
Machines
=
[]
string
{
"http://machine1:4001"
,
"http://machine2"
,
"http://machine3:4003"
}
fakeClient
.
Machines
=
[]
string
{
"http://machine1:4001"
,
"http://machine2"
,
"http://machine3:4003"
}
config
.
EtcdHelper
=
tools
.
NewEtcdHelper
(
fakeClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
config
.
DatabaseStorage
=
tools
.
NewEtcdStorage
(
fakeClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
config
.
EtcdHelper
.
Versioner
=
nil
master
.
nodeRegistry
=
registrytest
.
NewMinionRegistry
([]
string
{
"node1"
,
"node2"
},
api
.
NodeResources
{})
master
.
nodeRegistry
=
registrytest
.
NewMinionRegistry
([]
string
{
"node1"
,
"node2"
},
api
.
NodeResources
{})
...
...
pkg/registry/controller/etcd/etcd.go
View file @
7cc1855c
...
@@ -37,7 +37,7 @@ type REST struct {
...
@@ -37,7 +37,7 @@ type REST struct {
var
controllerPrefix
=
"/controllers"
var
controllerPrefix
=
"/controllers"
// NewREST returns a RESTStorage object that will work against replication controllers.
// NewREST returns a RESTStorage object that will work against replication controllers.
func
NewREST
(
h
tools
.
EtcdHelper
)
*
REST
{
func
NewREST
(
s
tools
.
StorageInterface
)
*
REST
{
store
:=
&
etcdgeneric
.
Etcd
{
store
:=
&
etcdgeneric
.
Etcd
{
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
ReplicationController
{}
},
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
ReplicationController
{}
},
...
@@ -69,7 +69,7 @@ func NewREST(h tools.EtcdHelper) *REST {
...
@@ -69,7 +69,7 @@ func NewREST(h tools.EtcdHelper) *REST {
// Used to validate controller updates
// Used to validate controller updates
UpdateStrategy
:
controller
.
Strategy
,
UpdateStrategy
:
controller
.
Strategy
,
Helper
:
h
,
Storage
:
s
,
}
}
return
&
REST
{
store
}
return
&
REST
{
store
}
...
...
pkg/registry/controller/etcd/etcd_test.go
View file @
7cc1855c
...
@@ -40,17 +40,17 @@ const (
...
@@ -40,17 +40,17 @@ const (
FAIL
FAIL
)
)
func
new
Helper
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
EtcdHelper
)
{
func
new
EtcdStorage
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
StorageInterface
)
{
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
.
TestIndex
=
true
fakeEtcdClient
.
TestIndex
=
true
helper
:=
tools
.
NewEtcdHelper
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
etcdStorage
:=
tools
.
NewEtcdStorage
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
return
fakeEtcdClient
,
helper
return
fakeEtcdClient
,
etcdStorage
}
}
// newStorage creates a REST storage backed by etcd helpers
// newStorage creates a REST storage backed by etcd helpers
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
tools
.
FakeEtcdClient
)
{
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
tools
.
FakeEtcdClient
)
{
fakeEtcdClient
,
h
:=
newHelper
(
t
)
fakeEtcdClient
,
s
:=
newEtcdStorage
(
t
)
storage
:=
NewREST
(
h
)
storage
:=
NewREST
(
s
)
return
storage
,
fakeEtcdClient
return
storage
,
fakeEtcdClient
}
}
...
...
pkg/registry/endpoint/etcd/etcd.go
View file @
7cc1855c
...
@@ -33,7 +33,7 @@ type REST struct {
...
@@ -33,7 +33,7 @@ type REST struct {
}
}
// NewStorage returns a RESTStorage object that will work against endpoints.
// NewStorage returns a RESTStorage object that will work against endpoints.
func
NewStorage
(
h
tools
.
EtcdHelper
)
*
REST
{
func
NewStorage
(
s
tools
.
StorageInterface
)
*
REST
{
prefix
:=
"/services/endpoints"
prefix
:=
"/services/endpoints"
return
&
REST
{
return
&
REST
{
&
etcdgeneric
.
Etcd
{
&
etcdgeneric
.
Etcd
{
...
@@ -56,7 +56,7 @@ func NewStorage(h tools.EtcdHelper) *REST {
...
@@ -56,7 +56,7 @@ func NewStorage(h tools.EtcdHelper) *REST {
CreateStrategy
:
endpoint
.
Strategy
,
CreateStrategy
:
endpoint
.
Strategy
,
UpdateStrategy
:
endpoint
.
Strategy
,
UpdateStrategy
:
endpoint
.
Strategy
,
Helper
:
h
,
Storage
:
s
,
},
},
}
}
}
}
pkg/registry/endpoint/etcd/etcd_test.go
View file @
7cc1855c
...
@@ -32,16 +32,16 @@ import (
...
@@ -32,16 +32,16 @@ import (
"github.com/coreos/go-etcd/etcd"
"github.com/coreos/go-etcd/etcd"
)
)
func
new
Helper
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
EtcdHelper
)
{
func
new
EtcdStorage
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
StorageInterface
)
{
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
.
TestIndex
=
true
fakeEtcdClient
.
TestIndex
=
true
helper
:=
tools
.
NewEtcdHelper
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
etcdStorage
:=
tools
.
NewEtcdStorage
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
return
fakeEtcdClient
,
helper
return
fakeEtcdClient
,
etcdStorage
}
}
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
tools
.
FakeEtcdClient
)
{
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
tools
.
FakeEtcdClient
)
{
fakeEtcdClient
,
h
:=
newHelper
(
t
)
fakeEtcdClient
,
s
:=
newEtcdStorage
(
t
)
storage
:=
NewStorage
(
h
)
storage
:=
NewStorage
(
s
)
return
storage
,
fakeEtcdClient
return
storage
,
fakeEtcdClient
}
}
...
...
pkg/registry/etcd/etcd.go
View file @
7cc1855c
...
@@ -44,17 +44,17 @@ const (
...
@@ -44,17 +44,17 @@ const (
// Registry implements BindingRegistry, ControllerRegistry, EndpointRegistry,
// Registry implements BindingRegistry, ControllerRegistry, EndpointRegistry,
// MinionRegistry, PodRegistry and ServiceRegistry, backed by etcd.
// MinionRegistry, PodRegistry and ServiceRegistry, backed by etcd.
type
Registry
struct
{
type
Registry
struct
{
tools
.
EtcdHelper
tools
.
StorageInterface
pods
pod
.
Registry
pods
pod
.
Registry
endpoints
endpoint
.
Registry
endpoints
endpoint
.
Registry
}
}
// NewRegistry creates an etcd registry.
// NewRegistry creates an etcd registry.
func
NewRegistry
(
helper
tools
.
EtcdHelper
,
pods
pod
.
Registry
,
endpoints
endpoint
.
Registry
)
*
Registry
{
func
NewRegistry
(
storage
tools
.
StorageInterface
,
pods
pod
.
Registry
,
endpoints
endpoint
.
Registry
)
*
Registry
{
registry
:=
&
Registry
{
registry
:=
&
Registry
{
EtcdHelper
:
helper
,
StorageInterface
:
storage
,
pods
:
pods
,
pods
:
pods
,
endpoints
:
endpoints
,
endpoints
:
endpoints
,
}
}
return
registry
return
registry
}
}
...
...
pkg/registry/etcd/etcd_test.go
View file @
7cc1855c
...
@@ -38,16 +38,16 @@ import (
...
@@ -38,16 +38,16 @@ import (
)
)
func
NewTestEtcdRegistry
(
client
tools
.
EtcdClient
)
*
Registry
{
func
NewTestEtcdRegistry
(
client
tools
.
EtcdClient
)
*
Registry
{
helper
:=
tools
.
NewEtcdHelper
(
client
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
storage
:=
tools
.
NewEtcdStorage
(
client
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
registry
:=
NewRegistry
(
helper
,
nil
,
nil
)
registry
:=
NewRegistry
(
storage
,
nil
,
nil
)
return
registry
return
registry
}
}
func
NewTestEtcdRegistryWithPods
(
client
tools
.
EtcdClient
)
*
Registry
{
func
NewTestEtcdRegistryWithPods
(
client
tools
.
EtcdClient
)
*
Registry
{
helper
:=
tools
.
NewEtcdHelper
(
client
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
etcdStorage
:=
tools
.
NewEtcdStorage
(
client
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
podStorage
:=
podetcd
.
NewStorage
(
helper
,
nil
)
podStorage
:=
podetcd
.
NewStorage
(
etcdStorage
,
nil
)
endpointStorage
:=
endpointetcd
.
NewStorage
(
helper
)
endpointStorage
:=
endpointetcd
.
NewStorage
(
etcdStorage
)
registry
:=
NewRegistry
(
helper
,
pod
.
NewRegistry
(
podStorage
.
Pod
),
endpoint
.
NewRegistry
(
endpointStorage
))
registry
:=
NewRegistry
(
etcdStorage
,
pod
.
NewRegistry
(
podStorage
.
Pod
),
endpoint
.
NewRegistry
(
endpointStorage
))
return
registry
return
registry
}
}
...
...
pkg/registry/event/registry.go
View file @
7cc1855c
...
@@ -30,8 +30,8 @@ type registry struct {
...
@@ -30,8 +30,8 @@ type registry struct {
}
}
// NewEtcdRegistry returns a registry which will store Events in the given
// NewEtcdRegistry returns a registry which will store Events in the given
// Etcd
Helper
. ttl is the time that Events will be retained by the system.
// Etcd
Storage
. ttl is the time that Events will be retained by the system.
func
NewEtcdRegistry
(
h
tools
.
EtcdHelper
,
ttl
uint64
)
generic
.
Registry
{
func
NewEtcdRegistry
(
s
tools
.
StorageInterface
,
ttl
uint64
)
generic
.
Registry
{
prefix
:=
"/events"
prefix
:=
"/events"
return
registry
{
return
registry
{
Etcd
:
&
etcdgeneric
.
Etcd
{
Etcd
:
&
etcdgeneric
.
Etcd
{
...
@@ -47,7 +47,7 @@ func NewEtcdRegistry(h tools.EtcdHelper, ttl uint64) generic.Registry {
...
@@ -47,7 +47,7 @@ func NewEtcdRegistry(h tools.EtcdHelper, ttl uint64) generic.Registry {
TTLFunc
:
func
(
runtime
.
Object
,
uint64
,
bool
)
(
uint64
,
error
)
{
TTLFunc
:
func
(
runtime
.
Object
,
uint64
,
bool
)
(
uint64
,
error
)
{
return
ttl
,
nil
return
ttl
,
nil
},
},
Helper
:
h
,
Storage
:
s
,
},
},
}
}
}
}
pkg/registry/event/registry_test.go
View file @
7cc1855c
...
@@ -39,8 +39,8 @@ func NewTestEventEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, generic.Regi
...
@@ -39,8 +39,8 @@ func NewTestEventEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, generic.Regi
f
:=
tools
.
NewFakeEtcdClient
(
t
)
f
:=
tools
.
NewFakeEtcdClient
(
t
)
f
.
TestIndex
=
true
f
.
TestIndex
=
true
h
:=
tools
.
NewEtcdHelper
(
f
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
s
:=
tools
.
NewEtcdStorage
(
f
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
return
f
,
NewEtcdRegistry
(
h
,
testTTL
)
return
f
,
NewEtcdRegistry
(
s
,
testTTL
)
}
}
func
TestEventCreate
(
t
*
testing
.
T
)
{
func
TestEventCreate
(
t
*
testing
.
T
)
{
...
...
pkg/registry/generic/etcd/etcd.go
View file @
7cc1855c
...
@@ -103,7 +103,7 @@ type Etcd struct {
...
@@ -103,7 +103,7 @@ type Etcd struct {
ReturnDeletedObject
bool
ReturnDeletedObject
bool
// Used for all etcd access functions
// Used for all etcd access functions
Helper
tools
.
EtcdHelper
Storage
tools
.
StorageInterface
}
}
// NamespaceKeyRootFunc is the default function for constructing etcd paths to resource directories enforcing namespace rules.
// NamespaceKeyRootFunc is the default function for constructing etcd paths to resource directories enforcing namespace rules.
...
@@ -157,14 +157,14 @@ func (e *Etcd) ListPredicate(ctx api.Context, m generic.Matcher) (runtime.Object
...
@@ -157,14 +157,14 @@ func (e *Etcd) ListPredicate(ctx api.Context, m generic.Matcher) (runtime.Object
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
err
=
e
.
Helper
.
ExtractObjToList
(
key
,
list
)
err
=
e
.
Storage
.
ExtractObjToList
(
key
,
list
)
trace
.
Step
(
"Object extracted"
)
trace
.
Step
(
"Object extracted"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
}
else
{
}
else
{
trace
.
Step
(
"About to list directory"
)
trace
.
Step
(
"About to list directory"
)
err
:=
e
.
Helper
.
ExtractToList
(
e
.
KeyRootFunc
(
ctx
),
list
)
err
:=
e
.
Storage
.
ExtractToList
(
e
.
KeyRootFunc
(
ctx
),
list
)
trace
.
Step
(
"List extracted"
)
trace
.
Step
(
"List extracted"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -190,7 +190,7 @@ func (e *Etcd) CreateWithName(ctx api.Context, name string, obj runtime.Object)
...
@@ -190,7 +190,7 @@ func (e *Etcd) CreateWithName(ctx api.Context, name string, obj runtime.Object)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
err
=
e
.
Helper
.
CreateObj
(
key
,
obj
,
nil
,
ttl
)
err
=
e
.
Storage
.
CreateObj
(
key
,
obj
,
nil
,
ttl
)
err
=
etcderr
.
InterpretCreateError
(
err
,
e
.
EndpointName
,
name
)
err
=
etcderr
.
InterpretCreateError
(
err
,
e
.
EndpointName
,
name
)
if
err
==
nil
&&
e
.
Decorator
!=
nil
{
if
err
==
nil
&&
e
.
Decorator
!=
nil
{
err
=
e
.
Decorator
(
obj
)
err
=
e
.
Decorator
(
obj
)
...
@@ -219,7 +219,7 @@ func (e *Etcd) Create(ctx api.Context, obj runtime.Object) (runtime.Object, erro
...
@@ -219,7 +219,7 @@ func (e *Etcd) Create(ctx api.Context, obj runtime.Object) (runtime.Object, erro
}
}
trace
.
Step
(
"About to create object"
)
trace
.
Step
(
"About to create object"
)
out
:=
e
.
NewFunc
()
out
:=
e
.
NewFunc
()
if
err
:=
e
.
Helper
.
CreateObj
(
key
,
obj
,
out
,
ttl
);
err
!=
nil
{
if
err
:=
e
.
Storage
.
CreateObj
(
key
,
obj
,
out
,
ttl
);
err
!=
nil
{
err
=
etcderr
.
InterpretCreateError
(
err
,
e
.
EndpointName
,
name
)
err
=
etcderr
.
InterpretCreateError
(
err
,
e
.
EndpointName
,
name
)
err
=
rest
.
CheckGeneratedNameError
(
e
.
CreateStrategy
,
err
,
obj
)
err
=
rest
.
CheckGeneratedNameError
(
e
.
CreateStrategy
,
err
,
obj
)
return
nil
,
err
return
nil
,
err
...
@@ -249,7 +249,7 @@ func (e *Etcd) UpdateWithName(ctx api.Context, name string, obj runtime.Object)
...
@@ -249,7 +249,7 @@ func (e *Etcd) UpdateWithName(ctx api.Context, name string, obj runtime.Object)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
err
=
e
.
Helper
.
SetObj
(
key
,
obj
,
nil
,
ttl
)
err
=
e
.
Storage
.
SetObj
(
key
,
obj
,
nil
,
ttl
)
err
=
etcderr
.
InterpretUpdateError
(
err
,
e
.
EndpointName
,
name
)
err
=
etcderr
.
InterpretUpdateError
(
err
,
e
.
EndpointName
,
name
)
if
err
==
nil
&&
e
.
Decorator
!=
nil
{
if
err
==
nil
&&
e
.
Decorator
!=
nil
{
err
=
e
.
Decorator
(
obj
)
err
=
e
.
Decorator
(
obj
)
...
@@ -274,7 +274,7 @@ func (e *Etcd) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool
...
@@ -274,7 +274,7 @@ func (e *Etcd) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool
// If AllowUnconditionalUpdate() is true and the object specified by the user does not have a resource version,
// If AllowUnconditionalUpdate() is true and the object specified by the user does not have a resource version,
// then we populate it with the latest version.
// then we populate it with the latest version.
// Else, we check that the version specified by the user matches the version of latest etcd object.
// Else, we check that the version specified by the user matches the version of latest etcd object.
resourceVersion
,
err
:=
e
.
Helper
.
Versioner
.
ObjectResourceVersion
(
obj
)
resourceVersion
,
err
:=
e
.
Storage
.
Versioner
()
.
ObjectResourceVersion
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
false
,
err
}
}
...
@@ -282,8 +282,8 @@ func (e *Etcd) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool
...
@@ -282,8 +282,8 @@ func (e *Etcd) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool
// TODO: expose TTL
// TODO: expose TTL
creating
:=
false
creating
:=
false
out
:=
e
.
NewFunc
()
out
:=
e
.
NewFunc
()
err
=
e
.
Helper
.
GuaranteedUpdate
(
key
,
out
,
true
,
func
(
existing
runtime
.
Object
,
res
tools
.
ResponseMeta
)
(
runtime
.
Object
,
*
uint64
,
error
)
{
err
=
e
.
Storage
.
GuaranteedUpdate
(
key
,
out
,
true
,
func
(
existing
runtime
.
Object
,
res
tools
.
ResponseMeta
)
(
runtime
.
Object
,
*
uint64
,
error
)
{
version
,
err
:=
e
.
Helper
.
Versioner
.
ObjectResourceVersion
(
existing
)
version
,
err
:=
e
.
Storage
.
Versioner
()
.
ObjectResourceVersion
(
existing
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
...
@@ -305,13 +305,13 @@ func (e *Etcd) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool
...
@@ -305,13 +305,13 @@ func (e *Etcd) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool
creating
=
false
creating
=
false
if
doUnconditionalUpdate
{
if
doUnconditionalUpdate
{
// Update the object's resource version to match the latest etcd object's resource version.
// Update the object's resource version to match the latest etcd object's resource version.
err
=
e
.
Helper
.
Versioner
.
UpdateObject
(
obj
,
res
.
Expiration
,
res
.
ResourceVersion
)
err
=
e
.
Storage
.
Versioner
()
.
UpdateObject
(
obj
,
res
.
Expiration
,
res
.
ResourceVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
}
else
{
}
else
{
// Check if the object's resource version matches the latest resource version.
// Check if the object's resource version matches the latest resource version.
newVersion
,
err
:=
e
.
Helper
.
Versioner
.
ObjectResourceVersion
(
obj
)
newVersion
,
err
:=
e
.
Storage
.
Versioner
()
.
ObjectResourceVersion
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
...
@@ -372,7 +372,7 @@ func (e *Etcd) Get(ctx api.Context, name string) (runtime.Object, error) {
...
@@ -372,7 +372,7 @@ func (e *Etcd) Get(ctx api.Context, name string) (runtime.Object, error) {
return
nil
,
err
return
nil
,
err
}
}
trace
.
Step
(
"About to read object"
)
trace
.
Step
(
"About to read object"
)
if
err
:=
e
.
Helper
.
ExtractObj
(
key
,
obj
,
false
);
err
!=
nil
{
if
err
:=
e
.
Storage
.
ExtractObj
(
key
,
obj
,
false
);
err
!=
nil
{
return
nil
,
etcderr
.
InterpretGetError
(
err
,
e
.
EndpointName
,
name
)
return
nil
,
etcderr
.
InterpretGetError
(
err
,
e
.
EndpointName
,
name
)
}
}
trace
.
Step
(
"Object read"
)
trace
.
Step
(
"Object read"
)
...
@@ -395,7 +395,7 @@ func (e *Etcd) Delete(ctx api.Context, name string, options *api.DeleteOptions)
...
@@ -395,7 +395,7 @@ func (e *Etcd) Delete(ctx api.Context, name string, options *api.DeleteOptions)
trace
:=
util
.
NewTrace
(
"Delete "
+
reflect
.
TypeOf
(
obj
)
.
String
())
trace
:=
util
.
NewTrace
(
"Delete "
+
reflect
.
TypeOf
(
obj
)
.
String
())
defer
trace
.
LogIfLong
(
time
.
Second
)
defer
trace
.
LogIfLong
(
time
.
Second
)
trace
.
Step
(
"About to read object"
)
trace
.
Step
(
"About to read object"
)
if
err
:=
e
.
Helper
.
ExtractObj
(
key
,
obj
,
false
);
err
!=
nil
{
if
err
:=
e
.
Storage
.
ExtractObj
(
key
,
obj
,
false
);
err
!=
nil
{
return
nil
,
etcderr
.
InterpretDeleteError
(
err
,
e
.
EndpointName
,
name
)
return
nil
,
etcderr
.
InterpretDeleteError
(
err
,
e
.
EndpointName
,
name
)
}
}
...
@@ -413,7 +413,7 @@ func (e *Etcd) Delete(ctx api.Context, name string, options *api.DeleteOptions)
...
@@ -413,7 +413,7 @@ func (e *Etcd) Delete(ctx api.Context, name string, options *api.DeleteOptions)
if
graceful
&&
*
options
.
GracePeriodSeconds
!=
0
{
if
graceful
&&
*
options
.
GracePeriodSeconds
!=
0
{
trace
.
Step
(
"Graceful deletion"
)
trace
.
Step
(
"Graceful deletion"
)
out
:=
e
.
NewFunc
()
out
:=
e
.
NewFunc
()
if
err
:=
e
.
Helper
.
SetObj
(
key
,
obj
,
out
,
uint64
(
*
options
.
GracePeriodSeconds
));
err
!=
nil
{
if
err
:=
e
.
Storage
.
SetObj
(
key
,
obj
,
out
,
uint64
(
*
options
.
GracePeriodSeconds
));
err
!=
nil
{
return
nil
,
etcderr
.
InterpretUpdateError
(
err
,
e
.
EndpointName
,
name
)
return
nil
,
etcderr
.
InterpretUpdateError
(
err
,
e
.
EndpointName
,
name
)
}
}
return
e
.
finalizeDelete
(
out
,
true
)
return
e
.
finalizeDelete
(
out
,
true
)
...
@@ -422,7 +422,7 @@ func (e *Etcd) Delete(ctx api.Context, name string, options *api.DeleteOptions)
...
@@ -422,7 +422,7 @@ func (e *Etcd) Delete(ctx api.Context, name string, options *api.DeleteOptions)
// delete immediately, or no graceful deletion supported
// delete immediately, or no graceful deletion supported
out
:=
e
.
NewFunc
()
out
:=
e
.
NewFunc
()
trace
.
Step
(
"About to delete object"
)
trace
.
Step
(
"About to delete object"
)
if
err
:=
e
.
Helper
.
DeleteObj
(
key
,
out
);
err
!=
nil
{
if
err
:=
e
.
Storage
.
DeleteObj
(
key
,
out
);
err
!=
nil
{
return
nil
,
etcderr
.
InterpretDeleteError
(
err
,
e
.
EndpointName
,
name
)
return
nil
,
etcderr
.
InterpretDeleteError
(
err
,
e
.
EndpointName
,
name
)
}
}
return
e
.
finalizeDelete
(
out
,
true
)
return
e
.
finalizeDelete
(
out
,
true
)
...
@@ -480,10 +480,10 @@ func (e *Etcd) WatchPredicate(ctx api.Context, m generic.Matcher, resourceVersio
...
@@ -480,10 +480,10 @@ func (e *Etcd) WatchPredicate(ctx api.Context, m generic.Matcher, resourceVersio
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
e
.
Helper
.
Watch
(
key
,
version
,
filterFunc
)
return
e
.
Storage
.
Watch
(
key
,
version
,
filterFunc
)
}
}
return
e
.
Helper
.
WatchList
(
e
.
KeyRootFunc
(
ctx
),
version
,
filterFunc
)
return
e
.
Storage
.
WatchList
(
e
.
KeyRootFunc
(
ctx
),
version
,
filterFunc
)
}
}
// calculateTTL is a helper for retrieving the updated TTL for an object or returning an error
// calculateTTL is a helper for retrieving the updated TTL for an object or returning an error
...
...
pkg/registry/generic/etcd/etcd_test.go
View file @
7cc1855c
...
@@ -69,7 +69,7 @@ func hasCreated(t *testing.T, pod *api.Pod) func(runtime.Object) bool {
...
@@ -69,7 +69,7 @@ func hasCreated(t *testing.T, pod *api.Pod) func(runtime.Object) bool {
func
NewTestGenericEtcdRegistry
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
*
Etcd
)
{
func
NewTestGenericEtcdRegistry
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
*
Etcd
)
{
f
:=
tools
.
NewFakeEtcdClient
(
t
)
f
:=
tools
.
NewFakeEtcdClient
(
t
)
f
.
TestIndex
=
true
f
.
TestIndex
=
true
h
:=
tools
.
NewEtcdHelper
(
f
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
s
:=
tools
.
NewEtcdStorage
(
f
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
strategy
:=
&
testRESTStrategy
{
api
.
Scheme
,
api
.
SimpleNameGenerator
,
true
,
false
,
true
}
strategy
:=
&
testRESTStrategy
{
api
.
Scheme
,
api
.
SimpleNameGenerator
,
true
,
false
,
true
}
podPrefix
:=
"/pods"
podPrefix
:=
"/pods"
return
f
,
&
Etcd
{
return
f
,
&
Etcd
{
...
@@ -85,7 +85,7 @@ func NewTestGenericEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, *Etcd) {
...
@@ -85,7 +85,7 @@ func NewTestGenericEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, *Etcd) {
return
path
.
Join
(
podPrefix
,
id
),
nil
return
path
.
Join
(
podPrefix
,
id
),
nil
},
},
ObjectNameFunc
:
func
(
obj
runtime
.
Object
)
(
string
,
error
)
{
return
obj
.
(
*
api
.
Pod
)
.
Name
,
nil
},
ObjectNameFunc
:
func
(
obj
runtime
.
Object
)
(
string
,
error
)
{
return
obj
.
(
*
api
.
Pod
)
.
Name
,
nil
},
Helper
:
h
,
Storage
:
s
,
}
}
}
}
...
...
pkg/registry/generic/registry.go
View file @
7cc1855c
...
@@ -141,7 +141,7 @@ type Registry interface {
...
@@ -141,7 +141,7 @@ type Registry interface {
// provided that 'm' works with the concrete type of list. d is an optional
// provided that 'm' works with the concrete type of list. d is an optional
// decorator for the returned functions. Only matching items are decorated.
// decorator for the returned functions. Only matching items are decorated.
func
FilterList
(
list
runtime
.
Object
,
m
Matcher
,
d
DecoratorFunc
)
(
filtered
runtime
.
Object
,
err
error
)
{
func
FilterList
(
list
runtime
.
Object
,
m
Matcher
,
d
DecoratorFunc
)
(
filtered
runtime
.
Object
,
err
error
)
{
// TODO: push a matcher down into tools.
E
tcdHelper to avoid all this
// TODO: push a matcher down into tools.
e
tcdHelper to avoid all this
// nonsense. This is a lot of unnecessary copies.
// nonsense. This is a lot of unnecessary copies.
items
,
err
:=
runtime
.
ExtractList
(
list
)
items
,
err
:=
runtime
.
ExtractList
(
list
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/registry/limitrange/registry.go
View file @
7cc1855c
...
@@ -29,8 +29,8 @@ type registry struct {
...
@@ -29,8 +29,8 @@ type registry struct {
*
etcdgeneric
.
Etcd
*
etcdgeneric
.
Etcd
}
}
// NewEtcdRegistry returns a registry which will store LimitRange in the given
helper
// NewEtcdRegistry returns a registry which will store LimitRange in the given
storage
func
NewEtcdRegistry
(
h
tools
.
EtcdHelper
)
generic
.
Registry
{
func
NewEtcdRegistry
(
s
tools
.
StorageInterface
)
generic
.
Registry
{
prefix
:=
"/limitranges"
prefix
:=
"/limitranges"
return
registry
{
return
registry
{
Etcd
:
&
etcdgeneric
.
Etcd
{
Etcd
:
&
etcdgeneric
.
Etcd
{
...
@@ -43,7 +43,7 @@ func NewEtcdRegistry(h tools.EtcdHelper) generic.Registry {
...
@@ -43,7 +43,7 @@ func NewEtcdRegistry(h tools.EtcdHelper) generic.Registry {
KeyFunc
:
func
(
ctx
api
.
Context
,
id
string
)
(
string
,
error
)
{
KeyFunc
:
func
(
ctx
api
.
Context
,
id
string
)
(
string
,
error
)
{
return
etcdgeneric
.
NamespaceKeyFunc
(
ctx
,
prefix
,
id
)
return
etcdgeneric
.
NamespaceKeyFunc
(
ctx
,
prefix
,
id
)
},
},
Helper
:
h
,
Storage
:
s
,
},
},
}
}
}
}
pkg/registry/limitrange/registry_test.go
View file @
7cc1855c
...
@@ -37,8 +37,8 @@ import (
...
@@ -37,8 +37,8 @@ import (
func
NewTestLimitRangeEtcdRegistry
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
generic
.
Registry
)
{
func
NewTestLimitRangeEtcdRegistry
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
generic
.
Registry
)
{
f
:=
tools
.
NewFakeEtcdClient
(
t
)
f
:=
tools
.
NewFakeEtcdClient
(
t
)
f
.
TestIndex
=
true
f
.
TestIndex
=
true
h
:=
tools
.
NewEtcdHelper
(
f
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
s
:=
tools
.
NewEtcdStorage
(
f
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
return
f
,
NewEtcdRegistry
(
h
)
return
f
,
NewEtcdRegistry
(
s
)
}
}
func
TestLimitRangeCreate
(
t
*
testing
.
T
)
{
func
TestLimitRangeCreate
(
t
*
testing
.
T
)
{
...
...
pkg/registry/minion/etcd/etcd.go
View file @
7cc1855c
...
@@ -49,7 +49,7 @@ func (r *StatusREST) Update(ctx api.Context, obj runtime.Object) (runtime.Object
...
@@ -49,7 +49,7 @@ func (r *StatusREST) Update(ctx api.Context, obj runtime.Object) (runtime.Object
}
}
// NewStorage returns a RESTStorage object that will work against nodes.
// NewStorage returns a RESTStorage object that will work against nodes.
func
NewStorage
(
h
tools
.
EtcdHelper
,
connection
client
.
ConnectionInfoGetter
)
(
*
REST
,
*
StatusREST
)
{
func
NewStorage
(
s
tools
.
StorageInterface
,
connection
client
.
ConnectionInfoGetter
)
(
*
REST
,
*
StatusREST
)
{
prefix
:=
"/minions"
prefix
:=
"/minions"
store
:=
&
etcdgeneric
.
Etcd
{
store
:=
&
etcdgeneric
.
Etcd
{
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
Node
{}
},
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
Node
{}
},
...
@@ -69,7 +69,7 @@ func NewStorage(h tools.EtcdHelper, connection client.ConnectionInfoGetter) (*RE
...
@@ -69,7 +69,7 @@ func NewStorage(h tools.EtcdHelper, connection client.ConnectionInfoGetter) (*RE
CreateStrategy
:
minion
.
Strategy
,
CreateStrategy
:
minion
.
Strategy
,
UpdateStrategy
:
minion
.
Strategy
,
UpdateStrategy
:
minion
.
Strategy
,
Helper
:
h
,
Storage
:
s
,
}
}
statusStore
:=
*
store
statusStore
:=
*
store
...
...
pkg/registry/minion/etcd/etcd_test.go
View file @
7cc1855c
...
@@ -47,16 +47,16 @@ func (fakeConnectionInfoGetter) GetConnectionInfo(host string) (string, uint, ht
...
@@ -47,16 +47,16 @@ func (fakeConnectionInfoGetter) GetConnectionInfo(host string) (string, uint, ht
return
"http"
,
12345
,
nil
,
nil
return
"http"
,
12345
,
nil
,
nil
}
}
func
new
Helper
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
EtcdHelper
)
{
func
new
EtcdStorage
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
StorageInterface
)
{
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
.
TestIndex
=
true
fakeEtcdClient
.
TestIndex
=
true
helper
:=
tools
.
NewEtcdHelper
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
etcdStorage
:=
tools
.
NewEtcdStorage
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
return
fakeEtcdClient
,
helper
return
fakeEtcdClient
,
etcdStorage
}
}
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
tools
.
FakeEtcdClient
)
{
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
tools
.
FakeEtcdClient
)
{
fakeEtcdClient
,
h
:=
newHelper
(
t
)
fakeEtcdClient
,
s
:=
newEtcdStorage
(
t
)
storage
,
_
:=
NewStorage
(
h
,
fakeConnectionInfoGetter
{})
storage
,
_
:=
NewStorage
(
s
,
fakeConnectionInfoGetter
{})
return
storage
,
fakeEtcdClient
return
storage
,
fakeEtcdClient
}
}
...
...
pkg/registry/namespace/etcd/etcd.go
View file @
7cc1855c
...
@@ -49,7 +49,7 @@ type FinalizeREST struct {
...
@@ -49,7 +49,7 @@ type FinalizeREST struct {
}
}
// NewStorage returns a RESTStorage object that will work against namespaces
// NewStorage returns a RESTStorage object that will work against namespaces
func
NewStorage
(
h
tools
.
EtcdHelper
)
(
*
REST
,
*
StatusREST
,
*
FinalizeREST
)
{
func
NewStorage
(
s
tools
.
StorageInterface
)
(
*
REST
,
*
StatusREST
,
*
FinalizeREST
)
{
prefix
:=
"/namespaces"
prefix
:=
"/namespaces"
store
:=
&
etcdgeneric
.
Etcd
{
store
:=
&
etcdgeneric
.
Etcd
{
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
Namespace
{}
},
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
Namespace
{}
},
...
@@ -67,7 +67,7 @@ func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST, *FinalizeREST) {
...
@@ -67,7 +67,7 @@ func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST, *FinalizeREST) {
return
namespace
.
MatchNamespace
(
label
,
field
)
return
namespace
.
MatchNamespace
(
label
,
field
)
},
},
EndpointName
:
"namespaces"
,
EndpointName
:
"namespaces"
,
Helper
:
h
,
Storage
:
s
,
}
}
store
.
CreateStrategy
=
namespace
.
Strategy
store
.
CreateStrategy
=
namespace
.
Strategy
store
.
UpdateStrategy
=
namespace
.
Strategy
store
.
UpdateStrategy
=
namespace
.
Strategy
...
...
pkg/registry/namespace/etcd/etcd_test.go
View file @
7cc1855c
...
@@ -33,17 +33,17 @@ import (
...
@@ -33,17 +33,17 @@ import (
"github.com/coreos/go-etcd/etcd"
"github.com/coreos/go-etcd/etcd"
)
)
func
new
Helper
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
EtcdHelper
)
{
func
new
EtcdStorage
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
StorageInterface
)
{
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
.
TestIndex
=
true
fakeEtcdClient
.
TestIndex
=
true
helper
:=
tools
.
NewEtcdHelper
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
etcdStorage
:=
tools
.
NewEtcdStorage
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
return
fakeEtcdClient
,
helper
return
fakeEtcdClient
,
etcdStorage
}
}
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
tools
.
FakeEtcdClient
,
tools
.
EtcdHelper
)
{
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
tools
.
FakeEtcdClient
,
tools
.
StorageInterface
)
{
fakeEtcdClient
,
h
:=
newHelper
(
t
)
fakeEtcdClient
,
s
:=
newEtcdStorage
(
t
)
storage
,
_
,
_
:=
NewStorage
(
h
)
storage
,
_
,
_
:=
NewStorage
(
s
)
return
storage
,
fakeEtcdClient
,
h
return
storage
,
fakeEtcdClient
,
s
}
}
func
validNewNamespace
()
*
api
.
Namespace
{
func
validNewNamespace
()
*
api
.
Namespace
{
...
@@ -69,8 +69,8 @@ func TestStorage(t *testing.T) {
...
@@ -69,8 +69,8 @@ func TestStorage(t *testing.T) {
}
}
func
TestCreate
(
t
*
testing
.
T
)
{
func
TestCreate
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
,
_
,
_
:=
NewStorage
(
helper
)
storage
,
_
,
_
:=
NewStorage
(
etcdStorage
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
.
ClusterScope
()
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
.
ClusterScope
()
namespace
:=
validNewNamespace
()
namespace
:=
validNewNamespace
()
namespace
.
ObjectMeta
=
api
.
ObjectMeta
{
GenerateName
:
"foo"
}
namespace
.
ObjectMeta
=
api
.
ObjectMeta
{
GenerateName
:
"foo"
}
...
@@ -94,8 +94,8 @@ func expectNamespace(t *testing.T, out runtime.Object) (*api.Namespace, bool) {
...
@@ -94,8 +94,8 @@ func expectNamespace(t *testing.T, out runtime.Object) (*api.Namespace, bool) {
}
}
func
TestCreateSetsFields
(
t
*
testing
.
T
)
{
func
TestCreateSetsFields
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
,
_
,
_
:=
NewStorage
(
helper
)
storage
,
_
,
_
:=
NewStorage
(
etcdStorage
)
namespace
:=
validNewNamespace
()
namespace
:=
validNewNamespace
()
_
,
err
:=
storage
.
Create
(
api
.
NewContext
(),
namespace
)
_
,
err
:=
storage
.
Create
(
api
.
NewContext
(),
namespace
)
if
err
!=
fakeEtcdClient
.
Err
{
if
err
!=
fakeEtcdClient
.
Err
{
...
@@ -108,7 +108,7 @@ func TestCreateSetsFields(t *testing.T) {
...
@@ -108,7 +108,7 @@ func TestCreateSetsFields(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected key error: %v"
,
err
)
t
.
Fatalf
(
"unexpected key error: %v"
,
err
)
}
}
if
err
:=
helper
.
ExtractObj
(
key
,
actual
,
false
);
err
!=
nil
{
if
err
:=
etcdStorage
.
ExtractObj
(
key
,
actual
,
false
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected extraction error: %v"
,
err
)
t
.
Fatalf
(
"unexpected extraction error: %v"
,
err
)
}
}
if
actual
.
Name
!=
namespace
.
Name
{
if
actual
.
Name
!=
namespace
.
Name
{
...
@@ -123,7 +123,7 @@ func TestCreateSetsFields(t *testing.T) {
...
@@ -123,7 +123,7 @@ func TestCreateSetsFields(t *testing.T) {
}
}
func
TestListEmptyNamespaceList
(
t
*
testing
.
T
)
{
func
TestListEmptyNamespaceList
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
fakeEtcdClient
.
ChangeIndex
=
1
fakeEtcdClient
.
ChangeIndex
=
1
key
:=
etcdtest
.
AddPrefix
(
"/namespaces"
)
key
:=
etcdtest
.
AddPrefix
(
"/namespaces"
)
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
...
@@ -131,7 +131,7 @@ func TestListEmptyNamespaceList(t *testing.T) {
...
@@ -131,7 +131,7 @@ func TestListEmptyNamespaceList(t *testing.T) {
E
:
fakeEtcdClient
.
NewError
(
tools
.
EtcdErrorCodeNotFound
),
E
:
fakeEtcdClient
.
NewError
(
tools
.
EtcdErrorCodeNotFound
),
}
}
storage
,
_
,
_
:=
NewStorage
(
helper
)
storage
,
_
,
_
:=
NewStorage
(
etcdStorage
)
namespaces
,
err
:=
storage
.
List
(
api
.
NewContext
(),
labels
.
Everything
(),
fields
.
Everything
())
namespaces
,
err
:=
storage
.
List
(
api
.
NewContext
(),
labels
.
Everything
(),
fields
.
Everything
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
...
@@ -145,7 +145,7 @@ func TestListEmptyNamespaceList(t *testing.T) {
...
@@ -145,7 +145,7 @@ func TestListEmptyNamespaceList(t *testing.T) {
}
}
func
TestListNamespaceList
(
t
*
testing
.
T
)
{
func
TestListNamespaceList
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
key
:=
etcdtest
.
AddPrefix
(
"/namespaces"
)
key
:=
etcdtest
.
AddPrefix
(
"/namespaces"
)
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{
R
:
&
etcd
.
Response
{
...
@@ -165,7 +165,7 @@ func TestListNamespaceList(t *testing.T) {
...
@@ -165,7 +165,7 @@ func TestListNamespaceList(t *testing.T) {
},
},
},
},
}
}
storage
,
_
,
_
:=
NewStorage
(
helper
)
storage
,
_
,
_
:=
NewStorage
(
etcdStorage
)
namespacesObj
,
err
:=
storage
.
List
(
api
.
NewContext
(),
labels
.
Everything
(),
fields
.
Everything
())
namespacesObj
,
err
:=
storage
.
List
(
api
.
NewContext
(),
labels
.
Everything
(),
fields
.
Everything
())
namespaces
:=
namespacesObj
.
(
*
api
.
NamespaceList
)
namespaces
:=
namespacesObj
.
(
*
api
.
NamespaceList
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -184,7 +184,7 @@ func TestListNamespaceList(t *testing.T) {
...
@@ -184,7 +184,7 @@ func TestListNamespaceList(t *testing.T) {
}
}
func
TestListNamespaceListSelection
(
t
*
testing
.
T
)
{
func
TestListNamespaceListSelection
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
key
:=
etcdtest
.
AddPrefix
(
"/namespaces"
)
key
:=
etcdtest
.
AddPrefix
(
"/namespaces"
)
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{
R
:
&
etcd
.
Response
{
...
@@ -213,7 +213,7 @@ func TestListNamespaceListSelection(t *testing.T) {
...
@@ -213,7 +213,7 @@ func TestListNamespaceListSelection(t *testing.T) {
},
},
},
},
}
}
storage
,
_
,
_
:=
NewStorage
(
helper
)
storage
,
_
,
_
:=
NewStorage
(
etcdStorage
)
ctx
:=
api
.
NewContext
()
ctx
:=
api
.
NewContext
()
table
:=
[]
struct
{
table
:=
[]
struct
{
label
,
field
string
label
,
field
string
...
@@ -261,8 +261,8 @@ func TestListNamespaceListSelection(t *testing.T) {
...
@@ -261,8 +261,8 @@ func TestListNamespaceListSelection(t *testing.T) {
}
}
func
TestNamespaceDecode
(
t
*
testing
.
T
)
{
func
TestNamespaceDecode
(
t
*
testing
.
T
)
{
_
,
helper
:=
newHelper
(
t
)
_
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
,
_
,
_
:=
NewStorage
(
helper
)
storage
,
_
,
_
:=
NewStorage
(
etcdStorage
)
expected
:=
validNewNamespace
()
expected
:=
validNewNamespace
()
expected
.
Status
.
Phase
=
api
.
NamespaceActive
expected
.
Status
.
Phase
=
api
.
NamespaceActive
expected
.
Spec
.
Finalizers
=
[]
api
.
FinalizerName
{
api
.
FinalizerKubernetes
}
expected
.
Spec
.
Finalizers
=
[]
api
.
FinalizerName
{
api
.
FinalizerKubernetes
}
...
@@ -311,9 +311,9 @@ func TestGet(t *testing.T) {
...
@@ -311,9 +311,9 @@ func TestGet(t *testing.T) {
}
}
func
TestDeleteNamespace
(
t
*
testing
.
T
)
{
func
TestDeleteNamespace
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
fakeEtcdClient
.
ChangeIndex
=
1
fakeEtcdClient
.
ChangeIndex
=
1
storage
,
_
,
_
:=
NewStorage
(
helper
)
storage
,
_
,
_
:=
NewStorage
(
etcdStorage
)
ctx
:=
api
.
NewContext
()
ctx
:=
api
.
NewContext
()
key
,
err
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
key
,
err
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
...
@@ -340,7 +340,7 @@ func TestDeleteNamespace(t *testing.T) {
...
@@ -340,7 +340,7 @@ func TestDeleteNamespace(t *testing.T) {
func
TestDeleteNamespaceWithIncompleteFinalizers
(
t
*
testing
.
T
)
{
func
TestDeleteNamespaceWithIncompleteFinalizers
(
t
*
testing
.
T
)
{
now
:=
util
.
Now
()
now
:=
util
.
Now
()
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
fakeEtcdClient
.
ChangeIndex
=
1
fakeEtcdClient
.
ChangeIndex
=
1
key
:=
etcdtest
.
AddPrefix
(
"/namespaces/foo"
)
key
:=
etcdtest
.
AddPrefix
(
"/namespaces/foo"
)
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
...
@@ -361,7 +361,7 @@ func TestDeleteNamespaceWithIncompleteFinalizers(t *testing.T) {
...
@@ -361,7 +361,7 @@ func TestDeleteNamespaceWithIncompleteFinalizers(t *testing.T) {
},
},
},
},
}
}
storage
,
_
,
_
:=
NewStorage
(
helper
)
storage
,
_
,
_
:=
NewStorage
(
etcdStorage
)
_
,
err
:=
storage
.
Delete
(
api
.
NewContext
(),
"foo"
,
nil
)
_
,
err
:=
storage
.
Delete
(
api
.
NewContext
(),
"foo"
,
nil
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatalf
(
"expected error: %v"
,
err
)
t
.
Fatalf
(
"expected error: %v"
,
err
)
...
@@ -370,7 +370,7 @@ func TestDeleteNamespaceWithIncompleteFinalizers(t *testing.T) {
...
@@ -370,7 +370,7 @@ func TestDeleteNamespaceWithIncompleteFinalizers(t *testing.T) {
func
TestDeleteNamespaceWithCompleteFinalizers
(
t
*
testing
.
T
)
{
func
TestDeleteNamespaceWithCompleteFinalizers
(
t
*
testing
.
T
)
{
now
:=
util
.
Now
()
now
:=
util
.
Now
()
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
fakeEtcdClient
.
ChangeIndex
=
1
fakeEtcdClient
.
ChangeIndex
=
1
key
:=
etcdtest
.
AddPrefix
(
"/namespaces/foo"
)
key
:=
etcdtest
.
AddPrefix
(
"/namespaces/foo"
)
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
...
@@ -391,7 +391,7 @@ func TestDeleteNamespaceWithCompleteFinalizers(t *testing.T) {
...
@@ -391,7 +391,7 @@ func TestDeleteNamespaceWithCompleteFinalizers(t *testing.T) {
},
},
},
},
}
}
storage
,
_
,
_
:=
NewStorage
(
helper
)
storage
,
_
,
_
:=
NewStorage
(
etcdStorage
)
_
,
err
:=
storage
.
Delete
(
api
.
NewContext
(),
"foo"
,
nil
)
_
,
err
:=
storage
.
Delete
(
api
.
NewContext
(),
"foo"
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
...
...
pkg/registry/persistentvolume/etcd/etcd.go
View file @
7cc1855c
...
@@ -35,7 +35,7 @@ type REST struct {
...
@@ -35,7 +35,7 @@ type REST struct {
}
}
// NewREST returns a RESTStorage object that will work against PersistentVolume objects.
// NewREST returns a RESTStorage object that will work against PersistentVolume objects.
func
NewStorage
(
h
tools
.
EtcdHelper
)
(
*
REST
,
*
StatusREST
)
{
func
NewStorage
(
s
tools
.
StorageInterface
)
(
*
REST
,
*
StatusREST
)
{
prefix
:=
"/persistentvolumes"
prefix
:=
"/persistentvolumes"
store
:=
&
etcdgeneric
.
Etcd
{
store
:=
&
etcdgeneric
.
Etcd
{
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
PersistentVolume
{}
},
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
PersistentVolume
{}
},
...
@@ -54,7 +54,7 @@ func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST) {
...
@@ -54,7 +54,7 @@ func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST) {
},
},
EndpointName
:
"persistentvolume"
,
EndpointName
:
"persistentvolume"
,
Helper
:
h
,
Storage
:
s
,
}
}
store
.
CreateStrategy
=
persistentvolume
.
Strategy
store
.
CreateStrategy
=
persistentvolume
.
Strategy
...
...
pkg/registry/persistentvolume/etcd/etcd_test.go
View file @
7cc1855c
...
@@ -38,12 +38,12 @@ type testRegistry struct {
...
@@ -38,12 +38,12 @@ type testRegistry struct {
*
registrytest
.
GenericRegistry
*
registrytest
.
GenericRegistry
}
}
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
StatusREST
,
*
tools
.
FakeEtcdClient
,
tools
.
EtcdHelper
)
{
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
StatusREST
,
*
tools
.
FakeEtcdClient
,
tools
.
StorageInterface
)
{
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
.
TestIndex
=
true
fakeEtcdClient
.
TestIndex
=
true
helper
:=
tools
.
NewEtcdHelper
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
etcdStorage
:=
tools
.
NewEtcdStorage
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
storage
,
statusStorage
:=
NewStorage
(
helper
)
storage
,
statusStorage
:=
NewStorage
(
etcdStorage
)
return
storage
,
statusStorage
,
fakeEtcdClient
,
helper
return
storage
,
statusStorage
,
fakeEtcdClient
,
etcdStorage
}
}
func
validNewPersistentVolume
(
name
string
)
*
api
.
PersistentVolume
{
func
validNewPersistentVolume
(
name
string
)
*
api
.
PersistentVolume
{
...
@@ -320,7 +320,7 @@ func TestDeletePersistentVolumes(t *testing.T) {
...
@@ -320,7 +320,7 @@ func TestDeletePersistentVolumes(t *testing.T) {
}
}
func
TestEtcdUpdateStatus
(
t
*
testing
.
T
)
{
func
TestEtcdUpdateStatus
(
t
*
testing
.
T
)
{
storage
,
statusStorage
,
fakeClient
,
helper
:=
newStorage
(
t
)
storage
,
statusStorage
,
fakeClient
,
etcdStorage
:=
newStorage
(
t
)
ctx
:=
api
.
NewContext
()
ctx
:=
api
.
NewContext
()
fakeClient
.
TestIndex
=
true
fakeClient
.
TestIndex
=
true
...
@@ -350,7 +350,7 @@ func TestEtcdUpdateStatus(t *testing.T) {
...
@@ -350,7 +350,7 @@ func TestEtcdUpdateStatus(t *testing.T) {
}
}
var
pvOut
api
.
PersistentVolume
var
pvOut
api
.
PersistentVolume
key
,
_
=
storage
.
KeyFunc
(
ctx
,
"foo"
)
key
,
_
=
storage
.
KeyFunc
(
ctx
,
"foo"
)
if
err
:=
helper
.
ExtractObj
(
key
,
&
pvOut
,
false
);
err
!=
nil
{
if
err
:=
etcdStorage
.
ExtractObj
(
key
,
&
pvOut
,
false
);
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
if
!
api
.
Semantic
.
DeepEqual
(
expected
,
pvOut
)
{
if
!
api
.
Semantic
.
DeepEqual
(
expected
,
pvOut
)
{
...
...
pkg/registry/persistentvolumeclaim/etcd/etcd.go
View file @
7cc1855c
...
@@ -33,7 +33,7 @@ type REST struct {
...
@@ -33,7 +33,7 @@ type REST struct {
}
}
// NewREST returns a RESTStorage object that will work against PersistentVolumeClaim objects.
// NewREST returns a RESTStorage object that will work against PersistentVolumeClaim objects.
func
NewStorage
(
h
tools
.
EtcdHelper
)
(
*
REST
,
*
StatusREST
)
{
func
NewStorage
(
s
tools
.
StorageInterface
)
(
*
REST
,
*
StatusREST
)
{
prefix
:=
"/persistentvolumeclaims"
prefix
:=
"/persistentvolumeclaims"
store
:=
&
etcdgeneric
.
Etcd
{
store
:=
&
etcdgeneric
.
Etcd
{
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
PersistentVolumeClaim
{}
},
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
PersistentVolumeClaim
{}
},
...
@@ -52,7 +52,7 @@ func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST) {
...
@@ -52,7 +52,7 @@ func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST) {
},
},
EndpointName
:
"persistentvolumeclaims"
,
EndpointName
:
"persistentvolumeclaims"
,
Helper
:
h
,
Storage
:
s
,
}
}
store
.
CreateStrategy
=
persistentvolumeclaim
.
Strategy
store
.
CreateStrategy
=
persistentvolumeclaim
.
Strategy
...
...
pkg/registry/persistentvolumeclaim/etcd/etcd_test.go
View file @
7cc1855c
...
@@ -38,12 +38,12 @@ type testRegistry struct {
...
@@ -38,12 +38,12 @@ type testRegistry struct {
*
registrytest
.
GenericRegistry
*
registrytest
.
GenericRegistry
}
}
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
StatusREST
,
*
tools
.
FakeEtcdClient
,
tools
.
EtcdHelper
)
{
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
StatusREST
,
*
tools
.
FakeEtcdClient
,
tools
.
StorageInterface
)
{
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
.
TestIndex
=
true
fakeEtcdClient
.
TestIndex
=
true
helper
:=
tools
.
NewEtcdHelper
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
etcdStorage
:=
tools
.
NewEtcdStorage
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
storage
,
statusStorage
:=
NewStorage
(
helper
)
storage
,
statusStorage
:=
NewStorage
(
etcdStorage
)
return
storage
,
statusStorage
,
fakeEtcdClient
,
helper
return
storage
,
statusStorage
,
fakeEtcdClient
,
etcdStorage
}
}
func
validNewPersistentVolumeClaim
(
name
,
ns
string
)
*
api
.
PersistentVolumeClaim
{
func
validNewPersistentVolumeClaim
(
name
,
ns
string
)
*
api
.
PersistentVolumeClaim
{
...
@@ -318,7 +318,7 @@ func TestDeletePersistentVolumeClaims(t *testing.T) {
...
@@ -318,7 +318,7 @@ func TestDeletePersistentVolumeClaims(t *testing.T) {
}
}
func
TestEtcdUpdateStatus
(
t
*
testing
.
T
)
{
func
TestEtcdUpdateStatus
(
t
*
testing
.
T
)
{
storage
,
statusStorage
,
fakeClient
,
helper
:=
newStorage
(
t
)
storage
,
statusStorage
,
fakeClient
,
etcdStorage
:=
newStorage
(
t
)
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
fakeClient
.
TestIndex
=
true
fakeClient
.
TestIndex
=
true
...
@@ -357,7 +357,7 @@ func TestEtcdUpdateStatus(t *testing.T) {
...
@@ -357,7 +357,7 @@ func TestEtcdUpdateStatus(t *testing.T) {
}
}
var
pvcOut
api
.
PersistentVolumeClaim
var
pvcOut
api
.
PersistentVolumeClaim
key
,
_
=
storage
.
KeyFunc
(
ctx
,
"foo"
)
key
,
_
=
storage
.
KeyFunc
(
ctx
,
"foo"
)
if
err
:=
helper
.
ExtractObj
(
key
,
&
pvcOut
,
false
);
err
!=
nil
{
if
err
:=
etcdStorage
.
ExtractObj
(
key
,
&
pvcOut
,
false
);
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
if
!
api
.
Semantic
.
DeepEqual
(
expected
,
pvcOut
)
{
if
!
api
.
Semantic
.
DeepEqual
(
expected
,
pvcOut
)
{
...
...
pkg/registry/pod/etcd/etcd.go
View file @
7cc1855c
...
@@ -55,7 +55,7 @@ type REST struct {
...
@@ -55,7 +55,7 @@ type REST struct {
}
}
// NewStorage returns a RESTStorage object that will work against pods.
// NewStorage returns a RESTStorage object that will work against pods.
func
NewStorage
(
h
tools
.
EtcdHelper
,
k
client
.
ConnectionInfoGetter
)
PodStorage
{
func
NewStorage
(
s
tools
.
StorageInterface
,
k
client
.
ConnectionInfoGetter
)
PodStorage
{
prefix
:=
"/pods"
prefix
:=
"/pods"
store
:=
&
etcdgeneric
.
Etcd
{
store
:=
&
etcdgeneric
.
Etcd
{
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
Pod
{}
},
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
Pod
{}
},
...
@@ -74,7 +74,7 @@ func NewStorage(h tools.EtcdHelper, k client.ConnectionInfoGetter) PodStorage {
...
@@ -74,7 +74,7 @@ func NewStorage(h tools.EtcdHelper, k client.ConnectionInfoGetter) PodStorage {
},
},
EndpointName
:
"pods"
,
EndpointName
:
"pods"
,
Helper
:
h
,
Storage
:
s
,
}
}
statusStore
:=
*
store
statusStore
:=
*
store
...
@@ -142,7 +142,7 @@ func (r *BindingREST) setPodHostAndAnnotations(ctx api.Context, podID, oldMachin
...
@@ -142,7 +142,7 @@ func (r *BindingREST) setPodHostAndAnnotations(ctx api.Context, podID, oldMachin
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
err
=
r
.
store
.
Helper
.
GuaranteedUpdate
(
podKey
,
&
api
.
Pod
{},
false
,
tools
.
SimpleUpdate
(
func
(
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
err
=
r
.
store
.
Storage
.
GuaranteedUpdate
(
podKey
,
&
api
.
Pod
{},
false
,
tools
.
SimpleUpdate
(
func
(
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
pod
,
ok
:=
obj
.
(
*
api
.
Pod
)
pod
,
ok
:=
obj
.
(
*
api
.
Pod
)
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"unexpected object: %#v"
,
obj
)
return
nil
,
fmt
.
Errorf
(
"unexpected object: %#v"
,
obj
)
...
...
pkg/registry/pod/etcd/etcd_test.go
View file @
7cc1855c
...
@@ -40,17 +40,17 @@ import (
...
@@ -40,17 +40,17 @@ import (
"github.com/coreos/go-etcd/etcd"
"github.com/coreos/go-etcd/etcd"
)
)
func
new
Helper
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
EtcdHelper
)
{
func
new
EtcdStorage
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
StorageInterface
)
{
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
.
TestIndex
=
true
fakeEtcdClient
.
TestIndex
=
true
helper
:=
tools
.
NewEtcdHelper
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
etcdStorage
:=
tools
.
NewEtcdStorage
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
return
fakeEtcdClient
,
helper
return
fakeEtcdClient
,
etcdStorage
}
}
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
BindingREST
,
*
StatusREST
,
*
tools
.
FakeEtcdClient
,
tools
.
EtcdHelper
)
{
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
BindingREST
,
*
StatusREST
,
*
tools
.
FakeEtcdClient
,
tools
.
StorageInterface
)
{
fakeEtcdClient
,
h
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
:=
NewStorage
(
h
,
nil
)
storage
:=
NewStorage
(
etcdStorage
,
nil
)
return
storage
.
Pod
,
storage
.
Binding
,
storage
.
Status
,
fakeEtcdClient
,
h
return
storage
.
Pod
,
storage
.
Binding
,
storage
.
Status
,
fakeEtcdClient
,
etcdStorage
}
}
func
validNewPod
()
*
api
.
Pod
{
func
validNewPod
()
*
api
.
Pod
{
...
@@ -91,8 +91,8 @@ func TestStorage(t *testing.T) {
...
@@ -91,8 +91,8 @@ func TestStorage(t *testing.T) {
}
}
func
TestCreate
(
t
*
testing
.
T
)
{
func
TestCreate
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
:=
NewStorage
(
helper
,
nil
)
.
Pod
storage
:=
NewStorage
(
etcdStorage
,
nil
)
.
Pod
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
pod
:=
validNewPod
()
pod
:=
validNewPod
()
pod
.
ObjectMeta
=
api
.
ObjectMeta
{}
pod
.
ObjectMeta
=
api
.
ObjectMeta
{}
...
@@ -109,8 +109,8 @@ func TestCreate(t *testing.T) {
...
@@ -109,8 +109,8 @@ func TestCreate(t *testing.T) {
}
}
func
TestDelete
(
t
*
testing
.
T
)
{
func
TestDelete
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
:=
NewStorage
(
helper
,
nil
)
.
Pod
storage
:=
NewStorage
(
etcdStorage
,
nil
)
.
Pod
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
key
,
_
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
key
,
_
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
...
@@ -147,9 +147,9 @@ func expectPod(t *testing.T, out runtime.Object) (*api.Pod, bool) {
...
@@ -147,9 +147,9 @@ func expectPod(t *testing.T, out runtime.Object) (*api.Pod, bool) {
}
}
func
TestCreateRegistryError
(
t
*
testing
.
T
)
{
func
TestCreateRegistryError
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
fakeEtcdClient
.
Err
=
fmt
.
Errorf
(
"test error"
)
fakeEtcdClient
.
Err
=
fmt
.
Errorf
(
"test error"
)
storage
:=
NewStorage
(
helper
,
nil
)
.
Pod
storage
:=
NewStorage
(
etcdStorage
,
nil
)
.
Pod
pod
:=
validNewPod
()
pod
:=
validNewPod
()
_
,
err
:=
storage
.
Create
(
api
.
NewDefaultContext
(),
pod
)
_
,
err
:=
storage
.
Create
(
api
.
NewDefaultContext
(),
pod
)
...
@@ -159,8 +159,8 @@ func TestCreateRegistryError(t *testing.T) {
...
@@ -159,8 +159,8 @@ func TestCreateRegistryError(t *testing.T) {
}
}
func
TestCreateSetsFields
(
t
*
testing
.
T
)
{
func
TestCreateSetsFields
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
:=
NewStorage
(
helper
,
nil
)
.
Pod
storage
:=
NewStorage
(
etcdStorage
,
nil
)
.
Pod
pod
:=
validNewPod
()
pod
:=
validNewPod
()
_
,
err
:=
storage
.
Create
(
api
.
NewDefaultContext
(),
pod
)
_
,
err
:=
storage
.
Create
(
api
.
NewDefaultContext
(),
pod
)
if
err
!=
fakeEtcdClient
.
Err
{
if
err
!=
fakeEtcdClient
.
Err
{
...
@@ -169,7 +169,7 @@ func TestCreateSetsFields(t *testing.T) {
...
@@ -169,7 +169,7 @@ func TestCreateSetsFields(t *testing.T) {
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
key
,
_
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
key
,
_
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
actual
:=
&
api
.
Pod
{}
actual
:=
&
api
.
Pod
{}
if
err
:=
helper
.
ExtractObj
(
key
,
actual
,
false
);
err
!=
nil
{
if
err
:=
etcdStorage
.
ExtractObj
(
key
,
actual
,
false
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected extraction error: %v"
,
err
)
t
.
Fatalf
(
"unexpected extraction error: %v"
,
err
)
}
}
if
actual
.
Name
!=
pod
.
Name
{
if
actual
.
Name
!=
pod
.
Name
{
...
@@ -181,9 +181,9 @@ func TestCreateSetsFields(t *testing.T) {
...
@@ -181,9 +181,9 @@ func TestCreateSetsFields(t *testing.T) {
}
}
func
TestListError
(
t
*
testing
.
T
)
{
func
TestListError
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
fakeEtcdClient
.
Err
=
fmt
.
Errorf
(
"test error"
)
fakeEtcdClient
.
Err
=
fmt
.
Errorf
(
"test error"
)
storage
:=
NewStorage
(
helper
,
nil
)
.
Pod
storage
:=
NewStorage
(
etcdStorage
,
nil
)
.
Pod
pods
,
err
:=
storage
.
List
(
api
.
NewDefaultContext
(),
labels
.
Everything
(),
fields
.
Everything
())
pods
,
err
:=
storage
.
List
(
api
.
NewDefaultContext
(),
labels
.
Everything
(),
fields
.
Everything
())
if
err
!=
fakeEtcdClient
.
Err
{
if
err
!=
fakeEtcdClient
.
Err
{
t
.
Fatalf
(
"Expected %#v, Got %#v"
,
fakeEtcdClient
.
Err
,
err
)
t
.
Fatalf
(
"Expected %#v, Got %#v"
,
fakeEtcdClient
.
Err
,
err
)
...
@@ -194,10 +194,10 @@ func TestListError(t *testing.T) {
...
@@ -194,10 +194,10 @@ func TestListError(t *testing.T) {
}
}
func
TestListEmptyPodList
(
t
*
testing
.
T
)
{
func
TestListEmptyPodList
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
fakeEtcdClient
.
ChangeIndex
=
1
fakeEtcdClient
.
ChangeIndex
=
1
ctx
:=
api
.
NewContext
()
ctx
:=
api
.
NewContext
()
storage
:=
NewStorage
(
helper
,
nil
)
.
Pod
storage
:=
NewStorage
(
etcdStorage
,
nil
)
.
Pod
key
:=
storage
.
Etcd
.
KeyRootFunc
(
ctx
)
key
:=
storage
.
Etcd
.
KeyRootFunc
(
ctx
)
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
...
@@ -219,9 +219,9 @@ func TestListEmptyPodList(t *testing.T) {
...
@@ -219,9 +219,9 @@ func TestListEmptyPodList(t *testing.T) {
}
}
func
TestListPodList
(
t
*
testing
.
T
)
{
func
TestListPodList
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
storage
:=
NewStorage
(
helper
,
nil
)
.
Pod
storage
:=
NewStorage
(
etcdStorage
,
nil
)
.
Pod
key
:=
storage
.
Etcd
.
KeyRootFunc
(
ctx
)
key
:=
storage
.
Etcd
.
KeyRootFunc
(
ctx
)
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
...
@@ -264,9 +264,9 @@ func TestListPodList(t *testing.T) {
...
@@ -264,9 +264,9 @@ func TestListPodList(t *testing.T) {
}
}
func
TestListPodListSelection
(
t
*
testing
.
T
)
{
func
TestListPodListSelection
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
storage
:=
NewStorage
(
helper
,
nil
)
.
Pod
storage
:=
NewStorage
(
etcdStorage
,
nil
)
.
Pod
rootKey
:=
etcdtest
.
AddPrefix
(
"pods/default"
)
rootKey
:=
etcdtest
.
AddPrefix
(
"pods/default"
)
key
:=
etcdtest
.
AddPrefix
(
"pods/default/zot"
)
key
:=
etcdtest
.
AddPrefix
(
"pods/default/zot"
)
fakeEtcdClient
.
Data
[
rootKey
]
=
tools
.
EtcdResponseWithError
{
fakeEtcdClient
.
Data
[
rootKey
]
=
tools
.
EtcdResponseWithError
{
...
@@ -368,7 +368,8 @@ func TestListPodListSelection(t *testing.T) {
...
@@ -368,7 +368,8 @@ func TestListPodListSelection(t *testing.T) {
}
}
func
TestPodDecode
(
t
*
testing
.
T
)
{
func
TestPodDecode
(
t
*
testing
.
T
)
{
storage
:=
NewStorage
(
tools
.
EtcdHelper
{},
nil
)
.
Pod
_
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
:=
NewStorage
(
etcdStorage
,
nil
)
.
Pod
expected
:=
validNewPod
()
expected
:=
validNewPod
()
body
,
err
:=
latest
.
Codec
.
Encode
(
expected
)
body
,
err
:=
latest
.
Codec
.
Encode
(
expected
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -390,7 +391,7 @@ func TestGet(t *testing.T) {
...
@@ -390,7 +391,7 @@ func TestGet(t *testing.T) {
expect
.
Status
.
Phase
=
api
.
PodRunning
expect
.
Status
.
Phase
=
api
.
PodRunning
expect
.
Spec
.
NodeName
=
"machine"
expect
.
Spec
.
NodeName
=
"machine"
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
key
:=
etcdtest
.
AddPrefix
(
"/pods/test/foo"
)
key
:=
etcdtest
.
AddPrefix
(
"/pods/test/foo"
)
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{
R
:
&
etcd
.
Response
{
...
@@ -399,7 +400,7 @@ func TestGet(t *testing.T) {
...
@@ -399,7 +400,7 @@ func TestGet(t *testing.T) {
},
},
},
},
}
}
storage
:=
NewStorage
(
helper
,
nil
)
.
Pod
storage
:=
NewStorage
(
etcdStorage
,
nil
)
.
Pod
obj
,
err
:=
storage
.
Get
(
api
.
WithNamespace
(
api
.
NewContext
(),
"test"
),
"foo"
)
obj
,
err
:=
storage
.
Get
(
api
.
WithNamespace
(
api
.
NewContext
(),
"test"
),
"foo"
)
pod
:=
obj
.
(
*
api
.
Pod
)
pod
:=
obj
.
(
*
api
.
Pod
)
...
@@ -414,9 +415,9 @@ func TestGet(t *testing.T) {
...
@@ -414,9 +415,9 @@ func TestGet(t *testing.T) {
// TODO: remove, this is covered by RESTTest.TestCreate
// TODO: remove, this is covered by RESTTest.TestCreate
func
TestPodStorageValidatesCreate
(
t
*
testing
.
T
)
{
func
TestPodStorageValidatesCreate
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
fakeEtcdClient
.
Err
=
fmt
.
Errorf
(
"test error"
)
fakeEtcdClient
.
Err
=
fmt
.
Errorf
(
"test error"
)
storage
:=
NewStorage
(
helper
,
nil
)
.
Pod
storage
:=
NewStorage
(
etcdStorage
,
nil
)
.
Pod
pod
:=
validNewPod
()
pod
:=
validNewPod
()
pod
.
Labels
=
map
[
string
]
string
{
pod
.
Labels
=
map
[
string
]
string
{
...
@@ -433,8 +434,8 @@ func TestPodStorageValidatesCreate(t *testing.T) {
...
@@ -433,8 +434,8 @@ func TestPodStorageValidatesCreate(t *testing.T) {
// TODO: remove, this is covered by RESTTest.TestCreate
// TODO: remove, this is covered by RESTTest.TestCreate
func
TestCreatePod
(
t
*
testing
.
T
)
{
func
TestCreatePod
(
t
*
testing
.
T
)
{
_
,
helper
:=
newHelper
(
t
)
_
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
:=
NewStorage
(
helper
,
nil
)
.
Pod
storage
:=
NewStorage
(
etcdStorage
,
nil
)
.
Pod
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
key
,
_
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
key
,
_
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
...
@@ -447,7 +448,7 @@ func TestCreatePod(t *testing.T) {
...
@@ -447,7 +448,7 @@ func TestCreatePod(t *testing.T) {
t
.
Fatalf
(
"unexpected object: %#v"
,
obj
)
t
.
Fatalf
(
"unexpected object: %#v"
,
obj
)
}
}
actual
:=
&
api
.
Pod
{}
actual
:=
&
api
.
Pod
{}
if
err
:=
helper
.
ExtractObj
(
key
,
actual
,
false
);
err
!=
nil
{
if
err
:=
etcdStorage
.
ExtractObj
(
key
,
actual
,
false
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected extraction error: %v"
,
err
)
t
.
Fatalf
(
"unexpected extraction error: %v"
,
err
)
}
}
if
!
api
.
HasObjectMetaSystemFieldValues
(
&
actual
.
ObjectMeta
)
{
if
!
api
.
HasObjectMetaSystemFieldValues
(
&
actual
.
ObjectMeta
)
{
...
@@ -457,8 +458,8 @@ func TestCreatePod(t *testing.T) {
...
@@ -457,8 +458,8 @@ func TestCreatePod(t *testing.T) {
// TODO: remove, this is covered by RESTTest.TestCreate
// TODO: remove, this is covered by RESTTest.TestCreate
func
TestCreateWithConflictingNamespace
(
t
*
testing
.
T
)
{
func
TestCreateWithConflictingNamespace
(
t
*
testing
.
T
)
{
_
,
helper
:=
newHelper
(
t
)
_
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
:=
NewStorage
(
helper
,
nil
)
.
Pod
storage
:=
NewStorage
(
etcdStorage
,
nil
)
.
Pod
pod
:=
validNewPod
()
pod
:=
validNewPod
()
pod
.
Namespace
=
"not-default"
pod
.
Namespace
=
"not-default"
...
@@ -475,8 +476,8 @@ func TestCreateWithConflictingNamespace(t *testing.T) {
...
@@ -475,8 +476,8 @@ func TestCreateWithConflictingNamespace(t *testing.T) {
}
}
func
TestUpdateWithConflictingNamespace
(
t
*
testing
.
T
)
{
func
TestUpdateWithConflictingNamespace
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
:=
NewStorage
(
helper
,
nil
)
.
Pod
storage
:=
NewStorage
(
etcdStorage
,
nil
)
.
Pod
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
key
,
_
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
key
,
_
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
...
@@ -600,8 +601,8 @@ func TestResourceLocation(t *testing.T) {
...
@@ -600,8 +601,8 @@ func TestResourceLocation(t *testing.T) {
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
for
_
,
tc
:=
range
testCases
{
for
_
,
tc
:=
range
testCases
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
:=
NewStorage
(
helper
,
nil
)
.
Pod
storage
:=
NewStorage
(
etcdStorage
,
nil
)
.
Pod
key
,
_
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
key
,
_
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
...
@@ -631,9 +632,9 @@ func TestResourceLocation(t *testing.T) {
...
@@ -631,9 +632,9 @@ func TestResourceLocation(t *testing.T) {
}
}
func
TestDeletePod
(
t
*
testing
.
T
)
{
func
TestDeletePod
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
fakeEtcdClient
.
ChangeIndex
=
1
fakeEtcdClient
.
ChangeIndex
=
1
storage
:=
NewStorage
(
helper
,
nil
)
.
Pod
storage
:=
NewStorage
(
etcdStorage
,
nil
)
.
Pod
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
key
,
_
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
key
,
_
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
...
@@ -1158,7 +1159,7 @@ func TestEtcdUpdateScheduled(t *testing.T) {
...
@@ -1158,7 +1159,7 @@ func TestEtcdUpdateScheduled(t *testing.T) {
}
}
func
TestEtcdUpdateStatus
(
t
*
testing
.
T
)
{
func
TestEtcdUpdateStatus
(
t
*
testing
.
T
)
{
registry
,
_
,
status
,
fakeClient
,
helper
:=
newStorage
(
t
)
registry
,
_
,
status
,
fakeClient
,
etcdStorage
:=
newStorage
(
t
)
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
fakeClient
.
TestIndex
=
true
fakeClient
.
TestIndex
=
true
...
@@ -1221,7 +1222,7 @@ func TestEtcdUpdateStatus(t *testing.T) {
...
@@ -1221,7 +1222,7 @@ func TestEtcdUpdateStatus(t *testing.T) {
}
}
var
podOut
api
.
Pod
var
podOut
api
.
Pod
key
,
_
=
registry
.
KeyFunc
(
ctx
,
"foo"
)
key
,
_
=
registry
.
KeyFunc
(
ctx
,
"foo"
)
if
err
:=
helper
.
ExtractObj
(
key
,
&
podOut
,
false
);
err
!=
nil
{
if
err
:=
etcdStorage
.
ExtractObj
(
key
,
&
podOut
,
false
);
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
if
!
api
.
Semantic
.
DeepEqual
(
expected
,
podOut
)
{
if
!
api
.
Semantic
.
DeepEqual
(
expected
,
podOut
)
{
...
...
pkg/registry/podtemplate/etcd/etcd.go
View file @
7cc1855c
...
@@ -33,7 +33,7 @@ type REST struct {
...
@@ -33,7 +33,7 @@ type REST struct {
}
}
// NewREST returns a RESTStorage object that will work against pod templates.
// NewREST returns a RESTStorage object that will work against pod templates.
func
NewREST
(
h
tools
.
EtcdHelper
)
*
REST
{
func
NewREST
(
s
tools
.
StorageInterface
)
*
REST
{
prefix
:=
"/podtemplates"
prefix
:=
"/podtemplates"
store
:=
etcdgeneric
.
Etcd
{
store
:=
etcdgeneric
.
Etcd
{
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
PodTemplate
{}
},
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
PodTemplate
{}
},
...
@@ -56,7 +56,7 @@ func NewREST(h tools.EtcdHelper) *REST {
...
@@ -56,7 +56,7 @@ func NewREST(h tools.EtcdHelper) *REST {
UpdateStrategy
:
podtemplate
.
Strategy
,
UpdateStrategy
:
podtemplate
.
Strategy
,
ReturnDeletedObject
:
true
,
ReturnDeletedObject
:
true
,
Helper
:
h
,
Storage
:
s
,
}
}
return
&
REST
{
store
}
return
&
REST
{
store
}
...
...
pkg/registry/podtemplate/etcd/etcd_test.go
View file @
7cc1855c
...
@@ -26,11 +26,11 @@ import (
...
@@ -26,11 +26,11 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
)
)
func
new
Helper
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
EtcdHelper
)
{
func
new
EtcdStorage
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
StorageInterface
)
{
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
.
TestIndex
=
true
fakeEtcdClient
.
TestIndex
=
true
helper
:=
tools
.
NewEtcdHelper
(
fakeEtcdClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
etcdStorage
:=
tools
.
NewEtcdStorage
(
fakeEtcdClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
return
fakeEtcdClient
,
helper
return
fakeEtcdClient
,
etcdStorage
}
}
func
validNewPodTemplate
(
name
string
)
*
api
.
PodTemplate
{
func
validNewPodTemplate
(
name
string
)
*
api
.
PodTemplate
{
...
@@ -61,8 +61,8 @@ func validNewPodTemplate(name string) *api.PodTemplate {
...
@@ -61,8 +61,8 @@ func validNewPodTemplate(name string) *api.PodTemplate {
}
}
func
TestCreate
(
t
*
testing
.
T
)
{
func
TestCreate
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
:=
NewREST
(
helper
)
storage
:=
NewREST
(
etcdStorage
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
pod
:=
validNewPodTemplate
(
"foo"
)
pod
:=
validNewPodTemplate
(
"foo"
)
pod
.
ObjectMeta
=
api
.
ObjectMeta
{}
pod
.
ObjectMeta
=
api
.
ObjectMeta
{}
...
@@ -77,8 +77,8 @@ func TestCreate(t *testing.T) {
...
@@ -77,8 +77,8 @@ func TestCreate(t *testing.T) {
}
}
func
TestUpdate
(
t
*
testing
.
T
)
{
func
TestUpdate
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
:=
NewREST
(
helper
)
storage
:=
NewREST
(
etcdStorage
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
key
,
err
:=
storage
.
KeyFunc
(
test
.
TestContext
(),
"foo"
)
key
,
err
:=
storage
.
KeyFunc
(
test
.
TestContext
(),
"foo"
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/registry/resourcequota/etcd/etcd.go
View file @
7cc1855c
...
@@ -33,7 +33,7 @@ type REST struct {
...
@@ -33,7 +33,7 @@ type REST struct {
}
}
// NewStorage returns a RESTStorage object that will work against ResourceQuota objects.
// NewStorage returns a RESTStorage object that will work against ResourceQuota objects.
func
NewStorage
(
h
tools
.
EtcdHelper
)
(
*
REST
,
*
StatusREST
)
{
func
NewStorage
(
s
tools
.
StorageInterface
)
(
*
REST
,
*
StatusREST
)
{
prefix
:=
"/resourcequotas"
prefix
:=
"/resourcequotas"
store
:=
&
etcdgeneric
.
Etcd
{
store
:=
&
etcdgeneric
.
Etcd
{
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
ResourceQuota
{}
},
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
ResourceQuota
{}
},
...
@@ -52,7 +52,7 @@ func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST) {
...
@@ -52,7 +52,7 @@ func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST) {
},
},
EndpointName
:
"resourcequotas"
,
EndpointName
:
"resourcequotas"
,
Helper
:
h
,
Storage
:
s
,
}
}
store
.
CreateStrategy
=
resourcequota
.
Strategy
store
.
CreateStrategy
=
resourcequota
.
Strategy
...
...
pkg/registry/resourcequota/etcd/etcd_test.go
View file @
7cc1855c
...
@@ -38,15 +38,15 @@ import (
...
@@ -38,15 +38,15 @@ import (
"github.com/coreos/go-etcd/etcd"
"github.com/coreos/go-etcd/etcd"
)
)
func
new
Helper
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
EtcdHelper
)
{
func
new
EtcdStorage
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
StorageInterface
)
{
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
.
TestIndex
=
true
fakeEtcdClient
.
TestIndex
=
true
helper
:=
tools
.
NewEtcdHelper
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
etcdStorage
:=
tools
.
NewEtcdStorage
(
fakeEtcdClient
,
latest
.
Codec
,
etcdtest
.
PathPrefix
())
return
fakeEtcdClient
,
helper
return
fakeEtcdClient
,
etcdStorage
}
}
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
StatusREST
,
*
tools
.
FakeEtcdClient
,
tools
.
EtcdHelper
)
{
func
newStorage
(
t
*
testing
.
T
)
(
*
REST
,
*
StatusREST
,
*
tools
.
FakeEtcdClient
,
tools
.
StorageInterface
)
{
fakeEtcdClient
,
h
:=
new
Helper
(
t
)
fakeEtcdClient
,
h
:=
new
EtcdStorage
(
t
)
storage
,
statusStorage
:=
NewStorage
(
h
)
storage
,
statusStorage
:=
NewStorage
(
h
)
return
storage
,
statusStorage
,
fakeEtcdClient
,
h
return
storage
,
statusStorage
,
fakeEtcdClient
,
h
}
}
...
@@ -85,8 +85,8 @@ func TestStorage(t *testing.T) {
...
@@ -85,8 +85,8 @@ func TestStorage(t *testing.T) {
}
}
func
TestCreate
(
t
*
testing
.
T
)
{
func
TestCreate
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
,
_
:=
NewStorage
(
helper
)
storage
,
_
:=
NewStorage
(
etcdStorage
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
resourcequota
:=
validNewResourceQuota
()
resourcequota
:=
validNewResourceQuota
()
resourcequota
.
ObjectMeta
=
api
.
ObjectMeta
{}
resourcequota
.
ObjectMeta
=
api
.
ObjectMeta
{}
...
@@ -110,9 +110,9 @@ func expectResourceQuota(t *testing.T, out runtime.Object) (*api.ResourceQuota,
...
@@ -110,9 +110,9 @@ func expectResourceQuota(t *testing.T, out runtime.Object) (*api.ResourceQuota,
}
}
func
TestCreateRegistryError
(
t
*
testing
.
T
)
{
func
TestCreateRegistryError
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
fakeEtcdClient
.
Err
=
fmt
.
Errorf
(
"test error"
)
fakeEtcdClient
.
Err
=
fmt
.
Errorf
(
"test error"
)
storage
,
_
:=
NewStorage
(
helper
)
storage
,
_
:=
NewStorage
(
etcdStorage
)
resourcequota
:=
validNewResourceQuota
()
resourcequota
:=
validNewResourceQuota
()
_
,
err
:=
storage
.
Create
(
api
.
NewDefaultContext
(),
resourcequota
)
_
,
err
:=
storage
.
Create
(
api
.
NewDefaultContext
(),
resourcequota
)
...
@@ -122,8 +122,8 @@ func TestCreateRegistryError(t *testing.T) {
...
@@ -122,8 +122,8 @@ func TestCreateRegistryError(t *testing.T) {
}
}
func
TestCreateSetsFields
(
t
*
testing
.
T
)
{
func
TestCreateSetsFields
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
,
_
:=
NewStorage
(
helper
)
storage
,
_
:=
NewStorage
(
etcdStorage
)
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
resourcequota
:=
validNewResourceQuota
()
resourcequota
:=
validNewResourceQuota
()
_
,
err
:=
storage
.
Create
(
api
.
NewDefaultContext
(),
resourcequota
)
_
,
err
:=
storage
.
Create
(
api
.
NewDefaultContext
(),
resourcequota
)
...
@@ -133,7 +133,7 @@ func TestCreateSetsFields(t *testing.T) {
...
@@ -133,7 +133,7 @@ func TestCreateSetsFields(t *testing.T) {
actual
:=
&
api
.
ResourceQuota
{}
actual
:=
&
api
.
ResourceQuota
{}
key
,
_
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
key
,
_
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
if
err
:=
helper
.
ExtractObj
(
key
,
actual
,
false
);
err
!=
nil
{
if
err
:=
etcdStorage
.
ExtractObj
(
key
,
actual
,
false
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected extraction error: %v"
,
err
)
t
.
Fatalf
(
"unexpected extraction error: %v"
,
err
)
}
}
if
actual
.
Name
!=
resourcequota
.
Name
{
if
actual
.
Name
!=
resourcequota
.
Name
{
...
@@ -145,9 +145,9 @@ func TestCreateSetsFields(t *testing.T) {
...
@@ -145,9 +145,9 @@ func TestCreateSetsFields(t *testing.T) {
}
}
func
TestListError
(
t
*
testing
.
T
)
{
func
TestListError
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
fakeEtcdClient
.
Err
=
fmt
.
Errorf
(
"test error"
)
fakeEtcdClient
.
Err
=
fmt
.
Errorf
(
"test error"
)
storage
,
_
:=
NewStorage
(
helper
)
storage
,
_
:=
NewStorage
(
etcdStorage
)
resourcequotas
,
err
:=
storage
.
List
(
api
.
NewDefaultContext
(),
labels
.
Everything
(),
fields
.
Everything
())
resourcequotas
,
err
:=
storage
.
List
(
api
.
NewDefaultContext
(),
labels
.
Everything
(),
fields
.
Everything
())
if
err
!=
fakeEtcdClient
.
Err
{
if
err
!=
fakeEtcdClient
.
Err
{
t
.
Fatalf
(
"Expected %#v, Got %#v"
,
fakeEtcdClient
.
Err
,
err
)
t
.
Fatalf
(
"Expected %#v, Got %#v"
,
fakeEtcdClient
.
Err
,
err
)
...
@@ -158,9 +158,9 @@ func TestListError(t *testing.T) {
...
@@ -158,9 +158,9 @@ func TestListError(t *testing.T) {
}
}
func
TestListEmptyResourceQuotaList
(
t
*
testing
.
T
)
{
func
TestListEmptyResourceQuotaList
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
fakeEtcdClient
.
ChangeIndex
=
1
fakeEtcdClient
.
ChangeIndex
=
1
storage
,
_
:=
NewStorage
(
helper
)
storage
,
_
:=
NewStorage
(
etcdStorage
)
ctx
:=
api
.
NewContext
()
ctx
:=
api
.
NewContext
()
key
:=
storage
.
Etcd
.
KeyRootFunc
(
ctx
)
key
:=
storage
.
Etcd
.
KeyRootFunc
(
ctx
)
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
...
@@ -184,8 +184,8 @@ func TestListEmptyResourceQuotaList(t *testing.T) {
...
@@ -184,8 +184,8 @@ func TestListEmptyResourceQuotaList(t *testing.T) {
}
}
func
TestListResourceQuotaList
(
t
*
testing
.
T
)
{
func
TestListResourceQuotaList
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
,
_
:=
NewStorage
(
helper
)
storage
,
_
:=
NewStorage
(
etcdStorage
)
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
key
:=
storage
.
Etcd
.
KeyRootFunc
(
ctx
)
key
:=
storage
.
Etcd
.
KeyRootFunc
(
ctx
)
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
...
@@ -225,8 +225,8 @@ func TestListResourceQuotaList(t *testing.T) {
...
@@ -225,8 +225,8 @@ func TestListResourceQuotaList(t *testing.T) {
}
}
func
TestListResourceQuotaListSelection
(
t
*
testing
.
T
)
{
func
TestListResourceQuotaListSelection
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
,
_
:=
NewStorage
(
helper
)
storage
,
_
:=
NewStorage
(
etcdStorage
)
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
key
:=
storage
.
Etcd
.
KeyRootFunc
(
ctx
)
key
:=
storage
.
Etcd
.
KeyRootFunc
(
ctx
)
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
...
@@ -294,7 +294,8 @@ func TestListResourceQuotaListSelection(t *testing.T) {
...
@@ -294,7 +294,8 @@ func TestListResourceQuotaListSelection(t *testing.T) {
}
}
func
TestResourceQuotaDecode
(
t
*
testing
.
T
)
{
func
TestResourceQuotaDecode
(
t
*
testing
.
T
)
{
storage
,
_
:=
NewStorage
(
tools
.
EtcdHelper
{})
_
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
,
_
:=
NewStorage
(
etcdStorage
)
expected
:=
validNewResourceQuota
()
expected
:=
validNewResourceQuota
()
body
,
err
:=
latest
.
Codec
.
Encode
(
expected
)
body
,
err
:=
latest
.
Codec
.
Encode
(
expected
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -313,8 +314,8 @@ func TestResourceQuotaDecode(t *testing.T) {
...
@@ -313,8 +314,8 @@ func TestResourceQuotaDecode(t *testing.T) {
func
TestGet
(
t
*
testing
.
T
)
{
func
TestGet
(
t
*
testing
.
T
)
{
expect
:=
validNewResourceQuota
()
expect
:=
validNewResourceQuota
()
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
,
_
:=
NewStorage
(
helper
)
storage
,
_
:=
NewStorage
(
etcdStorage
)
key
:=
"/resourcequotas/test/foo"
key
:=
"/resourcequotas/test/foo"
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
fakeEtcdClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
...
@@ -336,9 +337,9 @@ func TestGet(t *testing.T) {
...
@@ -336,9 +337,9 @@ func TestGet(t *testing.T) {
}
}
func
TestDeleteResourceQuota
(
t
*
testing
.
T
)
{
func
TestDeleteResourceQuota
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
fakeEtcdClient
.
ChangeIndex
=
1
fakeEtcdClient
.
ChangeIndex
=
1
storage
,
_
:=
NewStorage
(
helper
)
storage
,
_
:=
NewStorage
(
etcdStorage
)
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
key
,
_
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
key
,
_
:=
storage
.
Etcd
.
KeyFunc
(
ctx
,
"foo"
)
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
...
@@ -470,7 +471,7 @@ func TestEtcdCreateAlreadyExisting(t *testing.T) {
...
@@ -470,7 +471,7 @@ func TestEtcdCreateAlreadyExisting(t *testing.T) {
}
}
func
TestEtcdUpdateStatus
(
t
*
testing
.
T
)
{
func
TestEtcdUpdateStatus
(
t
*
testing
.
T
)
{
registry
,
status
,
fakeClient
,
helper
:=
newStorage
(
t
)
registry
,
status
,
fakeClient
,
etcdStorage
:=
newStorage
(
t
)
ctx
:=
api
.
NewDefaultContext
()
ctx
:=
api
.
NewDefaultContext
()
fakeClient
.
TestIndex
=
true
fakeClient
.
TestIndex
=
true
...
@@ -516,7 +517,7 @@ func TestEtcdUpdateStatus(t *testing.T) {
...
@@ -516,7 +517,7 @@ func TestEtcdUpdateStatus(t *testing.T) {
}
}
var
resourcequotaOut
api
.
ResourceQuota
var
resourcequotaOut
api
.
ResourceQuota
key
,
_
=
registry
.
KeyFunc
(
ctx
,
"foo"
)
key
,
_
=
registry
.
KeyFunc
(
ctx
,
"foo"
)
if
err
:=
helper
.
ExtractObj
(
key
,
&
resourcequotaOut
,
false
);
err
!=
nil
{
if
err
:=
etcdStorage
.
ExtractObj
(
key
,
&
resourcequotaOut
,
false
);
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
if
!
api
.
Semantic
.
DeepEqual
(
expected
,
resourcequotaOut
)
{
if
!
api
.
Semantic
.
DeepEqual
(
expected
,
resourcequotaOut
)
{
...
...
pkg/registry/secret/etcd/etcd.go
View file @
7cc1855c
...
@@ -32,9 +32,8 @@ type REST struct {
...
@@ -32,9 +32,8 @@ type REST struct {
*
etcdgeneric
.
Etcd
*
etcdgeneric
.
Etcd
}
}
// NewStorage returns a registry which will store Secret in the given helper
// NewStorage returns a registry which will store Secret in the given etcdStorage
func
NewStorage
(
h
tools
.
EtcdHelper
)
*
REST
{
func
NewStorage
(
s
tools
.
StorageInterface
)
*
REST
{
prefix
:=
"/secrets"
prefix
:=
"/secrets"
store
:=
&
etcdgeneric
.
Etcd
{
store
:=
&
etcdgeneric
.
Etcd
{
...
@@ -54,7 +53,7 @@ func NewStorage(h tools.EtcdHelper) *REST {
...
@@ -54,7 +53,7 @@ func NewStorage(h tools.EtcdHelper) *REST {
},
},
EndpointName
:
"secrets"
,
EndpointName
:
"secrets"
,
Helper
:
h
,
Storage
:
s
,
}
}
store
.
CreateStrategy
=
secret
.
Strategy
store
.
CreateStrategy
=
secret
.
Strategy
...
...
pkg/registry/secret/etcd/etcd_test.go
View file @
7cc1855c
...
@@ -26,11 +26,11 @@ import (
...
@@ -26,11 +26,11 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
)
)
func
new
Helper
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
EtcdHelper
)
{
func
new
EtcdStorage
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
StorageInterface
)
{
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
.
TestIndex
=
true
fakeEtcdClient
.
TestIndex
=
true
helper
:=
tools
.
NewEtcdHelper
(
fakeEtcdClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
etcdStorage
:=
tools
.
NewEtcdStorage
(
fakeEtcdClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
return
fakeEtcdClient
,
helper
return
fakeEtcdClient
,
etcdStorage
}
}
func
validNewSecret
(
name
string
)
*
api
.
Secret
{
func
validNewSecret
(
name
string
)
*
api
.
Secret
{
...
@@ -46,8 +46,8 @@ func validNewSecret(name string) *api.Secret {
...
@@ -46,8 +46,8 @@ func validNewSecret(name string) *api.Secret {
}
}
func
TestCreate
(
t
*
testing
.
T
)
{
func
TestCreate
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
:=
NewStorage
(
helper
)
storage
:=
NewStorage
(
etcdStorage
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
secret
:=
validNewSecret
(
"foo"
)
secret
:=
validNewSecret
(
"foo"
)
secret
.
ObjectMeta
=
api
.
ObjectMeta
{
GenerateName
:
"foo-"
}
secret
.
ObjectMeta
=
api
.
ObjectMeta
{
GenerateName
:
"foo-"
}
...
@@ -68,8 +68,8 @@ func TestCreate(t *testing.T) {
...
@@ -68,8 +68,8 @@ func TestCreate(t *testing.T) {
}
}
func
TestUpdate
(
t
*
testing
.
T
)
{
func
TestUpdate
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
:=
NewStorage
(
helper
)
storage
:=
NewStorage
(
etcdStorage
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
key
,
err
:=
storage
.
KeyFunc
(
test
.
TestContext
(),
"foo"
)
key
,
err
:=
storage
.
KeyFunc
(
test
.
TestContext
(),
"foo"
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/registry/service/allocator/etcd/etcd.go
View file @
7cc1855c
...
@@ -41,9 +41,9 @@ var (
...
@@ -41,9 +41,9 @@ var (
type
Etcd
struct
{
type
Etcd
struct
{
lock
sync
.
Mutex
lock
sync
.
Mutex
alloc
allocator
.
Snapshottable
alloc
allocator
.
Snapshottable
helper
tools
.
EtcdHelper
storage
tools
.
StorageInterface
last
string
last
string
baseKey
string
baseKey
string
kind
string
kind
string
...
@@ -55,10 +55,10 @@ var _ service.RangeRegistry = &Etcd{}
...
@@ -55,10 +55,10 @@ var _ service.RangeRegistry = &Etcd{}
// NewEtcd returns an allocator that is backed by Etcd and can manage
// NewEtcd returns an allocator that is backed by Etcd and can manage
// persisting the snapshot state of allocation after each allocation is made.
// persisting the snapshot state of allocation after each allocation is made.
func
NewEtcd
(
alloc
allocator
.
Snapshottable
,
baseKey
string
,
kind
string
,
helper
tools
.
EtcdHelper
)
*
Etcd
{
func
NewEtcd
(
alloc
allocator
.
Snapshottable
,
baseKey
string
,
kind
string
,
storage
tools
.
StorageInterface
)
*
Etcd
{
return
&
Etcd
{
return
&
Etcd
{
alloc
:
alloc
,
alloc
:
alloc
,
helper
:
helper
,
storage
:
storage
,
baseKey
:
baseKey
,
baseKey
:
baseKey
,
kind
:
kind
,
kind
:
kind
,
}
}
...
@@ -140,7 +140,7 @@ func (e *Etcd) Release(item int) error {
...
@@ -140,7 +140,7 @@ func (e *Etcd) Release(item int) error {
// tryUpdate performs a read-update to persist the latest snapshot state of allocation.
// tryUpdate performs a read-update to persist the latest snapshot state of allocation.
func
(
e
*
Etcd
)
tryUpdate
(
fn
func
()
error
)
error
{
func
(
e
*
Etcd
)
tryUpdate
(
fn
func
()
error
)
error
{
err
:=
e
.
helper
.
GuaranteedUpdate
(
e
.
baseKey
,
&
api
.
RangeAllocation
{},
true
,
err
:=
e
.
storage
.
GuaranteedUpdate
(
e
.
baseKey
,
&
api
.
RangeAllocation
{},
true
,
tools
.
SimpleUpdate
(
func
(
input
runtime
.
Object
)
(
output
runtime
.
Object
,
err
error
)
{
tools
.
SimpleUpdate
(
func
(
input
runtime
.
Object
)
(
output
runtime
.
Object
,
err
error
)
{
existing
:=
input
.
(
*
api
.
RangeAllocation
)
existing
:=
input
.
(
*
api
.
RangeAllocation
)
if
len
(
existing
.
ResourceVersion
)
==
0
{
if
len
(
existing
.
ResourceVersion
)
==
0
{
...
@@ -170,7 +170,7 @@ func (e *Etcd) Refresh() (*api.RangeAllocation, error) {
...
@@ -170,7 +170,7 @@ func (e *Etcd) Refresh() (*api.RangeAllocation, error) {
defer
e
.
lock
.
Unlock
()
defer
e
.
lock
.
Unlock
()
existing
:=
&
api
.
RangeAllocation
{}
existing
:=
&
api
.
RangeAllocation
{}
if
err
:=
e
.
helper
.
ExtractObj
(
e
.
baseKey
,
existing
,
false
);
err
!=
nil
{
if
err
:=
e
.
storage
.
ExtractObj
(
e
.
baseKey
,
existing
,
false
);
err
!=
nil
{
if
tools
.
IsEtcdNotFound
(
err
)
{
if
tools
.
IsEtcdNotFound
(
err
)
{
return
nil
,
nil
return
nil
,
nil
}
}
...
@@ -184,7 +184,7 @@ func (e *Etcd) Refresh() (*api.RangeAllocation, error) {
...
@@ -184,7 +184,7 @@ func (e *Etcd) Refresh() (*api.RangeAllocation, error) {
// etcd. If the key does not exist, the object will have an empty ResourceVersion.
// etcd. If the key does not exist, the object will have an empty ResourceVersion.
func
(
e
*
Etcd
)
Get
()
(
*
api
.
RangeAllocation
,
error
)
{
func
(
e
*
Etcd
)
Get
()
(
*
api
.
RangeAllocation
,
error
)
{
existing
:=
&
api
.
RangeAllocation
{}
existing
:=
&
api
.
RangeAllocation
{}
if
err
:=
e
.
helper
.
ExtractObj
(
e
.
baseKey
,
existing
,
true
);
err
!=
nil
{
if
err
:=
e
.
storage
.
ExtractObj
(
e
.
baseKey
,
existing
,
true
);
err
!=
nil
{
return
nil
,
etcderr
.
InterpretGetError
(
err
,
e
.
kind
,
""
)
return
nil
,
etcderr
.
InterpretGetError
(
err
,
e
.
kind
,
""
)
}
}
return
existing
,
nil
return
existing
,
nil
...
@@ -197,7 +197,7 @@ func (e *Etcd) CreateOrUpdate(snapshot *api.RangeAllocation) error {
...
@@ -197,7 +197,7 @@ func (e *Etcd) CreateOrUpdate(snapshot *api.RangeAllocation) error {
defer
e
.
lock
.
Unlock
()
defer
e
.
lock
.
Unlock
()
last
:=
""
last
:=
""
err
:=
e
.
helper
.
GuaranteedUpdate
(
e
.
baseKey
,
&
api
.
RangeAllocation
{},
true
,
err
:=
e
.
storage
.
GuaranteedUpdate
(
e
.
baseKey
,
&
api
.
RangeAllocation
{},
true
,
tools
.
SimpleUpdate
(
func
(
input
runtime
.
Object
)
(
output
runtime
.
Object
,
err
error
)
{
tools
.
SimpleUpdate
(
func
(
input
runtime
.
Object
)
(
output
runtime
.
Object
,
err
error
)
{
existing
:=
input
.
(
*
api
.
RangeAllocation
)
existing
:=
input
.
(
*
api
.
RangeAllocation
)
switch
{
switch
{
...
...
pkg/registry/service/allocator/etcd/etcd_test.go
View file @
7cc1855c
...
@@ -30,18 +30,18 @@ import (
...
@@ -30,18 +30,18 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
)
)
func
new
Helper
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
EtcdHelper
)
{
func
new
EtcdStorage
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
StorageInterface
)
{
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
.
TestIndex
=
true
fakeEtcdClient
.
TestIndex
=
true
helper
:=
tools
.
NewEtcdHelper
(
fakeEtcdClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
etcdStorage
:=
tools
.
NewEtcdStorage
(
fakeEtcdClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
return
fakeEtcdClient
,
helper
return
fakeEtcdClient
,
etcdStorage
}
}
func
newStorage
(
t
*
testing
.
T
)
(
*
Etcd
,
allocator
.
Interface
,
*
tools
.
FakeEtcdClient
)
{
func
newStorage
(
t
*
testing
.
T
)
(
*
Etcd
,
allocator
.
Interface
,
*
tools
.
FakeEtcdClient
)
{
fakeEtcdClient
,
h
:=
newHelper
(
t
)
fakeEtcdClient
,
s
:=
newEtcdStorage
(
t
)
mem
:=
allocator
.
NewAllocationMap
(
100
,
"rangeSpecValue"
)
mem
:=
allocator
.
NewAllocationMap
(
100
,
"rangeSpecValue"
)
etcd
:=
NewEtcd
(
mem
,
"/ranges/serviceips"
,
"serviceipallocation"
,
h
)
etcd
:=
NewEtcd
(
mem
,
"/ranges/serviceips"
,
"serviceipallocation"
,
s
)
return
etcd
,
mem
,
fakeEtcdClient
return
etcd
,
mem
,
fakeEtcdClient
}
}
...
@@ -101,7 +101,7 @@ func TestStore(t *testing.T) {
...
@@ -101,7 +101,7 @@ func TestStore(t *testing.T) {
other
:=
allocator
.
NewAllocationMap
(
100
,
"rangeSpecValue"
)
other
:=
allocator
.
NewAllocationMap
(
100
,
"rangeSpecValue"
)
allocation
:=
&
api
.
RangeAllocation
{}
allocation
:=
&
api
.
RangeAllocation
{}
if
err
:=
storage
.
helper
.
ExtractObj
(
key
(),
allocation
,
false
);
err
!=
nil
{
if
err
:=
storage
.
storage
.
ExtractObj
(
key
(),
allocation
,
false
);
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
allocation
.
ResourceVersion
!=
"1"
{
if
allocation
.
ResourceVersion
!=
"1"
{
...
@@ -118,7 +118,7 @@ func TestStore(t *testing.T) {
...
@@ -118,7 +118,7 @@ func TestStore(t *testing.T) {
}
}
other
=
allocator
.
NewAllocationMap
(
100
,
"rangeSpecValue"
)
other
=
allocator
.
NewAllocationMap
(
100
,
"rangeSpecValue"
)
otherStorage
:=
NewEtcd
(
other
,
"/ranges/serviceips"
,
"serviceipallocation"
,
storage
.
helper
)
otherStorage
:=
NewEtcd
(
other
,
"/ranges/serviceips"
,
"serviceipallocation"
,
storage
.
storage
)
if
ok
,
err
:=
otherStorage
.
Allocate
(
2
);
ok
||
err
!=
nil
{
if
ok
,
err
:=
otherStorage
.
Allocate
(
2
);
ok
||
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
...
pkg/registry/service/ipallocator/etcd/etcd_test.go
View file @
7cc1855c
...
@@ -33,15 +33,15 @@ import (
...
@@ -33,15 +33,15 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
)
)
func
new
Helper
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
EtcdHelper
)
{
func
new
EtcdStorage
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
StorageInterface
)
{
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
.
TestIndex
=
true
fakeEtcdClient
.
TestIndex
=
true
helper
:=
tools
.
NewEtcdHelper
(
fakeEtcdClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
etcdStorage
:=
tools
.
NewEtcdStorage
(
fakeEtcdClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
return
fakeEtcdClient
,
helper
return
fakeEtcdClient
,
etcdStorage
}
}
func
newStorage
(
t
*
testing
.
T
)
(
ipallocator
.
Interface
,
allocator
.
Interface
,
*
tools
.
FakeEtcdClient
)
{
func
newStorage
(
t
*
testing
.
T
)
(
ipallocator
.
Interface
,
allocator
.
Interface
,
*
tools
.
FakeEtcdClient
)
{
fakeEtcdClient
,
h
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
_
,
cidr
,
err
:=
net
.
ParseCIDR
(
"192.168.1.0/24"
)
_
,
cidr
,
err
:=
net
.
ParseCIDR
(
"192.168.1.0/24"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
@@ -51,7 +51,7 @@ func newStorage(t *testing.T) (ipallocator.Interface, allocator.Interface, *tool
...
@@ -51,7 +51,7 @@ func newStorage(t *testing.T) (ipallocator.Interface, allocator.Interface, *tool
storage
:=
ipallocator
.
NewAllocatorCIDRRange
(
cidr
,
func
(
max
int
,
rangeSpec
string
)
allocator
.
Interface
{
storage
:=
ipallocator
.
NewAllocatorCIDRRange
(
cidr
,
func
(
max
int
,
rangeSpec
string
)
allocator
.
Interface
{
mem
:=
allocator
.
NewAllocationMap
(
max
,
rangeSpec
)
mem
:=
allocator
.
NewAllocationMap
(
max
,
rangeSpec
)
backing
=
mem
backing
=
mem
etcd
:=
allocator_etcd
.
NewEtcd
(
mem
,
"/ranges/serviceips"
,
"serviceipallocation"
,
h
)
etcd
:=
allocator_etcd
.
NewEtcd
(
mem
,
"/ranges/serviceips"
,
"serviceipallocation"
,
etcdStorage
)
return
etcd
return
etcd
})
})
...
...
pkg/registry/serviceaccount/etcd/etcd.go
View file @
7cc1855c
...
@@ -35,7 +35,7 @@ type REST struct {
...
@@ -35,7 +35,7 @@ type REST struct {
const
Prefix
=
"/serviceaccounts"
const
Prefix
=
"/serviceaccounts"
// NewStorage returns a RESTStorage object that will work against service accounts objects.
// NewStorage returns a RESTStorage object that will work against service accounts objects.
func
NewStorage
(
h
tools
.
EtcdHelper
)
*
REST
{
func
NewStorage
(
s
tools
.
StorageInterface
)
*
REST
{
store
:=
&
etcdgeneric
.
Etcd
{
store
:=
&
etcdgeneric
.
Etcd
{
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
ServiceAccount
{}
},
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
ServiceAccount
{}
},
NewListFunc
:
func
()
runtime
.
Object
{
return
&
api
.
ServiceAccountList
{}
},
NewListFunc
:
func
()
runtime
.
Object
{
return
&
api
.
ServiceAccountList
{}
},
...
@@ -53,7 +53,7 @@ func NewStorage(h tools.EtcdHelper) *REST {
...
@@ -53,7 +53,7 @@ func NewStorage(h tools.EtcdHelper) *REST {
},
},
EndpointName
:
"serviceaccounts"
,
EndpointName
:
"serviceaccounts"
,
Helper
:
h
,
Storage
:
s
,
}
}
store
.
CreateStrategy
=
serviceaccount
.
Strategy
store
.
CreateStrategy
=
serviceaccount
.
Strategy
...
...
pkg/registry/serviceaccount/etcd/etcd_test.go
View file @
7cc1855c
...
@@ -26,11 +26,11 @@ import (
...
@@ -26,11 +26,11 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
)
)
func
new
Helper
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
EtcdHelper
)
{
func
new
EtcdStorage
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
tools
.
StorageInterface
)
{
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
:=
tools
.
NewFakeEtcdClient
(
t
)
fakeEtcdClient
.
TestIndex
=
true
fakeEtcdClient
.
TestIndex
=
true
helper
:=
tools
.
NewEtcdHelper
(
fakeEtcdClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
etcdStorage
:=
tools
.
NewEtcdStorage
(
fakeEtcdClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
return
fakeEtcdClient
,
helper
return
fakeEtcdClient
,
etcdStorage
}
}
func
validNewServiceAccount
(
name
string
)
*
api
.
ServiceAccount
{
func
validNewServiceAccount
(
name
string
)
*
api
.
ServiceAccount
{
...
@@ -44,8 +44,8 @@ func validNewServiceAccount(name string) *api.ServiceAccount {
...
@@ -44,8 +44,8 @@ func validNewServiceAccount(name string) *api.ServiceAccount {
}
}
func
TestCreate
(
t
*
testing
.
T
)
{
func
TestCreate
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
:=
NewStorage
(
helper
)
storage
:=
NewStorage
(
etcdStorage
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
serviceAccount
:=
validNewServiceAccount
(
"foo"
)
serviceAccount
:=
validNewServiceAccount
(
"foo"
)
serviceAccount
.
ObjectMeta
=
api
.
ObjectMeta
{
GenerateName
:
"foo-"
}
serviceAccount
.
ObjectMeta
=
api
.
ObjectMeta
{
GenerateName
:
"foo-"
}
...
@@ -61,8 +61,8 @@ func TestCreate(t *testing.T) {
...
@@ -61,8 +61,8 @@ func TestCreate(t *testing.T) {
}
}
func
TestUpdate
(
t
*
testing
.
T
)
{
func
TestUpdate
(
t
*
testing
.
T
)
{
fakeEtcdClient
,
helper
:=
newHelper
(
t
)
fakeEtcdClient
,
etcdStorage
:=
newEtcdStorage
(
t
)
storage
:=
NewStorage
(
helper
)
storage
:=
NewStorage
(
etcdStorage
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
test
:=
resttest
.
New
(
t
,
storage
,
fakeEtcdClient
.
SetError
)
key
,
err
:=
storage
.
KeyFunc
(
test
.
TestContext
(),
"foo"
)
key
,
err
:=
storage
.
KeyFunc
(
test
.
TestContext
(),
"foo"
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/serviceaccount/tokengetter.go
View file @
7cc1855c
...
@@ -71,11 +71,11 @@ func (r *registryGetter) GetSecret(namespace, name string) (*api.Secret, error)
...
@@ -71,11 +71,11 @@ func (r *registryGetter) GetSecret(namespace, name string) (*api.Secret, error)
return
r
.
secrets
.
GetSecret
(
ctx
,
name
)
return
r
.
secrets
.
GetSecret
(
ctx
,
name
)
}
}
// NewGetterFrom
EtcdHelper
returns a ServiceAccountTokenGetter that
// NewGetterFrom
StorageInterface
returns a ServiceAccountTokenGetter that
// uses the specified
helper
to retrieve service accounts and secrets.
// uses the specified
storage
to retrieve service accounts and secrets.
func
NewGetterFrom
EtcdHelper
(
helper
tools
.
EtcdHelper
)
ServiceAccountTokenGetter
{
func
NewGetterFrom
StorageInterface
(
storage
tools
.
StorageInterface
)
ServiceAccountTokenGetter
{
return
NewGetterFromRegistries
(
return
NewGetterFromRegistries
(
serviceaccount
.
NewRegistry
(
serviceaccountetcd
.
NewStorage
(
helper
)),
serviceaccount
.
NewRegistry
(
serviceaccountetcd
.
NewStorage
(
storage
)),
secret
.
NewRegistry
(
secretetcd
.
NewStorage
(
helper
)),
secret
.
NewRegistry
(
secretetcd
.
NewStorage
(
storage
)),
)
)
}
}
pkg/tools/etcd_helper.go
View file @
7cc1855c
This diff is collapsed.
Click to expand it.
pkg/tools/etcd_helper_test.go
View file @
7cc1855c
...
@@ -65,6 +65,10 @@ func init() {
...
@@ -65,6 +65,10 @@ func init() {
)
)
}
}
func
newEtcdHelper
(
client
EtcdClient
,
codec
runtime
.
Codec
,
prefix
string
)
etcdHelper
{
return
*
NewEtcdStorage
(
client
,
codec
,
prefix
)
.
(
*
etcdHelper
)
}
func
TestIsEtcdNotFound
(
t
*
testing
.
T
)
{
func
TestIsEtcdNotFound
(
t
*
testing
.
T
)
{
try
:=
func
(
err
error
,
isNotFound
bool
)
{
try
:=
func
(
err
error
,
isNotFound
bool
)
{
if
IsEtcdNotFound
(
err
)
!=
isNotFound
{
if
IsEtcdNotFound
(
err
)
!=
isNotFound
{
...
@@ -87,7 +91,7 @@ func getEncodedPod(name string) string {
...
@@ -87,7 +91,7 @@ func getEncodedPod(name string) string {
func
TestExtractToList
(
t
*
testing
.
T
)
{
func
TestExtractToList
(
t
*
testing
.
T
)
{
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
helper
:=
N
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
fakeClient
.
Data
[
key
]
=
EtcdResponseWithError
{
fakeClient
.
Data
[
key
]
=
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{
R
:
&
etcd
.
Response
{
...
@@ -157,7 +161,7 @@ func TestExtractToList(t *testing.T) {
...
@@ -157,7 +161,7 @@ func TestExtractToList(t *testing.T) {
// TestExtractToListAcrossDirectories ensures that the client excludes directories and flattens tree-response - simulates cross-namespace query
// TestExtractToListAcrossDirectories ensures that the client excludes directories and flattens tree-response - simulates cross-namespace query
func
TestExtractToListAcrossDirectories
(
t
*
testing
.
T
)
{
func
TestExtractToListAcrossDirectories
(
t
*
testing
.
T
)
{
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
helper
:=
N
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
fakeClient
.
Data
[
key
]
=
EtcdResponseWithError
{
fakeClient
.
Data
[
key
]
=
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{
R
:
&
etcd
.
Response
{
...
@@ -240,7 +244,7 @@ func TestExtractToListAcrossDirectories(t *testing.T) {
...
@@ -240,7 +244,7 @@ func TestExtractToListAcrossDirectories(t *testing.T) {
func
TestExtractToListExcludesDirectories
(
t
*
testing
.
T
)
{
func
TestExtractToListExcludesDirectories
(
t
*
testing
.
T
)
{
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
helper
:=
N
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
fakeClient
.
Data
[
key
]
=
EtcdResponseWithError
{
fakeClient
.
Data
[
key
]
=
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{
R
:
&
etcd
.
Response
{
...
@@ -311,7 +315,7 @@ func TestExtractToListExcludesDirectories(t *testing.T) {
...
@@ -311,7 +315,7 @@ func TestExtractToListExcludesDirectories(t *testing.T) {
func
TestExtractObj
(
t
*
testing
.
T
)
{
func
TestExtractObj
(
t
*
testing
.
T
)
{
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
helper
:=
N
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
expect
:=
api
.
Pod
{
expect
:=
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
},
...
@@ -333,7 +337,7 @@ func TestExtractObj(t *testing.T) {
...
@@ -333,7 +337,7 @@ func TestExtractObj(t *testing.T) {
func
TestExtractObjNotFoundErr
(
t
*
testing
.
T
)
{
func
TestExtractObjNotFoundErr
(
t
*
testing
.
T
)
{
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
helper
:=
N
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
key1
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
key1
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
fakeClient
.
Data
[
key1
]
=
EtcdResponseWithError
{
fakeClient
.
Data
[
key1
]
=
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{
R
:
&
etcd
.
Response
{
...
@@ -377,7 +381,7 @@ func TestExtractObjNotFoundErr(t *testing.T) {
...
@@ -377,7 +381,7 @@ func TestExtractObjNotFoundErr(t *testing.T) {
func
TestCreateObj
(
t
*
testing
.
T
)
{
func
TestCreateObj
(
t
*
testing
.
T
)
{
obj
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}
obj
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
helper
:=
N
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
returnedObj
:=
&
api
.
Pod
{}
returnedObj
:=
&
api
.
Pod
{}
err
:=
helper
.
CreateObj
(
"/some/key"
,
obj
,
returnedObj
,
5
)
err
:=
helper
.
CreateObj
(
"/some/key"
,
obj
,
returnedObj
,
5
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -403,7 +407,7 @@ func TestCreateObj(t *testing.T) {
...
@@ -403,7 +407,7 @@ func TestCreateObj(t *testing.T) {
func
TestCreateObjNilOutParam
(
t
*
testing
.
T
)
{
func
TestCreateObjNilOutParam
(
t
*
testing
.
T
)
{
obj
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}
obj
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
helper
:=
N
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
err
:=
helper
.
CreateObj
(
"/some/key"
,
obj
,
nil
,
5
)
err
:=
helper
.
CreateObj
(
"/some/key"
,
obj
,
nil
,
5
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error %#v"
,
err
)
t
.
Errorf
(
"Unexpected error %#v"
,
err
)
...
@@ -413,7 +417,7 @@ func TestCreateObjNilOutParam(t *testing.T) {
...
@@ -413,7 +417,7 @@ func TestCreateObjNilOutParam(t *testing.T) {
func
TestSetObj
(
t
*
testing
.
T
)
{
func
TestSetObj
(
t
*
testing
.
T
)
{
obj
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}
obj
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
helper
:=
N
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
returnedObj
:=
&
api
.
Pod
{}
returnedObj
:=
&
api
.
Pod
{}
err
:=
helper
.
SetObj
(
"/some/key"
,
obj
,
returnedObj
,
5
)
err
:=
helper
.
SetObj
(
"/some/key"
,
obj
,
returnedObj
,
5
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -441,7 +445,7 @@ func TestSetObjFailCAS(t *testing.T) {
...
@@ -441,7 +445,7 @@ func TestSetObjFailCAS(t *testing.T) {
obj
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
ResourceVersion
:
"1"
}}
obj
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
ResourceVersion
:
"1"
}}
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
.
CasErr
=
fakeClient
.
NewError
(
123
)
fakeClient
.
CasErr
=
fakeClient
.
NewError
(
123
)
helper
:=
N
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
err
:=
helper
.
SetObj
(
"/some/key"
,
obj
,
nil
,
5
)
err
:=
helper
.
SetObj
(
"/some/key"
,
obj
,
nil
,
5
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Errorf
(
"Expecting error."
)
t
.
Errorf
(
"Expecting error."
)
...
@@ -452,7 +456,7 @@ func TestSetObjWithVersion(t *testing.T) {
...
@@ -452,7 +456,7 @@ func TestSetObjWithVersion(t *testing.T) {
obj
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
ResourceVersion
:
"1"
}}
obj
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
ResourceVersion
:
"1"
}}
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
.
TestIndex
=
true
fakeClient
.
TestIndex
=
true
helper
:=
N
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
fakeClient
.
Data
[
key
]
=
EtcdResponseWithError
{
fakeClient
.
Data
[
key
]
=
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{
R
:
&
etcd
.
Response
{
...
@@ -488,8 +492,8 @@ func TestSetObjWithVersion(t *testing.T) {
...
@@ -488,8 +492,8 @@ func TestSetObjWithVersion(t *testing.T) {
func
TestSetObjWithoutResourceVersioner
(
t
*
testing
.
T
)
{
func
TestSetObjWithoutResourceVersioner
(
t
*
testing
.
T
)
{
obj
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}
obj
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
helper
:=
N
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
helper
.
V
ersioner
=
nil
helper
.
v
ersioner
=
nil
returnedObj
:=
&
api
.
Pod
{}
returnedObj
:=
&
api
.
Pod
{}
err
:=
helper
.
SetObj
(
"/some/key"
,
obj
,
returnedObj
,
3
)
err
:=
helper
.
SetObj
(
"/some/key"
,
obj
,
returnedObj
,
3
)
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
...
@@ -516,8 +520,8 @@ func TestSetObjWithoutResourceVersioner(t *testing.T) {
...
@@ -516,8 +520,8 @@ func TestSetObjWithoutResourceVersioner(t *testing.T) {
func
TestSetObjNilOutParam
(
t
*
testing
.
T
)
{
func
TestSetObjNilOutParam
(
t
*
testing
.
T
)
{
obj
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}
obj
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
helper
:=
N
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
helper
.
V
ersioner
=
nil
helper
.
v
ersioner
=
nil
err
:=
helper
.
SetObj
(
"/some/key"
,
obj
,
nil
,
3
)
err
:=
helper
.
SetObj
(
"/some/key"
,
obj
,
nil
,
3
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error %#v"
,
err
)
t
.
Errorf
(
"Unexpected error %#v"
,
err
)
...
@@ -527,7 +531,7 @@ func TestSetObjNilOutParam(t *testing.T) {
...
@@ -527,7 +531,7 @@ func TestSetObjNilOutParam(t *testing.T) {
func
TestGuaranteedUpdate
(
t
*
testing
.
T
)
{
func
TestGuaranteedUpdate
(
t
*
testing
.
T
)
{
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
.
TestIndex
=
true
fakeClient
.
TestIndex
=
true
helper
:=
N
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
// Create a new node.
// Create a new node.
...
@@ -582,7 +586,7 @@ func TestGuaranteedUpdate(t *testing.T) {
...
@@ -582,7 +586,7 @@ func TestGuaranteedUpdate(t *testing.T) {
func
TestGuaranteedUpdateTTL
(
t
*
testing
.
T
)
{
func
TestGuaranteedUpdateTTL
(
t
*
testing
.
T
)
{
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
.
TestIndex
=
true
fakeClient
.
TestIndex
=
true
helper
:=
N
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
// Create a new node.
// Create a new node.
...
@@ -683,7 +687,7 @@ func TestGuaranteedUpdateTTL(t *testing.T) {
...
@@ -683,7 +687,7 @@ func TestGuaranteedUpdateTTL(t *testing.T) {
func
TestGuaranteedUpdateNoChange
(
t
*
testing
.
T
)
{
func
TestGuaranteedUpdateNoChange
(
t
*
testing
.
T
)
{
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
.
TestIndex
=
true
fakeClient
.
TestIndex
=
true
helper
:=
N
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
// Create a new node.
// Create a new node.
...
@@ -715,7 +719,7 @@ func TestGuaranteedUpdateNoChange(t *testing.T) {
...
@@ -715,7 +719,7 @@ func TestGuaranteedUpdateNoChange(t *testing.T) {
func
TestGuaranteedUpdateKeyNotFound
(
t
*
testing
.
T
)
{
func
TestGuaranteedUpdateKeyNotFound
(
t
*
testing
.
T
)
{
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
.
TestIndex
=
true
fakeClient
.
TestIndex
=
true
helper
:=
N
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
// Create a new node.
// Create a new node.
...
@@ -742,7 +746,7 @@ func TestGuaranteedUpdateKeyNotFound(t *testing.T) {
...
@@ -742,7 +746,7 @@ func TestGuaranteedUpdateKeyNotFound(t *testing.T) {
func
TestGuaranteedUpdate_CreateCollision
(
t
*
testing
.
T
)
{
func
TestGuaranteedUpdate_CreateCollision
(
t
*
testing
.
T
)
{
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
.
TestIndex
=
true
fakeClient
.
TestIndex
=
true
helper
:=
N
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
helper
:=
n
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
key
:=
etcdtest
.
AddPrefix
(
"/some/key"
)
fakeClient
.
ExpectNotFoundGet
(
key
)
fakeClient
.
ExpectNotFoundGet
(
key
)
...
@@ -840,7 +844,7 @@ func TestGetEtcdVersion_NotListening(t *testing.T) {
...
@@ -840,7 +844,7 @@ func TestGetEtcdVersion_NotListening(t *testing.T) {
func
TestPrefixEtcdKey
(
t
*
testing
.
T
)
{
func
TestPrefixEtcdKey
(
t
*
testing
.
T
)
{
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
prefix
:=
path
.
Join
(
"/"
,
etcdtest
.
PathPrefix
())
prefix
:=
path
.
Join
(
"/"
,
etcdtest
.
PathPrefix
())
helper
:=
N
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
prefix
)
helper
:=
n
ewEtcdHelper
(
fakeClient
,
testapi
.
Codec
(),
prefix
)
baseKey
:=
"/some/key"
baseKey
:=
"/some/key"
...
...
pkg/tools/etcd_helper_watch.go
View file @
7cc1855c
...
@@ -70,46 +70,23 @@ func ParseWatchResourceVersion(resourceVersion, kind string) (uint64, error) {
...
@@ -70,46 +70,23 @@ func ParseWatchResourceVersion(resourceVersion, kind string) (uint64, error) {
// API objects, and any items passing 'filter' are sent down the returned
// API objects, and any items passing 'filter' are sent down the returned
// watch.Interface. resourceVersion may be used to specify what version to begin
// watch.Interface. resourceVersion may be used to specify what version to begin
// watching (e.g., for reconnecting without missing any updates).
// watching (e.g., for reconnecting without missing any updates).
func
(
h
*
E
tcdHelper
)
WatchList
(
key
string
,
resourceVersion
uint64
,
filter
FilterFunc
)
(
watch
.
Interface
,
error
)
{
func
(
h
*
e
tcdHelper
)
WatchList
(
key
string
,
resourceVersion
uint64
,
filter
FilterFunc
)
(
watch
.
Interface
,
error
)
{
key
=
h
.
prefixEtcdKey
(
key
)
key
=
h
.
prefixEtcdKey
(
key
)
w
:=
newEtcdWatcher
(
true
,
exceptKey
(
key
),
filter
,
h
.
Codec
,
h
.
V
ersioner
,
nil
,
h
)
w
:=
newEtcdWatcher
(
true
,
exceptKey
(
key
),
filter
,
h
.
codec
,
h
.
v
ersioner
,
nil
,
h
)
go
w
.
etcdWatch
(
h
.
C
lient
,
key
,
resourceVersion
)
go
w
.
etcdWatch
(
h
.
c
lient
,
key
,
resourceVersion
)
return
w
,
nil
return
w
,
nil
}
}
// Watch begins watching the specified key. Events are decoded into
// Watch begins watching the specified key. Events are decoded into
// API objects and sent down the returned watch.Interface.
// API objects and sent down the returned watch.Interface.
// Errors will be sent down the channel.
// Errors will be sent down the channel.
func
(
h
*
E
tcdHelper
)
Watch
(
key
string
,
resourceVersion
uint64
,
filter
FilterFunc
)
(
watch
.
Interface
,
error
)
{
func
(
h
*
e
tcdHelper
)
Watch
(
key
string
,
resourceVersion
uint64
,
filter
FilterFunc
)
(
watch
.
Interface
,
error
)
{
key
=
h
.
prefixEtcdKey
(
key
)
key
=
h
.
prefixEtcdKey
(
key
)
w
:=
newEtcdWatcher
(
false
,
nil
,
filter
,
h
.
Codec
,
h
.
V
ersioner
,
nil
,
h
)
w
:=
newEtcdWatcher
(
false
,
nil
,
filter
,
h
.
codec
,
h
.
v
ersioner
,
nil
,
h
)
go
w
.
etcdWatch
(
h
.
C
lient
,
key
,
resourceVersion
)
go
w
.
etcdWatch
(
h
.
c
lient
,
key
,
resourceVersion
)
return
w
,
nil
return
w
,
nil
}
}
// WatchAndTransform begins watching the specified key. Events are decoded into
// API objects and sent down the returned watch.Interface. If the transform
// function is provided, the value decoded from etcd will be passed to the function
// prior to being returned.
//
// The transform function can be used to populate data not available to etcd, or to
// change or wrap the serialized etcd object.
//
// startTime := time.Now()
// helper.WatchAndTransform(key, version, func(input runtime.Object) (runtime.Object, error) {
// value := input.(TimeAwareValue)
// value.Since = startTime
// return value, nil
// })
//
// Errors will be sent down the channel.
/*func (h *EtcdHelper) WatchAndTransform(key string, resourceVersion uint64, transform TransformFunc) watch.Interface {
key = h.prefixEtcdKey(key)
w := newEtcdWatcher(false, nil, Everything, h.Codec, h.Versioner, transform, h)
go w.etcdWatch(h.Client, key, resourceVersion)
return w
}*/
// TransformFunc attempts to convert an object to another object for use with a watcher.
// TransformFunc attempts to convert an object to another object for use with a watcher.
type
TransformFunc
func
(
runtime
.
Object
)
(
runtime
.
Object
,
error
)
type
TransformFunc
func
(
runtime
.
Object
)
(
runtime
.
Object
,
error
)
...
@@ -126,7 +103,7 @@ func exceptKey(except string) includeFunc {
...
@@ -126,7 +103,7 @@ func exceptKey(except string) includeFunc {
// etcdWatcher converts a native etcd watch to a watch.Interface.
// etcdWatcher converts a native etcd watch to a watch.Interface.
type
etcdWatcher
struct
{
type
etcdWatcher
struct
{
encoding
runtime
.
Codec
encoding
runtime
.
Codec
versioner
Etcd
Versioner
versioner
Storage
Versioner
transform
TransformFunc
transform
TransformFunc
list
bool
// If we're doing a recursive watch, should be true.
list
bool
// If we're doing a recursive watch, should be true.
...
@@ -154,7 +131,7 @@ const watchWaitDuration = 100 * time.Millisecond
...
@@ -154,7 +131,7 @@ const watchWaitDuration = 100 * time.Millisecond
// newEtcdWatcher returns a new etcdWatcher; if list is true, watch sub-nodes. If you provide a transform
// newEtcdWatcher returns a new etcdWatcher; if list is true, watch sub-nodes. If you provide a transform
// and a versioner, the versioner must be able to handle the objects that transform creates.
// and a versioner, the versioner must be able to handle the objects that transform creates.
func
newEtcdWatcher
(
list
bool
,
include
includeFunc
,
filter
FilterFunc
,
encoding
runtime
.
Codec
,
versioner
Etcd
Versioner
,
transform
TransformFunc
,
cache
etcdCache
)
*
etcdWatcher
{
func
newEtcdWatcher
(
list
bool
,
include
includeFunc
,
filter
FilterFunc
,
encoding
runtime
.
Codec
,
versioner
Storage
Versioner
,
transform
TransformFunc
,
cache
etcdCache
)
*
etcdWatcher
{
w
:=
&
etcdWatcher
{
w
:=
&
etcdWatcher
{
encoding
:
encoding
,
encoding
:
encoding
,
versioner
:
versioner
,
versioner
:
versioner
,
...
...
pkg/tools/etcd_helper_watch_test.go
View file @
7cc1855c
...
@@ -218,7 +218,7 @@ func TestWatchEtcdError(t *testing.T) {
...
@@ -218,7 +218,7 @@ func TestWatchEtcdError(t *testing.T) {
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
.
expectNotFoundGetSet
[
"/some/key"
]
=
struct
{}{}
fakeClient
.
expectNotFoundGetSet
[
"/some/key"
]
=
struct
{}{}
fakeClient
.
WatchImmediateError
=
fmt
.
Errorf
(
"immediate error"
)
fakeClient
.
WatchImmediateError
=
fmt
.
Errorf
(
"immediate error"
)
h
:=
N
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
h
:=
n
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
watching
,
err
:=
h
.
Watch
(
"/some/key"
,
4
,
Everything
)
watching
,
err
:=
h
.
Watch
(
"/some/key"
,
4
,
Everything
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -248,7 +248,7 @@ func TestWatch(t *testing.T) {
...
@@ -248,7 +248,7 @@ func TestWatch(t *testing.T) {
key
:=
"/some/key"
key
:=
"/some/key"
prefixedKey
:=
etcdtest
.
AddPrefix
(
key
)
prefixedKey
:=
etcdtest
.
AddPrefix
(
key
)
fakeClient
.
expectNotFoundGetSet
[
prefixedKey
]
=
struct
{}{}
fakeClient
.
expectNotFoundGetSet
[
prefixedKey
]
=
struct
{}{}
h
:=
N
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
h
:=
n
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
watching
,
err
:=
h
.
Watch
(
key
,
0
,
Everything
)
watching
,
err
:=
h
.
Watch
(
key
,
0
,
Everything
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -424,7 +424,7 @@ func TestWatchEtcdState(t *testing.T) {
...
@@ -424,7 +424,7 @@ func TestWatchEtcdState(t *testing.T) {
fakeClient
.
Data
[
key
]
=
value
fakeClient
.
Data
[
key
]
=
value
}
}
h
:=
N
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
h
:=
n
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
watching
,
err
:=
h
.
Watch
(
baseKey
,
testCase
.
From
,
Everything
)
watching
,
err
:=
h
.
Watch
(
baseKey
,
testCase
.
From
,
Everything
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
...
@@ -497,7 +497,7 @@ func TestWatchFromZeroIndex(t *testing.T) {
...
@@ -497,7 +497,7 @@ func TestWatchFromZeroIndex(t *testing.T) {
key
:=
"/some/key"
key
:=
"/some/key"
prefixedKey
:=
etcdtest
.
AddPrefix
(
key
)
prefixedKey
:=
etcdtest
.
AddPrefix
(
key
)
fakeClient
.
Data
[
prefixedKey
]
=
testCase
.
Response
fakeClient
.
Data
[
prefixedKey
]
=
testCase
.
Response
h
:=
N
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
h
:=
n
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
watching
,
err
:=
h
.
Watch
(
key
,
0
,
Everything
)
watching
,
err
:=
h
.
Watch
(
key
,
0
,
Everything
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -558,7 +558,7 @@ func TestWatchListFromZeroIndex(t *testing.T) {
...
@@ -558,7 +558,7 @@ func TestWatchListFromZeroIndex(t *testing.T) {
EtcdIndex
:
3
,
EtcdIndex
:
3
,
},
},
}
}
h
:=
N
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
h
:=
n
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
watching
,
err
:=
h
.
WatchList
(
key
,
0
,
Everything
)
watching
,
err
:=
h
.
WatchList
(
key
,
0
,
Everything
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -598,7 +598,7 @@ func TestWatchListIgnoresRootKey(t *testing.T) {
...
@@ -598,7 +598,7 @@ func TestWatchListIgnoresRootKey(t *testing.T) {
prefixedKey
:=
etcdtest
.
AddPrefix
(
key
)
prefixedKey
:=
etcdtest
.
AddPrefix
(
key
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
h
:=
N
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
h
:=
n
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
watching
,
err
:=
h
.
WatchList
(
key
,
1
,
Everything
)
watching
,
err
:=
h
.
WatchList
(
key
,
1
,
Everything
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -651,7 +651,7 @@ func TestWatchFromNotFound(t *testing.T) {
...
@@ -651,7 +651,7 @@ func TestWatchFromNotFound(t *testing.T) {
ErrorCode
:
100
,
ErrorCode
:
100
,
},
},
}
}
h
:=
N
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
h
:=
n
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
watching
,
err
:=
h
.
Watch
(
key
,
0
,
Everything
)
watching
,
err
:=
h
.
Watch
(
key
,
0
,
Everything
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -678,7 +678,7 @@ func TestWatchFromOtherError(t *testing.T) {
...
@@ -678,7 +678,7 @@ func TestWatchFromOtherError(t *testing.T) {
ErrorCode
:
101
,
ErrorCode
:
101
,
},
},
}
}
h
:=
N
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
h
:=
n
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
watching
,
err
:=
h
.
Watch
(
key
,
0
,
Everything
)
watching
,
err
:=
h
.
Watch
(
key
,
0
,
Everything
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -710,7 +710,7 @@ func TestWatchFromOtherError(t *testing.T) {
...
@@ -710,7 +710,7 @@ func TestWatchFromOtherError(t *testing.T) {
func
TestWatchPurposefulShutdown
(
t
*
testing
.
T
)
{
func
TestWatchPurposefulShutdown
(
t
*
testing
.
T
)
{
fakeClient
:=
NewFakeEtcdClient
(
t
)
fakeClient
:=
NewFakeEtcdClient
(
t
)
h
:=
N
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
h
:=
n
ewEtcdHelper
(
fakeClient
,
codec
,
etcdtest
.
PathPrefix
())
key
:=
"/some/key"
key
:=
"/some/key"
prefixedKey
:=
etcdtest
.
AddPrefix
(
key
)
prefixedKey
:=
etcdtest
.
AddPrefix
(
key
)
fakeClient
.
expectNotFoundGetSet
[
prefixedKey
]
=
struct
{}{}
fakeClient
.
expectNotFoundGetSet
[
prefixedKey
]
=
struct
{}{}
...
...
pkg/tools/etcd_object.go
View file @
7cc1855c
...
@@ -29,7 +29,7 @@ import (
...
@@ -29,7 +29,7 @@ import (
// for objects that have an embedded ObjectMeta or ListMeta field.
// for objects that have an embedded ObjectMeta or ListMeta field.
type
APIObjectVersioner
struct
{}
type
APIObjectVersioner
struct
{}
// UpdateObject implements
Etcd
Versioner
// UpdateObject implements
Storage
Versioner
func
(
a
APIObjectVersioner
)
UpdateObject
(
obj
runtime
.
Object
,
expiration
*
time
.
Time
,
resourceVersion
uint64
)
error
{
func
(
a
APIObjectVersioner
)
UpdateObject
(
obj
runtime
.
Object
,
expiration
*
time
.
Time
,
resourceVersion
uint64
)
error
{
objectMeta
,
err
:=
api
.
ObjectMetaFor
(
obj
)
objectMeta
,
err
:=
api
.
ObjectMetaFor
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -46,7 +46,7 @@ func (a APIObjectVersioner) UpdateObject(obj runtime.Object, expiration *time.Ti
...
@@ -46,7 +46,7 @@ func (a APIObjectVersioner) UpdateObject(obj runtime.Object, expiration *time.Ti
return
nil
return
nil
}
}
// UpdateList implements
Etcd
Versioner
// UpdateList implements
Storage
Versioner
func
(
a
APIObjectVersioner
)
UpdateList
(
obj
runtime
.
Object
,
resourceVersion
uint64
)
error
{
func
(
a
APIObjectVersioner
)
UpdateList
(
obj
runtime
.
Object
,
resourceVersion
uint64
)
error
{
listMeta
,
err
:=
api
.
ListMetaFor
(
obj
)
listMeta
,
err
:=
api
.
ListMetaFor
(
obj
)
if
err
!=
nil
||
listMeta
==
nil
{
if
err
!=
nil
||
listMeta
==
nil
{
...
@@ -60,7 +60,7 @@ func (a APIObjectVersioner) UpdateList(obj runtime.Object, resourceVersion uint6
...
@@ -60,7 +60,7 @@ func (a APIObjectVersioner) UpdateList(obj runtime.Object, resourceVersion uint6
return
nil
return
nil
}
}
// ObjectResourceVersion implements
Etcd
Versioner
// ObjectResourceVersion implements
Storage
Versioner
func
(
a
APIObjectVersioner
)
ObjectResourceVersion
(
obj
runtime
.
Object
)
(
uint64
,
error
)
{
func
(
a
APIObjectVersioner
)
ObjectResourceVersion
(
obj
runtime
.
Object
)
(
uint64
,
error
)
{
meta
,
err
:=
api
.
ObjectMetaFor
(
obj
)
meta
,
err
:=
api
.
ObjectMetaFor
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -73,5 +73,5 @@ func (a APIObjectVersioner) ObjectResourceVersion(obj runtime.Object) (uint64, e
...
@@ -73,5 +73,5 @@ func (a APIObjectVersioner) ObjectResourceVersion(obj runtime.Object) (uint64, e
return
strconv
.
ParseUint
(
version
,
10
,
64
)
return
strconv
.
ParseUint
(
version
,
10
,
64
)
}
}
// APIObjectVersioner implements
Etcd
Versioner
// APIObjectVersioner implements
Storage
Versioner
var
_
Etcd
Versioner
=
APIObjectVersioner
{}
var
_
Storage
Versioner
=
APIObjectVersioner
{}
pkg/tools/interfaces.go
View file @
7cc1855c
...
@@ -52,9 +52,9 @@ type EtcdClient interface {
...
@@ -52,9 +52,9 @@ type EtcdClient interface {
Watch
(
prefix
string
,
waitIndex
uint64
,
recursive
bool
,
receiver
chan
*
etcd
.
Response
,
stop
chan
bool
)
(
*
etcd
.
Response
,
error
)
Watch
(
prefix
string
,
waitIndex
uint64
,
recursive
bool
,
receiver
chan
*
etcd
.
Response
,
stop
chan
bool
)
(
*
etcd
.
Response
,
error
)
}
}
//
EtcdVersioner abstracts setting and retrieving
fields from the etcd response onto the object
//
StorageVersioner abstracts setting and retrieving metadata
fields from the etcd response onto the object
// or list.
// or list.
type
Etcd
Versioner
interface
{
type
Storage
Versioner
interface
{
// UpdateObject sets etcd storage metadata into an API object. Returns an error if the object
// UpdateObject sets etcd storage metadata into an API object. Returns an error if the object
// cannot be updated correctly. May return nil if the requested object does not need metadata
// cannot be updated correctly. May return nil if the requested object does not need metadata
// from etcd.
// from etcd.
...
@@ -91,6 +91,14 @@ type StorageUpdateFunc func(input runtime.Object, res ResponseMeta) (output runt
...
@@ -91,6 +91,14 @@ type StorageUpdateFunc func(input runtime.Object, res ResponseMeta) (output runt
// StorageInterface offers a common interface for object marshaling/unmarshling operations and
// StorageInterface offers a common interface for object marshaling/unmarshling operations and
// hids all the storage-related operations behind it.
// hids all the storage-related operations behind it.
type
StorageInterface
interface
{
type
StorageInterface
interface
{
// Returns list of servers addresses of the underyling database.
// TODO: This method is used only in a single place. Consider refactoring and getting rid
// of this method from the interface.
Backends
()
[]
string
// Returns StorageVersioner associated with this interface.
Versioner
()
StorageVersioner
// CreateObj adds a new object at a key unless it already exists. 'ttl' is time-to-live
// CreateObj adds a new object at a key unless it already exists. 'ttl' is time-to-live
// in seconds (0 means forever). If no error is returned and out is not nil, out will be
// in seconds (0 means forever). If no error is returned and out is not nil, out will be
// set to the read value from etcd.
// set to the read value from etcd.
...
...
test/integration/auth_test.go
View file @
7cc1855c
...
@@ -392,7 +392,7 @@ func TestAuthModeAlwaysAllow(t *testing.T) {
...
@@ -392,7 +392,7 @@ func TestAuthModeAlwaysAllow(t *testing.T) {
framework
.
DeleteAllEtcdKeys
()
framework
.
DeleteAllEtcdKeys
()
// Set up a master
// Set up a master
helper
,
err
:=
framework
.
NewHelper
()
etcdStorage
,
err
:=
framework
.
NewEtcdStorage
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -403,7 +403,7 @@ func TestAuthModeAlwaysAllow(t *testing.T) {
...
@@ -403,7 +403,7 @@ func TestAuthModeAlwaysAllow(t *testing.T) {
defer
s
.
Close
()
defer
s
.
Close
()
m
=
master
.
New
(
&
master
.
Config
{
m
=
master
.
New
(
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
KubeletClient
:
client
.
FakeKubeletClient
{},
KubeletClient
:
client
.
FakeKubeletClient
{},
EnableCoreControllers
:
true
,
EnableCoreControllers
:
true
,
EnableLogsSupport
:
false
,
EnableLogsSupport
:
false
,
...
@@ -507,7 +507,7 @@ func TestAuthModeAlwaysDeny(t *testing.T) {
...
@@ -507,7 +507,7 @@ func TestAuthModeAlwaysDeny(t *testing.T) {
framework
.
DeleteAllEtcdKeys
()
framework
.
DeleteAllEtcdKeys
()
// Set up a master
// Set up a master
helper
,
err
:=
framework
.
NewHelper
()
etcdStorage
,
err
:=
framework
.
NewEtcdStorage
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -519,7 +519,7 @@ func TestAuthModeAlwaysDeny(t *testing.T) {
...
@@ -519,7 +519,7 @@ func TestAuthModeAlwaysDeny(t *testing.T) {
defer
s
.
Close
()
defer
s
.
Close
()
m
=
master
.
New
(
&
master
.
Config
{
m
=
master
.
New
(
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
KubeletClient
:
client
.
FakeKubeletClient
{},
KubeletClient
:
client
.
FakeKubeletClient
{},
EnableCoreControllers
:
true
,
EnableCoreControllers
:
true
,
EnableLogsSupport
:
false
,
EnableLogsSupport
:
false
,
...
@@ -574,7 +574,7 @@ func TestAliceNotForbiddenOrUnauthorized(t *testing.T) {
...
@@ -574,7 +574,7 @@ func TestAliceNotForbiddenOrUnauthorized(t *testing.T) {
// This file has alice and bob in it.
// This file has alice and bob in it.
// Set up a master
// Set up a master
helper
,
err
:=
framework
.
NewHelper
()
etcdStorage
,
err
:=
framework
.
NewEtcdStorage
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -586,7 +586,7 @@ func TestAliceNotForbiddenOrUnauthorized(t *testing.T) {
...
@@ -586,7 +586,7 @@ func TestAliceNotForbiddenOrUnauthorized(t *testing.T) {
defer
s
.
Close
()
defer
s
.
Close
()
m
=
master
.
New
(
&
master
.
Config
{
m
=
master
.
New
(
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
KubeletClient
:
client
.
FakeKubeletClient
{},
KubeletClient
:
client
.
FakeKubeletClient
{},
EnableCoreControllers
:
true
,
EnableCoreControllers
:
true
,
EnableLogsSupport
:
false
,
EnableLogsSupport
:
false
,
...
@@ -661,7 +661,7 @@ func TestBobIsForbidden(t *testing.T) {
...
@@ -661,7 +661,7 @@ func TestBobIsForbidden(t *testing.T) {
framework
.
DeleteAllEtcdKeys
()
framework
.
DeleteAllEtcdKeys
()
// This file has alice and bob in it.
// This file has alice and bob in it.
helper
,
err
:=
framework
.
NewHelper
()
etcdStorage
,
err
:=
framework
.
NewEtcdStorage
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -673,7 +673,7 @@ func TestBobIsForbidden(t *testing.T) {
...
@@ -673,7 +673,7 @@ func TestBobIsForbidden(t *testing.T) {
defer
s
.
Close
()
defer
s
.
Close
()
m
=
master
.
New
(
&
master
.
Config
{
m
=
master
.
New
(
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
KubeletClient
:
client
.
FakeKubeletClient
{},
KubeletClient
:
client
.
FakeKubeletClient
{},
EnableCoreControllers
:
true
,
EnableCoreControllers
:
true
,
EnableLogsSupport
:
false
,
EnableLogsSupport
:
false
,
...
@@ -722,7 +722,7 @@ func TestUnknownUserIsUnauthorized(t *testing.T) {
...
@@ -722,7 +722,7 @@ func TestUnknownUserIsUnauthorized(t *testing.T) {
// This file has alice and bob in it.
// This file has alice and bob in it.
// Set up a master
// Set up a master
helper
,
err
:=
framework
.
NewHelper
()
etcdStorage
,
err
:=
framework
.
NewEtcdStorage
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -734,7 +734,7 @@ func TestUnknownUserIsUnauthorized(t *testing.T) {
...
@@ -734,7 +734,7 @@ func TestUnknownUserIsUnauthorized(t *testing.T) {
defer
s
.
Close
()
defer
s
.
Close
()
m
=
master
.
New
(
&
master
.
Config
{
m
=
master
.
New
(
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
KubeletClient
:
client
.
FakeKubeletClient
{},
KubeletClient
:
client
.
FakeKubeletClient
{},
EnableCoreControllers
:
true
,
EnableCoreControllers
:
true
,
EnableLogsSupport
:
false
,
EnableLogsSupport
:
false
,
...
@@ -799,7 +799,7 @@ func TestNamespaceAuthorization(t *testing.T) {
...
@@ -799,7 +799,7 @@ func TestNamespaceAuthorization(t *testing.T) {
framework
.
DeleteAllEtcdKeys
()
framework
.
DeleteAllEtcdKeys
()
// This file has alice and bob in it.
// This file has alice and bob in it.
helper
,
err
:=
framework
.
NewHelper
()
etcdStorage
,
err
:=
framework
.
NewEtcdStorage
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -814,7 +814,7 @@ func TestNamespaceAuthorization(t *testing.T) {
...
@@ -814,7 +814,7 @@ func TestNamespaceAuthorization(t *testing.T) {
defer
s
.
Close
()
defer
s
.
Close
()
m
=
master
.
New
(
&
master
.
Config
{
m
=
master
.
New
(
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
KubeletClient
:
client
.
FakeKubeletClient
{},
KubeletClient
:
client
.
FakeKubeletClient
{},
EnableCoreControllers
:
true
,
EnableCoreControllers
:
true
,
EnableLogsSupport
:
false
,
EnableLogsSupport
:
false
,
...
@@ -914,7 +914,7 @@ func TestKindAuthorization(t *testing.T) {
...
@@ -914,7 +914,7 @@ func TestKindAuthorization(t *testing.T) {
// This file has alice and bob in it.
// This file has alice and bob in it.
// Set up a master
// Set up a master
helper
,
err
:=
framework
.
NewHelper
()
etcdStorage
,
err
:=
framework
.
NewEtcdStorage
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -929,7 +929,7 @@ func TestKindAuthorization(t *testing.T) {
...
@@ -929,7 +929,7 @@ func TestKindAuthorization(t *testing.T) {
defer
s
.
Close
()
defer
s
.
Close
()
m
=
master
.
New
(
&
master
.
Config
{
m
=
master
.
New
(
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
KubeletClient
:
client
.
FakeKubeletClient
{},
KubeletClient
:
client
.
FakeKubeletClient
{},
EnableCoreControllers
:
true
,
EnableCoreControllers
:
true
,
EnableLogsSupport
:
false
,
EnableLogsSupport
:
false
,
...
@@ -1017,7 +1017,7 @@ func TestReadOnlyAuthorization(t *testing.T) {
...
@@ -1017,7 +1017,7 @@ func TestReadOnlyAuthorization(t *testing.T) {
// This file has alice and bob in it.
// This file has alice and bob in it.
// Set up a master
// Set up a master
helper
,
err
:=
framework
.
NewHelper
()
etcdStorage
,
err
:=
framework
.
NewEtcdStorage
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -1031,7 +1031,7 @@ func TestReadOnlyAuthorization(t *testing.T) {
...
@@ -1031,7 +1031,7 @@ func TestReadOnlyAuthorization(t *testing.T) {
defer
s
.
Close
()
defer
s
.
Close
()
m
=
master
.
New
(
&
master
.
Config
{
m
=
master
.
New
(
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
KubeletClient
:
client
.
FakeKubeletClient
{},
KubeletClient
:
client
.
FakeKubeletClient
{},
EnableCoreControllers
:
true
,
EnableCoreControllers
:
true
,
EnableLogsSupport
:
false
,
EnableLogsSupport
:
false
,
...
...
test/integration/etcd_tools_test.go
View file @
7cc1855c
...
@@ -31,66 +31,57 @@ import (
...
@@ -31,66 +31,57 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/test/integration/framework"
"github.com/GoogleCloudPlatform/kubernetes/test/integration/framework"
)
)
type
stringCodec
struct
{}
type
fakeAPIObject
string
func
(
*
fakeAPIObject
)
IsAnAPIObject
()
{}
func
(
c
stringCodec
)
Encode
(
obj
runtime
.
Object
)
([]
byte
,
error
)
{
return
[]
byte
(
*
obj
.
(
*
fakeAPIObject
)),
nil
}
func
(
c
stringCodec
)
Decode
(
data
[]
byte
)
(
runtime
.
Object
,
error
)
{
o
:=
fakeAPIObject
(
data
)
return
&
o
,
nil
}
func
(
c
stringCodec
)
DecodeInto
(
data
[]
byte
,
obj
runtime
.
Object
)
error
{
o
:=
obj
.
(
*
fakeAPIObject
)
*
o
=
fakeAPIObject
(
data
)
return
nil
}
func
TestSetObj
(
t
*
testing
.
T
)
{
func
TestSetObj
(
t
*
testing
.
T
)
{
client
:=
framework
.
NewEtcdClient
()
client
:=
framework
.
NewEtcdClient
()
helper
:=
tools
.
EtcdHelper
{
Client
:
client
,
Codec
:
stringCodec
{}}
etcdStorage
:=
tools
.
NewEtcdStorage
(
client
,
testapi
.
Codec
(),
""
)
framework
.
WithEtcdKey
(
func
(
key
string
)
{
framework
.
WithEtcdKey
(
func
(
key
string
)
{
fakeObject
:=
fakeAPIObject
(
"object"
)
testObject
:=
api
.
ServiceAccount
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}
if
err
:=
helper
.
SetObj
(
key
,
&
fake
Object
,
nil
,
0
);
err
!=
nil
{
if
err
:=
etcdStorage
.
SetObj
(
key
,
&
test
Object
,
nil
,
0
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
resp
,
err
:=
client
.
Get
(
key
,
false
,
false
)
resp
,
err
:=
client
.
Get
(
key
,
false
,
false
)
if
err
!=
nil
||
resp
.
Node
==
nil
{
if
err
!=
nil
||
resp
.
Node
==
nil
{
t
.
Fatalf
(
"unexpected error: %v %v"
,
err
,
resp
)
t
.
Fatalf
(
"unexpected error: %v %v"
,
err
,
resp
)
}
}
if
resp
.
Node
.
Value
!=
"object"
{
decoded
,
err
:=
testapi
.
Codec
()
.
Decode
([]
byte
(
resp
.
Node
.
Value
))
t
.
Errorf
(
"unexpected response: %#v"
,
resp
.
Node
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected response: %#v"
,
resp
.
Node
)
}
result
:=
*
decoded
.
(
*
api
.
ServiceAccount
)
if
!
api
.
Semantic
.
DeepEqual
(
testObject
,
result
)
{
t
.
Errorf
(
"expected: %#v got: %#v"
,
testObject
,
result
)
}
}
})
})
}
}
func
TestExtractObj
(
t
*
testing
.
T
)
{
func
TestExtractObj
(
t
*
testing
.
T
)
{
client
:=
framework
.
NewEtcdClient
()
client
:=
framework
.
NewEtcdClient
()
helper
:=
tools
.
EtcdHelper
{
Client
:
client
,
Codec
:
stringCodec
{}}
etcdStorage
:=
tools
.
NewEtcdStorage
(
client
,
testapi
.
Codec
(),
""
)
framework
.
WithEtcdKey
(
func
(
key
string
)
{
framework
.
WithEtcdKey
(
func
(
key
string
)
{
_
,
err
:=
client
.
Set
(
key
,
"object"
,
0
)
testObject
:=
api
.
ServiceAccount
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}
coded
,
err
:=
testapi
.
Codec
()
.
Encode
(
&
testObject
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
_
,
err
=
client
.
Set
(
key
,
string
(
coded
),
0
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
s
:=
fakeAPIObject
(
""
)
result
:=
api
.
ServiceAccount
{}
if
err
:=
helper
.
ExtractObj
(
key
,
&
s
,
false
);
err
!=
nil
{
if
err
:=
etcdStorage
.
ExtractObj
(
key
,
&
result
,
false
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
if
s
!=
"object"
{
// Propagate ResourceVersion (it is set automatically).
t
.
Errorf
(
"unexpected response: %#v"
,
s
)
testObject
.
ObjectMeta
.
ResourceVersion
=
result
.
ObjectMeta
.
ResourceVersion
if
!
api
.
Semantic
.
DeepEqual
(
testObject
,
result
)
{
t
.
Errorf
(
"expected: %#v got: %#v"
,
testObject
,
result
)
}
}
})
})
}
}
func
TestWatch
(
t
*
testing
.
T
)
{
func
TestWatch
(
t
*
testing
.
T
)
{
client
:=
framework
.
NewEtcdClient
()
client
:=
framework
.
NewEtcdClient
()
helper
:=
tools
.
NewEtcdHelper
(
client
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
etcdStorage
:=
tools
.
NewEtcdStorage
(
client
,
testapi
.
Codec
(),
etcdtest
.
PathPrefix
())
framework
.
WithEtcdKey
(
func
(
key
string
)
{
framework
.
WithEtcdKey
(
func
(
key
string
)
{
key
=
etcdtest
.
AddPrefix
(
key
)
key
=
etcdtest
.
AddPrefix
(
key
)
resp
,
err
:=
client
.
Set
(
key
,
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}),
0
)
resp
,
err
:=
client
.
Set
(
key
,
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}),
0
)
...
@@ -100,7 +91,7 @@ func TestWatch(t *testing.T) {
...
@@ -100,7 +91,7 @@ func TestWatch(t *testing.T) {
expectedVersion
:=
resp
.
Node
.
ModifiedIndex
expectedVersion
:=
resp
.
Node
.
ModifiedIndex
// watch should load the object at the current index
// watch should load the object at the current index
w
,
err
:=
helper
.
Watch
(
key
,
0
,
tools
.
Everything
)
w
,
err
:=
etcdStorage
.
Watch
(
key
,
0
,
tools
.
Everything
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
...
...
test/integration/framework/etcd_utils.go
View file @
7cc1855c
...
@@ -41,8 +41,8 @@ func NewEtcdClient() *etcd.Client {
...
@@ -41,8 +41,8 @@ func NewEtcdClient() *etcd.Client {
return
etcd
.
NewClient
([]
string
{})
return
etcd
.
NewClient
([]
string
{})
}
}
func
New
Helper
()
(
tools
.
EtcdHelper
,
error
)
{
func
New
EtcdStorage
()
(
tools
.
StorageInterface
,
error
)
{
return
master
.
NewEtcd
Helper
(
NewEtcdClient
(),
testapi
.
Version
(),
etcdtest
.
PathPrefix
())
return
master
.
NewEtcd
Storage
(
NewEtcdClient
(),
testapi
.
Version
(),
etcdtest
.
PathPrefix
())
}
}
func
RequireEtcd
()
{
func
RequireEtcd
()
{
...
...
test/integration/framework/master_utils.go
View file @
7cc1855c
...
@@ -61,7 +61,7 @@ const (
...
@@ -61,7 +61,7 @@ const (
type
MasterComponents
struct
{
type
MasterComponents
struct
{
// Raw http server in front of the master
// Raw http server in front of the master
ApiServer
*
httptest
.
Server
ApiServer
*
httptest
.
Server
// Kubernetes master, contains an embedded etcd
helper
// Kubernetes master, contains an embedded etcd
storage
KubeMaster
*
master
.
Master
KubeMaster
*
master
.
Master
// Restclient used to talk to the kubernetes master
// Restclient used to talk to the kubernetes master
RestClient
*
client
.
Client
RestClient
*
client
.
Client
...
@@ -71,8 +71,8 @@ type MasterComponents struct {
...
@@ -71,8 +71,8 @@ type MasterComponents struct {
rcStopCh
chan
struct
{}
rcStopCh
chan
struct
{}
// Used to stop master components individually, and via MasterComponents.Stop
// Used to stop master components individually, and via MasterComponents.Stop
once
sync
.
Once
once
sync
.
Once
// Kubernetes etcd
helper
, has embedded etcd client
// Kubernetes etcd
storage
, has embedded etcd client
Etcd
Helper
*
tools
.
EtcdHelper
Etcd
Storage
tools
.
StorageInterface
}
}
// Config is a struct of configuration directives for NewMasterComponents.
// Config is a struct of configuration directives for NewMasterComponents.
...
@@ -91,7 +91,7 @@ type Config struct {
...
@@ -91,7 +91,7 @@ type Config struct {
// NewMasterComponents creates, initializes and starts master components based on the given config.
// NewMasterComponents creates, initializes and starts master components based on the given config.
func
NewMasterComponents
(
c
*
Config
)
*
MasterComponents
{
func
NewMasterComponents
(
c
*
Config
)
*
MasterComponents
{
m
,
s
,
h
:=
startMasterOrDie
(
c
.
MasterConfig
)
m
,
s
,
e
:=
startMasterOrDie
(
c
.
MasterConfig
)
// TODO: Allow callers to pipe through a different master url and create a client/start components using it.
// TODO: Allow callers to pipe through a different master url and create a client/start components using it.
glog
.
Infof
(
"Master %+v"
,
s
.
URL
)
glog
.
Infof
(
"Master %+v"
,
s
.
URL
)
if
c
.
DeleteEtcdKeys
{
if
c
.
DeleteEtcdKeys
{
...
@@ -113,27 +113,27 @@ func NewMasterComponents(c *Config) *MasterComponents {
...
@@ -113,27 +113,27 @@ func NewMasterComponents(c *Config) *MasterComponents {
RestClient
:
restClient
,
RestClient
:
restClient
,
ControllerManager
:
controllerManager
,
ControllerManager
:
controllerManager
,
rcStopCh
:
rcStopCh
,
rcStopCh
:
rcStopCh
,
Etcd
Helper
:
h
,
Etcd
Storage
:
e
,
once
:
once
,
once
:
once
,
}
}
}
}
// startMasterOrDie starts a kubernetes master and an httpserver to handle api requests
// startMasterOrDie starts a kubernetes master and an httpserver to handle api requests
func
startMasterOrDie
(
masterConfig
*
master
.
Config
)
(
*
master
.
Master
,
*
httptest
.
Server
,
*
tools
.
EtcdHelper
)
{
func
startMasterOrDie
(
masterConfig
*
master
.
Config
)
(
*
master
.
Master
,
*
httptest
.
Server
,
tools
.
StorageInterface
)
{
var
m
*
master
.
Master
var
m
*
master
.
Master
s
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
s
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
m
.
Handler
.
ServeHTTP
(
w
,
req
)
m
.
Handler
.
ServeHTTP
(
w
,
req
)
}))
}))
var
helper
tools
.
EtcdHelper
var
etcdStorage
tools
.
StorageInterface
var
err
error
var
err
error
if
masterConfig
==
nil
{
if
masterConfig
==
nil
{
helper
,
err
=
master
.
NewEtcdHelper
(
NewEtcdClient
(),
""
,
etcdtest
.
PathPrefix
())
etcdStorage
,
err
=
master
.
NewEtcdStorage
(
NewEtcdClient
(),
""
,
etcdtest
.
PathPrefix
())
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"Failed to create etcd
helper
for master %v"
,
err
)
glog
.
Fatalf
(
"Failed to create etcd
storage
for master %v"
,
err
)
}
}
masterConfig
=
&
master
.
Config
{
masterConfig
=
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
KubeletClient
:
client
.
FakeKubeletClient
{},
KubeletClient
:
client
.
FakeKubeletClient
{},
EnableLogsSupport
:
false
,
EnableLogsSupport
:
false
,
EnableProfiling
:
true
,
EnableProfiling
:
true
,
...
@@ -143,10 +143,10 @@ func startMasterOrDie(masterConfig *master.Config) (*master.Master, *httptest.Se
...
@@ -143,10 +143,10 @@ func startMasterOrDie(masterConfig *master.Config) (*master.Master, *httptest.Se
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
}
}
}
else
{
}
else
{
helper
=
masterConfig
.
EtcdHelper
etcdStorage
=
masterConfig
.
DatabaseStorage
}
}
m
=
master
.
New
(
masterConfig
)
m
=
master
.
New
(
masterConfig
)
return
m
,
s
,
&
helper
return
m
,
s
,
etcdStorage
}
}
func
(
m
*
MasterComponents
)
stopRCManager
()
{
func
(
m
*
MasterComponents
)
stopRCManager
()
{
...
@@ -258,13 +258,13 @@ func StartPods(numPods int, host string, restClient *client.Client) error {
...
@@ -258,13 +258,13 @@ func StartPods(numPods int, host string, restClient *client.Client) error {
// TODO: Merge this into startMasterOrDie.
// TODO: Merge this into startMasterOrDie.
func
RunAMaster
(
t
*
testing
.
T
)
(
*
master
.
Master
,
*
httptest
.
Server
)
{
func
RunAMaster
(
t
*
testing
.
T
)
(
*
master
.
Master
,
*
httptest
.
Server
)
{
helper
,
err
:=
master
.
NewEtcdHelper
(
NewEtcdClient
(),
testapi
.
Version
(),
etcdtest
.
PathPrefix
())
etcdStorage
,
err
:=
master
.
NewEtcdStorage
(
NewEtcdClient
(),
testapi
.
Version
(),
etcdtest
.
PathPrefix
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
m
:=
master
.
New
(
&
master
.
Config
{
m
:=
master
.
New
(
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
KubeletClient
:
client
.
FakeKubeletClient
{},
KubeletClient
:
client
.
FakeKubeletClient
{},
EnableLogsSupport
:
false
,
EnableLogsSupport
:
false
,
EnableProfiling
:
true
,
EnableProfiling
:
true
,
...
...
test/integration/master_benchmark_test.go
View file @
7cc1855c
...
@@ -179,7 +179,7 @@ func BenchmarkPodListEtcd(b *testing.B) {
...
@@ -179,7 +179,7 @@ func BenchmarkPodListEtcd(b *testing.B) {
defer
func
()
{
defer
func
()
{
glog
.
V
(
3
)
.
Infof
(
"Worker %d: listing pods took %v"
,
id
,
time
.
Since
(
now
))
glog
.
V
(
3
)
.
Infof
(
"Worker %d: listing pods took %v"
,
id
,
time
.
Since
(
now
))
}()
}()
if
response
,
err
:=
m
.
Etcd
Helper
.
Client
.
Get
(
key
,
true
,
true
);
err
!=
nil
{
if
response
,
err
:=
m
.
Etcd
Storage
.
Client
.
Get
(
key
,
true
,
true
);
err
!=
nil
{
return
err
return
err
}
else
if
len
(
response
.
Node
.
Nodes
)
<
podsPerNode
{
}
else
if
len
(
response
.
Node
.
Nodes
)
<
podsPerNode
{
glog
.
Fatalf
(
"List retrieved %d pods, which is less than %d"
,
len
(
response
.
Node
.
Nodes
),
podsPerNode
)
glog
.
Fatalf
(
"List retrieved %d pods, which is less than %d"
,
len
(
response
.
Node
.
Nodes
),
podsPerNode
)
...
...
test/integration/scheduler_test.go
View file @
7cc1855c
...
@@ -53,9 +53,9 @@ type nodeStateManager struct {
...
@@ -53,9 +53,9 @@ type nodeStateManager struct {
}
}
func
TestUnschedulableNodes
(
t
*
testing
.
T
)
{
func
TestUnschedulableNodes
(
t
*
testing
.
T
)
{
helper
,
err
:=
framework
.
NewHelper
()
etcdStorage
,
err
:=
framework
.
NewEtcdStorage
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Couldn't create etcd
helper
: %v"
,
err
)
t
.
Fatalf
(
"Couldn't create etcd
storage
: %v"
,
err
)
}
}
framework
.
DeleteAllEtcdKeys
()
framework
.
DeleteAllEtcdKeys
()
...
@@ -66,7 +66,7 @@ func TestUnschedulableNodes(t *testing.T) {
...
@@ -66,7 +66,7 @@ func TestUnschedulableNodes(t *testing.T) {
defer
s
.
Close
()
defer
s
.
Close
()
m
=
master
.
New
(
&
master
.
Config
{
m
=
master
.
New
(
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
KubeletClient
:
client
.
FakeKubeletClient
{},
KubeletClient
:
client
.
FakeKubeletClient
{},
EnableCoreControllers
:
true
,
EnableCoreControllers
:
true
,
EnableLogsSupport
:
false
,
EnableLogsSupport
:
false
,
...
...
test/integration/secret_test.go
View file @
7cc1855c
...
@@ -47,7 +47,7 @@ func deleteSecretOrErrorf(t *testing.T, c *client.Client, ns, name string) {
...
@@ -47,7 +47,7 @@ func deleteSecretOrErrorf(t *testing.T, c *client.Client, ns, name string) {
// TestSecrets tests apiserver-side behavior of creation of secret objects and their use by pods.
// TestSecrets tests apiserver-side behavior of creation of secret objects and their use by pods.
func
TestSecrets
(
t
*
testing
.
T
)
{
func
TestSecrets
(
t
*
testing
.
T
)
{
helper
,
err
:=
framework
.
NewHelper
()
etcdStorage
,
err
:=
framework
.
NewEtcdStorage
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -59,7 +59,7 @@ func TestSecrets(t *testing.T) {
...
@@ -59,7 +59,7 @@ func TestSecrets(t *testing.T) {
defer
s
.
Close
()
defer
s
.
Close
()
m
=
master
.
New
(
&
master
.
Config
{
m
=
master
.
New
(
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
KubeletClient
:
client
.
FakeKubeletClient
{},
KubeletClient
:
client
.
FakeKubeletClient
{},
EnableCoreControllers
:
true
,
EnableCoreControllers
:
true
,
EnableLogsSupport
:
false
,
EnableLogsSupport
:
false
,
...
...
test/integration/service_account_test.go
View file @
7cc1855c
...
@@ -340,7 +340,7 @@ func startServiceAccountTestServer(t *testing.T) (*client.Client, client.Config,
...
@@ -340,7 +340,7 @@ func startServiceAccountTestServer(t *testing.T) (*client.Client, client.Config,
deleteAllEtcdKeys
()
deleteAllEtcdKeys
()
// Etcd
// Etcd
helper
,
err
:=
master
.
NewEtcdHelper
(
newEtcdClient
(),
testapi
.
Version
(),
etcdtest
.
PathPrefix
())
etcdStorage
,
err
:=
master
.
NewEtcdStorage
(
newEtcdClient
(),
testapi
.
Version
(),
etcdtest
.
PathPrefix
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -410,7 +410,7 @@ func startServiceAccountTestServer(t *testing.T) (*client.Client, client.Config,
...
@@ -410,7 +410,7 @@ func startServiceAccountTestServer(t *testing.T) (*client.Client, client.Config,
// Create a master and install handlers into mux.
// Create a master and install handlers into mux.
m
=
master
.
New
(
&
master
.
Config
{
m
=
master
.
New
(
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
KubeletClient
:
client
.
FakeKubeletClient
{},
KubeletClient
:
client
.
FakeKubeletClient
{},
EnableLogsSupport
:
false
,
EnableLogsSupport
:
false
,
EnableUISupport
:
false
,
EnableUISupport
:
false
,
...
...
test/integration/utils.go
View file @
7cc1855c
...
@@ -67,13 +67,13 @@ func deleteAllEtcdKeys() {
...
@@ -67,13 +67,13 @@ func deleteAllEtcdKeys() {
}
}
func
runAMaster
(
t
*
testing
.
T
)
(
*
master
.
Master
,
*
httptest
.
Server
)
{
func
runAMaster
(
t
*
testing
.
T
)
(
*
master
.
Master
,
*
httptest
.
Server
)
{
helper
,
err
:=
master
.
NewEtcdHelper
(
newEtcdClient
(),
testapi
.
Version
(),
etcdtest
.
PathPrefix
())
etcdStorage
,
err
:=
master
.
NewEtcdStorage
(
newEtcdClient
(),
testapi
.
Version
(),
etcdtest
.
PathPrefix
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
m
:=
master
.
New
(
&
master
.
Config
{
m
:=
master
.
New
(
&
master
.
Config
{
EtcdHelper
:
helper
,
DatabaseStorage
:
etcdStorage
,
KubeletClient
:
client
.
FakeKubeletClient
{},
KubeletClient
:
client
.
FakeKubeletClient
{},
EnableCoreControllers
:
true
,
EnableCoreControllers
:
true
,
EnableLogsSupport
:
false
,
EnableLogsSupport
:
false
,
...
...
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