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
519c1374
Commit
519c1374
authored
Sep 08, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
convert rest of kubectl to generated clients
parent
f756e43e
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
500 additions
and
606 deletions
+500
-606
cmd_test.go
pkg/kubectl/cmd/cmd_test.go
+0
-8
run.go
pkg/kubectl/cmd/run.go
+15
-24
top_node.go
pkg/kubectl/cmd/top_node.go
+10
-7
top_node_test.go
pkg/kubectl/cmd/top_node_test.go
+3
-5
top_pod.go
pkg/kubectl/cmd/top_pod.go
+7
-4
top_pod_test.go
pkg/kubectl/cmd/top_pod_test.go
+5
-7
top_test.go
pkg/kubectl/cmd/top_test.go
+2
-2
clientcache.go
pkg/kubectl/cmd/util/clientcache.go
+0
-36
factory.go
pkg/kubectl/cmd/util/factory.go
+46
-91
factory_test.go
pkg/kubectl/cmd/util/factory_test.go
+10
-12
describe.go
pkg/kubectl/describe.go
+68
-69
describe_test.go
pkg/kubectl/describe_test.go
+62
-51
metrics_client.go
pkg/kubectl/metricsutil/metrics_client.go
+7
-7
rolling_updater_test.go
pkg/kubectl/rolling_updater_test.go
+86
-69
rollout_status.go
pkg/kubectl/rollout_status.go
+4
-3
rollout_status_test.go
pkg/kubectl/rollout_status_test.go
+3
-2
scale.go
pkg/kubectl/scale.go
+1
-1
scale_test.go
pkg/kubectl/scale_test.go
+82
-52
stop.go
pkg/kubectl/stop.go
+1
-1
stop_test.go
pkg/kubectl/stop_test.go
+64
-137
batch_v1_jobs.go
test/e2e/batch_v1_jobs.go
+4
-3
daemon_set.go
test/e2e/daemon_set.go
+2
-1
deployment.go
test/e2e/deployment.go
+5
-5
util.go
test/e2e/framework/util.go
+4
-3
job.go
test/e2e/job.go
+4
-3
kubectl.go
test/e2e/kubectl.go
+2
-1
master_utils.go
test/integration/framework/master_utils.go
+3
-2
No files found.
pkg/kubectl/cmd/cmd_test.go
View file @
519c1374
...
@@ -301,14 +301,6 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec, runtime.Neg
...
@@ -301,14 +301,6 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec, runtime.Neg
return
kubectl
.
ShortcutExpander
{
RESTMapper
:
mapper
},
typer
,
nil
return
kubectl
.
ShortcutExpander
{
RESTMapper
:
mapper
},
typer
,
nil
},
},
Client
:
func
()
(
*
client
.
Client
,
error
)
{
// Swap out the HTTP client out of the client with the fake's version.
fakeClient
:=
t
.
Client
.
(
*
fake
.
RESTClient
)
c
:=
client
.
NewOrDie
(
t
.
ClientConfig
)
c
.
Client
=
fakeClient
.
Client
c
.
ExtensionsClient
.
Client
=
fakeClient
.
Client
return
c
,
t
.
Err
},
ClientSet
:
func
()
(
*
internalclientset
.
Clientset
,
error
)
{
ClientSet
:
func
()
(
*
internalclientset
.
Clientset
,
error
)
{
// Swap out the HTTP client out of the client with the fake's version.
// Swap out the HTTP client out of the client with the fake's version.
fakeClient
:=
t
.
Client
.
(
*
fake
.
RESTClient
)
fakeClient
:=
t
.
Client
.
(
*
fake
.
RESTClient
)
...
...
pkg/kubectl/cmd/run.go
View file @
519c1374
...
@@ -32,7 +32,7 @@ import (
...
@@ -32,7 +32,7 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
batchv1
"k8s.io/kubernetes/pkg/apis/batch/v1"
batchv1
"k8s.io/kubernetes/pkg/apis/batch/v1"
"k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
"k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
c
lient
"k8s.io/kubernetes/pkg/client
/unversioned"
c
oreclient
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core
/unversioned"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/resource"
...
@@ -179,11 +179,11 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
...
@@ -179,11 +179,11 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
generatorName
=
"scheduledjob/v2alpha1"
generatorName
=
"scheduledjob/v2alpha1"
}
}
if
len
(
generatorName
)
==
0
{
if
len
(
generatorName
)
==
0
{
client
,
err
:=
f
.
Clien
t
()
client
set
,
err
:=
f
.
ClientSe
t
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
resourcesList
,
err
:=
client
.
Discovery
()
.
ServerResources
()
resourcesList
,
err
:=
client
set
.
Discovery
()
.
ServerResources
()
// ServerResources ignores errors for old servers do not expose discovery
// ServerResources ignores errors for old servers do not expose discovery
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to discover supported resources: %v"
,
err
)
return
fmt
.
Errorf
(
"failed to discover supported resources: %v"
,
err
)
...
@@ -270,11 +270,6 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
...
@@ -270,11 +270,6 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
}
}
opts
.
Config
=
config
opts
.
Config
=
config
client
,
err
:=
f
.
Client
()
if
err
!=
nil
{
return
err
}
clientset
,
err
:=
f
.
ClientSet
()
clientset
,
err
:=
f
.
ClientSet
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -285,7 +280,7 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
...
@@ -285,7 +280,7 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
err
=
handleAttachPod
(
f
,
client
,
attachablePod
.
Namespace
,
attachablePod
.
Name
,
opts
,
quiet
)
err
=
handleAttachPod
(
f
,
client
set
.
Core
()
,
attachablePod
.
Namespace
,
attachablePod
.
Name
,
opts
,
quiet
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -294,7 +289,7 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
...
@@ -294,7 +289,7 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
leaveStdinOpen
:=
cmdutil
.
GetFlagBool
(
cmd
,
"leave-stdin-open"
)
leaveStdinOpen
:=
cmdutil
.
GetFlagBool
(
cmd
,
"leave-stdin-open"
)
waitForExitCode
:=
!
leaveStdinOpen
&&
restartPolicy
==
api
.
RestartPolicyNever
waitForExitCode
:=
!
leaveStdinOpen
&&
restartPolicy
==
api
.
RestartPolicyNever
if
waitForExitCode
{
if
waitForExitCode
{
pod
,
err
=
waitForPodTerminated
(
client
,
attachablePod
.
Namespace
,
attachablePod
.
Name
,
opts
.
Out
,
quiet
)
pod
,
err
=
waitForPodTerminated
(
client
set
.
Core
()
,
attachablePod
.
Namespace
,
attachablePod
.
Name
,
opts
.
Out
,
quiet
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -377,8 +372,8 @@ func contains(resourcesList map[string]*unversioned.APIResourceList, resource un
...
@@ -377,8 +372,8 @@ func contains(resourcesList map[string]*unversioned.APIResourceList, resource un
// waitForPod watches the given pod until the exitCondition is true. Each two seconds
// waitForPod watches the given pod until the exitCondition is true. Each two seconds
// the tick function is called e.g. for progress output.
// the tick function is called e.g. for progress output.
func
waitForPod
(
c
*
client
.
Client
,
ns
,
name
string
,
exitCondition
func
(
*
api
.
Pod
)
bool
,
tick
func
(
*
api
.
Pod
))
(
*
api
.
Pod
,
error
)
{
func
waitForPod
(
podClient
coreclient
.
PodsGetter
,
ns
,
name
string
,
exitCondition
func
(
*
api
.
Pod
)
bool
,
tick
func
(
*
api
.
Pod
))
(
*
api
.
Pod
,
error
)
{
pod
,
err
:=
c
.
Pods
(
ns
)
.
Get
(
name
)
pod
,
err
:=
podClient
.
Pods
(
ns
)
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -388,7 +383,7 @@ func waitForPod(c *client.Client, ns, name string, exitCondition func(*api.Pod)
...
@@ -388,7 +383,7 @@ func waitForPod(c *client.Client, ns, name string, exitCondition func(*api.Pod)
tick
(
pod
)
tick
(
pod
)
w
,
err
:=
c
.
Pods
(
ns
)
.
Watch
(
api
.
SingleObject
(
api
.
ObjectMeta
{
Name
:
pod
.
Name
,
ResourceVersion
:
pod
.
ResourceVersion
}))
w
,
err
:=
podClient
.
Pods
(
ns
)
.
Watch
(
api
.
SingleObject
(
api
.
ObjectMeta
{
Name
:
pod
.
Name
,
ResourceVersion
:
pod
.
ResourceVersion
}))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -424,7 +419,7 @@ func waitForPod(c *client.Client, ns, name string, exitCondition func(*api.Pod)
...
@@ -424,7 +419,7 @@ func waitForPod(c *client.Client, ns, name string, exitCondition func(*api.Pod)
return
result
,
err
return
result
,
err
}
}
func
waitForPodRunning
(
c
*
client
.
Client
,
ns
,
name
string
,
out
io
.
Writer
,
quiet
bool
)
(
*
api
.
Pod
,
error
)
{
func
waitForPodRunning
(
podClient
coreclient
.
PodsGetter
,
ns
,
name
string
,
out
io
.
Writer
,
quiet
bool
)
(
*
api
.
Pod
,
error
)
{
exitCondition
:=
func
(
pod
*
api
.
Pod
)
bool
{
exitCondition
:=
func
(
pod
*
api
.
Pod
)
bool
{
switch
pod
.
Status
.
Phase
{
switch
pod
.
Status
.
Phase
{
case
api
.
PodRunning
:
case
api
.
PodRunning
:
...
@@ -440,26 +435,26 @@ func waitForPodRunning(c *client.Client, ns, name string, out io.Writer, quiet b
...
@@ -440,26 +435,26 @@ func waitForPodRunning(c *client.Client, ns, name string, out io.Writer, quiet b
return
false
return
false
}
}
}
}
return
waitForPod
(
c
,
ns
,
name
,
exitCondition
,
func
(
pod
*
api
.
Pod
)
{
return
waitForPod
(
podClient
,
ns
,
name
,
exitCondition
,
func
(
pod
*
api
.
Pod
)
{
if
!
quiet
{
if
!
quiet
{
fmt
.
Fprintf
(
out
,
"Waiting for pod %s/%s to be running, status is %s, pod ready: false
\n
"
,
pod
.
Namespace
,
pod
.
Name
,
pod
.
Status
.
Phase
)
fmt
.
Fprintf
(
out
,
"Waiting for pod %s/%s to be running, status is %s, pod ready: false
\n
"
,
pod
.
Namespace
,
pod
.
Name
,
pod
.
Status
.
Phase
)
}
}
})
})
}
}
func
waitForPodTerminated
(
c
*
client
.
Client
,
ns
,
name
string
,
out
io
.
Writer
,
quiet
bool
)
(
*
api
.
Pod
,
error
)
{
func
waitForPodTerminated
(
podClient
coreclient
.
PodsGetter
,
ns
,
name
string
,
out
io
.
Writer
,
quiet
bool
)
(
*
api
.
Pod
,
error
)
{
exitCondition
:=
func
(
pod
*
api
.
Pod
)
bool
{
exitCondition
:=
func
(
pod
*
api
.
Pod
)
bool
{
return
pod
.
Status
.
Phase
==
api
.
PodSucceeded
||
pod
.
Status
.
Phase
==
api
.
PodFailed
return
pod
.
Status
.
Phase
==
api
.
PodSucceeded
||
pod
.
Status
.
Phase
==
api
.
PodFailed
}
}
return
waitForPod
(
c
,
ns
,
name
,
exitCondition
,
func
(
pod
*
api
.
Pod
)
{
return
waitForPod
(
podClient
,
ns
,
name
,
exitCondition
,
func
(
pod
*
api
.
Pod
)
{
if
!
quiet
{
if
!
quiet
{
fmt
.
Fprintf
(
out
,
"Waiting for pod %s/%s to terminate, status is %s
\n
"
,
pod
.
Namespace
,
pod
.
Name
,
pod
.
Status
.
Phase
)
fmt
.
Fprintf
(
out
,
"Waiting for pod %s/%s to terminate, status is %s
\n
"
,
pod
.
Namespace
,
pod
.
Name
,
pod
.
Status
.
Phase
)
}
}
})
})
}
}
func
handleAttachPod
(
f
*
cmdutil
.
Factory
,
c
*
client
.
Client
,
ns
,
name
string
,
opts
*
AttachOptions
,
quiet
bool
)
error
{
func
handleAttachPod
(
f
*
cmdutil
.
Factory
,
podClient
coreclient
.
PodsGetter
,
ns
,
name
string
,
opts
*
AttachOptions
,
quiet
bool
)
error
{
pod
,
err
:=
waitForPodRunning
(
c
,
ns
,
name
,
opts
.
Out
,
quiet
)
pod
,
err
:=
waitForPodRunning
(
podClient
,
ns
,
name
,
opts
.
Out
,
quiet
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -481,11 +476,7 @@ func handleAttachPod(f *cmdutil.Factory, c *client.Client, ns, name string, opts
...
@@ -481,11 +476,7 @@ func handleAttachPod(f *cmdutil.Factory, c *client.Client, ns, name string, opts
return
err
return
err
}
}
clientset
,
err
:=
f
.
ClientSet
()
opts
.
PodClient
=
podClient
if
err
!=
nil
{
return
nil
}
opts
.
PodClient
=
clientset
.
Core
()
opts
.
PodName
=
name
opts
.
PodName
=
name
opts
.
Namespace
=
ns
opts
.
Namespace
=
ns
...
...
pkg/kubectl/cmd/top_node.go
View file @
519c1374
...
@@ -20,12 +20,13 @@ import (
...
@@ -20,12 +20,13 @@ import (
"errors"
"errors"
"io"
"io"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/metricsutil"
"github.com/renstrom/dedent"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
coreclient
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/unversioned"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/metricsutil"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
)
)
...
@@ -33,6 +34,7 @@ import (
...
@@ -33,6 +34,7 @@ import (
type
TopNodeOptions
struct
{
type
TopNodeOptions
struct
{
ResourceName
string
ResourceName
string
Selector
string
Selector
string
NodeClient
coreclient
.
NodesGetter
Client
*
metricsutil
.
HeapsterMetricsClient
Client
*
metricsutil
.
HeapsterMetricsClient
Printer
*
metricsutil
.
TopCmdPrinter
Printer
*
metricsutil
.
TopCmdPrinter
}
}
...
@@ -84,11 +86,12 @@ func (o *TopNodeOptions) Complete(f *cmdutil.Factory, cmd *cobra.Command, args [
...
@@ -84,11 +86,12 @@ func (o *TopNodeOptions) Complete(f *cmdutil.Factory, cmd *cobra.Command, args [
return
cmdutil
.
UsageError
(
cmd
,
cmd
.
Use
)
return
cmdutil
.
UsageError
(
cmd
,
cmd
.
Use
)
}
}
cli
,
err
:=
f
.
Clien
t
()
cli
entset
,
err
:=
f
.
ClientSe
t
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
o
.
Client
=
metricsutil
.
DefaultHeapsterMetricsClient
(
cli
)
o
.
NodeClient
=
clientset
.
Core
()
o
.
Client
=
metricsutil
.
DefaultHeapsterMetricsClient
(
clientset
.
Core
())
o
.
Printer
=
metricsutil
.
NewTopCmdPrinter
(
out
)
o
.
Printer
=
metricsutil
.
NewTopCmdPrinter
(
out
)
return
nil
return
nil
}
}
...
@@ -122,13 +125,13 @@ func (o TopNodeOptions) RunTopNode() error {
...
@@ -122,13 +125,13 @@ func (o TopNodeOptions) RunTopNode() error {
var
nodes
[]
api
.
Node
var
nodes
[]
api
.
Node
if
len
(
o
.
ResourceName
)
>
0
{
if
len
(
o
.
ResourceName
)
>
0
{
node
,
err
:=
o
.
Client
.
Nodes
()
.
Get
(
o
.
ResourceName
)
node
,
err
:=
o
.
Node
Client
.
Nodes
()
.
Get
(
o
.
ResourceName
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
nodes
=
append
(
nodes
,
*
node
)
nodes
=
append
(
nodes
,
*
node
)
}
else
{
}
else
{
nodeList
,
err
:=
o
.
Client
.
Nodes
()
.
List
(
api
.
ListOptions
{
nodeList
,
err
:=
o
.
Node
Client
.
Nodes
()
.
List
(
api
.
ListOptions
{
LabelSelector
:
selector
,
LabelSelector
:
selector
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/kubectl/cmd/top_node_test.go
View file @
519c1374
...
@@ -25,8 +25,6 @@ import (
...
@@ -25,8 +25,6 @@ import (
"k8s.io/heapster/metrics/apis/metrics/v1alpha1"
"k8s.io/heapster/metrics/apis/metrics/v1alpha1"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"net/url"
"net/url"
)
)
...
@@ -63,7 +61,7 @@ func TestTopNodeAllMetrics(t *testing.T) {
...
@@ -63,7 +61,7 @@ func TestTopNodeAllMetrics(t *testing.T) {
}),
}),
}
}
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
tf
.
ClientConfig
=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
unversioned
.
GroupVersion
{
Version
:
"v1"
}}}
tf
.
ClientConfig
=
defaultClientConfig
()
buf
:=
bytes
.
NewBuffer
([]
byte
{})
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdTopNode
(
f
,
buf
)
cmd
:=
NewCmdTopNode
(
f
,
buf
)
...
@@ -111,7 +109,7 @@ func TestTopNodeWithNameMetrics(t *testing.T) {
...
@@ -111,7 +109,7 @@ func TestTopNodeWithNameMetrics(t *testing.T) {
}),
}),
}
}
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
tf
.
ClientConfig
=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
unversioned
.
GroupVersion
{
Version
:
"v1"
}}}
tf
.
ClientConfig
=
defaultClientConfig
()
buf
:=
bytes
.
NewBuffer
([]
byte
{})
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdTopNode
(
f
,
buf
)
cmd
:=
NewCmdTopNode
(
f
,
buf
)
...
@@ -170,7 +168,7 @@ func TestTopNodeWithLabelSelectorMetrics(t *testing.T) {
...
@@ -170,7 +168,7 @@ func TestTopNodeWithLabelSelectorMetrics(t *testing.T) {
}),
}),
}
}
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
tf
.
ClientConfig
=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
unversioned
.
GroupVersion
{
Version
:
"v1"
}}}
tf
.
ClientConfig
=
defaultClientConfig
()
buf
:=
bytes
.
NewBuffer
([]
byte
{})
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdTopNode
(
f
,
buf
)
cmd
:=
NewCmdTopNode
(
f
,
buf
)
...
...
pkg/kubectl/cmd/top_pod.go
View file @
519c1374
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
"time"
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
coreclient
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/unversioned"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/metricsutil"
"k8s.io/kubernetes/pkg/kubectl/metricsutil"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
...
@@ -38,6 +39,7 @@ type TopPodOptions struct {
...
@@ -38,6 +39,7 @@ type TopPodOptions struct {
Selector
string
Selector
string
AllNamespaces
bool
AllNamespaces
bool
PrintContainers
bool
PrintContainers
bool
PodClient
coreclient
.
PodsGetter
Client
*
metricsutil
.
HeapsterMetricsClient
Client
*
metricsutil
.
HeapsterMetricsClient
Printer
*
metricsutil
.
TopCmdPrinter
Printer
*
metricsutil
.
TopCmdPrinter
}
}
...
@@ -103,11 +105,12 @@ func (o *TopPodOptions) Complete(f *cmdutil.Factory, cmd *cobra.Command, args []
...
@@ -103,11 +105,12 @@ func (o *TopPodOptions) Complete(f *cmdutil.Factory, cmd *cobra.Command, args []
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
cli
,
err
:=
f
.
Clien
t
()
cli
entset
,
err
:=
f
.
ClientSe
t
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
o
.
Client
=
metricsutil
.
DefaultHeapsterMetricsClient
(
cli
)
o
.
PodClient
=
clientset
.
Core
()
o
.
Client
=
metricsutil
.
DefaultHeapsterMetricsClient
(
clientset
.
Core
())
o
.
Printer
=
metricsutil
.
NewTopCmdPrinter
(
out
)
o
.
Printer
=
metricsutil
.
NewTopCmdPrinter
(
out
)
return
nil
return
nil
}
}
...
@@ -147,7 +150,7 @@ func (o TopPodOptions) RunTopPod() error {
...
@@ -147,7 +150,7 @@ func (o TopPodOptions) RunTopPod() error {
func
verifyEmptyMetrics
(
o
TopPodOptions
,
selector
labels
.
Selector
)
error
{
func
verifyEmptyMetrics
(
o
TopPodOptions
,
selector
labels
.
Selector
)
error
{
if
len
(
o
.
ResourceName
)
>
0
{
if
len
(
o
.
ResourceName
)
>
0
{
pod
,
err
:=
o
.
Client
.
Pods
(
o
.
Namespace
)
.
Get
(
o
.
ResourceName
)
pod
,
err
:=
o
.
Pod
Client
.
Pods
(
o
.
Namespace
)
.
Get
(
o
.
ResourceName
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -155,7 +158,7 @@ func verifyEmptyMetrics(o TopPodOptions, selector labels.Selector) error {
...
@@ -155,7 +158,7 @@ func verifyEmptyMetrics(o TopPodOptions, selector labels.Selector) error {
return
err
return
err
}
}
}
else
{
}
else
{
pods
,
err
:=
o
.
Client
.
Pods
(
o
.
Namespace
)
.
List
(
api
.
ListOptions
{
pods
,
err
:=
o
.
Pod
Client
.
Pods
(
o
.
Namespace
)
.
List
(
api
.
ListOptions
{
LabelSelector
:
selector
,
LabelSelector
:
selector
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/kubectl/cmd/top_pod_test.go
View file @
519c1374
...
@@ -24,8 +24,6 @@ import (
...
@@ -24,8 +24,6 @@ import (
"testing"
"testing"
metrics_api
"k8s.io/heapster/metrics/apis/metrics/v1alpha1"
metrics_api
"k8s.io/heapster/metrics/apis/metrics/v1alpha1"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"net/url"
"net/url"
)
)
...
@@ -61,7 +59,7 @@ func TestTopPodAllNamespacesMetrics(t *testing.T) {
...
@@ -61,7 +59,7 @@ func TestTopPodAllNamespacesMetrics(t *testing.T) {
}),
}),
}
}
tf
.
Namespace
=
firstTestNamespace
tf
.
Namespace
=
firstTestNamespace
tf
.
ClientConfig
=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
unversioned
.
GroupVersion
{
Version
:
"v1"
}}}
tf
.
ClientConfig
=
defaultClientConfig
()
buf
:=
bytes
.
NewBuffer
([]
byte
{})
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdTopPod
(
f
,
buf
)
cmd
:=
NewCmdTopPod
(
f
,
buf
)
...
@@ -120,7 +118,7 @@ func TestTopPodAllInNamespaceMetrics(t *testing.T) {
...
@@ -120,7 +118,7 @@ func TestTopPodAllInNamespaceMetrics(t *testing.T) {
}),
}),
}
}
tf
.
Namespace
=
testNamespace
tf
.
Namespace
=
testNamespace
tf
.
ClientConfig
=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
unversioned
.
GroupVersion
{
Version
:
"v1"
}}}
tf
.
ClientConfig
=
defaultClientConfig
()
buf
:=
bytes
.
NewBuffer
([]
byte
{})
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdTopPod
(
f
,
buf
)
cmd
:=
NewCmdTopPod
(
f
,
buf
)
...
@@ -171,7 +169,7 @@ func TestTopPodWithNameMetrics(t *testing.T) {
...
@@ -171,7 +169,7 @@ func TestTopPodWithNameMetrics(t *testing.T) {
}),
}),
}
}
tf
.
Namespace
=
testNamespace
tf
.
Namespace
=
testNamespace
tf
.
ClientConfig
=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
unversioned
.
GroupVersion
{
Version
:
"v1"
}}}
tf
.
ClientConfig
=
defaultClientConfig
()
buf
:=
bytes
.
NewBuffer
([]
byte
{})
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdTopPod
(
f
,
buf
)
cmd
:=
NewCmdTopPod
(
f
,
buf
)
...
@@ -224,7 +222,7 @@ func TestTopPodWithLabelSelectorMetrics(t *testing.T) {
...
@@ -224,7 +222,7 @@ func TestTopPodWithLabelSelectorMetrics(t *testing.T) {
}),
}),
}
}
tf
.
Namespace
=
testNamespace
tf
.
Namespace
=
testNamespace
tf
.
ClientConfig
=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
unversioned
.
GroupVersion
{
Version
:
"v1"
}}}
tf
.
ClientConfig
=
defaultClientConfig
()
buf
:=
bytes
.
NewBuffer
([]
byte
{})
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdTopPod
(
f
,
buf
)
cmd
:=
NewCmdTopPod
(
f
,
buf
)
...
@@ -276,7 +274,7 @@ func TestTopPodWithContainersMetrics(t *testing.T) {
...
@@ -276,7 +274,7 @@ func TestTopPodWithContainersMetrics(t *testing.T) {
}),
}),
}
}
tf
.
Namespace
=
testNamespace
tf
.
Namespace
=
testNamespace
tf
.
ClientConfig
=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
unversioned
.
GroupVersion
{
Version
:
"v1"
}}}
tf
.
ClientConfig
=
defaultClientConfig
()
buf
:=
bytes
.
NewBuffer
([]
byte
{})
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdTopPod
(
f
,
buf
)
cmd
:=
NewCmdTopPod
(
f
,
buf
)
...
...
pkg/kubectl/cmd/top_test.go
View file @
519c1374
...
@@ -32,8 +32,8 @@ import (
...
@@ -32,8 +32,8 @@ import (
)
)
const
(
const
(
baseHeapsterServiceAddress
=
"/api/v1/namespaces/kube-system/services/http:heapster:"
baseHeapsterServiceAddress
=
"/api/v1/
proxy/
namespaces/kube-system/services/http:heapster:"
baseMetricsAddress
=
baseHeapsterServiceAddress
+
"/
proxy/
apis/metrics"
baseMetricsAddress
=
baseHeapsterServiceAddress
+
"/apis/metrics"
metricsApiVersion
=
"v1alpha1"
metricsApiVersion
=
"v1alpha1"
)
)
...
...
pkg/kubectl/cmd/util/clientcache.go
View file @
519c1374
...
@@ -28,7 +28,6 @@ import (
...
@@ -28,7 +28,6 @@ import (
func
NewClientCache
(
loader
clientcmd
.
ClientConfig
)
*
ClientCache
{
func
NewClientCache
(
loader
clientcmd
.
ClientConfig
)
*
ClientCache
{
return
&
ClientCache
{
return
&
ClientCache
{
clients
:
make
(
map
[
unversioned
.
GroupVersion
]
*
client
.
Client
),
clientsets
:
make
(
map
[
unversioned
.
GroupVersion
]
*
internalclientset
.
Clientset
),
clientsets
:
make
(
map
[
unversioned
.
GroupVersion
]
*
internalclientset
.
Clientset
),
configs
:
make
(
map
[
unversioned
.
GroupVersion
]
*
restclient
.
Config
),
configs
:
make
(
map
[
unversioned
.
GroupVersion
]
*
restclient
.
Config
),
fedClientSets
:
make
(
map
[
unversioned
.
GroupVersion
]
fed_clientset
.
Interface
),
fedClientSets
:
make
(
map
[
unversioned
.
GroupVersion
]
fed_clientset
.
Interface
),
...
@@ -40,7 +39,6 @@ func NewClientCache(loader clientcmd.ClientConfig) *ClientCache {
...
@@ -40,7 +39,6 @@ func NewClientCache(loader clientcmd.ClientConfig) *ClientCache {
// is invoked only once
// is invoked only once
type
ClientCache
struct
{
type
ClientCache
struct
{
loader
clientcmd
.
ClientConfig
loader
clientcmd
.
ClientConfig
clients
map
[
unversioned
.
GroupVersion
]
*
client
.
Client
clientsets
map
[
unversioned
.
GroupVersion
]
*
internalclientset
.
Clientset
clientsets
map
[
unversioned
.
GroupVersion
]
*
internalclientset
.
Clientset
fedClientSets
map
[
unversioned
.
GroupVersion
]
fed_clientset
.
Interface
fedClientSets
map
[
unversioned
.
GroupVersion
]
fed_clientset
.
Interface
configs
map
[
unversioned
.
GroupVersion
]
*
restclient
.
Config
configs
map
[
unversioned
.
GroupVersion
]
*
restclient
.
Config
...
@@ -132,40 +130,6 @@ func (c *ClientCache) ClientSetForVersion(version *unversioned.GroupVersion) (*i
...
@@ -132,40 +130,6 @@ func (c *ClientCache) ClientSetForVersion(version *unversioned.GroupVersion) (*i
return
clientset
,
nil
return
clientset
,
nil
}
}
// ClientForVersion initializes or reuses a client for the specified version, or returns an
// error if that is not possible
func
(
c
*
ClientCache
)
ClientForVersion
(
version
*
unversioned
.
GroupVersion
)
(
*
client
.
Client
,
error
)
{
if
version
!=
nil
{
if
client
,
ok
:=
c
.
clients
[
*
version
];
ok
{
return
client
,
nil
}
}
config
,
err
:=
c
.
ClientConfigForVersion
(
version
)
if
err
!=
nil
{
return
nil
,
err
}
kubeclient
,
err
:=
client
.
New
(
config
)
if
err
!=
nil
{
return
nil
,
err
}
c
.
clients
[
*
config
.
GroupVersion
]
=
kubeclient
// `version` does not necessarily equal `config.Version`. However, we know that if we call this method again with
// `version`, we should get a client based on the same config we just found. There's no guarantee that a client
// is copiable, so create a new client and save it in the cache.
if
version
!=
nil
{
configCopy
:=
*
config
kubeclient
,
err
:=
client
.
New
(
&
configCopy
)
if
err
!=
nil
{
return
nil
,
err
}
c
.
clients
[
*
version
]
=
kubeclient
}
return
kubeclient
,
nil
}
func
(
c
*
ClientCache
)
FederationClientSetForVersion
(
version
*
unversioned
.
GroupVersion
)
(
fed_clientset
.
Interface
,
error
)
{
func
(
c
*
ClientCache
)
FederationClientSetForVersion
(
version
*
unversioned
.
GroupVersion
)
(
fed_clientset
.
Interface
,
error
)
{
if
version
!=
nil
{
if
version
!=
nil
{
if
clientSet
,
found
:=
c
.
fedClientSets
[
*
version
];
found
{
if
clientSet
,
found
:=
c
.
fedClientSets
[
*
version
];
found
{
...
...
pkg/kubectl/cmd/util/factory.go
View file @
519c1374
...
@@ -49,17 +49,13 @@ import (
...
@@ -49,17 +49,13 @@ import (
"k8s.io/kubernetes/pkg/apis/apps"
"k8s.io/kubernetes/pkg/apis/apps"
"k8s.io/kubernetes/pkg/apis/autoscaling"
"k8s.io/kubernetes/pkg/apis/autoscaling"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/certificates"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/policy"
"k8s.io/kubernetes/pkg/apis/rbac"
"k8s.io/kubernetes/pkg/apis/storage"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
coreclient
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/unversioned"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/client/typed/discovery"
"k8s.io/kubernetes/pkg/client/typed/discovery"
"k8s.io/kubernetes/pkg/client/typed/dynamic"
"k8s.io/kubernetes/pkg/client/typed/dynamic"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
clientset
"k8s.io/kubernetes/pkg/client/unversioned/adapters/internalclientset"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
...
@@ -97,8 +93,6 @@ type Factory struct {
...
@@ -97,8 +93,6 @@ type Factory struct {
Decoder
func
(
toInternal
bool
)
runtime
.
Decoder
Decoder
func
(
toInternal
bool
)
runtime
.
Decoder
// Returns an encoder capable of encoding a provided object into JSON in the default desired version.
// Returns an encoder capable of encoding a provided object into JSON in the default desired version.
JSONEncoder
func
()
runtime
.
Encoder
JSONEncoder
func
()
runtime
.
Encoder
// Returns a client for accessing Kubernetes resources or an error.
Client
func
()
(
*
client
.
Client
,
error
)
// ClientSet gives you back an internal, generated clientset
// ClientSet gives you back an internal, generated clientset
ClientSet
func
()
(
*
internalclientset
.
Clientset
,
error
)
ClientSet
func
()
(
*
internalclientset
.
Clientset
,
error
)
// Returns a RESTClient for accessing Kubernetes resources or an error.
// Returns a RESTClient for accessing Kubernetes resources or an error.
...
@@ -310,14 +304,14 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -310,14 +304,14 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
cmdApiVersion
=
*
cfg
.
GroupVersion
cmdApiVersion
=
*
cfg
.
GroupVersion
}
}
if
discoverDynamicAPIs
{
if
discoverDynamicAPIs
{
client
,
err
:=
clients
.
Clien
tForVersion
(
&
unversioned
.
GroupVersion
{
Version
:
"v1"
})
client
set
,
err
:=
clients
.
ClientSe
tForVersion
(
&
unversioned
.
GroupVersion
{
Version
:
"v1"
})
checkErrWithPrefix
(
"failed to find client for version v1: "
,
err
)
checkErrWithPrefix
(
"failed to find client for version v1: "
,
err
)
var
versions
[]
unversioned
.
GroupVersion
var
versions
[]
unversioned
.
GroupVersion
var
gvks
[]
unversioned
.
GroupVersionKind
var
gvks
[]
unversioned
.
GroupVersionKind
retries
:=
3
retries
:=
3
for
i
:=
0
;
i
<
retries
;
i
++
{
for
i
:=
0
;
i
<
retries
;
i
++
{
versions
,
gvks
,
err
=
GetThirdPartyGroupVersions
(
client
.
Discovery
())
versions
,
gvks
,
err
=
GetThirdPartyGroupVersions
(
client
set
.
Discovery
())
// Retry if we got a NotFound error, because user may delete
// Retry if we got a NotFound error, because user may delete
// a thirdparty group when the GetThirdPartyGroupVersions is
// a thirdparty group when the GetThirdPartyGroupVersions is
// running.
// running.
...
@@ -420,9 +414,6 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -420,9 +414,6 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return
kubectl
.
ShortcutExpander
{
RESTMapper
:
mapper
},
typer
,
nil
return
kubectl
.
ShortcutExpander
{
RESTMapper
:
mapper
},
typer
,
nil
},
},
Client
:
func
()
(
*
client
.
Client
,
error
)
{
return
clients
.
ClientForVersion
(
nil
)
},
RESTClient
:
func
()
(
*
restclient
.
RESTClient
,
error
)
{
RESTClient
:
func
()
(
*
restclient
.
RESTClient
,
error
)
{
clientConfig
,
err
:=
clients
.
ClientConfigForVersion
(
nil
)
clientConfig
,
err
:=
clients
.
ClientConfigForVersion
(
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -489,11 +480,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -489,11 +480,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return
&
kubectl
.
ClusterDescriber
{
Interface
:
fedClientSet
},
nil
return
&
kubectl
.
ClusterDescriber
{
Interface
:
fedClientSet
},
nil
}
}
}
}
client
,
err
:=
clients
.
Clien
tForVersion
(
&
mappingVersion
)
client
set
,
err
:=
clients
.
ClientSe
tForVersion
(
&
mappingVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
describer
,
ok
:=
kubectl
.
DescriberFor
(
mapping
.
GroupVersionKind
.
GroupKind
(),
client
);
ok
{
if
describer
,
ok
:=
kubectl
.
DescriberFor
(
mapping
.
GroupVersionKind
.
GroupKind
(),
client
set
);
ok
{
return
describer
,
nil
return
describer
,
nil
}
}
return
nil
,
fmt
.
Errorf
(
"no description has been implemented for %q"
,
mapping
.
GroupVersionKind
.
Kind
)
return
nil
,
fmt
.
Errorf
(
"no description has been implemented for %q"
,
mapping
.
GroupVersionKind
.
Kind
)
...
@@ -597,7 +588,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -597,7 +588,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return
meta
.
NewAccessor
()
.
Labels
(
object
)
return
meta
.
NewAccessor
()
.
Labels
(
object
)
},
},
LogsForObject
:
func
(
object
,
options
runtime
.
Object
)
(
*
restclient
.
Request
,
error
)
{
LogsForObject
:
func
(
object
,
options
runtime
.
Object
)
(
*
restclient
.
Request
,
error
)
{
c
,
err
:=
clients
.
Clien
tForVersion
(
nil
)
c
lientset
,
err
:=
clients
.
ClientSe
tForVersion
(
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -608,7 +599,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -608,7 +599,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
if
!
ok
{
if
!
ok
{
return
nil
,
errors
.
New
(
"provided options object is not a PodLogOptions"
)
return
nil
,
errors
.
New
(
"provided options object is not a PodLogOptions"
)
}
}
return
c
.
Pods
(
t
.
Namespace
)
.
GetLogs
(
t
.
Name
,
opts
),
nil
return
c
lientset
.
Core
()
.
Pods
(
t
.
Namespace
)
.
GetLogs
(
t
.
Name
,
opts
),
nil
case
*
api
.
ReplicationController
:
case
*
api
.
ReplicationController
:
opts
,
ok
:=
options
.
(
*
api
.
PodLogOptions
)
opts
,
ok
:=
options
.
(
*
api
.
PodLogOptions
)
...
@@ -617,7 +608,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -617,7 +608,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
}
}
selector
:=
labels
.
SelectorFromSet
(
t
.
Spec
.
Selector
)
selector
:=
labels
.
SelectorFromSet
(
t
.
Spec
.
Selector
)
sortBy
:=
func
(
pods
[]
*
api
.
Pod
)
sort
.
Interface
{
return
controller
.
ByLogging
(
pods
)
}
sortBy
:=
func
(
pods
[]
*
api
.
Pod
)
sort
.
Interface
{
return
controller
.
ByLogging
(
pods
)
}
pod
,
numPods
,
err
:=
GetFirstPod
(
c
,
t
.
Namespace
,
selector
,
20
*
time
.
Second
,
sortBy
)
pod
,
numPods
,
err
:=
GetFirstPod
(
c
lientset
.
Core
()
,
t
.
Namespace
,
selector
,
20
*
time
.
Second
,
sortBy
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -625,7 +616,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -625,7 +616,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
fmt
.
Fprintf
(
os
.
Stderr
,
"Found %v pods, using pod/%v
\n
"
,
numPods
,
pod
.
Name
)
fmt
.
Fprintf
(
os
.
Stderr
,
"Found %v pods, using pod/%v
\n
"
,
numPods
,
pod
.
Name
)
}
}
return
c
.
Pods
(
pod
.
Namespace
)
.
GetLogs
(
pod
.
Name
,
opts
),
nil
return
c
lientset
.
Core
()
.
Pods
(
pod
.
Namespace
)
.
GetLogs
(
pod
.
Name
,
opts
),
nil
case
*
extensions
.
ReplicaSet
:
case
*
extensions
.
ReplicaSet
:
opts
,
ok
:=
options
.
(
*
api
.
PodLogOptions
)
opts
,
ok
:=
options
.
(
*
api
.
PodLogOptions
)
...
@@ -637,7 +628,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -637,7 +628,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return
nil
,
fmt
.
Errorf
(
"invalid label selector: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"invalid label selector: %v"
,
err
)
}
}
sortBy
:=
func
(
pods
[]
*
api
.
Pod
)
sort
.
Interface
{
return
controller
.
ByLogging
(
pods
)
}
sortBy
:=
func
(
pods
[]
*
api
.
Pod
)
sort
.
Interface
{
return
controller
.
ByLogging
(
pods
)
}
pod
,
numPods
,
err
:=
GetFirstPod
(
c
,
t
.
Namespace
,
selector
,
20
*
time
.
Second
,
sortBy
)
pod
,
numPods
,
err
:=
GetFirstPod
(
c
lientset
.
Core
()
,
t
.
Namespace
,
selector
,
20
*
time
.
Second
,
sortBy
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -645,7 +636,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -645,7 +636,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
fmt
.
Fprintf
(
os
.
Stderr
,
"Found %v pods, using pod/%v
\n
"
,
numPods
,
pod
.
Name
)
fmt
.
Fprintf
(
os
.
Stderr
,
"Found %v pods, using pod/%v
\n
"
,
numPods
,
pod
.
Name
)
}
}
return
c
.
Pods
(
pod
.
Namespace
)
.
GetLogs
(
pod
.
Name
,
opts
),
nil
return
c
lientset
.
Core
()
.
Pods
(
pod
.
Namespace
)
.
GetLogs
(
pod
.
Name
,
opts
),
nil
default
:
default
:
gvks
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
object
)
gvks
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
object
)
...
@@ -656,7 +647,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -656,7 +647,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
}
}
},
},
PauseObject
:
func
(
object
runtime
.
Object
)
(
bool
,
error
)
{
PauseObject
:
func
(
object
runtime
.
Object
)
(
bool
,
error
)
{
c
,
err
:=
clients
.
Clien
tForVersion
(
nil
)
c
lientset
,
err
:=
clients
.
ClientSe
tForVersion
(
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
...
@@ -667,7 +658,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -667,7 +658,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return
true
,
nil
return
true
,
nil
}
}
t
.
Spec
.
Paused
=
true
t
.
Spec
.
Paused
=
true
_
,
err
:=
c
.
Extensions
()
.
Deployments
(
t
.
Namespace
)
.
Update
(
t
)
_
,
err
:=
c
lientset
.
Extensions
()
.
Deployments
(
t
.
Namespace
)
.
Update
(
t
)
return
false
,
err
return
false
,
err
default
:
default
:
gvks
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
object
)
gvks
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
object
)
...
@@ -678,7 +669,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -678,7 +669,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
}
}
},
},
ResumeObject
:
func
(
object
runtime
.
Object
)
(
bool
,
error
)
{
ResumeObject
:
func
(
object
runtime
.
Object
)
(
bool
,
error
)
{
c
,
err
:=
clients
.
Clien
tForVersion
(
nil
)
c
lientset
,
err
:=
clients
.
ClientSe
tForVersion
(
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
...
@@ -689,7 +680,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -689,7 +680,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return
true
,
nil
return
true
,
nil
}
}
t
.
Spec
.
Paused
=
false
t
.
Spec
.
Paused
=
false
_
,
err
:=
c
.
Extensions
()
.
Deployments
(
t
.
Namespace
)
.
Update
(
t
)
_
,
err
:=
c
lientset
.
Extensions
()
.
Deployments
(
t
.
Namespace
)
.
Update
(
t
)
return
false
,
err
return
false
,
err
default
:
default
:
gvks
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
object
)
gvks
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
object
)
...
@@ -717,39 +708,45 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -717,39 +708,45 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
},
},
HistoryViewer
:
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
HistoryViewer
,
error
)
{
HistoryViewer
:
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
HistoryViewer
,
error
)
{
mappingVersion
:=
mapping
.
GroupVersionKind
.
GroupVersion
()
mappingVersion
:=
mapping
.
GroupVersionKind
.
GroupVersion
()
client
,
err
:=
clients
.
Clien
tForVersion
(
&
mappingVersion
)
client
set
,
err
:=
clients
.
ClientSe
tForVersion
(
&
mappingVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
clientset
:=
clientset
.
FromUnversionedClient
(
client
)
return
kubectl
.
HistoryViewerFor
(
mapping
.
GroupVersionKind
.
GroupKind
(),
clientset
)
return
kubectl
.
HistoryViewerFor
(
mapping
.
GroupVersionKind
.
GroupKind
(),
clientset
)
},
},
Rollbacker
:
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
Rollbacker
,
error
)
{
Rollbacker
:
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
Rollbacker
,
error
)
{
mappingVersion
:=
mapping
.
GroupVersionKind
.
GroupVersion
()
mappingVersion
:=
mapping
.
GroupVersionKind
.
GroupVersion
()
client
,
err
:=
clients
.
Clien
tForVersion
(
&
mappingVersion
)
client
set
,
err
:=
clients
.
ClientSe
tForVersion
(
&
mappingVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
clientset
:=
clientset
.
FromUnversionedClient
(
client
)
return
kubectl
.
RollbackerFor
(
mapping
.
GroupVersionKind
.
GroupKind
(),
clientset
)
return
kubectl
.
RollbackerFor
(
mapping
.
GroupVersionKind
.
GroupKind
(),
clientset
)
},
},
StatusViewer
:
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
StatusViewer
,
error
)
{
StatusViewer
:
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
StatusViewer
,
error
)
{
mappingVersion
:=
mapping
.
GroupVersionKind
.
GroupVersion
()
mappingVersion
:=
mapping
.
GroupVersionKind
.
GroupVersion
()
client
,
err
:=
clients
.
Clien
tForVersion
(
&
mappingVersion
)
client
set
,
err
:=
clients
.
ClientSe
tForVersion
(
&
mappingVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
kubectl
.
StatusViewerFor
(
mapping
.
GroupVersionKind
.
GroupKind
(),
client
)
return
kubectl
.
StatusViewerFor
(
mapping
.
GroupVersionKind
.
GroupKind
(),
client
set
)
},
},
Validator
:
func
(
validate
bool
,
cacheDir
string
)
(
validation
.
Schema
,
error
)
{
Validator
:
func
(
validate
bool
,
cacheDir
string
)
(
validation
.
Schema
,
error
)
{
if
validate
{
if
validate
{
client
,
err
:=
clients
.
ClientForVersion
(
nil
)
clientConfig
,
err
:=
clients
.
ClientConfigForVersion
(
nil
)
if
err
!=
nil
{
return
nil
,
err
}
restclient
,
err
:=
restclient
.
RESTClientFor
(
clientConfig
)
if
err
!=
nil
{
return
nil
,
err
}
clientset
,
err
:=
clients
.
ClientSetForVersion
(
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
dir
:=
cacheDir
dir
:=
cacheDir
if
len
(
dir
)
>
0
{
if
len
(
dir
)
>
0
{
version
,
err
:=
client
.
ServerVersion
()
version
,
err
:=
client
set
.
Discovery
()
.
ServerVersion
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -760,7 +757,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -760,7 +757,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return
nil
,
err
return
nil
,
err
}
}
return
&
clientSwaggerSchema
{
return
&
clientSwaggerSchema
{
c
:
client
,
c
:
rest
client
,
fedc
:
fedClient
,
fedc
:
fedClient
,
cacheDir
:
dir
,
cacheDir
:
dir
,
mapper
:
api
.
RESTMapper
,
mapper
:
api
.
RESTMapper
,
...
@@ -769,18 +766,12 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -769,18 +766,12 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return
validation
.
NullSchema
{},
nil
return
validation
.
NullSchema
{},
nil
},
},
SwaggerSchema
:
func
(
gvk
unversioned
.
GroupVersionKind
)
(
*
swagger
.
ApiDeclaration
,
error
)
{
SwaggerSchema
:
func
(
gvk
unversioned
.
GroupVersionKind
)
(
*
swagger
.
ApiDeclaration
,
error
)
{
// discovery doesn't care about which groupversion you get a client for,
version
:=
gvk
.
GroupVersion
()
// so get whichever one you happen to have available and use that.
clientset
,
err
:=
clients
.
ClientSetForVersion
(
&
version
)
cfg
,
err
:=
clients
.
ClientConfigForVersion
(
nil
)
if
err
!=
nil
{
return
nil
,
err
}
dc
,
err
:=
discovery
.
NewDiscoveryClientForConfig
(
cfg
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
clientset
.
Discovery
()
.
SwaggerSchema
(
version
)
return
dc
.
SwaggerSchema
(
gvk
.
GroupVersion
())
},
},
DefaultNamespace
:
func
()
(
string
,
bool
,
error
)
{
DefaultNamespace
:
func
()
(
string
,
bool
,
error
)
{
return
clientConfig
.
Namespace
()
return
clientConfig
.
Namespace
()
...
@@ -807,7 +798,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -807,7 +798,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return
nil
return
nil
},
},
AttachablePodForObject
:
func
(
object
runtime
.
Object
)
(
*
api
.
Pod
,
error
)
{
AttachablePodForObject
:
func
(
object
runtime
.
Object
)
(
*
api
.
Pod
,
error
)
{
client
,
err
:=
clients
.
Clien
tForVersion
(
nil
)
client
set
,
err
:=
clients
.
ClientSe
tForVersion
(
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -815,7 +806,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -815,7 +806,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
case
*
api
.
ReplicationController
:
case
*
api
.
ReplicationController
:
selector
:=
labels
.
SelectorFromSet
(
t
.
Spec
.
Selector
)
selector
:=
labels
.
SelectorFromSet
(
t
.
Spec
.
Selector
)
sortBy
:=
func
(
pods
[]
*
api
.
Pod
)
sort
.
Interface
{
return
sort
.
Reverse
(
controller
.
ActivePods
(
pods
))
}
sortBy
:=
func
(
pods
[]
*
api
.
Pod
)
sort
.
Interface
{
return
sort
.
Reverse
(
controller
.
ActivePods
(
pods
))
}
pod
,
_
,
err
:=
GetFirstPod
(
client
,
t
.
Namespace
,
selector
,
1
*
time
.
Minute
,
sortBy
)
pod
,
_
,
err
:=
GetFirstPod
(
client
set
.
Core
()
,
t
.
Namespace
,
selector
,
1
*
time
.
Minute
,
sortBy
)
return
pod
,
err
return
pod
,
err
case
*
extensions
.
Deployment
:
case
*
extensions
.
Deployment
:
selector
,
err
:=
unversioned
.
LabelSelectorAsSelector
(
t
.
Spec
.
Selector
)
selector
,
err
:=
unversioned
.
LabelSelectorAsSelector
(
t
.
Spec
.
Selector
)
...
@@ -823,7 +814,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -823,7 +814,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return
nil
,
fmt
.
Errorf
(
"invalid label selector: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"invalid label selector: %v"
,
err
)
}
}
sortBy
:=
func
(
pods
[]
*
api
.
Pod
)
sort
.
Interface
{
return
sort
.
Reverse
(
controller
.
ActivePods
(
pods
))
}
sortBy
:=
func
(
pods
[]
*
api
.
Pod
)
sort
.
Interface
{
return
sort
.
Reverse
(
controller
.
ActivePods
(
pods
))
}
pod
,
_
,
err
:=
GetFirstPod
(
client
,
t
.
Namespace
,
selector
,
1
*
time
.
Minute
,
sortBy
)
pod
,
_
,
err
:=
GetFirstPod
(
client
set
.
Core
()
,
t
.
Namespace
,
selector
,
1
*
time
.
Minute
,
sortBy
)
return
pod
,
err
return
pod
,
err
case
*
batch
.
Job
:
case
*
batch
.
Job
:
selector
,
err
:=
unversioned
.
LabelSelectorAsSelector
(
t
.
Spec
.
Selector
)
selector
,
err
:=
unversioned
.
LabelSelectorAsSelector
(
t
.
Spec
.
Selector
)
...
@@ -831,7 +822,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -831,7 +822,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return
nil
,
fmt
.
Errorf
(
"invalid label selector: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"invalid label selector: %v"
,
err
)
}
}
sortBy
:=
func
(
pods
[]
*
api
.
Pod
)
sort
.
Interface
{
return
sort
.
Reverse
(
controller
.
ActivePods
(
pods
))
}
sortBy
:=
func
(
pods
[]
*
api
.
Pod
)
sort
.
Interface
{
return
sort
.
Reverse
(
controller
.
ActivePods
(
pods
))
}
pod
,
_
,
err
:=
GetFirstPod
(
client
,
t
.
Namespace
,
selector
,
1
*
time
.
Minute
,
sortBy
)
pod
,
_
,
err
:=
GetFirstPod
(
client
set
.
Core
()
,
t
.
Namespace
,
selector
,
1
*
time
.
Minute
,
sortBy
)
return
pod
,
err
return
pod
,
err
case
*
api
.
Pod
:
case
*
api
.
Pod
:
return
t
,
nil
return
t
,
nil
...
@@ -903,7 +894,7 @@ See http://releases.k8s.io/HEAD/docs/user-guide/services-firewalls.md for more d
...
@@ -903,7 +894,7 @@ See http://releases.k8s.io/HEAD/docs/user-guide/services-firewalls.md for more d
// GetFirstPod returns a pod matching the namespace and label selector
// GetFirstPod returns a pod matching the namespace and label selector
// and the number of all pods that match the label selector.
// and the number of all pods that match the label selector.
func
GetFirstPod
(
client
c
lient
.
PodsNamespac
er
,
namespace
string
,
selector
labels
.
Selector
,
timeout
time
.
Duration
,
sortBy
func
([]
*
api
.
Pod
)
sort
.
Interface
)
(
*
api
.
Pod
,
int
,
error
)
{
func
GetFirstPod
(
client
c
oreclient
.
PodsGett
er
,
namespace
string
,
selector
labels
.
Selector
,
timeout
time
.
Duration
,
sortBy
func
([]
*
api
.
Pod
)
sort
.
Interface
)
(
*
api
.
Pod
,
int
,
error
)
{
options
:=
api
.
ListOptions
{
LabelSelector
:
selector
}
options
:=
api
.
ListOptions
{
LabelSelector
:
selector
}
podList
,
err
:=
client
.
Pods
(
namespace
)
.
List
(
options
)
podList
,
err
:=
client
.
Pods
(
namespace
)
.
List
(
options
)
...
@@ -1029,7 +1020,7 @@ func getServiceProtocols(spec api.ServiceSpec) map[string]string {
...
@@ -1029,7 +1020,7 @@ func getServiceProtocols(spec api.ServiceSpec) map[string]string {
}
}
type
clientSwaggerSchema
struct
{
type
clientSwaggerSchema
struct
{
c
*
client
.
Client
c
*
restclient
.
REST
Client
fedc
*
restclient
.
RESTClient
fedc
*
restclient
.
RESTClient
cacheDir
string
cacheDir
string
mapper
meta
.
RESTMapper
mapper
meta
.
RESTMapper
...
@@ -1160,60 +1151,24 @@ func (c *clientSwaggerSchema) ValidateBytes(data []byte) error {
...
@@ -1160,60 +1151,24 @@ func (c *clientSwaggerSchema) ValidateBytes(data []byte) error {
if
ok
:=
registered
.
IsEnabledVersion
(
gvk
.
GroupVersion
());
!
ok
{
if
ok
:=
registered
.
IsEnabledVersion
(
gvk
.
GroupVersion
());
!
ok
{
return
fmt
.
Errorf
(
"API version %q isn't supported, only supports API versions %q"
,
gvk
.
GroupVersion
()
.
String
(),
registered
.
EnabledVersions
())
return
fmt
.
Errorf
(
"API version %q isn't supported, only supports API versions %q"
,
gvk
.
GroupVersion
()
.
String
(),
registered
.
EnabledVersions
())
}
}
switch
gvk
.
Group
{
case
autoscaling
.
GroupName
:
if
c
.
c
.
AutoscalingClient
==
nil
{
return
errors
.
New
(
"unable to validate: no autoscaling client"
)
}
return
getSchemaAndValidate
(
c
.
c
.
AutoscalingClient
.
RESTClient
,
data
,
"apis/"
,
gvk
.
GroupVersion
()
.
String
(),
c
.
cacheDir
,
c
)
case
policy
.
GroupName
:
if
c
.
c
.
PolicyClient
==
nil
{
return
errors
.
New
(
"unable to validate: no policy client"
)
}
return
getSchemaAndValidate
(
c
.
c
.
PolicyClient
.
RESTClient
,
data
,
"apis/"
,
gvk
.
GroupVersion
()
.
String
(),
c
.
cacheDir
,
c
)
case
apps
.
GroupName
:
if
c
.
c
.
AppsClient
==
nil
{
return
errors
.
New
(
"unable to validate: no apps client"
)
}
return
getSchemaAndValidate
(
c
.
c
.
AppsClient
.
RESTClient
,
data
,
"apis/"
,
gvk
.
GroupVersion
()
.
String
(),
c
.
cacheDir
,
c
)
case
batch
.
GroupName
:
if
c
.
c
.
BatchClient
==
nil
{
return
errors
.
New
(
"unable to validate: no batch client"
)
}
return
getSchemaAndValidate
(
c
.
c
.
BatchClient
.
RESTClient
,
data
,
"apis/"
,
gvk
.
GroupVersion
()
.
String
(),
c
.
cacheDir
,
c
)
case
rbac
.
GroupName
:
if
c
.
c
.
RbacClient
==
nil
{
return
errors
.
New
(
"unable to validate: no rbac client"
)
}
return
getSchemaAndValidate
(
c
.
c
.
RbacClient
.
RESTClient
,
data
,
"apis/"
,
gvk
.
GroupVersion
()
.
String
(),
c
.
cacheDir
,
c
)
case
storage
.
GroupName
:
if
c
.
c
.
StorageClient
==
nil
{
return
errors
.
New
(
"unable to validate: no storage client"
)
}
return
getSchemaAndValidate
(
c
.
c
.
StorageClient
.
RESTClient
,
data
,
"apis/"
,
gvk
.
GroupVersion
()
.
String
(),
c
.
cacheDir
,
c
)
}
if
registered
.
IsThirdPartyAPIGroupVersion
(
gvk
.
GroupVersion
())
{
if
registered
.
IsThirdPartyAPIGroupVersion
(
gvk
.
GroupVersion
())
{
// Don't attempt to validate third party objects
// Don't attempt to validate third party objects
return
nil
return
nil
}
}
switch
gvk
.
Group
{
switch
gvk
.
Group
{
case
extensions
.
GroupName
:
if
c
.
c
.
ExtensionsClient
==
nil
{
return
errors
.
New
(
"unable to validate: no experimental client"
)
}
return
getSchemaAndValidate
(
c
.
c
.
ExtensionsClient
.
RESTClient
,
data
,
"apis/"
,
gvk
.
GroupVersion
()
.
String
(),
c
.
cacheDir
,
c
)
case
federation
.
GroupName
:
case
federation
.
GroupName
:
if
c
.
fedc
==
nil
{
if
c
.
fedc
==
nil
{
return
errors
.
New
(
"unable to validate: no federation client"
)
return
errors
.
New
(
"unable to validate: no federation client"
)
}
}
return
getSchemaAndValidate
(
c
.
fedc
,
data
,
"apis/"
,
gvk
.
GroupVersion
()
.
String
(),
c
.
cacheDir
,
c
)
return
getSchemaAndValidate
(
c
.
fedc
,
data
,
"apis/"
,
gvk
.
GroupVersion
()
.
String
(),
c
.
cacheDir
,
c
)
case
certificates
.
GroupName
:
if
c
.
c
.
CertificatesClient
==
nil
{
case
api
.
GroupName
:
return
errors
.
New
(
"unable to validate: no certificates client"
)
return
getSchemaAndValidate
(
c
.
c
,
data
,
"api"
,
gvk
.
GroupVersion
()
.
String
(),
c
.
cacheDir
,
c
)
}
return
getSchemaAndValidate
(
c
.
c
.
CertificatesClient
.
RESTClient
,
data
,
"apis/"
,
gvk
.
GroupVersion
()
.
String
(),
c
.
cacheDir
,
c
)
default
:
return
getSchemaAndValidate
(
c
.
c
,
data
,
"apis/"
,
gvk
.
GroupVersion
()
.
String
(),
c
.
cacheDir
,
c
)
}
}
return
getSchemaAndValidate
(
c
.
c
.
RESTClient
,
data
,
"api"
,
gvk
.
GroupVersion
()
.
String
(),
c
.
cacheDir
,
c
)
}
}
// DefaultClientConfig creates a clientcmd.ClientConfig with the following hierarchy:
// DefaultClientConfig creates a clientcmd.ClientConfig with the following hierarchy:
...
...
pkg/kubectl/cmd/util/factory_test.go
View file @
519c1374
...
@@ -36,10 +36,11 @@ import (
...
@@ -36,10 +36,11 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/validation"
"k8s.io/kubernetes/pkg/api/validation"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
testcore
"k8s.io/kubernetes/pkg/client/testing/core"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
clientcmdapi
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
clientcmdapi
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
manualfake
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
...
@@ -262,9 +263,9 @@ func TestRefetchSchemaWhenValidationFails(t *testing.T) {
...
@@ -262,9 +263,9 @@ func TestRefetchSchemaWhenValidationFails(t *testing.T) {
}
}
requests
:=
map
[
string
]
int
{}
requests
:=
map
[
string
]
int
{}
c
:=
&
fake
.
RESTClient
{
c
:=
&
manual
fake
.
RESTClient
{
NegotiatedSerializer
:
testapi
.
Default
.
NegotiatedSerializer
(),
NegotiatedSerializer
:
testapi
.
Default
.
NegotiatedSerializer
(),
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
Client
:
manual
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
strings
.
HasPrefix
(
p
,
"/swaggerapi"
)
&&
m
==
"GET"
:
case
strings
.
HasPrefix
(
p
,
"/swaggerapi"
)
&&
m
==
"GET"
:
requests
[
p
]
=
requests
[
p
]
+
1
requests
[
p
]
=
requests
[
p
]
+
1
...
@@ -319,9 +320,9 @@ func TestValidateCachesSchema(t *testing.T) {
...
@@ -319,9 +320,9 @@ func TestValidateCachesSchema(t *testing.T) {
}
}
requests
:=
map
[
string
]
int
{}
requests
:=
map
[
string
]
int
{}
c
:=
&
fake
.
RESTClient
{
c
:=
&
manual
fake
.
RESTClient
{
NegotiatedSerializer
:
testapi
.
Default
.
NegotiatedSerializer
(),
NegotiatedSerializer
:
testapi
.
Default
.
NegotiatedSerializer
(),
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
Client
:
manual
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
strings
.
HasPrefix
(
p
,
"/swaggerapi"
)
&&
m
==
"GET"
:
case
strings
.
HasPrefix
(
p
,
"/swaggerapi"
)
&&
m
==
"GET"
:
requests
[
p
]
=
requests
[
p
]
+
1
requests
[
p
]
=
requests
[
p
]
+
1
...
@@ -587,10 +588,7 @@ func TestGetFirstPod(t *testing.T) {
...
@@ -587,10 +588,7 @@ func TestGetFirstPod(t *testing.T) {
for
i
:=
range
tests
{
for
i
:=
range
tests
{
test
:=
tests
[
i
]
test
:=
tests
[
i
]
client
:=
&
testclient
.
Fake
{}
fake
:=
fake
.
NewSimpleClientset
(
test
.
podList
)
client
.
PrependReactor
(
"list"
,
"pods"
,
func
(
action
testclient
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
return
true
,
test
.
podList
,
nil
})
if
len
(
test
.
watching
)
>
0
{
if
len
(
test
.
watching
)
>
0
{
watcher
:=
watch
.
NewFake
()
watcher
:=
watch
.
NewFake
()
for
_
,
event
:=
range
test
.
watching
{
for
_
,
event
:=
range
test
.
watching
{
...
@@ -601,11 +599,11 @@ func TestGetFirstPod(t *testing.T) {
...
@@ -601,11 +599,11 @@ func TestGetFirstPod(t *testing.T) {
go
watcher
.
Modify
(
event
.
Object
)
go
watcher
.
Modify
(
event
.
Object
)
}
}
}
}
client
.
PrependWatchReactor
(
"pods"
,
testclient
.
DefaultWatchReactor
(
watcher
,
nil
))
fake
.
PrependWatchReactor
(
"pods"
,
testcore
.
DefaultWatchReactor
(
watcher
,
nil
))
}
}
selector
:=
labels
.
Set
(
labelSet
)
.
AsSelector
()
selector
:=
labels
.
Set
(
labelSet
)
.
AsSelector
()
pod
,
numPods
,
err
:=
GetFirstPod
(
client
,
api
.
NamespaceDefault
,
selector
,
1
*
time
.
Minute
,
test
.
sortBy
)
pod
,
numPods
,
err
:=
GetFirstPod
(
fake
.
Core
()
,
api
.
NamespaceDefault
,
selector
,
1
*
time
.
Minute
,
test
.
sortBy
)
if
!
test
.
expectedErr
&&
err
!=
nil
{
if
!
test
.
expectedErr
&&
err
!=
nil
{
t
.
Errorf
(
"%s: unexpected error: %v"
,
test
.
name
,
err
)
t
.
Errorf
(
"%s: unexpected error: %v"
,
test
.
name
,
err
)
continue
continue
...
...
pkg/kubectl/describe.go
View file @
519c1374
...
@@ -42,7 +42,6 @@ import (
...
@@ -42,7 +42,6 @@ import (
"k8s.io/kubernetes/pkg/apis/storage"
"k8s.io/kubernetes/pkg/apis/storage"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
adapter
"k8s.io/kubernetes/pkg/client/unversioned/adapters/internalclientset"
deploymentutil
"k8s.io/kubernetes/pkg/controller/deployment/util"
deploymentutil
"k8s.io/kubernetes/pkg/controller/deployment/util"
"k8s.io/kubernetes/pkg/fieldpath"
"k8s.io/kubernetes/pkg/fieldpath"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/fields"
...
@@ -89,7 +88,7 @@ func (e ErrNoDescriber) Error() string {
...
@@ -89,7 +88,7 @@ func (e ErrNoDescriber) Error() string {
return
fmt
.
Sprintf
(
"no describer has been defined for %v"
,
e
.
Types
)
return
fmt
.
Sprintf
(
"no describer has been defined for %v"
,
e
.
Types
)
}
}
func
describerMap
(
c
*
client
.
Client
)
map
[
unversioned
.
GroupKind
]
Describer
{
func
describerMap
(
c
clientset
.
Interface
)
map
[
unversioned
.
GroupKind
]
Describer
{
m
:=
map
[
unversioned
.
GroupKind
]
Describer
{
m
:=
map
[
unversioned
.
GroupKind
]
Describer
{
api
.
Kind
(
"Pod"
)
:
&
PodDescriber
{
c
},
api
.
Kind
(
"Pod"
)
:
&
PodDescriber
{
c
},
api
.
Kind
(
"ReplicationController"
)
:
&
ReplicationControllerDescriber
{
c
},
api
.
Kind
(
"ReplicationController"
)
:
&
ReplicationControllerDescriber
{
c
},
...
@@ -110,11 +109,11 @@ func describerMap(c *client.Client) map[unversioned.GroupKind]Describer {
...
@@ -110,11 +109,11 @@ func describerMap(c *client.Client) map[unversioned.GroupKind]Describer {
extensions
.
Kind
(
"NetworkPolicy"
)
:
&
NetworkPolicyDescriber
{
c
},
extensions
.
Kind
(
"NetworkPolicy"
)
:
&
NetworkPolicyDescriber
{
c
},
autoscaling
.
Kind
(
"HorizontalPodAutoscaler"
)
:
&
HorizontalPodAutoscalerDescriber
{
c
},
autoscaling
.
Kind
(
"HorizontalPodAutoscaler"
)
:
&
HorizontalPodAutoscalerDescriber
{
c
},
extensions
.
Kind
(
"DaemonSet"
)
:
&
DaemonSetDescriber
{
c
},
extensions
.
Kind
(
"DaemonSet"
)
:
&
DaemonSetDescriber
{
c
},
extensions
.
Kind
(
"Deployment"
)
:
&
DeploymentDescriber
{
adapter
.
FromUnversionedClient
(
c
)
},
extensions
.
Kind
(
"Deployment"
)
:
&
DeploymentDescriber
{
c
},
extensions
.
Kind
(
"Job"
)
:
&
JobDescriber
{
c
},
extensions
.
Kind
(
"Job"
)
:
&
JobDescriber
{
c
},
extensions
.
Kind
(
"Ingress"
)
:
&
IngressDescriber
{
c
},
extensions
.
Kind
(
"Ingress"
)
:
&
IngressDescriber
{
c
},
batch
.
Kind
(
"Job"
)
:
&
JobDescriber
{
c
},
batch
.
Kind
(
"Job"
)
:
&
JobDescriber
{
c
},
batch
.
Kind
(
"ScheduledJob"
)
:
&
ScheduledJobDescriber
{
adapter
.
FromUnversionedClient
(
c
)
},
batch
.
Kind
(
"ScheduledJob"
)
:
&
ScheduledJobDescriber
{
c
},
apps
.
Kind
(
"PetSet"
)
:
&
PetSetDescriber
{
c
},
apps
.
Kind
(
"PetSet"
)
:
&
PetSetDescriber
{
c
},
certificates
.
Kind
(
"CertificateSigningRequest"
)
:
&
CertificateSigningRequestDescriber
{
c
},
certificates
.
Kind
(
"CertificateSigningRequest"
)
:
&
CertificateSigningRequestDescriber
{
c
},
storage
.
Kind
(
"StorageClass"
)
:
&
StorageClassDescriber
{
c
},
storage
.
Kind
(
"StorageClass"
)
:
&
StorageClassDescriber
{
c
},
...
@@ -136,7 +135,7 @@ func DescribableResources() []string {
...
@@ -136,7 +135,7 @@ func DescribableResources() []string {
// Describer returns the default describe functions for each of the standard
// Describer returns the default describe functions for each of the standard
// Kubernetes types.
// Kubernetes types.
func
DescriberFor
(
kind
unversioned
.
GroupKind
,
c
*
client
.
Client
)
(
Describer
,
bool
)
{
func
DescriberFor
(
kind
unversioned
.
GroupKind
,
c
clientset
.
Interface
)
(
Describer
,
bool
)
{
f
,
ok
:=
describerMap
(
c
)[
kind
]
f
,
ok
:=
describerMap
(
c
)[
kind
]
return
f
,
ok
return
f
,
ok
}
}
...
@@ -164,19 +163,19 @@ func init() {
...
@@ -164,19 +163,19 @@ func init() {
// NamespaceDescriber generates information about a namespace
// NamespaceDescriber generates information about a namespace
type
NamespaceDescriber
struct
{
type
NamespaceDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
NamespaceDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
NamespaceDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
ns
,
err
:=
d
.
Namespaces
()
.
Get
(
name
)
ns
,
err
:=
d
.
Core
()
.
Namespaces
()
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
resourceQuotaList
,
err
:=
d
.
ResourceQuotas
(
name
)
.
List
(
api
.
ListOptions
{})
resourceQuotaList
,
err
:=
d
.
Core
()
.
ResourceQuotas
(
name
)
.
List
(
api
.
ListOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
limitRangeList
,
err
:=
d
.
LimitRanges
(
name
)
.
List
(
api
.
ListOptions
{})
limitRangeList
,
err
:=
d
.
Core
()
.
LimitRanges
(
name
)
.
List
(
api
.
ListOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
...
@@ -320,11 +319,11 @@ func DescribeResourceQuotas(quotas *api.ResourceQuotaList, w io.Writer) {
...
@@ -320,11 +319,11 @@ func DescribeResourceQuotas(quotas *api.ResourceQuotaList, w io.Writer) {
// LimitRangeDescriber generates information about a limit range
// LimitRangeDescriber generates information about a limit range
type
LimitRangeDescriber
struct
{
type
LimitRangeDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
LimitRangeDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
LimitRangeDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
lr
:=
d
.
LimitRanges
(
namespace
)
lr
:=
d
.
Core
()
.
LimitRanges
(
namespace
)
limitRange
,
err
:=
lr
.
Get
(
name
)
limitRange
,
err
:=
lr
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -407,11 +406,11 @@ func describeLimitRange(limitRange *api.LimitRange) (string, error) {
...
@@ -407,11 +406,11 @@ func describeLimitRange(limitRange *api.LimitRange) (string, error) {
// ResourceQuotaDescriber generates information about a resource quota
// ResourceQuotaDescriber generates information about a resource quota
type
ResourceQuotaDescriber
struct
{
type
ResourceQuotaDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
ResourceQuotaDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
ResourceQuotaDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
rq
:=
d
.
ResourceQuotas
(
namespace
)
rq
:=
d
.
Core
()
.
ResourceQuotas
(
namespace
)
resourceQuota
,
err
:=
rq
.
Get
(
name
)
resourceQuota
,
err
:=
rq
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -476,14 +475,14 @@ func describeQuota(resourceQuota *api.ResourceQuota) (string, error) {
...
@@ -476,14 +475,14 @@ func describeQuota(resourceQuota *api.ResourceQuota) (string, error) {
// PodDescriber generates information about a pod and the replication controllers that
// PodDescriber generates information about a pod and the replication controllers that
// create it.
// create it.
type
PodDescriber
struct
{
type
PodDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
PodDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
PodDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
pod
,
err
:=
d
.
Pods
(
namespace
)
.
Get
(
name
)
pod
,
err
:=
d
.
Core
()
.
Pods
(
namespace
)
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
if
describerSettings
.
ShowEvents
{
if
describerSettings
.
ShowEvents
{
eventsInterface
:=
d
.
Events
(
namespace
)
eventsInterface
:=
d
.
Core
()
.
Events
(
namespace
)
selector
:=
eventsInterface
.
GetFieldSelector
(
&
name
,
&
namespace
,
nil
,
nil
)
selector
:=
eventsInterface
.
GetFieldSelector
(
&
name
,
&
namespace
,
nil
,
nil
)
options
:=
api
.
ListOptions
{
FieldSelector
:
selector
}
options
:=
api
.
ListOptions
{
FieldSelector
:
selector
}
events
,
err2
:=
eventsInterface
.
List
(
options
)
events
,
err2
:=
eventsInterface
.
List
(
options
)
...
@@ -504,7 +503,7 @@ func (d *PodDescriber) Describe(namespace, name string, describerSettings Descri
...
@@ -504,7 +503,7 @@ func (d *PodDescriber) Describe(namespace, name string, describerSettings Descri
glog
.
Errorf
(
"Unable to construct reference to '%#v': %v"
,
pod
,
err
)
glog
.
Errorf
(
"Unable to construct reference to '%#v': %v"
,
pod
,
err
)
}
else
{
}
else
{
ref
.
Kind
=
""
ref
.
Kind
=
""
events
,
_
=
d
.
Events
(
namespace
)
.
Search
(
ref
)
events
,
_
=
d
.
Core
()
.
Events
(
namespace
)
.
Search
(
ref
)
}
}
}
}
...
@@ -759,11 +758,11 @@ func printCinderVolumeSource(cinder *api.CinderVolumeSource, out io.Writer) {
...
@@ -759,11 +758,11 @@ func printCinderVolumeSource(cinder *api.CinderVolumeSource, out io.Writer) {
}
}
type
PersistentVolumeDescriber
struct
{
type
PersistentVolumeDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
PersistentVolumeDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
PersistentVolumeDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
c
:=
d
.
PersistentVolumes
()
c
:=
d
.
Core
()
.
PersistentVolumes
()
pv
,
err
:=
c
.
Get
(
name
)
pv
,
err
:=
c
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -774,7 +773,7 @@ func (d *PersistentVolumeDescriber) Describe(namespace, name string, describerSe
...
@@ -774,7 +773,7 @@ func (d *PersistentVolumeDescriber) Describe(namespace, name string, describerSe
var
events
*
api
.
EventList
var
events
*
api
.
EventList
if
describerSettings
.
ShowEvents
{
if
describerSettings
.
ShowEvents
{
events
,
_
=
d
.
Events
(
namespace
)
.
Search
(
pv
)
events
,
_
=
d
.
Core
()
.
Events
(
namespace
)
.
Search
(
pv
)
}
}
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
...
@@ -824,11 +823,11 @@ func (d *PersistentVolumeDescriber) Describe(namespace, name string, describerSe
...
@@ -824,11 +823,11 @@ func (d *PersistentVolumeDescriber) Describe(namespace, name string, describerSe
}
}
type
PersistentVolumeClaimDescriber
struct
{
type
PersistentVolumeClaimDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
PersistentVolumeClaimDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
PersistentVolumeClaimDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
c
:=
d
.
PersistentVolumeClaims
(
namespace
)
c
:=
d
.
Core
()
.
PersistentVolumeClaims
(
namespace
)
pvc
,
err
:=
c
.
Get
(
name
)
pvc
,
err
:=
c
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -844,7 +843,7 @@ func (d *PersistentVolumeClaimDescriber) Describe(namespace, name string, descri
...
@@ -844,7 +843,7 @@ func (d *PersistentVolumeClaimDescriber) Describe(namespace, name string, descri
capacity
=
storage
.
String
()
capacity
=
storage
.
String
()
}
}
events
,
_
:=
d
.
Events
(
namespace
)
.
Search
(
pvc
)
events
,
_
:=
d
.
Core
()
.
Events
(
namespace
)
.
Search
(
pvc
)
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
pvc
.
Name
)
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
pvc
.
Name
)
...
@@ -1096,12 +1095,12 @@ func printBool(value bool) string {
...
@@ -1096,12 +1095,12 @@ func printBool(value bool) string {
// ReplicationControllerDescriber generates information about a replication controller
// ReplicationControllerDescriber generates information about a replication controller
// and the pods it has created.
// and the pods it has created.
type
ReplicationControllerDescriber
struct
{
type
ReplicationControllerDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
ReplicationControllerDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
ReplicationControllerDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
rc
:=
d
.
ReplicationControllers
(
namespace
)
rc
:=
d
.
Core
()
.
ReplicationControllers
(
namespace
)
pc
:=
d
.
Pods
(
namespace
)
pc
:=
d
.
Core
()
.
Pods
(
namespace
)
controller
,
err
:=
rc
.
Get
(
name
)
controller
,
err
:=
rc
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -1115,7 +1114,7 @@ func (d *ReplicationControllerDescriber) Describe(namespace, name string, descri
...
@@ -1115,7 +1114,7 @@ func (d *ReplicationControllerDescriber) Describe(namespace, name string, descri
var
events
*
api
.
EventList
var
events
*
api
.
EventList
if
describerSettings
.
ShowEvents
{
if
describerSettings
.
ShowEvents
{
events
,
_
=
d
.
Events
(
namespace
)
.
Search
(
controller
)
events
,
_
=
d
.
Core
()
.
Events
(
namespace
)
.
Search
(
controller
)
}
}
return
describeReplicationController
(
controller
,
events
,
running
,
waiting
,
succeeded
,
failed
)
return
describeReplicationController
(
controller
,
events
,
running
,
waiting
,
succeeded
,
failed
)
...
@@ -1165,12 +1164,12 @@ func DescribePodTemplate(template *api.PodTemplateSpec, out io.Writer) {
...
@@ -1165,12 +1164,12 @@ func DescribePodTemplate(template *api.PodTemplateSpec, out io.Writer) {
// ReplicaSetDescriber generates information about a ReplicaSet and the pods it has created.
// ReplicaSetDescriber generates information about a ReplicaSet and the pods it has created.
type
ReplicaSetDescriber
struct
{
type
ReplicaSetDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
ReplicaSetDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
ReplicaSetDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
rsc
:=
d
.
Extensions
()
.
ReplicaSets
(
namespace
)
rsc
:=
d
.
Extensions
()
.
ReplicaSets
(
namespace
)
pc
:=
d
.
Pods
(
namespace
)
pc
:=
d
.
Core
()
.
Pods
(
namespace
)
rs
,
err
:=
rsc
.
Get
(
name
)
rs
,
err
:=
rsc
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -1189,7 +1188,7 @@ func (d *ReplicaSetDescriber) Describe(namespace, name string, describerSettings
...
@@ -1189,7 +1188,7 @@ func (d *ReplicaSetDescriber) Describe(namespace, name string, describerSettings
var
events
*
api
.
EventList
var
events
*
api
.
EventList
if
describerSettings
.
ShowEvents
{
if
describerSettings
.
ShowEvents
{
events
,
_
=
d
.
Events
(
namespace
)
.
Search
(
rs
)
events
,
_
=
d
.
Core
()
.
Events
(
namespace
)
.
Search
(
rs
)
}
}
return
describeReplicaSet
(
rs
,
events
,
running
,
waiting
,
succeeded
,
failed
)
return
describeReplicaSet
(
rs
,
events
,
running
,
waiting
,
succeeded
,
failed
)
...
@@ -1214,7 +1213,7 @@ func describeReplicaSet(rs *extensions.ReplicaSet, events *api.EventList, runnin
...
@@ -1214,7 +1213,7 @@ func describeReplicaSet(rs *extensions.ReplicaSet, events *api.EventList, runnin
// JobDescriber generates information about a job and the pods it has created.
// JobDescriber generates information about a job and the pods it has created.
type
JobDescriber
struct
{
type
JobDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
JobDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
JobDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
...
@@ -1225,7 +1224,7 @@ func (d *JobDescriber) Describe(namespace, name string, describerSettings Descri
...
@@ -1225,7 +1224,7 @@ func (d *JobDescriber) Describe(namespace, name string, describerSettings Descri
var
events
*
api
.
EventList
var
events
*
api
.
EventList
if
describerSettings
.
ShowEvents
{
if
describerSettings
.
ShowEvents
{
events
,
_
=
d
.
Events
(
namespace
)
.
Search
(
job
)
events
,
_
=
d
.
Core
()
.
Events
(
namespace
)
.
Search
(
job
)
}
}
return
describeJob
(
job
,
events
)
return
describeJob
(
job
,
events
)
...
@@ -1348,12 +1347,12 @@ func printActiveJobs(out io.Writer, title string, jobs []api.ObjectReference) {
...
@@ -1348,12 +1347,12 @@ func printActiveJobs(out io.Writer, title string, jobs []api.ObjectReference) {
// DaemonSetDescriber generates information about a daemon set and the pods it has created.
// DaemonSetDescriber generates information about a daemon set and the pods it has created.
type
DaemonSetDescriber
struct
{
type
DaemonSetDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
DaemonSetDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
DaemonSetDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
dc
:=
d
.
Extensions
()
.
DaemonSets
(
namespace
)
dc
:=
d
.
Extensions
()
.
DaemonSets
(
namespace
)
pc
:=
d
.
Pods
(
namespace
)
pc
:=
d
.
Core
()
.
Pods
(
namespace
)
daemon
,
err
:=
dc
.
Get
(
name
)
daemon
,
err
:=
dc
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -1371,7 +1370,7 @@ func (d *DaemonSetDescriber) Describe(namespace, name string, describerSettings
...
@@ -1371,7 +1370,7 @@ func (d *DaemonSetDescriber) Describe(namespace, name string, describerSettings
var
events
*
api
.
EventList
var
events
*
api
.
EventList
if
describerSettings
.
ShowEvents
{
if
describerSettings
.
ShowEvents
{
events
,
_
=
d
.
Events
(
namespace
)
.
Search
(
daemon
)
events
,
_
=
d
.
Core
()
.
Events
(
namespace
)
.
Search
(
daemon
)
}
}
return
describeDaemonSet
(
daemon
,
events
,
running
,
waiting
,
succeeded
,
failed
)
return
describeDaemonSet
(
daemon
,
events
,
running
,
waiting
,
succeeded
,
failed
)
...
@@ -1402,11 +1401,11 @@ func describeDaemonSet(daemon *extensions.DaemonSet, events *api.EventList, runn
...
@@ -1402,11 +1401,11 @@ func describeDaemonSet(daemon *extensions.DaemonSet, events *api.EventList, runn
// SecretDescriber generates information about a secret
// SecretDescriber generates information about a secret
type
SecretDescriber
struct
{
type
SecretDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
SecretDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
SecretDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
c
:=
d
.
Secrets
(
namespace
)
c
:=
d
.
Core
()
.
Secrets
(
namespace
)
secret
,
err
:=
c
.
Get
(
name
)
secret
,
err
:=
c
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -1440,11 +1439,11 @@ func describeSecret(secret *api.Secret) (string, error) {
...
@@ -1440,11 +1439,11 @@ func describeSecret(secret *api.Secret) (string, error) {
}
}
type
IngressDescriber
struct
{
type
IngressDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
i
*
IngressDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
i
*
IngressDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
c
:=
i
.
Extensions
()
.
Ingress
(
namespace
)
c
:=
i
.
Extensions
()
.
Ingress
es
(
namespace
)
ing
,
err
:=
c
.
Get
(
name
)
ing
,
err
:=
c
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
...
@@ -1453,8 +1452,8 @@ func (i *IngressDescriber) Describe(namespace, name string, describerSettings De
...
@@ -1453,8 +1452,8 @@ func (i *IngressDescriber) Describe(namespace, name string, describerSettings De
}
}
func
(
i
*
IngressDescriber
)
describeBackend
(
ns
string
,
backend
*
extensions
.
IngressBackend
)
string
{
func
(
i
*
IngressDescriber
)
describeBackend
(
ns
string
,
backend
*
extensions
.
IngressBackend
)
string
{
endpoints
,
_
:=
i
.
Endpoints
(
ns
)
.
Get
(
backend
.
ServiceName
)
endpoints
,
_
:=
i
.
Core
()
.
Endpoints
(
ns
)
.
Get
(
backend
.
ServiceName
)
service
,
_
:=
i
.
Services
(
ns
)
.
Get
(
backend
.
ServiceName
)
service
,
_
:=
i
.
Core
()
.
Services
(
ns
)
.
Get
(
backend
.
ServiceName
)
spName
:=
""
spName
:=
""
for
i
:=
range
service
.
Spec
.
Ports
{
for
i
:=
range
service
.
Spec
.
Ports
{
sp
:=
&
service
.
Spec
.
Ports
[
i
]
sp
:=
&
service
.
Spec
.
Ports
[
i
]
...
@@ -1515,7 +1514,7 @@ func (i *IngressDescriber) describeIngress(ing *extensions.Ingress, describerSet
...
@@ -1515,7 +1514,7 @@ func (i *IngressDescriber) describeIngress(ing *extensions.Ingress, describerSet
describeIngressAnnotations
(
out
,
ing
.
Annotations
)
describeIngressAnnotations
(
out
,
ing
.
Annotations
)
if
describerSettings
.
ShowEvents
{
if
describerSettings
.
ShowEvents
{
events
,
_
:=
i
.
Events
(
ing
.
Namespace
)
.
Search
(
ing
)
events
,
_
:=
i
.
Core
()
.
Events
(
ing
.
Namespace
)
.
Search
(
ing
)
if
events
!=
nil
{
if
events
!=
nil
{
DescribeEvents
(
events
,
out
)
DescribeEvents
(
events
,
out
)
}
}
...
@@ -1552,21 +1551,21 @@ func describeIngressAnnotations(out io.Writer, annotations map[string]string) {
...
@@ -1552,21 +1551,21 @@ func describeIngressAnnotations(out io.Writer, annotations map[string]string) {
// ServiceDescriber generates information about a service.
// ServiceDescriber generates information about a service.
type
ServiceDescriber
struct
{
type
ServiceDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
ServiceDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
ServiceDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
c
:=
d
.
Services
(
namespace
)
c
:=
d
.
Core
()
.
Services
(
namespace
)
service
,
err
:=
c
.
Get
(
name
)
service
,
err
:=
c
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
endpoints
,
_
:=
d
.
Endpoints
(
namespace
)
.
Get
(
name
)
endpoints
,
_
:=
d
.
Core
()
.
Endpoints
(
namespace
)
.
Get
(
name
)
var
events
*
api
.
EventList
var
events
*
api
.
EventList
if
describerSettings
.
ShowEvents
{
if
describerSettings
.
ShowEvents
{
events
,
_
=
d
.
Events
(
namespace
)
.
Search
(
service
)
events
,
_
=
d
.
Core
()
.
Events
(
namespace
)
.
Search
(
service
)
}
}
return
describeService
(
service
,
endpoints
,
events
)
return
describeService
(
service
,
endpoints
,
events
)
}
}
...
@@ -1631,11 +1630,11 @@ func describeService(service *api.Service, endpoints *api.Endpoints, events *api
...
@@ -1631,11 +1630,11 @@ func describeService(service *api.Service, endpoints *api.Endpoints, events *api
// EndpointsDescriber generates information about an Endpoint.
// EndpointsDescriber generates information about an Endpoint.
type
EndpointsDescriber
struct
{
type
EndpointsDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
EndpointsDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
EndpointsDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
c
:=
d
.
Endpoints
(
namespace
)
c
:=
d
.
Core
()
.
Endpoints
(
namespace
)
ep
,
err
:=
c
.
Get
(
name
)
ep
,
err
:=
c
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -1644,7 +1643,7 @@ func (d *EndpointsDescriber) Describe(namespace, name string, describerSettings
...
@@ -1644,7 +1643,7 @@ func (d *EndpointsDescriber) Describe(namespace, name string, describerSettings
var
events
*
api
.
EventList
var
events
*
api
.
EventList
if
describerSettings
.
ShowEvents
{
if
describerSettings
.
ShowEvents
{
events
,
_
=
d
.
Events
(
namespace
)
.
Search
(
ep
)
events
,
_
=
d
.
Core
()
.
Events
(
namespace
)
.
Search
(
ep
)
}
}
return
describeEndpoints
(
ep
,
events
)
return
describeEndpoints
(
ep
,
events
)
...
@@ -1704,11 +1703,11 @@ func describeEndpoints(ep *api.Endpoints, events *api.EventList) (string, error)
...
@@ -1704,11 +1703,11 @@ func describeEndpoints(ep *api.Endpoints, events *api.EventList) (string, error)
// ServiceAccountDescriber generates information about a service.
// ServiceAccountDescriber generates information about a service.
type
ServiceAccountDescriber
struct
{
type
ServiceAccountDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
ServiceAccountDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
ServiceAccountDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
c
:=
d
.
ServiceAccounts
(
namespace
)
c
:=
d
.
Core
()
.
ServiceAccounts
(
namespace
)
serviceAccount
,
err
:=
c
.
Get
(
name
)
serviceAccount
,
err
:=
c
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -1719,7 +1718,7 @@ func (d *ServiceAccountDescriber) Describe(namespace, name string, describerSett
...
@@ -1719,7 +1718,7 @@ func (d *ServiceAccountDescriber) Describe(namespace, name string, describerSett
tokenSelector
:=
fields
.
SelectorFromSet
(
map
[
string
]
string
{
api
.
SecretTypeField
:
string
(
api
.
SecretTypeServiceAccountToken
)})
tokenSelector
:=
fields
.
SelectorFromSet
(
map
[
string
]
string
{
api
.
SecretTypeField
:
string
(
api
.
SecretTypeServiceAccountToken
)})
options
:=
api
.
ListOptions
{
FieldSelector
:
tokenSelector
}
options
:=
api
.
ListOptions
{
FieldSelector
:
tokenSelector
}
secrets
,
err
:=
d
.
Secrets
(
namespace
)
.
List
(
options
)
secrets
,
err
:=
d
.
Core
()
.
Secrets
(
namespace
)
.
List
(
options
)
if
err
==
nil
{
if
err
==
nil
{
for
_
,
s
:=
range
secrets
.
Items
{
for
_
,
s
:=
range
secrets
.
Items
{
name
,
_
:=
s
.
Annotations
[
api
.
ServiceAccountNameKey
]
name
,
_
:=
s
.
Annotations
[
api
.
ServiceAccountNameKey
]
...
@@ -1785,11 +1784,11 @@ func describeServiceAccount(serviceAccount *api.ServiceAccount, tokens []api.Sec
...
@@ -1785,11 +1784,11 @@ func describeServiceAccount(serviceAccount *api.ServiceAccount, tokens []api.Sec
// NodeDescriber generates information about a node.
// NodeDescriber generates information about a node.
type
NodeDescriber
struct
{
type
NodeDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
NodeDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
NodeDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
mc
:=
d
.
Nodes
()
mc
:=
d
.
Core
()
.
Nodes
()
node
,
err
:=
mc
.
Get
(
name
)
node
,
err
:=
mc
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
...
@@ -1802,7 +1801,7 @@ func (d *NodeDescriber) Describe(namespace, name string, describerSettings Descr
...
@@ -1802,7 +1801,7 @@ func (d *NodeDescriber) Describe(namespace, name string, describerSettings Descr
// in a policy aware setting, users may have access to a node, but not all pods
// in a policy aware setting, users may have access to a node, but not all pods
// in that case, we note that the user does not have access to the pods
// in that case, we note that the user does not have access to the pods
canViewPods
:=
true
canViewPods
:=
true
nodeNonTerminatedPodsList
,
err
:=
d
.
Pods
(
namespace
)
.
List
(
api
.
ListOptions
{
FieldSelector
:
fieldSelector
})
nodeNonTerminatedPodsList
,
err
:=
d
.
Core
()
.
Pods
(
namespace
)
.
List
(
api
.
ListOptions
{
FieldSelector
:
fieldSelector
})
if
err
!=
nil
{
if
err
!=
nil
{
if
!
errors
.
IsForbidden
(
err
)
{
if
!
errors
.
IsForbidden
(
err
)
{
return
""
,
err
return
""
,
err
...
@@ -1817,7 +1816,7 @@ func (d *NodeDescriber) Describe(namespace, name string, describerSettings Descr
...
@@ -1817,7 +1816,7 @@ func (d *NodeDescriber) Describe(namespace, name string, describerSettings Descr
}
else
{
}
else
{
// TODO: We haven't decided the namespace for Node object yet.
// TODO: We haven't decided the namespace for Node object yet.
ref
.
UID
=
types
.
UID
(
ref
.
Name
)
ref
.
UID
=
types
.
UID
(
ref
.
Name
)
events
,
_
=
d
.
Events
(
""
)
.
Search
(
ref
)
events
,
_
=
d
.
Core
()
.
Events
(
""
)
.
Search
(
ref
)
}
}
}
}
...
@@ -1904,7 +1903,7 @@ func describeNode(node *api.Node, nodeNonTerminatedPodsList *api.PodList, events
...
@@ -1904,7 +1903,7 @@ func describeNode(node *api.Node, nodeNonTerminatedPodsList *api.PodList, events
}
}
type
PetSetDescriber
struct
{
type
PetSetDescriber
struct
{
client
*
client
.
Client
client
clientset
.
Interface
}
}
func
(
p
*
PetSetDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
p
*
PetSetDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
...
@@ -1912,7 +1911,7 @@ func (p *PetSetDescriber) Describe(namespace, name string, describerSettings Des
...
@@ -1912,7 +1911,7 @@ func (p *PetSetDescriber) Describe(namespace, name string, describerSettings Des
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
pc
:=
p
.
client
.
Pods
(
namespace
)
pc
:=
p
.
client
.
Core
()
.
Pods
(
namespace
)
selector
,
err
:=
unversioned
.
LabelSelectorAsSelector
(
ps
.
Spec
.
Selector
)
selector
,
err
:=
unversioned
.
LabelSelectorAsSelector
(
ps
.
Spec
.
Selector
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -1936,7 +1935,7 @@ func (p *PetSetDescriber) Describe(namespace, name string, describerSettings Des
...
@@ -1936,7 +1935,7 @@ func (p *PetSetDescriber) Describe(namespace, name string, describerSettings Des
fmt
.
Fprintf
(
out
,
"Pods Status:
\t
%d Running / %d Waiting / %d Succeeded / %d Failed
\n
"
,
running
,
waiting
,
succeeded
,
failed
)
fmt
.
Fprintf
(
out
,
"Pods Status:
\t
%d Running / %d Waiting / %d Succeeded / %d Failed
\n
"
,
running
,
waiting
,
succeeded
,
failed
)
describeVolumes
(
ps
.
Spec
.
Template
.
Spec
.
Volumes
,
out
,
""
)
describeVolumes
(
ps
.
Spec
.
Template
.
Spec
.
Volumes
,
out
,
""
)
if
describerSettings
.
ShowEvents
{
if
describerSettings
.
ShowEvents
{
events
,
_
:=
p
.
client
.
Events
(
namespace
)
.
Search
(
ps
)
events
,
_
:=
p
.
client
.
Core
()
.
Events
(
namespace
)
.
Search
(
ps
)
if
events
!=
nil
{
if
events
!=
nil
{
DescribeEvents
(
events
,
out
)
DescribeEvents
(
events
,
out
)
}
}
...
@@ -1946,7 +1945,7 @@ func (p *PetSetDescriber) Describe(namespace, name string, describerSettings Des
...
@@ -1946,7 +1945,7 @@ func (p *PetSetDescriber) Describe(namespace, name string, describerSettings Des
}
}
type
CertificateSigningRequestDescriber
struct
{
type
CertificateSigningRequestDescriber
struct
{
client
*
client
.
Client
client
clientset
.
Interface
}
}
func
(
p
*
CertificateSigningRequestDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
p
*
CertificateSigningRequestDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
...
@@ -2004,7 +2003,7 @@ func (p *CertificateSigningRequestDescriber) Describe(namespace, name string, de
...
@@ -2004,7 +2003,7 @@ func (p *CertificateSigningRequestDescriber) Describe(namespace, name string, de
}
}
if
describerSettings
.
ShowEvents
{
if
describerSettings
.
ShowEvents
{
events
,
_
:=
p
.
client
.
Events
(
namespace
)
.
Search
(
csr
)
events
,
_
:=
p
.
client
.
Core
()
.
Events
(
namespace
)
.
Search
(
csr
)
if
events
!=
nil
{
if
events
!=
nil
{
DescribeEvents
(
events
,
out
)
DescribeEvents
(
events
,
out
)
}
}
...
@@ -2015,7 +2014,7 @@ func (p *CertificateSigningRequestDescriber) Describe(namespace, name string, de
...
@@ -2015,7 +2014,7 @@ func (p *CertificateSigningRequestDescriber) Describe(namespace, name string, de
// HorizontalPodAutoscalerDescriber generates information about a horizontal pod autoscaler.
// HorizontalPodAutoscalerDescriber generates information about a horizontal pod autoscaler.
type
HorizontalPodAutoscalerDescriber
struct
{
type
HorizontalPodAutoscalerDescriber
struct
{
client
*
client
.
Client
client
clientset
.
Interface
}
}
func
(
d
*
HorizontalPodAutoscalerDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
HorizontalPodAutoscalerDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
...
@@ -2051,7 +2050,7 @@ func (d *HorizontalPodAutoscalerDescriber) Describe(namespace, name string, desc
...
@@ -2051,7 +2050,7 @@ func (d *HorizontalPodAutoscalerDescriber) Describe(namespace, name string, desc
// TODO: switch to scale subresource once the required code is submitted.
// TODO: switch to scale subresource once the required code is submitted.
if
strings
.
ToLower
(
hpa
.
Spec
.
ScaleTargetRef
.
Kind
)
==
"replicationcontroller"
{
if
strings
.
ToLower
(
hpa
.
Spec
.
ScaleTargetRef
.
Kind
)
==
"replicationcontroller"
{
fmt
.
Fprintf
(
out
,
"ReplicationController pods:
\t
"
)
fmt
.
Fprintf
(
out
,
"ReplicationController pods:
\t
"
)
rc
,
err
:=
d
.
client
.
ReplicationControllers
(
hpa
.
Namespace
)
.
Get
(
hpa
.
Spec
.
ScaleTargetRef
.
Name
)
rc
,
err
:=
d
.
client
.
Core
()
.
ReplicationControllers
(
hpa
.
Namespace
)
.
Get
(
hpa
.
Spec
.
ScaleTargetRef
.
Name
)
if
err
==
nil
{
if
err
==
nil
{
fmt
.
Fprintf
(
out
,
"%d current / %d desired
\n
"
,
rc
.
Status
.
Replicas
,
rc
.
Spec
.
Replicas
)
fmt
.
Fprintf
(
out
,
"%d current / %d desired
\n
"
,
rc
.
Status
.
Replicas
,
rc
.
Spec
.
Replicas
)
}
else
{
}
else
{
...
@@ -2060,7 +2059,7 @@ func (d *HorizontalPodAutoscalerDescriber) Describe(namespace, name string, desc
...
@@ -2060,7 +2059,7 @@ func (d *HorizontalPodAutoscalerDescriber) Describe(namespace, name string, desc
}
}
if
describerSettings
.
ShowEvents
{
if
describerSettings
.
ShowEvents
{
events
,
_
:=
d
.
client
.
Events
(
namespace
)
.
Search
(
hpa
)
events
,
_
:=
d
.
client
.
Core
()
.
Events
(
namespace
)
.
Search
(
hpa
)
if
events
!=
nil
{
if
events
!=
nil
{
DescribeEvents
(
events
,
out
)
DescribeEvents
(
events
,
out
)
}
}
...
@@ -2301,11 +2300,11 @@ func getPodStatusForController(c client.PodInterface, selector labels.Selector)
...
@@ -2301,11 +2300,11 @@ func getPodStatusForController(c client.PodInterface, selector labels.Selector)
// ConfigMapDescriber generates information about a ConfigMap
// ConfigMapDescriber generates information about a ConfigMap
type
ConfigMapDescriber
struct
{
type
ConfigMapDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
ConfigMapDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
ConfigMapDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
c
:=
d
.
ConfigMaps
(
namespace
)
c
:=
d
.
Co
re
()
.
Co
nfigMaps
(
namespace
)
configMap
,
err
:=
c
.
Get
(
name
)
configMap
,
err
:=
c
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -2373,7 +2372,7 @@ func describeCluster(cluster *federation.Cluster) (string, error) {
...
@@ -2373,7 +2372,7 @@ func describeCluster(cluster *federation.Cluster) (string, error) {
// NetworkPolicyDescriber generates information about a NetworkPolicy
// NetworkPolicyDescriber generates information about a NetworkPolicy
type
NetworkPolicyDescriber
struct
{
type
NetworkPolicyDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
d
*
NetworkPolicyDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
d
*
NetworkPolicyDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
...
@@ -2399,7 +2398,7 @@ func describeNetworkPolicy(networkPolicy *extensions.NetworkPolicy) (string, err
...
@@ -2399,7 +2398,7 @@ func describeNetworkPolicy(networkPolicy *extensions.NetworkPolicy) (string, err
}
}
type
StorageClassDescriber
struct
{
type
StorageClassDescriber
struct
{
client
.
Interface
client
set
.
Interface
}
}
func
(
s
*
StorageClassDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
func
(
s
*
StorageClassDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
...
@@ -2413,7 +2412,7 @@ func (s *StorageClassDescriber) Describe(namespace, name string, describerSettin
...
@@ -2413,7 +2412,7 @@ func (s *StorageClassDescriber) Describe(namespace, name string, describerSettin
fmt
.
Fprintf
(
out
,
"Provisioner:
\t
%s
\n
"
,
sc
.
Provisioner
)
fmt
.
Fprintf
(
out
,
"Provisioner:
\t
%s
\n
"
,
sc
.
Provisioner
)
fmt
.
Fprintf
(
out
,
"Parameters:
\t
%s
\n
"
,
labels
.
FormatLabels
(
sc
.
Parameters
))
fmt
.
Fprintf
(
out
,
"Parameters:
\t
%s
\n
"
,
labels
.
FormatLabels
(
sc
.
Parameters
))
if
describerSettings
.
ShowEvents
{
if
describerSettings
.
ShowEvents
{
events
,
err
:=
s
.
Events
(
namespace
)
.
Search
(
sc
)
events
,
err
:=
s
.
Core
()
.
Events
(
namespace
)
.
Search
(
sc
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/kubectl/describe_test.go
View file @
519c1374
...
@@ -32,20 +32,19 @@ import (
...
@@ -32,20 +32,19 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/storage"
"k8s.io/kubernetes/pkg/apis/storage"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
)
)
type
describeClient
struct
{
type
describeClient
struct
{
T
*
testing
.
T
T
*
testing
.
T
Namespace
string
Namespace
string
Err
error
Err
error
clien
t
.
Interface
internalclientse
t
.
Interface
}
}
func
TestDescribePod
(
t
*
testing
.
T
)
{
func
TestDescribePod
(
t
*
testing
.
T
)
{
fake
:=
testclient
.
NewSimpleFake
(
&
api
.
Pod
{
fake
:=
fake
.
NewSimpleClientset
(
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
Name
:
"bar"
,
Namespace
:
"foo"
,
Namespace
:
"foo"
,
...
@@ -67,7 +66,7 @@ func TestDescribePodTolerations(t *testing.T) {
...
@@ -67,7 +66,7 @@ func TestDescribePodTolerations(t *testing.T) {
podTolerations
:=
[]
api
.
Toleration
{{
Key
:
"key1"
,
Value
:
"value1"
},
podTolerations
:=
[]
api
.
Toleration
{{
Key
:
"key1"
,
Value
:
"value1"
},
{
Key
:
"key2"
,
Value
:
"value2"
}}
{
Key
:
"key2"
,
Value
:
"value2"
}}
pt
,
_
:=
json
.
Marshal
(
podTolerations
)
pt
,
_
:=
json
.
Marshal
(
podTolerations
)
fake
:=
testclient
.
NewSimpleFake
(
&
api
.
Pod
{
fake
:=
fake
.
NewSimpleClientset
(
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
Name
:
"bar"
,
Namespace
:
"foo"
,
Namespace
:
"foo"
,
...
@@ -88,7 +87,7 @@ func TestDescribePodTolerations(t *testing.T) {
...
@@ -88,7 +87,7 @@ func TestDescribePodTolerations(t *testing.T) {
}
}
func
TestDescribeService
(
t
*
testing
.
T
)
{
func
TestDescribeService
(
t
*
testing
.
T
)
{
fake
:=
testclient
.
NewSimpleFake
(
&
api
.
Service
{
fake
:=
fake
.
NewSimpleClientset
(
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
Name
:
"bar"
,
Namespace
:
"foo"
,
Namespace
:
"foo"
,
...
@@ -107,34 +106,40 @@ func TestDescribeService(t *testing.T) {
...
@@ -107,34 +106,40 @@ func TestDescribeService(t *testing.T) {
func
TestPodDescribeResultsSorted
(
t
*
testing
.
T
)
{
func
TestPodDescribeResultsSorted
(
t
*
testing
.
T
)
{
// Arrange
// Arrange
fake
:=
testclient
.
NewSimpleFake
(
&
api
.
EventList
{
fake
:=
fake
.
NewSimpleClientset
(
Items
:
[]
api
.
Event
{
&
api
.
EventList
{
{
Items
:
[]
api
.
Event
{
Source
:
api
.
EventSource
{
Component
:
"kubelet"
},
{
Message
:
"Item 1"
,
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"one"
},
FirstTimestamp
:
unversioned
.
NewTime
(
time
.
Date
(
2014
,
time
.
January
,
15
,
0
,
0
,
0
,
0
,
time
.
UTC
)),
Source
:
api
.
EventSource
{
Component
:
"kubelet"
},
LastTimestamp
:
unversioned
.
NewTime
(
time
.
Date
(
2014
,
time
.
January
,
15
,
0
,
0
,
0
,
0
,
time
.
UTC
)),
Message
:
"Item 1"
,
Count
:
1
,
FirstTimestamp
:
unversioned
.
NewTime
(
time
.
Date
(
2014
,
time
.
January
,
15
,
0
,
0
,
0
,
0
,
time
.
UTC
)),
Type
:
api
.
EventTypeNormal
,
LastTimestamp
:
unversioned
.
NewTime
(
time
.
Date
(
2014
,
time
.
January
,
15
,
0
,
0
,
0
,
0
,
time
.
UTC
)),
},
Count
:
1
,
{
Type
:
api
.
EventTypeNormal
,
Source
:
api
.
EventSource
{
Component
:
"scheduler"
},
},
Message
:
"Item 2"
,
{
FirstTimestamp
:
unversioned
.
NewTime
(
time
.
Date
(
1987
,
time
.
June
,
17
,
0
,
0
,
0
,
0
,
time
.
UTC
)),
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"two"
},
LastTimestamp
:
unversioned
.
NewTime
(
time
.
Date
(
1987
,
time
.
June
,
17
,
0
,
0
,
0
,
0
,
time
.
UTC
)),
Source
:
api
.
EventSource
{
Component
:
"scheduler"
},
Count
:
1
,
Message
:
"Item 2"
,
Type
:
api
.
EventTypeNormal
,
FirstTimestamp
:
unversioned
.
NewTime
(
time
.
Date
(
1987
,
time
.
June
,
17
,
0
,
0
,
0
,
0
,
time
.
UTC
)),
},
LastTimestamp
:
unversioned
.
NewTime
(
time
.
Date
(
1987
,
time
.
June
,
17
,
0
,
0
,
0
,
0
,
time
.
UTC
)),
{
Count
:
1
,
Source
:
api
.
EventSource
{
Component
:
"kubelet"
},
Type
:
api
.
EventTypeNormal
,
Message
:
"Item 3"
,
},
FirstTimestamp
:
unversioned
.
NewTime
(
time
.
Date
(
2002
,
time
.
December
,
25
,
0
,
0
,
0
,
0
,
time
.
UTC
)),
{
LastTimestamp
:
unversioned
.
NewTime
(
time
.
Date
(
2002
,
time
.
December
,
25
,
0
,
0
,
0
,
0
,
time
.
UTC
)),
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"three"
},
Count
:
1
,
Source
:
api
.
EventSource
{
Component
:
"kubelet"
},
Type
:
api
.
EventTypeNormal
,
Message
:
"Item 3"
,
FirstTimestamp
:
unversioned
.
NewTime
(
time
.
Date
(
2002
,
time
.
December
,
25
,
0
,
0
,
0
,
0
,
time
.
UTC
)),
LastTimestamp
:
unversioned
.
NewTime
(
time
.
Date
(
2002
,
time
.
December
,
25
,
0
,
0
,
0
,
0
,
time
.
UTC
)),
Count
:
1
,
Type
:
api
.
EventTypeNormal
,
},
},
},
},
},
})
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
"foo"
,
Name
:
"bar"
}},
)
c
:=
&
describeClient
{
T
:
t
,
Namespace
:
"foo"
,
Interface
:
fake
}
c
:=
&
describeClient
{
T
:
t
,
Namespace
:
"foo"
,
Interface
:
fake
}
d
:=
PodDescriber
{
c
}
d
:=
PodDescriber
{
c
}
...
@@ -483,6 +488,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
...
@@ -483,6 +488,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
tests
:=
map
[
string
]
*
api
.
PersistentVolume
{
tests
:=
map
[
string
]
*
api
.
PersistentVolume
{
"hostpath"
:
{
"hostpath"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
},
Spec
:
api
.
PersistentVolumeSpec
{
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
HostPath
:
&
api
.
HostPathVolumeSource
{},
HostPath
:
&
api
.
HostPathVolumeSource
{},
...
@@ -490,6 +496,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
...
@@ -490,6 +496,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
},
},
},
},
"gce"
:
{
"gce"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
},
Spec
:
api
.
PersistentVolumeSpec
{
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
GCEPersistentDisk
:
&
api
.
GCEPersistentDiskVolumeSource
{},
GCEPersistentDisk
:
&
api
.
GCEPersistentDiskVolumeSource
{},
...
@@ -497,6 +504,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
...
@@ -497,6 +504,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
},
},
},
},
"ebs"
:
{
"ebs"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
},
Spec
:
api
.
PersistentVolumeSpec
{
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
AWSElasticBlockStore
:
&
api
.
AWSElasticBlockStoreVolumeSource
{},
AWSElasticBlockStore
:
&
api
.
AWSElasticBlockStoreVolumeSource
{},
...
@@ -504,6 +512,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
...
@@ -504,6 +512,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
},
},
},
},
"nfs"
:
{
"nfs"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
},
Spec
:
api
.
PersistentVolumeSpec
{
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
NFS
:
&
api
.
NFSVolumeSource
{},
NFS
:
&
api
.
NFSVolumeSource
{},
...
@@ -511,6 +520,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
...
@@ -511,6 +520,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
},
},
},
},
"iscsi"
:
{
"iscsi"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
},
Spec
:
api
.
PersistentVolumeSpec
{
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
ISCSI
:
&
api
.
ISCSIVolumeSource
{},
ISCSI
:
&
api
.
ISCSIVolumeSource
{},
...
@@ -518,6 +528,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
...
@@ -518,6 +528,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
},
},
},
},
"gluster"
:
{
"gluster"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
},
Spec
:
api
.
PersistentVolumeSpec
{
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
Glusterfs
:
&
api
.
GlusterfsVolumeSource
{},
Glusterfs
:
&
api
.
GlusterfsVolumeSource
{},
...
@@ -525,6 +536,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
...
@@ -525,6 +536,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
},
},
},
},
"rbd"
:
{
"rbd"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
},
Spec
:
api
.
PersistentVolumeSpec
{
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
RBD
:
&
api
.
RBDVolumeSource
{},
RBD
:
&
api
.
RBDVolumeSource
{},
...
@@ -532,6 +544,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
...
@@ -532,6 +544,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
},
},
},
},
"quobyte"
:
{
"quobyte"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
},
Spec
:
api
.
PersistentVolumeSpec
{
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
Quobyte
:
&
api
.
QuobyteVolumeSource
{},
Quobyte
:
&
api
.
QuobyteVolumeSource
{},
...
@@ -539,6 +552,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
...
@@ -539,6 +552,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
},
},
},
},
"cinder"
:
{
"cinder"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
},
Spec
:
api
.
PersistentVolumeSpec
{
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
Cinder
:
&
api
.
CinderVolumeSource
{},
Cinder
:
&
api
.
CinderVolumeSource
{},
...
@@ -548,7 +562,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
...
@@ -548,7 +562,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
}
}
for
name
,
pv
:=
range
tests
{
for
name
,
pv
:=
range
tests
{
fake
:=
testclient
.
NewSimpleFake
(
pv
)
fake
:=
fake
.
NewSimpleClientset
(
pv
)
c
:=
PersistentVolumeDescriber
{
fake
}
c
:=
PersistentVolumeDescriber
{
fake
}
str
,
err
:=
c
.
Describe
(
"foo"
,
"bar"
,
DescriberSettings
{
ShowEvents
:
true
})
str
,
err
:=
c
.
Describe
(
"foo"
,
"bar"
,
DescriberSettings
{
ShowEvents
:
true
})
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -615,7 +629,7 @@ func TestDescribeCluster(t *testing.T) {
...
@@ -615,7 +629,7 @@ func TestDescribeCluster(t *testing.T) {
}
}
func
TestDescribeStorageClass
(
t
*
testing
.
T
)
{
func
TestDescribeStorageClass
(
t
*
testing
.
T
)
{
f
:=
testclient
.
NewSimpleFake
(
&
storage
.
StorageClass
{
f
:=
fake
.
NewSimpleClientset
(
&
storage
.
StorageClass
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Name
:
"foo"
,
ResourceVersion
:
"4"
,
ResourceVersion
:
"4"
,
...
@@ -659,7 +673,7 @@ func TestDescribeEvents(t *testing.T) {
...
@@ -659,7 +673,7 @@ func TestDescribeEvents(t *testing.T) {
m
:=
map
[
string
]
Describer
{
m
:=
map
[
string
]
Describer
{
"DaemonSetDescriber"
:
&
DaemonSetDescriber
{
"DaemonSetDescriber"
:
&
DaemonSetDescriber
{
testclient
.
NewSimpleFake
(
&
extensions
.
DaemonSet
{
fake
.
NewSimpleClientset
(
&
extensions
.
DaemonSet
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
Name
:
"bar"
,
Namespace
:
"foo"
,
Namespace
:
"foo"
,
...
@@ -675,7 +689,7 @@ func TestDescribeEvents(t *testing.T) {
...
@@ -675,7 +689,7 @@ func TestDescribeEvents(t *testing.T) {
},
events
),
},
events
),
},
},
"EndpointsDescriber"
:
&
EndpointsDescriber
{
"EndpointsDescriber"
:
&
EndpointsDescriber
{
testclient
.
NewSimpleFake
(
&
api
.
Endpoints
{
fake
.
NewSimpleClientset
(
&
api
.
Endpoints
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
Name
:
"bar"
,
Namespace
:
"foo"
,
Namespace
:
"foo"
,
...
@@ -687,25 +701,23 @@ func TestDescribeEvents(t *testing.T) {
...
@@ -687,25 +701,23 @@ func TestDescribeEvents(t *testing.T) {
// - IngressDescriber
// - IngressDescriber
// - JobDescriber
// - JobDescriber
"NodeDescriber"
:
&
NodeDescriber
{
"NodeDescriber"
:
&
NodeDescriber
{
testclient
.
NewSimpleFake
(
&
api
.
Node
{
fake
.
NewSimpleClientset
(
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
Name
:
"bar"
,
Namespace
:
"foo"
,
SelfLink
:
"url/url/url"
,
SelfLink
:
"url/url/url"
,
},
},
},
events
),
},
events
),
},
},
"PersistentVolumeDescriber"
:
&
PersistentVolumeDescriber
{
"PersistentVolumeDescriber"
:
&
PersistentVolumeDescriber
{
testclient
.
NewSimpleFake
(
&
api
.
PersistentVolume
{
fake
.
NewSimpleClientset
(
&
api
.
PersistentVolume
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
Name
:
"bar"
,
Namespace
:
"foo"
,
SelfLink
:
"url/url/url"
,
SelfLink
:
"url/url/url"
,
},
},
},
events
),
},
events
),
},
},
"PodDescriber"
:
&
PodDescriber
{
"PodDescriber"
:
&
PodDescriber
{
testclient
.
NewSimpleFake
(
&
api
.
Pod
{
fake
.
NewSimpleClientset
(
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
Name
:
"bar"
,
Namespace
:
"foo"
,
Namespace
:
"foo"
,
...
@@ -714,7 +726,7 @@ func TestDescribeEvents(t *testing.T) {
...
@@ -714,7 +726,7 @@ func TestDescribeEvents(t *testing.T) {
},
events
),
},
events
),
},
},
"ReplicaSetDescriber"
:
&
ReplicaSetDescriber
{
"ReplicaSetDescriber"
:
&
ReplicaSetDescriber
{
testclient
.
NewSimpleFake
(
&
extensions
.
ReplicaSet
{
fake
.
NewSimpleClientset
(
&
extensions
.
ReplicaSet
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
Name
:
"bar"
,
Namespace
:
"foo"
,
Namespace
:
"foo"
,
...
@@ -722,7 +734,7 @@ func TestDescribeEvents(t *testing.T) {
...
@@ -722,7 +734,7 @@ func TestDescribeEvents(t *testing.T) {
},
events
),
},
events
),
},
},
"ReplicationControllerDescriber"
:
&
ReplicationControllerDescriber
{
"ReplicationControllerDescriber"
:
&
ReplicationControllerDescriber
{
testclient
.
NewSimpleFake
(
&
api
.
ReplicationController
{
fake
.
NewSimpleClientset
(
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
Name
:
"bar"
,
Namespace
:
"foo"
,
Namespace
:
"foo"
,
...
@@ -730,7 +742,7 @@ func TestDescribeEvents(t *testing.T) {
...
@@ -730,7 +742,7 @@ func TestDescribeEvents(t *testing.T) {
},
events
),
},
events
),
},
},
"Service"
:
&
ServiceDescriber
{
"Service"
:
&
ServiceDescriber
{
testclient
.
NewSimpleFake
(
&
api
.
Service
{
fake
.
NewSimpleClientset
(
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
Name
:
"bar"
,
Namespace
:
"foo"
,
Namespace
:
"foo"
,
...
@@ -738,10 +750,9 @@ func TestDescribeEvents(t *testing.T) {
...
@@ -738,10 +750,9 @@ func TestDescribeEvents(t *testing.T) {
},
events
),
},
events
),
},
},
"StorageClass"
:
&
StorageClassDescriber
{
"StorageClass"
:
&
StorageClassDescriber
{
testclient
.
NewSimpleFake
(
&
storage
.
StorageClass
{
fake
.
NewSimpleClientset
(
&
storage
.
StorageClass
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
Name
:
"bar"
,
Namespace
:
"foo"
,
},
},
},
events
),
},
events
),
},
},
...
...
pkg/kubectl/metricsutil/metrics_client.go
View file @
519c1374
...
@@ -25,7 +25,7 @@ import (
...
@@ -25,7 +25,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/validation"
"k8s.io/kubernetes/pkg/api/validation"
c
lient
"k8s.io/kubernetes/pkg/client
/unversioned"
c
oreclient
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core
/unversioned"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
)
)
...
@@ -46,16 +46,16 @@ var (
...
@@ -46,16 +46,16 @@ var (
)
)
type
HeapsterMetricsClient
struct
{
type
HeapsterMetricsClient
struct
{
*
client
.
Client
SVCClient
coreclient
.
ServicesGetter
HeapsterNamespace
string
HeapsterNamespace
string
HeapsterScheme
string
HeapsterScheme
string
HeapsterService
string
HeapsterService
string
HeapsterPort
string
HeapsterPort
string
}
}
func
NewHeapsterMetricsClient
(
client
*
client
.
Client
,
namespace
,
scheme
,
service
,
port
string
)
*
HeapsterMetricsClient
{
func
NewHeapsterMetricsClient
(
svcClient
coreclient
.
ServicesGetter
,
namespace
,
scheme
,
service
,
port
string
)
*
HeapsterMetricsClient
{
return
&
HeapsterMetricsClient
{
return
&
HeapsterMetricsClient
{
Client
:
c
lient
,
SVCClient
:
svcC
lient
,
HeapsterNamespace
:
namespace
,
HeapsterNamespace
:
namespace
,
HeapsterScheme
:
scheme
,
HeapsterScheme
:
scheme
,
HeapsterService
:
service
,
HeapsterService
:
service
,
...
@@ -63,8 +63,8 @@ func NewHeapsterMetricsClient(client *client.Client, namespace, scheme, service,
...
@@ -63,8 +63,8 @@ func NewHeapsterMetricsClient(client *client.Client, namespace, scheme, service,
}
}
}
}
func
DefaultHeapsterMetricsClient
(
client
*
client
.
Client
)
*
HeapsterMetricsClient
{
func
DefaultHeapsterMetricsClient
(
svcClient
coreclient
.
ServicesGetter
)
*
HeapsterMetricsClient
{
return
NewHeapsterMetricsClient
(
c
lient
,
DefaultHeapsterNamespace
,
DefaultHeapsterScheme
,
DefaultHeapsterService
,
DefaultHeapsterPort
)
return
NewHeapsterMetricsClient
(
svcC
lient
,
DefaultHeapsterNamespace
,
DefaultHeapsterScheme
,
DefaultHeapsterService
,
DefaultHeapsterPort
)
}
}
func
podMetricsUrl
(
namespace
string
,
name
string
)
(
string
,
error
)
{
func
podMetricsUrl
(
namespace
string
,
name
string
)
(
string
,
error
)
{
...
@@ -161,7 +161,7 @@ func (cli *HeapsterMetricsClient) GetPodMetrics(namespace string, podName string
...
@@ -161,7 +161,7 @@ func (cli *HeapsterMetricsClient) GetPodMetrics(namespace string, podName string
}
}
func
GetHeapsterMetrics
(
cli
*
HeapsterMetricsClient
,
path
string
,
params
map
[
string
]
string
)
([]
byte
,
error
)
{
func
GetHeapsterMetrics
(
cli
*
HeapsterMetricsClient
,
path
string
,
params
map
[
string
]
string
)
([]
byte
,
error
)
{
return
cli
.
Services
(
cli
.
HeapsterNamespace
)
.
return
cli
.
S
VCClient
.
S
ervices
(
cli
.
HeapsterNamespace
)
.
ProxyGet
(
cli
.
HeapsterScheme
,
cli
.
HeapsterService
,
cli
.
HeapsterPort
,
path
,
params
)
.
ProxyGet
(
cli
.
HeapsterScheme
,
cli
.
HeapsterService
,
cli
.
HeapsterPort
,
path
,
params
)
.
DoRaw
()
DoRaw
()
}
}
pkg/kubectl/rolling_updater_test.go
View file @
519c1374
...
@@ -31,10 +31,11 @@ import (
...
@@ -31,10 +31,11 @@ import (
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/testapi"
apitesting
"k8s.io/kubernetes/pkg/api/testing"
apitesting
"k8s.io/kubernetes/pkg/api/testing"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/client/restclient"
client
"k8s.io/kubernetes/pkg/client/unversioned"
testcore
"k8s.io/kubernetes/pkg/client/testing/core"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
manualfake
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/sets"
...
@@ -43,8 +44,9 @@ import (
...
@@ -43,8 +44,9 @@ import (
func
oldRc
(
replicas
int
,
original
int
)
*
api
.
ReplicationController
{
func
oldRc
(
replicas
int
,
original
int
)
*
api
.
ReplicationController
{
return
&
api
.
ReplicationController
{
return
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo-v1"
,
Namespace
:
api
.
NamespaceDefault
,
UID
:
"7764ae47-9092-11e4-8393-42010af018ff"
,
Name
:
"foo-v1"
,
UID
:
"7764ae47-9092-11e4-8393-42010af018ff"
,
Annotations
:
map
[
string
]
string
{
Annotations
:
map
[
string
]
string
{
originalReplicasAnnotation
:
fmt
.
Sprintf
(
"%d"
,
original
),
originalReplicasAnnotation
:
fmt
.
Sprintf
(
"%d"
,
original
),
},
},
...
@@ -75,7 +77,8 @@ func newRc(replicas int, desired int) *api.ReplicationController {
...
@@ -75,7 +77,8 @@ func newRc(replicas int, desired int) *api.ReplicationController {
}
}
rc
.
Spec
.
Selector
=
map
[
string
]
string
{
"version"
:
"v2"
}
rc
.
Spec
.
Selector
=
map
[
string
]
string
{
"version"
:
"v2"
}
rc
.
ObjectMeta
=
api
.
ObjectMeta
{
rc
.
ObjectMeta
=
api
.
ObjectMeta
{
Name
:
"foo-v2"
,
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo-v2"
,
Annotations
:
map
[
string
]
string
{
Annotations
:
map
[
string
]
string
{
desiredReplicasAnnotation
:
fmt
.
Sprintf
(
"%d"
,
desired
),
desiredReplicasAnnotation
:
fmt
.
Sprintf
(
"%d"
,
desired
),
sourceIdAnnotation
:
"foo-v1:7764ae47-9092-11e4-8393-42010af018ff"
,
sourceIdAnnotation
:
"foo-v1:7764ae47-9092-11e4-8393-42010af018ff"
,
...
@@ -891,21 +894,11 @@ func TestUpdate_assignOriginalAnnotation(t *testing.T) {
...
@@ -891,21 +894,11 @@ func TestUpdate_assignOriginalAnnotation(t *testing.T) {
oldRc
:=
oldRc
(
1
,
1
)
oldRc
:=
oldRc
(
1
,
1
)
delete
(
oldRc
.
Annotations
,
originalReplicasAnnotation
)
delete
(
oldRc
.
Annotations
,
originalReplicasAnnotation
)
newRc
:=
newRc
(
1
,
1
)
newRc
:=
newRc
(
1
,
1
)
var
updatedOldRc
*
api
.
ReplicationController
fake
:=
fake
.
NewSimpleClientset
(
oldRc
)
fake
:=
&
testclient
.
Fake
{}
fake
.
AddReactor
(
"*"
,
"*"
,
func
(
action
testclient
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
switch
a
:=
action
.
(
type
)
{
case
testclient
.
GetAction
:
return
true
,
oldRc
,
nil
case
testclient
.
UpdateAction
:
updatedOldRc
=
a
.
GetObject
()
.
(
*
api
.
ReplicationController
)
return
true
,
updatedOldRc
,
nil
}
return
false
,
nil
,
nil
})
updater
:=
&
RollingUpdater
{
updater
:=
&
RollingUpdater
{
c
:
fake
,
rcClient
:
fake
.
Core
(),
ns
:
"default"
,
podClient
:
fake
.
Core
(),
ns
:
"default"
,
scaleAndWait
:
func
(
rc
*
api
.
ReplicationController
,
retry
*
RetryParams
,
wait
*
RetryParams
)
(
*
api
.
ReplicationController
,
error
)
{
scaleAndWait
:
func
(
rc
*
api
.
ReplicationController
,
retry
*
RetryParams
,
wait
*
RetryParams
)
(
*
api
.
ReplicationController
,
error
)
{
return
rc
,
nil
return
rc
,
nil
},
},
...
@@ -934,10 +927,11 @@ func TestUpdate_assignOriginalAnnotation(t *testing.T) {
...
@@ -934,10 +927,11 @@ func TestUpdate_assignOriginalAnnotation(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
if
updatedOldRc
==
nil
{
updateAction
:=
fake
.
Actions
()[
1
]
.
(
testcore
.
UpdateAction
)
t
.
Fatalf
(
"expected rc to be updated"
)
if
updateAction
.
GetResource
()
.
GroupResource
()
!=
api
.
Resource
(
"replicationcontrollers"
)
{
t
.
Fatalf
(
"expected rc to be updated: %#v"
,
updateAction
)
}
}
if
e
,
a
:=
"1"
,
update
dOldRc
.
Annotations
[
originalReplicasAnnotation
];
e
!=
a
{
if
e
,
a
:=
"1"
,
update
Action
.
GetObject
()
.
(
*
api
.
ReplicationController
)
.
Annotations
[
originalReplicasAnnotation
];
e
!=
a
{
t
.
Fatalf
(
"expected annotation value %s, got %s"
,
e
,
a
)
t
.
Fatalf
(
"expected annotation value %s, got %s"
,
e
,
a
)
}
}
}
}
...
@@ -954,7 +948,8 @@ func TestRollingUpdater_multipleContainersInPod(t *testing.T) {
...
@@ -954,7 +948,8 @@ func TestRollingUpdater_multipleContainersInPod(t *testing.T) {
{
{
oldRc
:
&
api
.
ReplicationController
{
oldRc
:
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
,
},
},
Spec
:
api
.
ReplicationControllerSpec
{
Spec
:
api
.
ReplicationControllerSpec
{
Selector
:
map
[
string
]
string
{
Selector
:
map
[
string
]
string
{
...
@@ -983,7 +978,8 @@ func TestRollingUpdater_multipleContainersInPod(t *testing.T) {
...
@@ -983,7 +978,8 @@ func TestRollingUpdater_multipleContainersInPod(t *testing.T) {
},
},
newRc
:
&
api
.
ReplicationController
{
newRc
:
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
,
},
},
Spec
:
api
.
ReplicationControllerSpec
{
Spec
:
api
.
ReplicationControllerSpec
{
Selector
:
map
[
string
]
string
{
Selector
:
map
[
string
]
string
{
...
@@ -1017,7 +1013,8 @@ func TestRollingUpdater_multipleContainersInPod(t *testing.T) {
...
@@ -1017,7 +1013,8 @@ func TestRollingUpdater_multipleContainersInPod(t *testing.T) {
{
{
oldRc
:
&
api
.
ReplicationController
{
oldRc
:
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
Namespace
:
api
.
NamespaceDefault
,
Name
:
"bar"
,
},
},
Spec
:
api
.
ReplicationControllerSpec
{
Spec
:
api
.
ReplicationControllerSpec
{
Selector
:
map
[
string
]
string
{
Selector
:
map
[
string
]
string
{
...
@@ -1042,7 +1039,8 @@ func TestRollingUpdater_multipleContainersInPod(t *testing.T) {
...
@@ -1042,7 +1039,8 @@ func TestRollingUpdater_multipleContainersInPod(t *testing.T) {
},
},
newRc
:
&
api
.
ReplicationController
{
newRc
:
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
Namespace
:
api
.
NamespaceDefault
,
Name
:
"bar"
,
},
},
Spec
:
api
.
ReplicationControllerSpec
{
Spec
:
api
.
ReplicationControllerSpec
{
Selector
:
map
[
string
]
string
{
Selector
:
map
[
string
]
string
{
...
@@ -1072,14 +1070,7 @@ func TestRollingUpdater_multipleContainersInPod(t *testing.T) {
...
@@ -1072,14 +1070,7 @@ func TestRollingUpdater_multipleContainersInPod(t *testing.T) {
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
fake
:=
&
testclient
.
Fake
{}
fake
:=
fake
.
NewSimpleClientset
(
test
.
oldRc
)
fake
.
AddReactor
(
"*"
,
"*"
,
func
(
action
testclient
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
switch
action
.
(
type
)
{
case
testclient
.
GetAction
:
return
true
,
test
.
oldRc
,
nil
}
return
false
,
nil
,
nil
})
codec
:=
testapi
.
Default
.
Codec
()
codec
:=
testapi
.
Default
.
Codec
()
...
@@ -1093,13 +1084,14 @@ func TestRollingUpdater_multipleContainersInPod(t *testing.T) {
...
@@ -1093,13 +1084,14 @@ func TestRollingUpdater_multipleContainersInPod(t *testing.T) {
test
.
newRc
.
Name
=
fmt
.
Sprintf
(
"%s-%s"
,
test
.
newRc
.
Name
,
deploymentHash
)
test
.
newRc
.
Name
=
fmt
.
Sprintf
(
"%s-%s"
,
test
.
newRc
.
Name
,
deploymentHash
)
config
:=
&
NewControllerConfig
{
config
:=
&
NewControllerConfig
{
Namespace
:
api
.
NamespaceDefault
,
OldName
:
test
.
oldRc
.
ObjectMeta
.
Name
,
OldName
:
test
.
oldRc
.
ObjectMeta
.
Name
,
NewName
:
test
.
newRc
.
ObjectMeta
.
Name
,
NewName
:
test
.
newRc
.
ObjectMeta
.
Name
,
Image
:
test
.
image
,
Image
:
test
.
image
,
Container
:
test
.
container
,
Container
:
test
.
container
,
DeploymentKey
:
test
.
deploymentKey
,
DeploymentKey
:
test
.
deploymentKey
,
}
}
updatedRc
,
err
:=
CreateNewControllerFromCurrentController
(
fake
,
codec
,
config
)
updatedRc
,
err
:=
CreateNewControllerFromCurrentController
(
fake
.
Core
()
,
codec
,
config
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -1168,10 +1160,13 @@ func TestRollingUpdater_cleanupWithClients(t *testing.T) {
...
@@ -1168,10 +1160,13 @@ func TestRollingUpdater_cleanupWithClients(t *testing.T) {
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
fake
:=
testclient
.
NewSimpleFake
(
test
.
responses
...
)
objs
:=
[]
runtime
.
Object
{
rc
}
objs
=
append
(
objs
,
test
.
responses
...
)
fake
:=
fake
.
NewSimpleClientset
(
objs
...
)
updater
:=
&
RollingUpdater
{
updater
:=
&
RollingUpdater
{
ns
:
"default"
,
ns
:
"default"
,
c
:
fake
,
rcClient
:
fake
.
Core
(),
podClient
:
fake
.
Core
(),
}
}
config
:=
&
RollingUpdaterConfig
{
config
:=
&
RollingUpdaterConfig
{
Out
:
ioutil
.
Discard
,
Out
:
ioutil
.
Discard
,
...
@@ -1206,20 +1201,20 @@ func TestRollingUpdater_cleanupWithClients_Rename(t *testing.T) {
...
@@ -1206,20 +1201,20 @@ func TestRollingUpdater_cleanupWithClients_Rename(t *testing.T) {
rc
:=
oldRc
(
2
,
2
)
rc
:=
oldRc
(
2
,
2
)
rcExisting
:=
newRc
(
1
,
3
)
rcExisting
:=
newRc
(
1
,
3
)
expectedActions
:=
[]
string
{
"delete"
,
"get"
,
"create"
}
expectedActions
:=
[]
string
{
"delete"
,
"get"
,
"create"
}
fake
:=
&
testclient
.
Fake
{}
fake
:=
fake
.
NewSimpleClientset
()
fake
.
AddReactor
(
"*"
,
"*"
,
func
(
action
testc
lient
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
fake
.
AddReactor
(
"*"
,
"*"
,
func
(
action
testc
ore
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
switch
action
.
(
type
)
{
switch
action
.
(
type
)
{
case
testc
lient
.
CreateAction
:
case
testc
ore
.
CreateAction
:
return
true
,
nil
,
nil
return
true
,
nil
,
nil
case
testc
lient
.
GetAction
:
case
testc
ore
.
GetAction
:
return
true
,
nil
,
errors
.
NewNotFound
(
unversioned
.
GroupResource
{},
""
)
return
true
,
nil
,
errors
.
NewNotFound
(
unversioned
.
GroupResource
{},
""
)
case
testc
lient
.
DeleteAction
:
case
testc
ore
.
DeleteAction
:
return
true
,
nil
,
nil
return
true
,
nil
,
nil
}
}
return
false
,
nil
,
nil
return
false
,
nil
,
nil
})
})
err
:=
Rename
(
fake
,
rcExisting
,
rc
.
Name
)
err
:=
Rename
(
fake
.
Core
()
,
rcExisting
,
rc
.
Name
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -1233,7 +1228,8 @@ func TestRollingUpdater_cleanupWithClients_Rename(t *testing.T) {
...
@@ -1233,7 +1228,8 @@ func TestRollingUpdater_cleanupWithClients_Rename(t *testing.T) {
func
TestFindSourceController
(
t
*
testing
.
T
)
{
func
TestFindSourceController
(
t
*
testing
.
T
)
{
ctrl1
:=
api
.
ReplicationController
{
ctrl1
:=
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
,
Annotations
:
map
[
string
]
string
{
Annotations
:
map
[
string
]
string
{
sourceIdAnnotation
:
"bar:1234"
,
sourceIdAnnotation
:
"bar:1234"
,
},
},
...
@@ -1241,7 +1237,8 @@ func TestFindSourceController(t *testing.T) {
...
@@ -1241,7 +1237,8 @@ func TestFindSourceController(t *testing.T) {
}
}
ctrl2
:=
api
.
ReplicationController
{
ctrl2
:=
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
Namespace
:
api
.
NamespaceDefault
,
Name
:
"bar"
,
Annotations
:
map
[
string
]
string
{
Annotations
:
map
[
string
]
string
{
sourceIdAnnotation
:
"foo:12345"
,
sourceIdAnnotation
:
"foo:12345"
,
},
},
...
@@ -1249,6 +1246,8 @@ func TestFindSourceController(t *testing.T) {
...
@@ -1249,6 +1246,8 @@ func TestFindSourceController(t *testing.T) {
}
}
ctrl3
:=
api
.
ReplicationController
{
ctrl3
:=
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"baz"
,
Annotations
:
map
[
string
]
string
{
Annotations
:
map
[
string
]
string
{
sourceIdAnnotation
:
"baz:45667"
,
sourceIdAnnotation
:
"baz:45667"
,
},
},
...
@@ -1302,8 +1301,8 @@ func TestFindSourceController(t *testing.T) {
...
@@ -1302,8 +1301,8 @@ func TestFindSourceController(t *testing.T) {
},
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
fakeClient
:=
testclient
.
NewSimpleFake
(
test
.
list
)
fakeClient
:=
fake
.
NewSimpleClientset
(
test
.
list
)
ctrl
,
err
:=
FindSourceController
(
fakeClient
,
"default"
,
test
.
name
)
ctrl
,
err
:=
FindSourceController
(
fakeClient
.
Core
()
,
"default"
,
test
.
name
)
if
test
.
expectError
&&
err
==
nil
{
if
test
.
expectError
&&
err
==
nil
{
t
.
Errorf
(
"unexpected non-error"
)
t
.
Errorf
(
"unexpected non-error"
)
}
}
...
@@ -1328,6 +1327,10 @@ func TestUpdateExistingReplicationController(t *testing.T) {
...
@@ -1328,6 +1327,10 @@ func TestUpdateExistingReplicationController(t *testing.T) {
}{
}{
{
{
rc
:
&
api
.
ReplicationController
{
rc
:
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
,
},
Spec
:
api
.
ReplicationControllerSpec
{
Spec
:
api
.
ReplicationControllerSpec
{
Template
:
&
api
.
PodTemplateSpec
{},
Template
:
&
api
.
PodTemplateSpec
{},
},
},
...
@@ -1338,6 +1341,8 @@ func TestUpdateExistingReplicationController(t *testing.T) {
...
@@ -1338,6 +1341,8 @@ func TestUpdateExistingReplicationController(t *testing.T) {
expectedRc
:
&
api
.
ReplicationController
{
expectedRc
:
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
,
Annotations
:
map
[
string
]
string
{
Annotations
:
map
[
string
]
string
{
"kubectl.kubernetes.io/next-controller-id"
:
"foo"
,
"kubectl.kubernetes.io/next-controller-id"
:
"foo"
,
},
},
...
@@ -1358,6 +1363,10 @@ func TestUpdateExistingReplicationController(t *testing.T) {
...
@@ -1358,6 +1363,10 @@ func TestUpdateExistingReplicationController(t *testing.T) {
},
},
{
{
rc
:
&
api
.
ReplicationController
{
rc
:
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
,
},
Spec
:
api
.
ReplicationControllerSpec
{
Spec
:
api
.
ReplicationControllerSpec
{
Template
:
&
api
.
PodTemplateSpec
{
Template
:
&
api
.
PodTemplateSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
...
@@ -1377,6 +1386,8 @@ func TestUpdateExistingReplicationController(t *testing.T) {
...
@@ -1377,6 +1386,8 @@ func TestUpdateExistingReplicationController(t *testing.T) {
expectedRc
:
&
api
.
ReplicationController
{
expectedRc
:
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
,
Annotations
:
map
[
string
]
string
{
Annotations
:
map
[
string
]
string
{
"kubectl.kubernetes.io/next-controller-id"
:
"foo"
,
"kubectl.kubernetes.io/next-controller-id"
:
"foo"
,
},
},
...
@@ -1398,8 +1409,8 @@ func TestUpdateExistingReplicationController(t *testing.T) {
...
@@ -1398,8 +1409,8 @@ func TestUpdateExistingReplicationController(t *testing.T) {
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
buffer
:=
&
bytes
.
Buffer
{}
buffer
:=
&
bytes
.
Buffer
{}
fakeClient
:=
testclient
.
NewSimpleFake
(
test
.
expectedRc
)
fakeClient
:=
fake
.
NewSimpleClientset
(
test
.
expectedRc
)
rc
,
err
:=
UpdateExistingReplicationController
(
fakeClient
,
test
.
rc
,
"default"
,
test
.
name
,
test
.
deploymentKey
,
test
.
deploymentValue
,
buffer
)
rc
,
err
:=
UpdateExistingReplicationController
(
fakeClient
.
Core
(),
fakeClient
.
Core
()
,
test
.
rc
,
"default"
,
test
.
name
,
test
.
deploymentKey
,
test
.
deploymentValue
,
buffer
)
if
!
reflect
.
DeepEqual
(
rc
,
test
.
expectedRc
)
{
if
!
reflect
.
DeepEqual
(
rc
,
test
.
expectedRc
)
{
t
.
Errorf
(
"expected:
\n
%#v
\n
got:
\n
%#v
\n
"
,
test
.
expectedRc
,
rc
)
t
.
Errorf
(
"expected:
\n
%#v
\n
got:
\n
%#v
\n
"
,
test
.
expectedRc
,
rc
)
}
}
...
@@ -1453,9 +1464,9 @@ func TestUpdateRcWithRetries(t *testing.T) {
...
@@ -1453,9 +1464,9 @@ func TestUpdateRcWithRetries(t *testing.T) {
{
StatusCode
:
500
,
Header
:
header
,
Body
:
objBody
(
codec
,
&
api
.
ReplicationController
{})},
{
StatusCode
:
500
,
Header
:
header
,
Body
:
objBody
(
codec
,
&
api
.
ReplicationController
{})},
{
StatusCode
:
200
,
Header
:
header
,
Body
:
objBody
(
codec
,
rc
)},
{
StatusCode
:
200
,
Header
:
header
,
Body
:
objBody
(
codec
,
rc
)},
}
}
fakeClient
:=
&
fake
.
RESTClient
{
fakeClient
:=
&
manual
fake
.
RESTClient
{
NegotiatedSerializer
:
testapi
.
Default
.
NegotiatedSerializer
(),
NegotiatedSerializer
:
testapi
.
Default
.
NegotiatedSerializer
(),
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
Client
:
manual
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
p
==
testapi
.
Default
.
ResourcePath
(
"replicationcontrollers"
,
"default"
,
"rc"
)
&&
m
==
"PUT"
:
case
p
==
testapi
.
Default
.
ResourcePath
(
"replicationcontrollers"
,
"default"
,
"rc"
)
&&
m
==
"PUT"
:
update
:=
updates
[
0
]
update
:=
updates
[
0
]
...
@@ -1480,12 +1491,13 @@ func TestUpdateRcWithRetries(t *testing.T) {
...
@@ -1480,12 +1491,13 @@ func TestUpdateRcWithRetries(t *testing.T) {
}
}
}),
}),
}
}
clientConfig
:=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}}
clientConfig
:=
&
restclient
.
Config
{
APIPath
:
"/api"
,
ContentConfig
:
restclient
.
ContentConfig
{
NegotiatedSerializer
:
api
.
Codecs
,
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}}
client
:=
client
.
NewOrDie
(
clientConfig
)
restClient
,
_
:=
restclient
.
RESTClientFor
(
clientConfig
)
client
.
Client
=
fakeClient
.
Client
restClient
.
Client
=
fakeClient
.
Client
clientset
:=
internalclientset
.
New
(
restClient
)
if
rc
,
err
:=
updateRcWithRetries
(
if
rc
,
err
:=
updateRcWithRetries
(
client
,
"default"
,
rc
,
func
(
c
*
api
.
ReplicationController
)
{
client
set
,
"default"
,
rc
,
func
(
c
*
api
.
ReplicationController
)
{
c
.
Spec
.
Selector
[
"baz"
]
=
"foobar"
c
.
Spec
.
Selector
[
"baz"
]
=
"foobar"
});
err
!=
nil
{
});
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
...
@@ -1544,9 +1556,9 @@ func TestAddDeploymentHash(t *testing.T) {
...
@@ -1544,9 +1556,9 @@ func TestAddDeploymentHash(t *testing.T) {
seen
:=
sets
.
String
{}
seen
:=
sets
.
String
{}
updatedRc
:=
false
updatedRc
:=
false
fakeClient
:=
&
fake
.
RESTClient
{
fakeClient
:=
&
manual
fake
.
RESTClient
{
NegotiatedSerializer
:
testapi
.
Default
.
NegotiatedSerializer
(),
NegotiatedSerializer
:
testapi
.
Default
.
NegotiatedSerializer
(),
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
Client
:
manual
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
header
:=
http
.
Header
{}
header
:=
http
.
Header
{}
header
.
Set
(
"Content-Type"
,
runtime
.
ContentTypeJSON
)
header
.
Set
(
"Content-Type"
,
runtime
.
ContentTypeJSON
)
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
...
@@ -1579,11 +1591,12 @@ func TestAddDeploymentHash(t *testing.T) {
...
@@ -1579,11 +1591,12 @@ func TestAddDeploymentHash(t *testing.T) {
}
}
}),
}),
}
}
clientConfig
:=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}}
clientConfig
:=
&
restclient
.
Config
{
APIPath
:
"/api"
,
ContentConfig
:
restclient
.
ContentConfig
{
NegotiatedSerializer
:
api
.
Codecs
,
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}}
client
:=
client
.
NewOrDie
(
clientConfig
)
restClient
,
_
:=
restclient
.
RESTClientFor
(
clientConfig
)
client
.
Client
=
fakeClient
.
Client
restClient
.
Client
=
fakeClient
.
Client
clientset
:=
internalclientset
.
New
(
restClient
)
if
_
,
err
:=
AddDeploymentKeyToReplicationController
(
rc
,
client
,
"dk"
,
"hash"
,
api
.
NamespaceDefault
,
buf
);
err
!=
nil
{
if
_
,
err
:=
AddDeploymentKeyToReplicationController
(
rc
,
client
set
.
Core
(),
clientset
.
Core
()
,
"dk"
,
"hash"
,
api
.
NamespaceDefault
,
buf
);
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
for
_
,
pod
:=
range
podList
.
Items
{
for
_
,
pod
:=
range
podList
.
Items
{
...
@@ -1597,8 +1610,10 @@ func TestAddDeploymentHash(t *testing.T) {
...
@@ -1597,8 +1610,10 @@ func TestAddDeploymentHash(t *testing.T) {
}
}
func
TestRollingUpdater_readyPods
(
t
*
testing
.
T
)
{
func
TestRollingUpdater_readyPods
(
t
*
testing
.
T
)
{
count
:=
0
now
:=
unversioned
.
Date
(
2016
,
time
.
April
,
1
,
1
,
0
,
0
,
0
,
time
.
UTC
)
now
:=
unversioned
.
Date
(
2016
,
time
.
April
,
1
,
1
,
0
,
0
,
0
,
time
.
UTC
)
mkpod
:=
func
(
owner
*
api
.
ReplicationController
,
ready
bool
,
readyTime
unversioned
.
Time
)
*
api
.
Pod
{
mkpod
:=
func
(
owner
*
api
.
ReplicationController
,
ready
bool
,
readyTime
unversioned
.
Time
)
*
api
.
Pod
{
count
=
count
+
1
labels
:=
map
[
string
]
string
{}
labels
:=
map
[
string
]
string
{}
for
k
,
v
:=
range
owner
.
Spec
.
Selector
{
for
k
,
v
:=
range
owner
.
Spec
.
Selector
{
labels
[
k
]
=
v
labels
[
k
]
=
v
...
@@ -1609,8 +1624,9 @@ func TestRollingUpdater_readyPods(t *testing.T) {
...
@@ -1609,8 +1624,9 @@ func TestRollingUpdater_readyPods(t *testing.T) {
}
}
return
&
api
.
Pod
{
return
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"pod"
,
Namespace
:
api
.
NamespaceDefault
,
Labels
:
labels
,
Name
:
fmt
.
Sprintf
(
"pod-%d"
,
count
),
Labels
:
labels
,
},
},
Status
:
api
.
PodStatus
{
Status
:
api
.
PodStatus
{
Conditions
:
[]
api
.
PodCondition
{
Conditions
:
[]
api
.
PodCondition
{
...
@@ -1728,12 +1744,13 @@ func TestRollingUpdater_readyPods(t *testing.T) {
...
@@ -1728,12 +1744,13 @@ func TestRollingUpdater_readyPods(t *testing.T) {
for
_
,
ready
:=
range
test
.
newPods
{
for
_
,
ready
:=
range
test
.
newPods
{
pods
=
append
(
pods
,
mkpod
(
test
.
newRc
,
ready
,
test
.
podReadyTimeFn
()))
pods
=
append
(
pods
,
mkpod
(
test
.
newRc
,
ready
,
test
.
podReadyTimeFn
()))
}
}
client
:=
testclient
.
NewSimpleFake
(
pods
...
)
client
:=
fake
.
NewSimpleClientset
(
pods
...
)
updater
:=
&
RollingUpdater
{
updater
:=
&
RollingUpdater
{
ns
:
"default"
,
ns
:
"default"
,
c
:
client
,
rcClient
:
client
.
Core
(),
nowFn
:
test
.
nowFn
,
podClient
:
client
.
Core
(),
nowFn
:
test
.
nowFn
,
}
}
oldReady
,
newReady
,
err
:=
updater
.
readyPods
(
test
.
oldRc
,
test
.
newRc
,
test
.
minReadySeconds
)
oldReady
,
newReady
,
err
:=
updater
.
readyPods
(
test
.
oldRc
,
test
.
newRc
,
test
.
minReadySeconds
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/kubectl/rollout_status.go
View file @
519c1374
...
@@ -21,7 +21,8 @@ import (
...
@@ -21,7 +21,8 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/extensions"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
extensionsclient
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/extensions/unversioned"
)
)
// StatusViewer provides an interface for resources that provides rollout status.
// StatusViewer provides an interface for resources that provides rollout status.
...
@@ -29,7 +30,7 @@ type StatusViewer interface {
...
@@ -29,7 +30,7 @@ type StatusViewer interface {
Status
(
namespace
,
name
string
)
(
string
,
bool
,
error
)
Status
(
namespace
,
name
string
)
(
string
,
bool
,
error
)
}
}
func
StatusViewerFor
(
kind
unversioned
.
GroupKind
,
c
clien
t
.
Interface
)
(
StatusViewer
,
error
)
{
func
StatusViewerFor
(
kind
unversioned
.
GroupKind
,
c
internalclientse
t
.
Interface
)
(
StatusViewer
,
error
)
{
switch
kind
{
switch
kind
{
case
extensions
.
Kind
(
"Deployment"
)
:
case
extensions
.
Kind
(
"Deployment"
)
:
return
&
DeploymentStatusViewer
{
c
.
Extensions
()},
nil
return
&
DeploymentStatusViewer
{
c
.
Extensions
()},
nil
...
@@ -38,7 +39,7 @@ func StatusViewerFor(kind unversioned.GroupKind, c client.Interface) (StatusView
...
@@ -38,7 +39,7 @@ func StatusViewerFor(kind unversioned.GroupKind, c client.Interface) (StatusView
}
}
type
DeploymentStatusViewer
struct
{
type
DeploymentStatusViewer
struct
{
c
client
.
ExtensionsInterface
c
extensionsclient
.
DeploymentsGetter
}
}
// Status returns a message describing deployment status, and a bool value indicating if the status is considered done
// Status returns a message describing deployment status, and a bool value indicating if the status is considered done
...
...
pkg/kubectl/rollout_status_test.go
View file @
519c1374
...
@@ -21,7 +21,7 @@ import (
...
@@ -21,7 +21,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/client/
unversioned/testclient
"
"k8s.io/kubernetes/pkg/client/
clientset_generated/internalclientset/fake
"
)
)
func
TestDeploymentStatusViewerStatus
(
t
*
testing
.
T
)
{
func
TestDeploymentStatusViewerStatus
(
t
*
testing
.
T
)
{
...
@@ -107,6 +107,7 @@ func TestDeploymentStatusViewerStatus(t *testing.T) {
...
@@ -107,6 +107,7 @@ func TestDeploymentStatusViewerStatus(t *testing.T) {
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
d
:=
&
extensions
.
Deployment
{
d
:=
&
extensions
.
Deployment
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
"bar"
,
Name
:
"foo"
,
Name
:
"foo"
,
UID
:
"8764ae47-9092-11e4-8393-42010af018ff"
,
UID
:
"8764ae47-9092-11e4-8393-42010af018ff"
,
Generation
:
test
.
generation
,
Generation
:
test
.
generation
,
...
@@ -116,7 +117,7 @@ func TestDeploymentStatusViewerStatus(t *testing.T) {
...
@@ -116,7 +117,7 @@ func TestDeploymentStatusViewerStatus(t *testing.T) {
},
},
Status
:
test
.
status
,
Status
:
test
.
status
,
}
}
client
:=
testclient
.
NewSimpleFake
(
d
)
.
Extensions
()
client
:=
fake
.
NewSimpleClientset
(
d
)
.
Extensions
()
dsv
:=
&
DeploymentStatusViewer
{
c
:
client
}
dsv
:=
&
DeploymentStatusViewer
{
c
:
client
}
msg
,
done
,
err
:=
dsv
.
Status
(
"bar"
,
"foo"
)
msg
,
done
,
err
:=
dsv
.
Status
(
"bar"
,
"foo"
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/kubectl/scale.go
View file @
519c1374
...
@@ -49,7 +49,7 @@ type Scaler interface {
...
@@ -49,7 +49,7 @@ type Scaler interface {
ScaleSimple
(
namespace
,
name
string
,
preconditions
*
ScalePrecondition
,
newSize
uint
)
(
updatedResourceVersion
string
,
err
error
)
ScaleSimple
(
namespace
,
name
string
,
preconditions
*
ScalePrecondition
,
newSize
uint
)
(
updatedResourceVersion
string
,
err
error
)
}
}
func
ScalerFor
(
kind
unversioned
.
GroupKind
,
c
*
internalclientset
.
Clientset
)
(
Scaler
,
error
)
{
func
ScalerFor
(
kind
unversioned
.
GroupKind
,
c
internalclientset
.
Interface
)
(
Scaler
,
error
)
{
switch
kind
{
switch
kind
{
case
api
.
Kind
(
"ReplicationController"
)
:
case
api
.
Kind
(
"ReplicationController"
)
:
return
&
ReplicationControllerScaler
{
c
.
Core
()},
nil
return
&
ReplicationControllerScaler
{
c
.
Core
()},
nil
...
...
pkg/kubectl/scale_test.go
View file @
519c1374
...
@@ -24,12 +24,15 @@ import (
...
@@ -24,12 +24,15 @@ import (
kerrors
"k8s.io/kubernetes/pkg/api/errors"
kerrors
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/extensions"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
batchclient
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/batch/unversioned"
coreclient
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/unversioned"
extensionsclient
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/extensions/unversioned"
testcore
"k8s.io/kubernetes/pkg/client/testing/core"
)
)
type
ErrorReplicationControllers
struct
{
type
ErrorReplicationControllers
struct
{
testclient
.
FakeReplicationControllers
coreclient
.
ReplicationControllerInterface
conflict
bool
conflict
bool
invalid
bool
invalid
bool
}
}
...
@@ -45,26 +48,26 @@ func (c *ErrorReplicationControllers) Update(controller *api.ReplicationControll
...
@@ -45,26 +48,26 @@ func (c *ErrorReplicationControllers) Update(controller *api.ReplicationControll
}
}
type
ErrorReplicationControllerClient
struct
{
type
ErrorReplicationControllerClient
struct
{
testclient
.
Fake
*
fake
.
Clientset
conflict
bool
conflict
bool
invalid
bool
invalid
bool
}
}
func
(
c
*
ErrorReplicationControllerClient
)
ReplicationControllers
(
namespace
string
)
client
.
ReplicationControllerInterface
{
func
(
c
*
ErrorReplicationControllerClient
)
ReplicationControllers
(
namespace
string
)
c
orec
lient
.
ReplicationControllerInterface
{
return
&
ErrorReplicationControllers
{
return
&
ErrorReplicationControllers
{
FakeReplicationControllers
:
testclient
.
FakeReplicationControllers
{
Fake
:
&
c
.
Fake
,
Namespace
:
namespace
}
,
ReplicationControllerInterface
:
c
.
Clientset
.
Core
()
.
ReplicationControllers
(
namespace
)
,
conflict
:
c
.
conflict
,
conflict
:
c
.
conflict
,
invalid
:
c
.
invalid
,
invalid
:
c
.
invalid
,
}
}
}
}
func
TestReplicationControllerScaleRetry
(
t
*
testing
.
T
)
{
func
TestReplicationControllerScaleRetry
(
t
*
testing
.
T
)
{
fake
:=
&
ErrorReplicationControllerClient
{
Fake
:
testclient
.
Fake
{}
,
conflict
:
true
}
fake
:=
&
ErrorReplicationControllerClient
{
Clientset
:
fake
.
NewSimpleClientset
(
oldRc
(
0
,
0
))
,
conflict
:
true
}
scaler
:=
ReplicationControllerScaler
{
fake
}
scaler
:=
ReplicationControllerScaler
{
fake
}
preconditions
:=
ScalePrecondition
{
-
1
,
""
}
preconditions
:=
ScalePrecondition
{
-
1
,
""
}
count
:=
uint
(
3
)
count
:=
uint
(
3
)
name
:=
"foo"
name
:=
"foo
-v1
"
namespace
:=
"default"
namespace
:=
api
.
NamespaceDefault
scaleFunc
:=
ScaleCondition
(
&
scaler
,
&
preconditions
,
namespace
,
name
,
count
,
nil
)
scaleFunc
:=
ScaleCondition
(
&
scaler
,
&
preconditions
,
namespace
,
name
,
count
,
nil
)
pass
,
err
:=
scaleFunc
()
pass
,
err
:=
scaleFunc
()
...
@@ -83,11 +86,11 @@ func TestReplicationControllerScaleRetry(t *testing.T) {
...
@@ -83,11 +86,11 @@ func TestReplicationControllerScaleRetry(t *testing.T) {
}
}
func
TestReplicationControllerScaleInvalid
(
t
*
testing
.
T
)
{
func
TestReplicationControllerScaleInvalid
(
t
*
testing
.
T
)
{
fake
:=
&
ErrorReplicationControllerClient
{
Fake
:
testclient
.
Fake
{}
,
invalid
:
true
}
fake
:=
&
ErrorReplicationControllerClient
{
Clientset
:
fake
.
NewSimpleClientset
(
oldRc
(
0
,
0
))
,
invalid
:
true
}
scaler
:=
ReplicationControllerScaler
{
fake
}
scaler
:=
ReplicationControllerScaler
{
fake
}
preconditions
:=
ScalePrecondition
{
-
1
,
""
}
preconditions
:=
ScalePrecondition
{
-
1
,
""
}
count
:=
uint
(
3
)
count
:=
uint
(
3
)
name
:=
"foo"
name
:=
"foo
-v1
"
namespace
:=
"default"
namespace
:=
"default"
scaleFunc
:=
ScaleCondition
(
&
scaler
,
&
preconditions
,
namespace
,
name
,
count
,
nil
)
scaleFunc
:=
ScaleCondition
(
&
scaler
,
&
preconditions
,
namespace
,
name
,
count
,
nil
)
...
@@ -102,32 +105,33 @@ func TestReplicationControllerScaleInvalid(t *testing.T) {
...
@@ -102,32 +105,33 @@ func TestReplicationControllerScaleInvalid(t *testing.T) {
}
}
func
TestReplicationControllerScale
(
t
*
testing
.
T
)
{
func
TestReplicationControllerScale
(
t
*
testing
.
T
)
{
fake
:=
&
testclient
.
Fake
{}
fake
:=
fake
.
NewSimpleClientset
(
oldRc
(
0
,
0
))
scaler
:=
ReplicationControllerScaler
{
fake
}
scaler
:=
ReplicationControllerScaler
{
fake
.
Core
()
}
preconditions
:=
ScalePrecondition
{
-
1
,
""
}
preconditions
:=
ScalePrecondition
{
-
1
,
""
}
count
:=
uint
(
3
)
count
:=
uint
(
3
)
name
:=
"foo"
name
:=
"foo
-v1
"
scaler
.
Scale
(
"default"
,
name
,
count
,
&
preconditions
,
nil
,
nil
)
scaler
.
Scale
(
"default"
,
name
,
count
,
&
preconditions
,
nil
,
nil
)
actions
:=
fake
.
Actions
()
actions
:=
fake
.
Actions
()
if
len
(
actions
)
!=
2
{
if
len
(
actions
)
!=
2
{
t
.
Errorf
(
"unexpected actions: %v, expected 2 actions (get, update)"
,
actions
)
t
.
Errorf
(
"unexpected actions: %v, expected 2 actions (get, update)"
,
actions
)
}
}
if
action
,
ok
:=
actions
[
0
]
.
(
testc
lient
.
GetAction
);
!
ok
||
action
.
GetResource
()
!=
"replicationcontrollers"
||
action
.
GetName
()
!=
name
{
if
action
,
ok
:=
actions
[
0
]
.
(
testc
ore
.
GetAction
);
!
ok
||
action
.
GetResource
()
.
GroupResource
()
!=
api
.
Resource
(
"replicationcontrollers"
)
||
action
.
GetName
()
!=
name
{
t
.
Errorf
(
"unexpected action: %v, expected get-replicationController %s"
,
actions
[
0
],
name
)
t
.
Errorf
(
"unexpected action: %v, expected get-replicationController %s"
,
actions
[
0
],
name
)
}
}
if
action
,
ok
:=
actions
[
1
]
.
(
testc
lient
.
UpdateAction
);
!
ok
||
action
.
GetResource
()
!=
"replicationcontrollers"
||
action
.
GetObject
()
.
(
*
api
.
ReplicationController
)
.
Spec
.
Replicas
!=
int32
(
count
)
{
if
action
,
ok
:=
actions
[
1
]
.
(
testc
ore
.
UpdateAction
);
!
ok
||
action
.
GetResource
()
.
GroupResource
()
!=
api
.
Resource
(
"replicationcontrollers"
)
||
action
.
GetObject
()
.
(
*
api
.
ReplicationController
)
.
Spec
.
Replicas
!=
int32
(
count
)
{
t
.
Errorf
(
"unexpected action %v, expected update-replicationController with replicas = %d"
,
actions
[
1
],
count
)
t
.
Errorf
(
"unexpected action %v, expected update-replicationController with replicas = %d"
,
actions
[
1
],
count
)
}
}
}
}
func
TestReplicationControllerScaleFailsPreconditions
(
t
*
testing
.
T
)
{
func
TestReplicationControllerScaleFailsPreconditions
(
t
*
testing
.
T
)
{
fake
:=
testclient
.
NewSimpleFake
(
&
api
.
ReplicationController
{
fake
:=
fake
.
NewSimpleClientset
(
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
},
Spec
:
api
.
ReplicationControllerSpec
{
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
10
,
Replicas
:
10
,
},
},
})
})
scaler
:=
ReplicationControllerScaler
{
fake
}
scaler
:=
ReplicationControllerScaler
{
fake
.
Core
()
}
preconditions
:=
ScalePrecondition
{
2
,
""
}
preconditions
:=
ScalePrecondition
{
2
,
""
}
count
:=
uint
(
3
)
count
:=
uint
(
3
)
name
:=
"foo"
name
:=
"foo"
...
@@ -137,7 +141,7 @@ func TestReplicationControllerScaleFailsPreconditions(t *testing.T) {
...
@@ -137,7 +141,7 @@ func TestReplicationControllerScaleFailsPreconditions(t *testing.T) {
if
len
(
actions
)
!=
1
{
if
len
(
actions
)
!=
1
{
t
.
Errorf
(
"unexpected actions: %v, expected 1 action (get)"
,
actions
)
t
.
Errorf
(
"unexpected actions: %v, expected 1 action (get)"
,
actions
)
}
}
if
action
,
ok
:=
actions
[
0
]
.
(
testc
lient
.
GetAction
);
!
ok
||
action
.
GetResource
()
!=
"replicationcontrollers"
||
action
.
GetName
()
!=
name
{
if
action
,
ok
:=
actions
[
0
]
.
(
testc
ore
.
GetAction
);
!
ok
||
action
.
GetResource
()
.
GroupResource
()
!=
api
.
Resource
(
"replicationcontrollers"
)
||
action
.
GetName
()
!=
name
{
t
.
Errorf
(
"unexpected action: %v, expected get-replicationController %s"
,
actions
[
0
],
name
)
t
.
Errorf
(
"unexpected action: %v, expected get-replicationController %s"
,
actions
[
0
],
name
)
}
}
}
}
...
@@ -258,7 +262,7 @@ func TestValidateReplicationController(t *testing.T) {
...
@@ -258,7 +262,7 @@ func TestValidateReplicationController(t *testing.T) {
}
}
type
ErrorJobs
struct
{
type
ErrorJobs
struct
{
testclient
.
FakeJobsV1
batchclient
.
JobInterface
conflict
bool
conflict
bool
invalid
bool
invalid
bool
}
}
...
@@ -283,21 +287,21 @@ func (c *ErrorJobs) Get(name string) (*batch.Job, error) {
...
@@ -283,21 +287,21 @@ func (c *ErrorJobs) Get(name string) (*batch.Job, error) {
}
}
type
ErrorJobClient
struct
{
type
ErrorJobClient
struct
{
testclient
.
FakeBatch
batchclient
.
JobsGetter
conflict
bool
conflict
bool
invalid
bool
invalid
bool
}
}
func
(
c
*
ErrorJobClient
)
Jobs
(
namespace
string
)
client
.
JobInterface
{
func
(
c
*
ErrorJobClient
)
Jobs
(
namespace
string
)
batch
client
.
JobInterface
{
return
&
ErrorJobs
{
return
&
ErrorJobs
{
FakeJobsV1
:
testclient
.
FakeJobsV1
{
Fake
:
&
c
.
FakeBatch
,
Namespace
:
namespace
}
,
JobInterface
:
c
.
JobsGetter
.
Jobs
(
namespace
)
,
conflict
:
c
.
conflict
,
conflict
:
c
.
conflict
,
invalid
:
c
.
invalid
,
invalid
:
c
.
invalid
,
}
}
}
}
func
TestJobScaleRetry
(
t
*
testing
.
T
)
{
func
TestJobScaleRetry
(
t
*
testing
.
T
)
{
fake
:=
&
ErrorJobClient
{
FakeBatch
:
testclient
.
FakeBatch
{}
,
conflict
:
true
}
fake
:=
&
ErrorJobClient
{
JobsGetter
:
fake
.
NewSimpleClientset
()
.
Batch
()
,
conflict
:
true
}
scaler
:=
JobScaler
{
fake
}
scaler
:=
JobScaler
{
fake
}
preconditions
:=
ScalePrecondition
{
-
1
,
""
}
preconditions
:=
ScalePrecondition
{
-
1
,
""
}
count
:=
uint
(
3
)
count
:=
uint
(
3
)
...
@@ -320,28 +324,37 @@ func TestJobScaleRetry(t *testing.T) {
...
@@ -320,28 +324,37 @@ func TestJobScaleRetry(t *testing.T) {
}
}
}
}
func
job
()
*
batch
.
Job
{
return
&
batch
.
Job
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
,
},
}
}
func
TestJobScale
(
t
*
testing
.
T
)
{
func
TestJobScale
(
t
*
testing
.
T
)
{
fake
:=
&
testclient
.
FakeBatch
{
Fake
:
&
testclient
.
Fake
{}}
fake
Clientset
:=
fake
.
NewSimpleClientset
(
job
())
scaler
:=
JobScaler
{
fake
}
scaler
:=
JobScaler
{
fake
Clientset
.
Batch
()
}
preconditions
:=
ScalePrecondition
{
-
1
,
""
}
preconditions
:=
ScalePrecondition
{
-
1
,
""
}
count
:=
uint
(
3
)
count
:=
uint
(
3
)
name
:=
"foo"
name
:=
"foo"
scaler
.
Scale
(
"default"
,
name
,
count
,
&
preconditions
,
nil
,
nil
)
scaler
.
Scale
(
"default"
,
name
,
count
,
&
preconditions
,
nil
,
nil
)
actions
:=
fake
.
Actions
()
actions
:=
fake
Clientset
.
Actions
()
if
len
(
actions
)
!=
2
{
if
len
(
actions
)
!=
2
{
t
.
Errorf
(
"unexpected actions: %v, expected 2 actions (get, update)"
,
actions
)
t
.
Errorf
(
"unexpected actions: %v, expected 2 actions (get, update)"
,
actions
)
}
}
if
action
,
ok
:=
actions
[
0
]
.
(
testc
lient
.
GetAction
);
!
ok
||
action
.
GetResource
()
!=
"jobs"
||
action
.
GetName
()
!=
name
{
if
action
,
ok
:=
actions
[
0
]
.
(
testc
ore
.
GetAction
);
!
ok
||
action
.
GetResource
()
.
GroupResource
()
!=
batch
.
Resource
(
"jobs"
)
||
action
.
GetName
()
!=
name
{
t
.
Errorf
(
"unexpected action: %v, expected get-replicationController %s"
,
actions
[
0
],
name
)
t
.
Errorf
(
"unexpected action: %v, expected get-replicationController %s"
,
actions
[
0
],
name
)
}
}
if
action
,
ok
:=
actions
[
1
]
.
(
testc
lient
.
UpdateAction
);
!
ok
||
action
.
GetResource
()
!=
"jobs"
||
*
action
.
GetObject
()
.
(
*
batch
.
Job
)
.
Spec
.
Parallelism
!=
int32
(
count
)
{
if
action
,
ok
:=
actions
[
1
]
.
(
testc
ore
.
UpdateAction
);
!
ok
||
action
.
GetResource
()
.
GroupResource
()
!=
batch
.
Resource
(
"jobs"
)
||
*
action
.
GetObject
()
.
(
*
batch
.
Job
)
.
Spec
.
Parallelism
!=
int32
(
count
)
{
t
.
Errorf
(
"unexpected action %v, expected update-job with parallelism = %d"
,
actions
[
1
],
count
)
t
.
Errorf
(
"unexpected action %v, expected update-job with parallelism = %d"
,
actions
[
1
],
count
)
}
}
}
}
func
TestJobScaleInvalid
(
t
*
testing
.
T
)
{
func
TestJobScaleInvalid
(
t
*
testing
.
T
)
{
fake
:=
&
ErrorJobClient
{
FakeBatch
:
testclient
.
FakeBatch
{}
,
invalid
:
true
}
fake
:=
&
ErrorJobClient
{
JobsGetter
:
fake
.
NewSimpleClientset
()
.
Batch
()
,
invalid
:
true
}
scaler
:=
JobScaler
{
fake
}
scaler
:=
JobScaler
{
fake
}
preconditions
:=
ScalePrecondition
{
-
1
,
""
}
preconditions
:=
ScalePrecondition
{
-
1
,
""
}
count
:=
uint
(
3
)
count
:=
uint
(
3
)
...
@@ -361,12 +374,16 @@ func TestJobScaleInvalid(t *testing.T) {
...
@@ -361,12 +374,16 @@ func TestJobScaleInvalid(t *testing.T) {
func
TestJobScaleFailsPreconditions
(
t
*
testing
.
T
)
{
func
TestJobScaleFailsPreconditions
(
t
*
testing
.
T
)
{
ten
:=
int32
(
10
)
ten
:=
int32
(
10
)
fake
:=
testclient
.
NewSimpleFake
(
&
batch
.
Job
{
fake
:=
fake
.
NewSimpleClientset
(
&
batch
.
Job
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
,
},
Spec
:
batch
.
JobSpec
{
Spec
:
batch
.
JobSpec
{
Parallelism
:
&
ten
,
Parallelism
:
&
ten
,
},
},
})
})
scaler
:=
JobScaler
{
&
testclient
.
FakeBatch
{
Fake
:
fake
}
}
scaler
:=
JobScaler
{
fake
.
Batch
()
}
preconditions
:=
ScalePrecondition
{
2
,
""
}
preconditions
:=
ScalePrecondition
{
2
,
""
}
count
:=
uint
(
3
)
count
:=
uint
(
3
)
name
:=
"foo"
name
:=
"foo"
...
@@ -376,7 +393,7 @@ func TestJobScaleFailsPreconditions(t *testing.T) {
...
@@ -376,7 +393,7 @@ func TestJobScaleFailsPreconditions(t *testing.T) {
if
len
(
actions
)
!=
1
{
if
len
(
actions
)
!=
1
{
t
.
Errorf
(
"unexpected actions: %v, expected 1 actions (get)"
,
actions
)
t
.
Errorf
(
"unexpected actions: %v, expected 1 actions (get)"
,
actions
)
}
}
if
action
,
ok
:=
actions
[
0
]
.
(
testc
lient
.
GetAction
);
!
ok
||
action
.
GetResource
()
!=
"jobs"
||
action
.
GetName
()
!=
name
{
if
action
,
ok
:=
actions
[
0
]
.
(
testc
ore
.
GetAction
);
!
ok
||
action
.
GetResource
()
.
GroupResource
()
!=
batch
.
Resource
(
"jobs"
)
||
action
.
GetName
()
!=
name
{
t
.
Errorf
(
"unexpected action: %v, expected get-job %s"
,
actions
[
0
],
name
)
t
.
Errorf
(
"unexpected action: %v, expected get-job %s"
,
actions
[
0
],
name
)
}
}
}
}
...
@@ -508,7 +525,7 @@ func TestValidateJob(t *testing.T) {
...
@@ -508,7 +525,7 @@ func TestValidateJob(t *testing.T) {
}
}
type
ErrorDeployments
struct
{
type
ErrorDeployments
struct
{
testclient
.
FakeDeployments
extensionsclient
.
DeploymentInterface
conflict
bool
conflict
bool
invalid
bool
invalid
bool
}
}
...
@@ -532,21 +549,21 @@ func (c *ErrorDeployments) Get(name string) (*extensions.Deployment, error) {
...
@@ -532,21 +549,21 @@ func (c *ErrorDeployments) Get(name string) (*extensions.Deployment, error) {
}
}
type
ErrorDeploymentClient
struct
{
type
ErrorDeploymentClient
struct
{
testclient
.
FakeExperimental
extensionsclient
.
DeploymentsGetter
conflict
bool
conflict
bool
invalid
bool
invalid
bool
}
}
func
(
c
*
ErrorDeploymentClient
)
Deployments
(
namespace
string
)
client
.
DeploymentInterface
{
func
(
c
*
ErrorDeploymentClient
)
Deployments
(
namespace
string
)
extensions
client
.
DeploymentInterface
{
return
&
ErrorDeployments
{
return
&
ErrorDeployments
{
FakeDeployments
:
testclient
.
FakeDeployments
{
Fake
:
&
c
.
FakeExperimental
,
Namespace
:
namespace
}
,
DeploymentInterface
:
c
.
DeploymentsGetter
.
Deployments
(
namespace
)
,
invalid
:
c
.
invalid
,
invalid
:
c
.
invalid
,
conflict
:
c
.
conflict
,
conflict
:
c
.
conflict
,
}
}
}
}
func
TestDeploymentScaleRetry
(
t
*
testing
.
T
)
{
func
TestDeploymentScaleRetry
(
t
*
testing
.
T
)
{
fake
:=
&
ErrorDeploymentClient
{
FakeExperimental
:
testclient
.
FakeExperimental
{}
,
conflict
:
true
}
fake
:=
&
ErrorDeploymentClient
{
DeploymentsGetter
:
fake
.
NewSimpleClientset
()
.
Extensions
()
,
conflict
:
true
}
scaler
:=
&
DeploymentScaler
{
fake
}
scaler
:=
&
DeploymentScaler
{
fake
}
preconditions
:=
&
ScalePrecondition
{
-
1
,
""
}
preconditions
:=
&
ScalePrecondition
{
-
1
,
""
}
count
:=
uint
(
3
)
count
:=
uint
(
3
)
...
@@ -569,9 +586,18 @@ func TestDeploymentScaleRetry(t *testing.T) {
...
@@ -569,9 +586,18 @@ func TestDeploymentScaleRetry(t *testing.T) {
}
}
}
}
func
deployment
()
*
extensions
.
Deployment
{
return
&
extensions
.
Deployment
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
,
},
}
}
func
TestDeploymentScale
(
t
*
testing
.
T
)
{
func
TestDeploymentScale
(
t
*
testing
.
T
)
{
fake
:=
&
testclient
.
FakeExperimental
{
Fake
:
&
testclient
.
Fake
{}}
fake
:=
fake
.
NewSimpleClientset
(
deployment
())
scaler
:=
DeploymentScaler
{
fake
}
scaler
:=
DeploymentScaler
{
fake
.
Extensions
()
}
preconditions
:=
ScalePrecondition
{
-
1
,
""
}
preconditions
:=
ScalePrecondition
{
-
1
,
""
}
count
:=
uint
(
3
)
count
:=
uint
(
3
)
name
:=
"foo"
name
:=
"foo"
...
@@ -581,16 +607,16 @@ func TestDeploymentScale(t *testing.T) {
...
@@ -581,16 +607,16 @@ func TestDeploymentScale(t *testing.T) {
if
len
(
actions
)
!=
2
{
if
len
(
actions
)
!=
2
{
t
.
Errorf
(
"unexpected actions: %v, expected 2 actions (get, update)"
,
actions
)
t
.
Errorf
(
"unexpected actions: %v, expected 2 actions (get, update)"
,
actions
)
}
}
if
action
,
ok
:=
actions
[
0
]
.
(
testc
lient
.
GetAction
);
!
ok
||
action
.
GetResource
()
!=
"deployments"
||
action
.
GetName
()
!=
name
{
if
action
,
ok
:=
actions
[
0
]
.
(
testc
ore
.
GetAction
);
!
ok
||
action
.
GetResource
()
.
GroupResource
()
!=
extensions
.
Resource
(
"deployments"
)
||
action
.
GetName
()
!=
name
{
t
.
Errorf
(
"unexpected action: %v, expected get-replicationController %s"
,
actions
[
0
],
name
)
t
.
Errorf
(
"unexpected action: %v, expected get-replicationController %s"
,
actions
[
0
],
name
)
}
}
if
action
,
ok
:=
actions
[
1
]
.
(
testc
lient
.
UpdateAction
);
!
ok
||
action
.
GetResource
()
!=
"deployments"
||
action
.
GetObject
()
.
(
*
extensions
.
Deployment
)
.
Spec
.
Replicas
!=
int32
(
count
)
{
if
action
,
ok
:=
actions
[
1
]
.
(
testc
ore
.
UpdateAction
);
!
ok
||
action
.
GetResource
()
.
GroupResource
()
!=
extensions
.
Resource
(
"deployments"
)
||
action
.
GetObject
()
.
(
*
extensions
.
Deployment
)
.
Spec
.
Replicas
!=
int32
(
count
)
{
t
.
Errorf
(
"unexpected action %v, expected update-deployment with replicas = %d"
,
actions
[
1
],
count
)
t
.
Errorf
(
"unexpected action %v, expected update-deployment with replicas = %d"
,
actions
[
1
],
count
)
}
}
}
}
func
TestDeploymentScaleInvalid
(
t
*
testing
.
T
)
{
func
TestDeploymentScaleInvalid
(
t
*
testing
.
T
)
{
fake
:=
&
ErrorDeploymentClient
{
FakeExperimental
:
testclient
.
FakeExperimental
{}
,
invalid
:
true
}
fake
:=
&
ErrorDeploymentClient
{
DeploymentsGetter
:
fake
.
NewSimpleClientset
()
.
Extensions
()
,
invalid
:
true
}
scaler
:=
DeploymentScaler
{
fake
}
scaler
:=
DeploymentScaler
{
fake
}
preconditions
:=
ScalePrecondition
{
-
1
,
""
}
preconditions
:=
ScalePrecondition
{
-
1
,
""
}
count
:=
uint
(
3
)
count
:=
uint
(
3
)
...
@@ -609,12 +635,16 @@ func TestDeploymentScaleInvalid(t *testing.T) {
...
@@ -609,12 +635,16 @@ func TestDeploymentScaleInvalid(t *testing.T) {
}
}
func
TestDeploymentScaleFailsPreconditions
(
t
*
testing
.
T
)
{
func
TestDeploymentScaleFailsPreconditions
(
t
*
testing
.
T
)
{
fake
:=
testclient
.
NewSimpleFake
(
&
extensions
.
Deployment
{
fake
:=
fake
.
NewSimpleClientset
(
&
extensions
.
Deployment
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
,
},
Spec
:
extensions
.
DeploymentSpec
{
Spec
:
extensions
.
DeploymentSpec
{
Replicas
:
10
,
Replicas
:
10
,
},
},
})
})
scaler
:=
DeploymentScaler
{
&
testclient
.
FakeExperimental
{
Fake
:
fake
}
}
scaler
:=
DeploymentScaler
{
fake
.
Extensions
()
}
preconditions
:=
ScalePrecondition
{
2
,
""
}
preconditions
:=
ScalePrecondition
{
2
,
""
}
count
:=
uint
(
3
)
count
:=
uint
(
3
)
name
:=
"foo"
name
:=
"foo"
...
@@ -624,7 +654,7 @@ func TestDeploymentScaleFailsPreconditions(t *testing.T) {
...
@@ -624,7 +654,7 @@ func TestDeploymentScaleFailsPreconditions(t *testing.T) {
if
len
(
actions
)
!=
1
{
if
len
(
actions
)
!=
1
{
t
.
Errorf
(
"unexpected actions: %v, expected 1 actions (get)"
,
actions
)
t
.
Errorf
(
"unexpected actions: %v, expected 1 actions (get)"
,
actions
)
}
}
if
action
,
ok
:=
actions
[
0
]
.
(
testc
lient
.
GetAction
);
!
ok
||
action
.
GetResource
()
!=
"deployments"
||
action
.
GetName
()
!=
name
{
if
action
,
ok
:=
actions
[
0
]
.
(
testc
ore
.
GetAction
);
!
ok
||
action
.
GetResource
()
.
GroupResource
()
!=
extensions
.
Resource
(
"deployments"
)
||
action
.
GetName
()
!=
name
{
t
.
Errorf
(
"unexpected action: %v, expected get-deployment %s"
,
actions
[
0
],
name
)
t
.
Errorf
(
"unexpected action: %v, expected get-deployment %s"
,
actions
[
0
],
name
)
}
}
}
}
...
...
pkg/kubectl/stop.go
View file @
519c1374
...
@@ -68,7 +68,7 @@ func IsNoSuchReaperError(err error) bool {
...
@@ -68,7 +68,7 @@ func IsNoSuchReaperError(err error) bool {
return
ok
return
ok
}
}
func
ReaperFor
(
kind
unversioned
.
GroupKind
,
c
*
internalclientset
.
Clientset
)
(
Reaper
,
error
)
{
func
ReaperFor
(
kind
unversioned
.
GroupKind
,
c
internalclientset
.
Interface
)
(
Reaper
,
error
)
{
switch
kind
{
switch
kind
{
case
api
.
Kind
(
"ReplicationController"
)
:
case
api
.
Kind
(
"ReplicationController"
)
:
return
&
ReplicationControllerReaper
{
c
.
Core
(),
Interval
,
Timeout
},
nil
return
&
ReplicationControllerReaper
{
c
.
Core
(),
Interval
,
Timeout
},
nil
...
...
pkg/kubectl/stop_test.go
View file @
519c1374
...
@@ -28,8 +28,9 @@ import (
...
@@ -28,8 +28,9 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/extensions"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
coreclient
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/unversioned"
testcore
"k8s.io/kubernetes/pkg/client/testing/core"
deploymentutil
"k8s.io/kubernetes/pkg/controller/deployment/util"
deploymentutil
"k8s.io/kubernetes/pkg/controller/deployment/util"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/watch"
"k8s.io/kubernetes/pkg/watch"
...
@@ -47,15 +48,6 @@ func TestReplicationControllerStop(t *testing.T) {
...
@@ -47,15 +48,6 @@ func TestReplicationControllerStop(t *testing.T) {
{
{
Name
:
"OnlyOneRC"
,
Name
:
"OnlyOneRC"
,
Objs
:
[]
runtime
.
Object
{
Objs
:
[]
runtime
.
Object
{
&
api
.
ReplicationController
{
// GET
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Namespace
:
ns
,
},
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
0
,
Selector
:
map
[
string
]
string
{
"k1"
:
"v1"
}},
},
&
api
.
ReplicationControllerList
{
// LIST
&
api
.
ReplicationControllerList
{
// LIST
Items
:
[]
api
.
ReplicationController
{
Items
:
[]
api
.
ReplicationController
{
{
{
...
@@ -76,15 +68,6 @@ func TestReplicationControllerStop(t *testing.T) {
...
@@ -76,15 +68,6 @@ func TestReplicationControllerStop(t *testing.T) {
{
{
Name
:
"NoOverlapping"
,
Name
:
"NoOverlapping"
,
Objs
:
[]
runtime
.
Object
{
Objs
:
[]
runtime
.
Object
{
&
api
.
ReplicationController
{
// GET
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Namespace
:
ns
,
},
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
0
,
Selector
:
map
[
string
]
string
{
"k1"
:
"v1"
}},
},
&
api
.
ReplicationControllerList
{
// LIST
&
api
.
ReplicationControllerList
{
// LIST
Items
:
[]
api
.
ReplicationController
{
Items
:
[]
api
.
ReplicationController
{
{
{
...
@@ -115,15 +98,6 @@ func TestReplicationControllerStop(t *testing.T) {
...
@@ -115,15 +98,6 @@ func TestReplicationControllerStop(t *testing.T) {
Name
:
"OverlappingError"
,
Name
:
"OverlappingError"
,
Objs
:
[]
runtime
.
Object
{
Objs
:
[]
runtime
.
Object
{
&
api
.
ReplicationController
{
// GET
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Namespace
:
ns
,
},
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
0
,
Selector
:
map
[
string
]
string
{
"k1"
:
"v1"
}},
},
&
api
.
ReplicationControllerList
{
// LIST
&
api
.
ReplicationControllerList
{
// LIST
Items
:
[]
api
.
ReplicationController
{
Items
:
[]
api
.
ReplicationController
{
{
{
...
@@ -155,15 +129,6 @@ func TestReplicationControllerStop(t *testing.T) {
...
@@ -155,15 +129,6 @@ func TestReplicationControllerStop(t *testing.T) {
Name
:
"OverlappingButSafeDelete"
,
Name
:
"OverlappingButSafeDelete"
,
Objs
:
[]
runtime
.
Object
{
Objs
:
[]
runtime
.
Object
{
&
api
.
ReplicationController
{
// GET
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Namespace
:
ns
,
},
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
0
,
Selector
:
map
[
string
]
string
{
"k1"
:
"v1"
,
"k2"
:
"v2"
}},
},
&
api
.
ReplicationControllerList
{
// LIST
&
api
.
ReplicationControllerList
{
// LIST
Items
:
[]
api
.
ReplicationController
{
Items
:
[]
api
.
ReplicationController
{
{
{
...
@@ -205,15 +170,6 @@ func TestReplicationControllerStop(t *testing.T) {
...
@@ -205,15 +170,6 @@ func TestReplicationControllerStop(t *testing.T) {
Name
:
"TwoExactMatchRCs"
,
Name
:
"TwoExactMatchRCs"
,
Objs
:
[]
runtime
.
Object
{
Objs
:
[]
runtime
.
Object
{
&
api
.
ReplicationController
{
// GET
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Namespace
:
ns
,
},
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
0
,
Selector
:
map
[
string
]
string
{
"k1"
:
"v1"
}},
},
&
api
.
ReplicationControllerList
{
// LIST
&
api
.
ReplicationControllerList
{
// LIST
Items
:
[]
api
.
ReplicationController
{
Items
:
[]
api
.
ReplicationController
{
{
{
...
@@ -248,15 +204,15 @@ func TestReplicationControllerStop(t *testing.T) {
...
@@ -248,15 +204,15 @@ func TestReplicationControllerStop(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"%s unexpected error: %v"
,
test
.
Name
,
err
)
t
.
Fatalf
(
"%s unexpected error: %v"
,
test
.
Name
,
err
)
}
}
fake
:=
testclient
.
NewSimpleFake
(
test
.
Objs
...
)
fake
:=
fake
.
NewSimpleClientset
(
test
.
Objs
...
)
fakeWatch
:=
watch
.
NewFake
()
fakeWatch
:=
watch
.
NewFake
()
fake
.
PrependWatchReactor
(
"replicationcontrollers"
,
testc
lient
.
DefaultWatchReactor
(
fakeWatch
,
nil
))
fake
.
PrependWatchReactor
(
"replicationcontrollers"
,
testc
ore
.
DefaultWatchReactor
(
fakeWatch
,
nil
))
go
func
()
{
go
func
()
{
fakeWatch
.
Add
(
copiedForWatch
)
fakeWatch
.
Add
(
copiedForWatch
)
}()
}()
reaper
:=
ReplicationControllerReaper
{
fake
,
time
.
Millisecond
,
time
.
Millisecond
}
reaper
:=
ReplicationControllerReaper
{
fake
.
Core
()
,
time
.
Millisecond
,
time
.
Millisecond
}
err
=
reaper
.
Stop
(
ns
,
name
,
0
,
nil
)
err
=
reaper
.
Stop
(
ns
,
name
,
0
,
nil
)
if
!
reflect
.
DeepEqual
(
err
,
test
.
StopError
)
{
if
!
reflect
.
DeepEqual
(
err
,
test
.
StopError
)
{
t
.
Errorf
(
"%s unexpected error: %v"
,
test
.
Name
,
err
)
t
.
Errorf
(
"%s unexpected error: %v"
,
test
.
Name
,
err
)
...
@@ -269,7 +225,7 @@ func TestReplicationControllerStop(t *testing.T) {
...
@@ -269,7 +225,7 @@ func TestReplicationControllerStop(t *testing.T) {
continue
continue
}
}
for
i
,
verb
:=
range
test
.
ExpectedActions
{
for
i
,
verb
:=
range
test
.
ExpectedActions
{
if
actions
[
i
]
.
GetResource
()
!=
"replicationcontrollers"
{
if
actions
[
i
]
.
GetResource
()
.
GroupResource
()
!=
api
.
Resource
(
"replicationcontrollers"
)
{
t
.
Errorf
(
"%s unexpected action: %+v, expected %s-replicationController"
,
test
.
Name
,
actions
[
i
],
verb
)
t
.
Errorf
(
"%s unexpected action: %+v, expected %s-replicationController"
,
test
.
Name
,
actions
[
i
],
verb
)
}
}
if
actions
[
i
]
.
GetVerb
()
!=
verb
{
if
actions
[
i
]
.
GetVerb
()
!=
verb
{
...
@@ -291,16 +247,6 @@ func TestReplicaSetStop(t *testing.T) {
...
@@ -291,16 +247,6 @@ func TestReplicaSetStop(t *testing.T) {
{
{
Name
:
"OnlyOneRS"
,
Name
:
"OnlyOneRS"
,
Objs
:
[]
runtime
.
Object
{
Objs
:
[]
runtime
.
Object
{
&
extensions
.
ReplicaSet
{
// GET
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Namespace
:
ns
,
},
Spec
:
extensions
.
ReplicaSetSpec
{
Replicas
:
0
,
Selector
:
&
unversioned
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"k1"
:
"v1"
}},
},
},
&
extensions
.
ReplicaSetList
{
// LIST
&
extensions
.
ReplicaSetList
{
// LIST
Items
:
[]
extensions
.
ReplicaSet
{
Items
:
[]
extensions
.
ReplicaSet
{
{
{
...
@@ -322,16 +268,6 @@ func TestReplicaSetStop(t *testing.T) {
...
@@ -322,16 +268,6 @@ func TestReplicaSetStop(t *testing.T) {
{
{
Name
:
"NoOverlapping"
,
Name
:
"NoOverlapping"
,
Objs
:
[]
runtime
.
Object
{
Objs
:
[]
runtime
.
Object
{
&
extensions
.
ReplicaSet
{
// GET
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Namespace
:
ns
,
},
Spec
:
extensions
.
ReplicaSetSpec
{
Replicas
:
0
,
Selector
:
&
unversioned
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"k1"
:
"v1"
}},
},
},
&
extensions
.
ReplicaSetList
{
// LIST
&
extensions
.
ReplicaSetList
{
// LIST
Items
:
[]
extensions
.
ReplicaSet
{
Items
:
[]
extensions
.
ReplicaSet
{
{
{
...
@@ -365,8 +301,8 @@ func TestReplicaSetStop(t *testing.T) {
...
@@ -365,8 +301,8 @@ func TestReplicaSetStop(t *testing.T) {
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
fake
:=
testclient
.
NewSimpleFake
(
test
.
Objs
...
)
fake
:=
fake
.
NewSimpleClientset
(
test
.
Objs
...
)
reaper
:=
ReplicaSetReaper
{
fake
,
time
.
Millisecond
,
time
.
Millisecond
}
reaper
:=
ReplicaSetReaper
{
fake
.
Extensions
()
,
time
.
Millisecond
,
time
.
Millisecond
}
err
:=
reaper
.
Stop
(
ns
,
name
,
0
,
nil
)
err
:=
reaper
.
Stop
(
ns
,
name
,
0
,
nil
)
if
!
reflect
.
DeepEqual
(
err
,
test
.
StopError
)
{
if
!
reflect
.
DeepEqual
(
err
,
test
.
StopError
)
{
t
.
Errorf
(
"%s unexpected error: %v"
,
test
.
Name
,
err
)
t
.
Errorf
(
"%s unexpected error: %v"
,
test
.
Name
,
err
)
...
@@ -379,7 +315,7 @@ func TestReplicaSetStop(t *testing.T) {
...
@@ -379,7 +315,7 @@ func TestReplicaSetStop(t *testing.T) {
continue
continue
}
}
for
i
,
verb
:=
range
test
.
ExpectedActions
{
for
i
,
verb
:=
range
test
.
ExpectedActions
{
if
actions
[
i
]
.
GetResource
()
!=
"replicasets"
{
if
actions
[
i
]
.
GetResource
()
.
GroupResource
()
!=
extensions
.
Resource
(
"replicasets"
)
{
t
.
Errorf
(
"%s unexpected action: %+v, expected %s-replicaSet"
,
test
.
Name
,
actions
[
i
],
verb
)
t
.
Errorf
(
"%s unexpected action: %+v, expected %s-replicaSet"
,
test
.
Name
,
actions
[
i
],
verb
)
}
}
if
actions
[
i
]
.
GetVerb
()
!=
verb
{
if
actions
[
i
]
.
GetVerb
()
!=
verb
{
...
@@ -402,18 +338,6 @@ func TestJobStop(t *testing.T) {
...
@@ -402,18 +338,6 @@ func TestJobStop(t *testing.T) {
{
{
Name
:
"OnlyOneJob"
,
Name
:
"OnlyOneJob"
,
Objs
:
[]
runtime
.
Object
{
Objs
:
[]
runtime
.
Object
{
&
batch
.
Job
{
// GET
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Namespace
:
ns
,
},
Spec
:
batch
.
JobSpec
{
Parallelism
:
&
zero
,
Selector
:
&
unversioned
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"k1"
:
"v1"
},
},
},
},
&
batch
.
JobList
{
// LIST
&
batch
.
JobList
{
// LIST
Items
:
[]
batch
.
Job
{
Items
:
[]
batch
.
Job
{
{
{
...
@@ -438,18 +362,6 @@ func TestJobStop(t *testing.T) {
...
@@ -438,18 +362,6 @@ func TestJobStop(t *testing.T) {
{
{
Name
:
"JobWithDeadPods"
,
Name
:
"JobWithDeadPods"
,
Objs
:
[]
runtime
.
Object
{
Objs
:
[]
runtime
.
Object
{
&
batch
.
Job
{
// GET
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Namespace
:
ns
,
},
Spec
:
batch
.
JobSpec
{
Parallelism
:
&
zero
,
Selector
:
&
unversioned
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"k1"
:
"v1"
},
},
},
},
&
batch
.
JobList
{
// LIST
&
batch
.
JobList
{
// LIST
Items
:
[]
batch
.
Job
{
Items
:
[]
batch
.
Job
{
{
{
...
@@ -485,8 +397,8 @@ func TestJobStop(t *testing.T) {
...
@@ -485,8 +397,8 @@ func TestJobStop(t *testing.T) {
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
fake
:=
testclient
.
NewSimpleFake
(
test
.
Objs
...
)
fake
:=
fake
.
NewSimpleClientset
(
test
.
Objs
...
)
reaper
:=
JobReaper
{
fake
,
time
.
Millisecond
,
time
.
Millisecond
}
reaper
:=
JobReaper
{
fake
.
Batch
(),
fake
.
Core
()
,
time
.
Millisecond
,
time
.
Millisecond
}
err
:=
reaper
.
Stop
(
ns
,
name
,
0
,
nil
)
err
:=
reaper
.
Stop
(
ns
,
name
,
0
,
nil
)
if
!
reflect
.
DeepEqual
(
err
,
test
.
StopError
)
{
if
!
reflect
.
DeepEqual
(
err
,
test
.
StopError
)
{
t
.
Errorf
(
"%s unexpected error: %v"
,
test
.
Name
,
err
)
t
.
Errorf
(
"%s unexpected error: %v"
,
test
.
Name
,
err
)
...
@@ -503,7 +415,7 @@ func TestJobStop(t *testing.T) {
...
@@ -503,7 +415,7 @@ func TestJobStop(t *testing.T) {
if
actions
[
i
]
.
GetVerb
()
!=
action
[
0
]
{
if
actions
[
i
]
.
GetVerb
()
!=
action
[
0
]
{
t
.
Errorf
(
"%s unexpected verb: %+v, expected %s"
,
test
.
Name
,
actions
[
i
],
expAction
)
t
.
Errorf
(
"%s unexpected verb: %+v, expected %s"
,
test
.
Name
,
actions
[
i
],
expAction
)
}
}
if
actions
[
i
]
.
GetResource
()
!=
action
[
1
]
{
if
actions
[
i
]
.
GetResource
()
.
Resource
!=
action
[
1
]
{
t
.
Errorf
(
"%s unexpected resource: %+v, expected %s"
,
test
.
Name
,
actions
[
i
],
expAction
)
t
.
Errorf
(
"%s unexpected resource: %+v, expected %s"
,
test
.
Name
,
actions
[
i
],
expAction
)
}
}
}
}
...
@@ -564,6 +476,7 @@ func TestDeploymentStop(t *testing.T) {
...
@@ -564,6 +476,7 @@ func TestDeploymentStop(t *testing.T) {
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Name
:
name
,
Namespace
:
ns
,
Namespace
:
ns
,
Labels
:
map
[
string
]
string
{
"k1"
:
"v1"
},
},
},
Spec
:
extensions
.
ReplicaSetSpec
{
Spec
:
extensions
.
ReplicaSetSpec
{
Template
:
template
,
Template
:
template
,
...
@@ -581,8 +494,8 @@ func TestDeploymentStop(t *testing.T) {
...
@@ -581,8 +494,8 @@ func TestDeploymentStop(t *testing.T) {
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
fake
:=
testclient
.
NewSimpleFake
(
test
.
Objs
...
)
fake
:=
fake
.
NewSimpleClientset
(
test
.
Objs
...
)
reaper
:=
DeploymentReaper
{
fake
,
time
.
Millisecond
,
time
.
Millisecond
}
reaper
:=
DeploymentReaper
{
fake
.
Extensions
(),
fake
.
Extensions
()
,
time
.
Millisecond
,
time
.
Millisecond
}
err
:=
reaper
.
Stop
(
ns
,
name
,
0
,
nil
)
err
:=
reaper
.
Stop
(
ns
,
name
,
0
,
nil
)
if
!
reflect
.
DeepEqual
(
err
,
test
.
StopError
)
{
if
!
reflect
.
DeepEqual
(
err
,
test
.
StopError
)
{
t
.
Errorf
(
"%s unexpected error: %v"
,
test
.
Name
,
err
)
t
.
Errorf
(
"%s unexpected error: %v"
,
test
.
Name
,
err
)
...
@@ -599,7 +512,7 @@ func TestDeploymentStop(t *testing.T) {
...
@@ -599,7 +512,7 @@ func TestDeploymentStop(t *testing.T) {
if
actions
[
i
]
.
GetVerb
()
!=
action
[
0
]
{
if
actions
[
i
]
.
GetVerb
()
!=
action
[
0
]
{
t
.
Errorf
(
"%s unexpected verb: %+v, expected %s"
,
test
.
Name
,
actions
[
i
],
expAction
)
t
.
Errorf
(
"%s unexpected verb: %+v, expected %s"
,
test
.
Name
,
actions
[
i
],
expAction
)
}
}
if
actions
[
i
]
.
GetResource
()
!=
action
[
1
]
{
if
actions
[
i
]
.
GetResource
()
.
Resource
!=
action
[
1
]
{
t
.
Errorf
(
"%s unexpected resource: %+v, expected %s"
,
test
.
Name
,
actions
[
i
],
expAction
)
t
.
Errorf
(
"%s unexpected resource: %+v, expected %s"
,
test
.
Name
,
actions
[
i
],
expAction
)
}
}
if
len
(
action
)
==
3
&&
actions
[
i
]
.
GetSubresource
()
!=
action
[
2
]
{
if
len
(
action
)
==
3
&&
actions
[
i
]
.
GetSubresource
()
!=
action
[
2
]
{
...
@@ -610,7 +523,7 @@ func TestDeploymentStop(t *testing.T) {
...
@@ -610,7 +523,7 @@ func TestDeploymentStop(t *testing.T) {
}
}
type
noSuchPod
struct
{
type
noSuchPod
struct
{
*
testclient
.
FakePods
coreclient
.
PodInterface
}
}
func
(
c
*
noSuchPod
)
Get
(
name
string
)
(
*
api
.
Pod
,
error
)
{
func
(
c
*
noSuchPod
)
Get
(
name
string
)
(
*
api
.
Pod
,
error
)
{
...
@@ -618,84 +531,101 @@ func (c *noSuchPod) Get(name string) (*api.Pod, error) {
...
@@ -618,84 +531,101 @@ func (c *noSuchPod) Get(name string) (*api.Pod, error) {
}
}
type
noDeleteService
struct
{
type
noDeleteService
struct
{
*
testclient
.
FakeServices
coreclient
.
ServiceInterface
}
}
func
(
c
*
noDeleteService
)
Delete
(
service
string
)
error
{
func
(
c
*
noDeleteService
)
Delete
(
service
string
,
o
*
api
.
DeleteOptions
)
error
{
return
fmt
.
Errorf
(
"I'm afraid I can't do that, Dave"
)
return
fmt
.
Errorf
(
"I'm afraid I can't do that, Dave"
)
}
}
type
reaperFake
struct
{
type
reaperFake
struct
{
*
testclient
.
Fake
*
fake
.
Clientset
noSuchPod
,
noDeleteService
bool
}
func
(
c
*
reaperFake
)
Core
()
coreclient
.
CoreInterface
{
return
&
reaperCoreFake
{
c
.
Clientset
.
Core
(),
c
.
noSuchPod
,
c
.
noDeleteService
}
}
type
reaperCoreFake
struct
{
coreclient
.
CoreInterface
noSuchPod
,
noDeleteService
bool
noSuchPod
,
noDeleteService
bool
}
}
func
(
c
*
reaper
Fake
)
Pods
(
namespace
string
)
client
.
PodInterface
{
func
(
c
*
reaper
CoreFake
)
Pods
(
namespace
string
)
core
client
.
PodInterface
{
pods
:=
&
testclient
.
FakePods
{
Fake
:
c
.
Fake
,
Namespace
:
namespace
}
pods
:=
c
.
CoreInterface
.
Pods
(
namespace
)
if
c
.
noSuchPod
{
if
c
.
noSuchPod
{
return
&
noSuchPod
{
pods
}
return
&
noSuchPod
{
pods
}
}
}
return
pods
return
pods
}
}
func
(
c
*
reaper
Fake
)
Services
(
namespace
string
)
client
.
ServiceInterface
{
func
(
c
*
reaper
CoreFake
)
Services
(
namespace
string
)
core
client
.
ServiceInterface
{
services
:=
&
testclient
.
FakeServices
{
Fake
:
c
.
Fake
,
Namespace
:
namespace
}
services
:=
c
.
CoreInterface
.
Services
(
namespace
)
if
c
.
noDeleteService
{
if
c
.
noDeleteService
{
return
&
noDeleteService
{
services
}
return
&
noDeleteService
{
services
}
}
}
return
services
return
services
}
}
func
pod
()
*
api
.
Pod
{
return
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
}}
}
func
service
()
*
api
.
Service
{
return
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
}}
}
func
TestSimpleStop
(
t
*
testing
.
T
)
{
func
TestSimpleStop
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
fake
*
reaperFake
fake
*
reaperFake
kind
unversioned
.
GroupKind
kind
unversioned
.
GroupKind
actions
[]
testc
lient
.
Action
actions
[]
testc
ore
.
Action
expectError
bool
expectError
bool
test
string
test
string
}{
}{
{
{
fake
:
&
reaperFake
{
fake
:
&
reaperFake
{
Fake
:
&
testclient
.
Fake
{}
,
Clientset
:
fake
.
NewSimpleClientset
(
pod
())
,
},
},
kind
:
api
.
Kind
(
"Pod"
),
kind
:
api
.
Kind
(
"Pod"
),
actions
:
[]
testc
lient
.
Action
{
actions
:
[]
testc
ore
.
Action
{
testc
lient
.
NewGetAction
(
"pods"
,
api
.
NamespaceDefault
,
"foo"
),
testc
ore
.
NewGetAction
(
api
.
Resource
(
"pods"
)
.
WithVersion
(
""
)
,
api
.
NamespaceDefault
,
"foo"
),
testc
lient
.
NewDeleteAction
(
"pods"
,
api
.
NamespaceDefault
,
"foo"
),
testc
ore
.
NewDeleteAction
(
api
.
Resource
(
"pods"
)
.
WithVersion
(
""
)
,
api
.
NamespaceDefault
,
"foo"
),
},
},
expectError
:
false
,
expectError
:
false
,
test
:
"stop pod succeeds"
,
test
:
"stop pod succeeds"
,
},
},
{
{
fake
:
&
reaperFake
{
fake
:
&
reaperFake
{
Fake
:
&
testclient
.
Fake
{}
,
Clientset
:
fake
.
NewSimpleClientset
(
service
())
,
},
},
kind
:
api
.
Kind
(
"Service"
),
kind
:
api
.
Kind
(
"Service"
),
actions
:
[]
testc
lient
.
Action
{
actions
:
[]
testc
ore
.
Action
{
testc
lient
.
NewGetAction
(
"services"
,
api
.
NamespaceDefault
,
"foo"
),
testc
ore
.
NewGetAction
(
api
.
Resource
(
"services"
)
.
WithVersion
(
""
)
,
api
.
NamespaceDefault
,
"foo"
),
testc
lient
.
NewDeleteAction
(
"services"
,
api
.
NamespaceDefault
,
"foo"
),
testc
ore
.
NewDeleteAction
(
api
.
Resource
(
"services"
)
.
WithVersion
(
""
)
,
api
.
NamespaceDefault
,
"foo"
),
},
},
expectError
:
false
,
expectError
:
false
,
test
:
"stop service succeeds"
,
test
:
"stop service succeeds"
,
},
},
{
{
fake
:
&
reaperFake
{
fake
:
&
reaperFake
{
Fake
:
&
testclient
.
Fake
{}
,
Clientset
:
fake
.
NewSimpleClientset
()
,
noSuchPod
:
true
,
noSuchPod
:
true
,
},
},
kind
:
api
.
Kind
(
"Pod"
),
kind
:
api
.
Kind
(
"Pod"
),
actions
:
[]
testc
lient
.
Action
{},
actions
:
[]
testc
ore
.
Action
{},
expectError
:
true
,
expectError
:
true
,
test
:
"stop pod fails, no pod"
,
test
:
"stop pod fails, no pod"
,
},
},
{
{
fake
:
&
reaperFake
{
fake
:
&
reaperFake
{
Fake
:
&
testclient
.
Fake
{}
,
Clientset
:
fake
.
NewSimpleClientset
(
service
())
,
noDeleteService
:
true
,
noDeleteService
:
true
,
},
},
kind
:
api
.
Kind
(
"Service"
),
kind
:
api
.
Kind
(
"Service"
),
actions
:
[]
testc
lient
.
Action
{
actions
:
[]
testc
ore
.
Action
{
testc
lient
.
NewGetAction
(
"services"
,
api
.
NamespaceDefault
,
"foo"
),
testc
ore
.
NewGetAction
(
api
.
Resource
(
"services"
)
.
WithVersion
(
""
)
,
api
.
NamespaceDefault
,
"foo"
),
},
},
expectError
:
true
,
expectError
:
true
,
test
:
"stop service fails, can't delete"
,
test
:
"stop service fails, can't delete"
,
...
@@ -747,12 +677,9 @@ func TestDeploymentNotFoundError(t *testing.T) {
...
@@ -747,12 +677,9 @@ func TestDeploymentNotFoundError(t *testing.T) {
}
}
template
:=
deploymentutil
.
GetNewReplicaSetTemplate
(
deployment
)
template
:=
deploymentutil
.
GetNewReplicaSetTemplate
(
deployment
)
fake
:=
&
testclient
.
Fake
{}
fake
:=
fake
.
NewSimpleClientset
(
fake
.
AddReactor
(
"get"
,
"deployments"
,
func
(
action
testclient
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
deployment
,
return
true
,
deployment
,
nil
&
extensions
.
ReplicaSetList
{
Items
:
[]
extensions
.
ReplicaSet
{
})
fake
.
AddReactor
(
"list"
,
"replicasets"
,
func
(
action
testclient
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
list
:=
&
extensions
.
ReplicaSetList
{
Items
:
[]
extensions
.
ReplicaSet
{
{
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Name
:
name
,
...
@@ -762,14 +689,14 @@ func TestDeploymentNotFoundError(t *testing.T) {
...
@@ -762,14 +689,14 @@ func TestDeploymentNotFoundError(t *testing.T) {
Template
:
template
,
Template
:
template
,
},
},
},
},
}
}
}
,
return
true
,
list
,
nil
},
}
)
)
fake
.
AddReactor
(
"get"
,
"replicasets"
,
func
(
action
testc
lient
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
fake
.
AddReactor
(
"get"
,
"replicasets"
,
func
(
action
testc
ore
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
return
true
,
nil
,
ScaleError
{
ActualError
:
errors
.
NewNotFound
(
api
.
Resource
(
"replicaset"
),
"doesn't-matter"
)}
return
true
,
nil
,
ScaleError
{
ActualError
:
errors
.
NewNotFound
(
api
.
Resource
(
"replicaset"
),
"doesn't-matter"
)}
})
})
reaper
:=
DeploymentReaper
{
fake
,
time
.
Millisecond
,
time
.
Millisecond
}
reaper
:=
DeploymentReaper
{
fake
.
Extensions
(),
fake
.
Extensions
()
,
time
.
Millisecond
,
time
.
Millisecond
}
if
err
:=
reaper
.
Stop
(
ns
,
name
,
0
,
nil
);
err
!=
nil
{
if
err
:=
reaper
.
Stop
(
ns
,
name
,
0
,
nil
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %#v"
,
err
)
t
.
Fatalf
(
"unexpected error: %#v"
,
err
)
}
}
...
...
test/e2e/batch_v1_jobs.go
View file @
519c1374
...
@@ -27,6 +27,7 @@ import (
...
@@ -27,6 +27,7 @@ import (
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/batch"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
clientsetadapter
"k8s.io/kubernetes/pkg/client/unversioned/adapters/internalclientset"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/util/wait"
...
@@ -128,7 +129,7 @@ var _ = framework.KubeDescribe("V1Job", func() {
...
@@ -128,7 +129,7 @@ var _ = framework.KubeDescribe("V1Job", func() {
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"scale job up"
)
By
(
"scale job up"
)
scaler
,
err
:=
kubectl
.
ScalerFor
(
batch
.
Kind
(
"Job"
),
f
.
Client
)
scaler
,
err
:=
kubectl
.
ScalerFor
(
batch
.
Kind
(
"Job"
),
clientsetadapter
.
FromUnversionedClient
(
f
.
Client
)
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
waitForScale
:=
kubectl
.
NewRetryParams
(
5
*
time
.
Second
,
1
*
time
.
Minute
)
waitForScale
:=
kubectl
.
NewRetryParams
(
5
*
time
.
Second
,
1
*
time
.
Minute
)
waitForReplicas
:=
kubectl
.
NewRetryParams
(
5
*
time
.
Second
,
5
*
time
.
Minute
)
waitForReplicas
:=
kubectl
.
NewRetryParams
(
5
*
time
.
Second
,
5
*
time
.
Minute
)
...
@@ -153,7 +154,7 @@ var _ = framework.KubeDescribe("V1Job", func() {
...
@@ -153,7 +154,7 @@ var _ = framework.KubeDescribe("V1Job", func() {
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"scale job down"
)
By
(
"scale job down"
)
scaler
,
err
:=
kubectl
.
ScalerFor
(
batch
.
Kind
(
"Job"
),
f
.
Client
)
scaler
,
err
:=
kubectl
.
ScalerFor
(
batch
.
Kind
(
"Job"
),
clientsetadapter
.
FromUnversionedClient
(
f
.
Client
)
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
waitForScale
:=
kubectl
.
NewRetryParams
(
5
*
time
.
Second
,
1
*
time
.
Minute
)
waitForScale
:=
kubectl
.
NewRetryParams
(
5
*
time
.
Second
,
1
*
time
.
Minute
)
waitForReplicas
:=
kubectl
.
NewRetryParams
(
5
*
time
.
Second
,
5
*
time
.
Minute
)
waitForReplicas
:=
kubectl
.
NewRetryParams
(
5
*
time
.
Second
,
5
*
time
.
Minute
)
...
@@ -176,7 +177,7 @@ var _ = framework.KubeDescribe("V1Job", func() {
...
@@ -176,7 +177,7 @@ var _ = framework.KubeDescribe("V1Job", func() {
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"delete a job"
)
By
(
"delete a job"
)
reaper
,
err
:=
kubectl
.
ReaperFor
(
batch
.
Kind
(
"Job"
),
f
.
Client
)
reaper
,
err
:=
kubectl
.
ReaperFor
(
batch
.
Kind
(
"Job"
),
clientsetadapter
.
FromUnversionedClient
(
f
.
Client
)
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
timeout
:=
1
*
time
.
Minute
timeout
:=
1
*
time
.
Minute
err
=
reaper
.
Stop
(
f
.
Namespace
.
Name
,
job
.
Name
,
timeout
,
api
.
NewDeleteOptions
(
0
))
err
=
reaper
.
Stop
(
f
.
Namespace
.
Name
,
job
.
Name
,
timeout
,
api
.
NewDeleteOptions
(
0
))
...
...
test/e2e/daemon_set.go
View file @
519c1374
...
@@ -28,6 +28,7 @@ import (
...
@@ -28,6 +28,7 @@ import (
"k8s.io/kubernetes/pkg/apimachinery/registered"
"k8s.io/kubernetes/pkg/apimachinery/registered"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/extensions"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
clientsetadapter
"k8s.io/kubernetes/pkg/client/unversioned/adapters/internalclientset"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
...
@@ -115,7 +116,7 @@ var _ = framework.KubeDescribe("Daemon set [Serial]", func() {
...
@@ -115,7 +116,7 @@ var _ = framework.KubeDescribe("Daemon set [Serial]", func() {
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
defer
func
()
{
defer
func
()
{
framework
.
Logf
(
"Check that reaper kills all daemon pods for %s"
,
dsName
)
framework
.
Logf
(
"Check that reaper kills all daemon pods for %s"
,
dsName
)
dsReaper
,
err
:=
kubectl
.
ReaperFor
(
extensions
.
Kind
(
"DaemonSet"
),
c
)
dsReaper
,
err
:=
kubectl
.
ReaperFor
(
extensions
.
Kind
(
"DaemonSet"
),
c
lientsetadapter
.
FromUnversionedClient
(
c
)
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
err
=
dsReaper
.
Stop
(
ns
,
dsName
,
0
,
nil
)
err
=
dsReaper
.
Stop
(
ns
,
dsName
,
0
,
nil
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
...
...
test/e2e/deployment.go
View file @
519c1374
...
@@ -195,7 +195,7 @@ func stopDeploymentMaybeOverlap(c *clientset.Clientset, oldC client.Interface, n
...
@@ -195,7 +195,7 @@ func stopDeploymentMaybeOverlap(c *clientset.Clientset, oldC client.Interface, n
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
framework
.
Logf
(
"Deleting deployment %s"
,
deploymentName
)
framework
.
Logf
(
"Deleting deployment %s"
,
deploymentName
)
reaper
,
err
:=
kubectl
.
ReaperFor
(
extensions
.
Kind
(
"Deployment"
),
oldC
)
reaper
,
err
:=
kubectl
.
ReaperFor
(
extensions
.
Kind
(
"Deployment"
),
c
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
timeout
:=
1
*
time
.
Minute
timeout
:=
1
*
time
.
Minute
err
=
reaper
.
Stop
(
ns
,
deployment
.
Name
,
timeout
,
api
.
NewDeleteOptions
(
0
))
err
=
reaper
.
Stop
(
ns
,
deployment
.
Name
,
timeout
,
api
.
NewDeleteOptions
(
0
))
...
@@ -1114,10 +1114,10 @@ func testScaledRolloutDeployment(f *framework.Framework) {
...
@@ -1114,10 +1114,10 @@ func testScaledRolloutDeployment(f *framework.Framework) {
first
,
err
=
c
.
Extensions
()
.
ReplicaSets
(
first
.
Namespace
)
.
Get
(
first
.
Name
)
first
,
err
=
c
.
Extensions
()
.
ReplicaSets
(
first
.
Namespace
)
.
Get
(
first
.
Name
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
firstCond
:=
client
.
ReplicaSetHasDesiredReplicas
(
f
.
Client
.
Extensions
(),
first
)
firstCond
:=
client
.
ReplicaSetHasDesiredReplicas
(
c
.
Extensions
(),
first
)
wait
.
PollImmediate
(
10
*
time
.
Millisecond
,
1
*
time
.
Minute
,
firstCond
)
wait
.
PollImmediate
(
10
*
time
.
Millisecond
,
1
*
time
.
Minute
,
firstCond
)
secondCond
:=
client
.
ReplicaSetHasDesiredReplicas
(
f
.
Client
.
Extensions
(),
second
)
secondCond
:=
client
.
ReplicaSetHasDesiredReplicas
(
c
.
Extensions
(),
second
)
wait
.
PollImmediate
(
10
*
time
.
Millisecond
,
1
*
time
.
Minute
,
secondCond
)
wait
.
PollImmediate
(
10
*
time
.
Millisecond
,
1
*
time
.
Minute
,
secondCond
)
By
(
fmt
.
Sprintf
(
"Updating the size (up) and template at the same time for deployment %q"
,
deploymentName
))
By
(
fmt
.
Sprintf
(
"Updating the size (up) and template at the same time for deployment %q"
,
deploymentName
))
...
@@ -1175,10 +1175,10 @@ func testScaledRolloutDeployment(f *framework.Framework) {
...
@@ -1175,10 +1175,10 @@ func testScaledRolloutDeployment(f *framework.Framework) {
newRs
,
err
:=
deploymentutil
.
GetNewReplicaSet
(
deployment
,
c
)
newRs
,
err
:=
deploymentutil
.
GetNewReplicaSet
(
deployment
,
c
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
oldCond
:=
client
.
ReplicaSetHasDesiredReplicas
(
f
.
Client
.
Extensions
(),
oldRs
)
oldCond
:=
client
.
ReplicaSetHasDesiredReplicas
(
c
.
Extensions
(),
oldRs
)
wait
.
PollImmediate
(
10
*
time
.
Millisecond
,
1
*
time
.
Minute
,
oldCond
)
wait
.
PollImmediate
(
10
*
time
.
Millisecond
,
1
*
time
.
Minute
,
oldCond
)
newCond
:=
client
.
ReplicaSetHasDesiredReplicas
(
f
.
Client
.
Extensions
(),
newRs
)
newCond
:=
client
.
ReplicaSetHasDesiredReplicas
(
c
.
Extensions
(),
newRs
)
wait
.
PollImmediate
(
10
*
time
.
Millisecond
,
1
*
time
.
Minute
,
newCond
)
wait
.
PollImmediate
(
10
*
time
.
Millisecond
,
1
*
time
.
Minute
,
newCond
)
By
(
fmt
.
Sprintf
(
"Updating the size (down) and template at the same time for deployment %q"
,
deploymentName
))
By
(
fmt
.
Sprintf
(
"Updating the size (down) and template at the same time for deployment %q"
,
deploymentName
))
...
...
test/e2e/framework/util.go
View file @
519c1374
...
@@ -56,6 +56,7 @@ import (
...
@@ -56,6 +56,7 @@ import (
"k8s.io/kubernetes/pkg/client/typed/discovery"
"k8s.io/kubernetes/pkg/client/typed/discovery"
"k8s.io/kubernetes/pkg/client/typed/dynamic"
"k8s.io/kubernetes/pkg/client/typed/dynamic"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
clientsetadapter
"k8s.io/kubernetes/pkg/client/unversioned/adapters/internalclientset"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
clientcmdapi
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
clientcmdapi
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
gcecloud
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce"
gcecloud
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce"
...
@@ -3197,7 +3198,7 @@ func RemoveTaintOffNode(c *client.Client, nodeName string, taint api.Taint) {
...
@@ -3197,7 +3198,7 @@ func RemoveTaintOffNode(c *client.Client, nodeName string, taint api.Taint) {
func
ScaleRC
(
c
*
client
.
Client
,
ns
,
name
string
,
size
uint
,
wait
bool
)
error
{
func
ScaleRC
(
c
*
client
.
Client
,
ns
,
name
string
,
size
uint
,
wait
bool
)
error
{
By
(
fmt
.
Sprintf
(
"Scaling replication controller %s in namespace %s to %d"
,
name
,
ns
,
size
))
By
(
fmt
.
Sprintf
(
"Scaling replication controller %s in namespace %s to %d"
,
name
,
ns
,
size
))
scaler
,
err
:=
kubectl
.
ScalerFor
(
api
.
Kind
(
"ReplicationController"
),
c
)
scaler
,
err
:=
kubectl
.
ScalerFor
(
api
.
Kind
(
"ReplicationController"
),
c
lientsetadapter
.
FromUnversionedClient
(
c
)
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -3314,7 +3315,7 @@ func DeleteRCAndPods(c *client.Client, ns, name string) error {
...
@@ -3314,7 +3315,7 @@ func DeleteRCAndPods(c *client.Client, ns, name string) error {
}
}
return
err
return
err
}
}
reaper
,
err
:=
kubectl
.
ReaperForReplicationController
(
c
,
10
*
time
.
Minute
)
reaper
,
err
:=
kubectl
.
ReaperForReplicationController
(
c
lientsetadapter
.
FromUnversionedClient
(
c
)
.
Core
()
,
10
*
time
.
Minute
)
if
err
!=
nil
{
if
err
!=
nil
{
if
apierrs
.
IsNotFound
(
err
)
{
if
apierrs
.
IsNotFound
(
err
)
{
Logf
(
"RC %s was already deleted: %v"
,
name
,
err
)
Logf
(
"RC %s was already deleted: %v"
,
name
,
err
)
...
@@ -3462,7 +3463,7 @@ func DeleteReplicaSet(c *client.Client, ns, name string) error {
...
@@ -3462,7 +3463,7 @@ func DeleteReplicaSet(c *client.Client, ns, name string) error {
}
}
return
err
return
err
}
}
reaper
,
err
:=
kubectl
.
ReaperFor
(
extensions
.
Kind
(
"ReplicaSet"
),
c
)
reaper
,
err
:=
kubectl
.
ReaperFor
(
extensions
.
Kind
(
"ReplicaSet"
),
c
lientsetadapter
.
FromUnversionedClient
(
c
)
)
if
err
!=
nil
{
if
err
!=
nil
{
if
apierrs
.
IsNotFound
(
err
)
{
if
apierrs
.
IsNotFound
(
err
)
{
Logf
(
"ReplicaSet %s was already deleted: %v"
,
name
,
err
)
Logf
(
"ReplicaSet %s was already deleted: %v"
,
name
,
err
)
...
...
test/e2e/job.go
View file @
519c1374
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/batch"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
clientsetadapter
"k8s.io/kubernetes/pkg/client/unversioned/adapters/internalclientset"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/util/wait"
...
@@ -124,7 +125,7 @@ var _ = framework.KubeDescribe("Job", func() {
...
@@ -124,7 +125,7 @@ var _ = framework.KubeDescribe("Job", func() {
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"scale job up"
)
By
(
"scale job up"
)
scaler
,
err
:=
kubectl
.
ScalerFor
(
batch
.
Kind
(
"Job"
),
f
.
Client
)
scaler
,
err
:=
kubectl
.
ScalerFor
(
batch
.
Kind
(
"Job"
),
clientsetadapter
.
FromUnversionedClient
(
f
.
Client
)
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
waitForScale
:=
kubectl
.
NewRetryParams
(
5
*
time
.
Second
,
1
*
time
.
Minute
)
waitForScale
:=
kubectl
.
NewRetryParams
(
5
*
time
.
Second
,
1
*
time
.
Minute
)
waitForReplicas
:=
kubectl
.
NewRetryParams
(
5
*
time
.
Second
,
5
*
time
.
Minute
)
waitForReplicas
:=
kubectl
.
NewRetryParams
(
5
*
time
.
Second
,
5
*
time
.
Minute
)
...
@@ -149,7 +150,7 @@ var _ = framework.KubeDescribe("Job", func() {
...
@@ -149,7 +150,7 @@ var _ = framework.KubeDescribe("Job", func() {
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"scale job down"
)
By
(
"scale job down"
)
scaler
,
err
:=
kubectl
.
ScalerFor
(
batch
.
Kind
(
"Job"
),
f
.
Client
)
scaler
,
err
:=
kubectl
.
ScalerFor
(
batch
.
Kind
(
"Job"
),
clientsetadapter
.
FromUnversionedClient
(
f
.
Client
)
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
waitForScale
:=
kubectl
.
NewRetryParams
(
5
*
time
.
Second
,
1
*
time
.
Minute
)
waitForScale
:=
kubectl
.
NewRetryParams
(
5
*
time
.
Second
,
1
*
time
.
Minute
)
waitForReplicas
:=
kubectl
.
NewRetryParams
(
5
*
time
.
Second
,
5
*
time
.
Minute
)
waitForReplicas
:=
kubectl
.
NewRetryParams
(
5
*
time
.
Second
,
5
*
time
.
Minute
)
...
@@ -172,7 +173,7 @@ var _ = framework.KubeDescribe("Job", func() {
...
@@ -172,7 +173,7 @@ var _ = framework.KubeDescribe("Job", func() {
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"delete a job"
)
By
(
"delete a job"
)
reaper
,
err
:=
kubectl
.
ReaperFor
(
batch
.
Kind
(
"Job"
),
f
.
Client
)
reaper
,
err
:=
kubectl
.
ReaperFor
(
batch
.
Kind
(
"Job"
),
clientsetadapter
.
FromUnversionedClient
(
f
.
Client
)
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
timeout
:=
1
*
time
.
Minute
timeout
:=
1
*
time
.
Minute
err
=
reaper
.
Stop
(
f
.
Namespace
.
Name
,
job
.
Name
,
timeout
,
api
.
NewDeleteOptions
(
0
))
err
=
reaper
.
Stop
(
f
.
Namespace
.
Name
,
job
.
Name
,
timeout
,
api
.
NewDeleteOptions
(
0
))
...
...
test/e2e/kubectl.go
View file @
519c1374
...
@@ -47,6 +47,7 @@ import (
...
@@ -47,6 +47,7 @@ import (
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
clientsetadapter
"k8s.io/kubernetes/pkg/client/unversioned/adapters/internalclientset"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
...
@@ -420,7 +421,7 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
...
@@ -420,7 +421,7 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
ExecOrDie
()
ExecOrDie
()
Expect
(
runOutput
)
.
ToNot
(
ContainSubstring
(
"stdin closed"
))
Expect
(
runOutput
)
.
ToNot
(
ContainSubstring
(
"stdin closed"
))
f
:=
func
(
pods
[]
*
api
.
Pod
)
sort
.
Interface
{
return
sort
.
Reverse
(
controller
.
ActivePods
(
pods
))
}
f
:=
func
(
pods
[]
*
api
.
Pod
)
sort
.
Interface
{
return
sort
.
Reverse
(
controller
.
ActivePods
(
pods
))
}
runTestPod
,
_
,
err
:=
util
.
GetFirstPod
(
c
,
ns
,
labels
.
SelectorFromSet
(
map
[
string
]
string
{
"run"
:
"run-test-3"
}),
1
*
time
.
Minute
,
f
)
runTestPod
,
_
,
err
:=
util
.
GetFirstPod
(
c
lientsetadapter
.
FromUnversionedClient
(
c
)
,
ns
,
labels
.
SelectorFromSet
(
map
[
string
]
string
{
"run"
:
"run-test-3"
}),
1
*
time
.
Minute
,
f
)
if
err
!=
nil
{
if
err
!=
nil
{
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
...
...
test/integration/framework/master_utils.go
View file @
519c1374
...
@@ -42,6 +42,7 @@ import (
...
@@ -42,6 +42,7 @@ import (
"k8s.io/kubernetes/pkg/client/record"
"k8s.io/kubernetes/pkg/client/record"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/client/restclient"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
clientsetadapter
"k8s.io/kubernetes/pkg/client/unversioned/adapters/internalclientset"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller"
replicationcontroller
"k8s.io/kubernetes/pkg/controller/replication"
replicationcontroller
"k8s.io/kubernetes/pkg/controller/replication"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/fields"
...
@@ -290,7 +291,7 @@ func RCFromManifest(fileName string) *api.ReplicationController {
...
@@ -290,7 +291,7 @@ func RCFromManifest(fileName string) *api.ReplicationController {
// StopRC stops the rc via kubectl's stop library
// StopRC stops the rc via kubectl's stop library
func
StopRC
(
rc
*
api
.
ReplicationController
,
restClient
*
client
.
Client
)
error
{
func
StopRC
(
rc
*
api
.
ReplicationController
,
restClient
*
client
.
Client
)
error
{
reaper
,
err
:=
kubectl
.
ReaperFor
(
api
.
Kind
(
"ReplicationController"
),
restClient
)
reaper
,
err
:=
kubectl
.
ReaperFor
(
api
.
Kind
(
"ReplicationController"
),
clientsetadapter
.
FromUnversionedClient
(
restClient
)
)
if
err
!=
nil
||
reaper
==
nil
{
if
err
!=
nil
||
reaper
==
nil
{
return
err
return
err
}
}
...
@@ -303,7 +304,7 @@ func StopRC(rc *api.ReplicationController, restClient *client.Client) error {
...
@@ -303,7 +304,7 @@ func StopRC(rc *api.ReplicationController, restClient *client.Client) error {
// ScaleRC scales the given rc to the given replicas.
// ScaleRC scales the given rc to the given replicas.
func
ScaleRC
(
name
,
ns
string
,
replicas
int32
,
restClient
*
client
.
Client
)
(
*
api
.
ReplicationController
,
error
)
{
func
ScaleRC
(
name
,
ns
string
,
replicas
int32
,
restClient
*
client
.
Client
)
(
*
api
.
ReplicationController
,
error
)
{
scaler
,
err
:=
kubectl
.
ScalerFor
(
api
.
Kind
(
"ReplicationController"
),
restClient
)
scaler
,
err
:=
kubectl
.
ScalerFor
(
api
.
Kind
(
"ReplicationController"
),
clientsetadapter
.
FromUnversionedClient
(
restClient
)
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
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