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
f8f45df5
Commit
f8f45df5
authored
Feb 16, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make kubectl logs work for replication controllers
parent
d2ee8f7e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
8 deletions
+54
-8
factory.go
pkg/kubectl/cmd/util/factory.go
+46
-7
kubectl.go
test/e2e/kubectl.go
+8
-1
No files found.
pkg/kubectl/cmd/util/factory.go
View file @
f8f45df5
...
@@ -380,6 +380,42 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -380,6 +380,42 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
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
.
Pods
(
t
.
Namespace
)
.
GetLogs
(
t
.
Name
,
opts
),
nil
case
*
api
.
ReplicationController
:
opts
,
ok
:=
options
.
(
*
api
.
PodLogOptions
)
if
!
ok
{
return
nil
,
errors
.
New
(
"provided options object is not a PodLogOptions"
)
}
selector
:=
labels
.
SelectorFromSet
(
t
.
Spec
.
Selector
)
pod
,
numPods
,
err
:=
GetFirstPod
(
c
,
t
.
Namespace
,
selector
)
if
err
!=
nil
{
return
nil
,
err
}
if
numPods
>
1
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Found %v pods, using pod/%v
\n
"
,
numPods
,
pod
.
Name
)
}
return
c
.
Pods
(
pod
.
Namespace
)
.
GetLogs
(
pod
.
Name
,
opts
),
nil
case
*
extensions
.
ReplicaSet
:
opts
,
ok
:=
options
.
(
*
api
.
PodLogOptions
)
if
!
ok
{
return
nil
,
errors
.
New
(
"provided options object is not a PodLogOptions"
)
}
selector
,
err
:=
unversioned
.
LabelSelectorAsSelector
(
t
.
Spec
.
Selector
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid label selector: %v"
,
err
)
}
pod
,
numPods
,
err
:=
GetFirstPod
(
c
,
t
.
Namespace
,
selector
)
if
err
!=
nil
{
return
nil
,
err
}
if
numPods
>
1
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Found %v pods, using pod/%v
\n
"
,
numPods
,
pod
.
Name
)
}
return
c
.
Pods
(
pod
.
Namespace
)
.
GetLogs
(
pod
.
Name
,
opts
),
nil
default
:
default
:
gvk
,
err
:=
api
.
Scheme
.
ObjectKind
(
object
)
gvk
,
err
:=
api
.
Scheme
.
ObjectKind
(
object
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -527,19 +563,22 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -527,19 +563,22 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
switch
t
:=
object
.
(
type
)
{
switch
t
:=
object
.
(
type
)
{
case
*
api
.
ReplicationController
:
case
*
api
.
ReplicationController
:
selector
:=
labels
.
SelectorFromSet
(
t
.
Spec
.
Selector
)
selector
:=
labels
.
SelectorFromSet
(
t
.
Spec
.
Selector
)
return
GetFirstPod
(
client
,
t
.
Namespace
,
selector
)
pod
,
_
,
err
:=
GetFirstPod
(
client
,
t
.
Namespace
,
selector
)
return
pod
,
err
case
*
extensions
.
Deployment
:
case
*
extensions
.
Deployment
:
selector
,
err
:=
unversioned
.
LabelSelectorAsSelector
(
t
.
Spec
.
Selector
)
selector
,
err
:=
unversioned
.
LabelSelectorAsSelector
(
t
.
Spec
.
Selector
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid label selector: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"invalid label selector: %v"
,
err
)
}
}
return
GetFirstPod
(
client
,
t
.
Namespace
,
selector
)
pod
,
_
,
err
:=
GetFirstPod
(
client
,
t
.
Namespace
,
selector
)
return
pod
,
err
case
*
extensions
.
Job
:
case
*
extensions
.
Job
:
selector
,
err
:=
unversioned
.
LabelSelectorAsSelector
(
t
.
Spec
.
Selector
)
selector
,
err
:=
unversioned
.
LabelSelectorAsSelector
(
t
.
Spec
.
Selector
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid label selector: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"invalid label selector: %v"
,
err
)
}
}
return
GetFirstPod
(
client
,
t
.
Namespace
,
selector
)
pod
,
_
,
err
:=
GetFirstPod
(
client
,
t
.
Namespace
,
selector
)
return
pod
,
err
case
*
api
.
Pod
:
case
*
api
.
Pod
:
return
t
,
nil
return
t
,
nil
default
:
default
:
...
@@ -556,21 +595,21 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -556,21 +595,21 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
}
}
}
}
// GetFirstPod returns the first pod of an object from its namespace and selector
// GetFirstPod returns the first pod of an object from its namespace and selector
and the number of matching pods
func
GetFirstPod
(
client
*
client
.
Client
,
namespace
string
,
selector
labels
.
Selector
)
(
*
api
.
Pod
,
error
)
{
func
GetFirstPod
(
client
*
client
.
Client
,
namespace
string
,
selector
labels
.
Selector
)
(
*
api
.
Pod
,
int
,
error
)
{
var
pods
*
api
.
PodList
var
pods
*
api
.
PodList
for
pods
==
nil
||
len
(
pods
.
Items
)
==
0
{
for
pods
==
nil
||
len
(
pods
.
Items
)
==
0
{
var
err
error
var
err
error
options
:=
api
.
ListOptions
{
LabelSelector
:
selector
}
options
:=
api
.
ListOptions
{
LabelSelector
:
selector
}
if
pods
,
err
=
client
.
Pods
(
namespace
)
.
List
(
options
);
err
!=
nil
{
if
pods
,
err
=
client
.
Pods
(
namespace
)
.
List
(
options
);
err
!=
nil
{
return
nil
,
err
return
nil
,
0
,
err
}
}
if
len
(
pods
.
Items
)
==
0
{
if
len
(
pods
.
Items
)
==
0
{
time
.
Sleep
(
2
*
time
.
Second
)
time
.
Sleep
(
2
*
time
.
Second
)
}
}
}
}
pod
:=
&
pods
.
Items
[
0
]
pod
:=
&
pods
.
Items
[
0
]
return
pod
,
nil
return
pod
,
len
(
pods
.
Items
),
nil
}
}
// Command will stringify and return all environment arguments ie. a command run by a client
// Command will stringify and return all environment arguments ie. a command run by a client
...
...
test/e2e/kubectl.go
View file @
f8f45df5
...
@@ -464,7 +464,7 @@ var _ = Describe("Kubectl client", func() {
...
@@ -464,7 +464,7 @@ var _ = Describe("Kubectl client", func() {
withStdinData
(
"abcd1234
\n
"
)
.
withStdinData
(
"abcd1234
\n
"
)
.
execOrDie
()
execOrDie
()
Expect
(
runOutput
)
.
ToNot
(
ContainSubstring
(
"stdin closed"
))
Expect
(
runOutput
)
.
ToNot
(
ContainSubstring
(
"stdin closed"
))
runTestPod
,
err
:=
util
.
GetFirstPod
(
c
,
ns
,
labels
.
SelectorFromSet
(
map
[
string
]
string
{
"run"
:
"run-test-3"
}))
runTestPod
,
_
,
err
:=
util
.
GetFirstPod
(
c
,
ns
,
labels
.
SelectorFromSet
(
map
[
string
]
string
{
"run"
:
"run-test-3"
}))
if
err
!=
nil
{
if
err
!=
nil
{
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
...
@@ -898,6 +898,13 @@ var _ = Describe("Kubectl client", func() {
...
@@ -898,6 +898,13 @@ var _ = Describe("Kubectl client", func() {
runKubectlOrDie
(
"get"
,
"pods"
,
"-L"
,
"run"
,
nsFlag
)
runKubectlOrDie
(
"get"
,
"pods"
,
"-L"
,
"run"
,
nsFlag
)
Failf
(
"Failed creating 1 pod with expected image %s. Number of pods = %v"
,
nginxImage
,
len
(
pods
))
Failf
(
"Failed creating 1 pod with expected image %s. Number of pods = %v"
,
nginxImage
,
len
(
pods
))
}
}
By
(
"confirm that you can get logs from an rc"
)
_
,
err
=
runKubectl
(
"logs"
,
"rc/"
+
rcName
,
nsFlag
)
// a non-nil error is fine as long as we actually found a pod.
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
" in pod "
)
{
Failf
(
"Failed getting logs by rc %s: %v"
,
rcName
,
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