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
54b2b47c
Commit
54b2b47c
authored
Mar 05, 2015
by
Dawn Chen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4756 from vishh/kubelet
Relax constraints on container status while fetching container logs
parents
ab58268d
f6910803
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
19 deletions
+90
-19
kubelet.go
pkg/kubelet/kubelet.go
+26
-19
kubelet_test.go
pkg/kubelet/kubelet_test.go
+64
-0
No files found.
pkg/kubelet/kubelet.go
View file @
54b2b47c
...
@@ -1538,6 +1538,26 @@ func (kl *Kubelet) GetDockerVersion() ([]uint, error) {
...
@@ -1538,6 +1538,26 @@ func (kl *Kubelet) GetDockerVersion() ([]uint, error) {
return
dockerRunner
.
GetDockerServerVersion
()
return
dockerRunner
.
GetDockerServerVersion
()
}
}
func
(
kl
*
Kubelet
)
validatePodPhase
(
podStatus
*
api
.
PodStatus
)
error
{
switch
podStatus
.
Phase
{
case
api
.
PodRunning
,
api
.
PodSucceeded
,
api
.
PodFailed
:
return
nil
}
return
fmt
.
Errorf
(
"pod is not in 'Running', 'Succeeded' or 'Failed' state - State: %q"
,
podStatus
.
Phase
)
}
func
(
kl
*
Kubelet
)
validateContainerStatus
(
podStatus
*
api
.
PodStatus
,
containerName
string
)
(
dockerID
string
,
err
error
)
{
for
cName
,
cStatus
:=
range
podStatus
.
Info
{
if
containerName
==
cName
{
if
cStatus
.
State
.
Waiting
!=
nil
{
return
""
,
fmt
.
Errorf
(
"container %q is in waiting state."
,
containerName
)
}
return
strings
.
Replace
(
podStatus
.
Info
[
containerName
]
.
ContainerID
,
dockertools
.
DockerPrefix
,
""
,
1
),
nil
}
}
return
""
,
fmt
.
Errorf
(
"container %q not found in pod"
,
containerName
)
}
// GetKubeletContainerLogs returns logs from the container
// GetKubeletContainerLogs returns logs from the container
// The second parameter of GetPodStatus and FindPodContainer methods represents pod UUID, which is allowed to be blank
// The second parameter of GetPodStatus and FindPodContainer methods represents pod UUID, which is allowed to be blank
// TODO: this method is returning logs of random container attempts, when it should be returning the most recent attempt
// TODO: this method is returning logs of random container attempts, when it should be returning the most recent attempt
...
@@ -1551,27 +1571,14 @@ func (kl *Kubelet) GetKubeletContainerLogs(podFullName, containerName, tail stri
...
@@ -1551,27 +1571,14 @@ func (kl *Kubelet) GetKubeletContainerLogs(podFullName, containerName, tail stri
return
fmt
.
Errorf
(
"failed to get status for pod %q - %v"
,
podFullName
,
err
)
return
fmt
.
Errorf
(
"failed to get status for pod %q - %v"
,
podFullName
,
err
)
}
}
}
}
switch
podStatus
.
Phase
{
case
api
.
PodRunning
,
api
.
PodSucceeded
,
api
.
PodFailed
:
if
err
:=
kl
.
validatePodPhase
(
&
podStatus
);
err
!=
nil
{
break
return
err
default
:
return
fmt
.
Errorf
(
"pod %q is not in 'Running', 'Succeeded' or 'Failed' state - State: %q"
,
podFullName
,
podStatus
.
Phase
)
}
exists
:=
false
dockerContainerID
:=
""
for
cName
,
cStatus
:=
range
podStatus
.
Info
{
if
containerName
==
cName
{
exists
=
true
if
!
cStatus
.
Ready
{
return
fmt
.
Errorf
(
"container %q is not ready."
,
containerName
)
}
dockerContainerID
=
strings
.
Replace
(
podStatus
.
Info
[
containerName
]
.
ContainerID
,
dockertools
.
DockerPrefix
,
""
,
1
)
}
}
}
if
!
exists
{
dockerContainerID
,
err
:=
kl
.
validateContainerStatus
(
&
podStatus
,
containerName
)
return
fmt
.
Errorf
(
"container %q not found in pod %q"
,
containerName
,
podFullName
)
if
err
!=
nil
{
return
err
}
}
return
dockertools
.
GetKubeletDockerContainerLogs
(
kl
.
dockerClient
,
dockerContainerID
,
tail
,
follow
,
stdout
,
stderr
)
return
dockertools
.
GetKubeletDockerContainerLogs
(
kl
.
dockerClient
,
dockerContainerID
,
tail
,
follow
,
stdout
,
stderr
)
}
}
...
...
pkg/kubelet/kubelet_test.go
View file @
54b2b47c
...
@@ -3122,5 +3122,69 @@ func TestFilterHostPortConflicts(t *testing.T) {
...
@@ -3122,5 +3122,69 @@ func TestFilterHostPortConflicts(t *testing.T) {
if
filteredPods
[
0
]
.
Name
!=
"oldpod"
{
if
filteredPods
[
0
]
.
Name
!=
"oldpod"
{
t
.
Fatalf
(
"Expected pod %#v. Got pod %#v"
,
pods
[
1
],
filteredPods
[
0
])
t
.
Fatalf
(
"Expected pod %#v. Got pod %#v"
,
pods
[
1
],
filteredPods
[
0
])
}
}
}
func
TestValidatePodStatus
(
t
*
testing
.
T
)
{
kubelet
,
_
,
_
:=
newTestKubelet
(
t
)
testCases
:=
[]
struct
{
podPhase
api
.
PodPhase
success
bool
}{
{
api
.
PodRunning
,
true
},
{
api
.
PodSucceeded
,
true
},
{
api
.
PodFailed
,
true
},
{
api
.
PodPending
,
false
},
{
api
.
PodUnknown
,
false
},
}
for
i
,
tc
:=
range
testCases
{
err
:=
kubelet
.
validatePodPhase
(
&
api
.
PodStatus
{
Phase
:
tc
.
podPhase
})
if
tc
.
success
{
if
err
!=
nil
{
t
.
Errorf
(
"[case %d]: unexpected failure - %v"
,
i
,
err
)
}
}
else
if
err
==
nil
{
t
.
Errorf
(
"[case %d]: unexpected success"
,
i
)
}
}
}
func
TestValidateContainerStatus
(
t
*
testing
.
T
)
{
kubelet
,
_
,
_
:=
newTestKubelet
(
t
)
containerName
:=
"x"
testCases
:=
[]
struct
{
podInfo
api
.
PodInfo
success
bool
}{
{
podInfo
:
api
.
PodInfo
{
containerName
:
api
.
ContainerStatus
{
State
:
api
.
ContainerState
{
Running
:
&
api
.
ContainerStateRunning
{}}}},
success
:
true
,
},
{
podInfo
:
api
.
PodInfo
{
containerName
:
api
.
ContainerStatus
{
State
:
api
.
ContainerState
{
Termination
:
&
api
.
ContainerStateTerminated
{}}}},
success
:
true
,
},
{
podInfo
:
api
.
PodInfo
{
containerName
:
api
.
ContainerStatus
{
State
:
api
.
ContainerState
{
Waiting
:
&
api
.
ContainerStateWaiting
{}}}},
success
:
false
,
},
}
for
i
,
tc
:=
range
testCases
{
_
,
err
:=
kubelet
.
validateContainerStatus
(
&
api
.
PodStatus
{
Info
:
tc
.
podInfo
,
},
containerName
)
if
tc
.
success
{
if
err
!=
nil
{
t
.
Errorf
(
"[case %d]: unexpected failure - %v"
,
i
,
err
)
}
}
else
if
err
==
nil
{
t
.
Errorf
(
"[case %d]: unexpected success"
,
i
)
}
}
if
_
,
err
:=
kubelet
.
validateContainerStatus
(
&
api
.
PodStatus
{
Info
:
testCases
[
0
]
.
podInfo
,
},
"blah"
);
err
==
nil
{
t
.
Errorf
(
"expected error with invalid container name"
)
}
}
}
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