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
afd56495
Commit
afd56495
authored
Nov 27, 2015
by
Fabiano Franz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pod log location must validate container if provided
parent
c1af9dcb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
114 additions
and
4 deletions
+114
-4
strategy.go
pkg/registry/pod/strategy.go
+23
-4
strategy_test.go
pkg/registry/pod/strategy_test.go
+91
-0
No files found.
pkg/registry/pod/strategy.go
View file @
afd56495
...
@@ -240,13 +240,18 @@ func LogLocation(getter ResourceGetter, connInfo client.ConnectionInfoGetter, ct
...
@@ -240,13 +240,18 @@ func LogLocation(getter ResourceGetter, connInfo client.ConnectionInfoGetter, ct
}
}
// Try to figure out a container
// Try to figure out a container
// If a container was provided, it must be valid
container
:=
opts
.
Container
container
:=
opts
.
Container
if
container
==
""
{
if
len
(
container
)
==
0
{
if
len
(
pod
.
Spec
.
Containers
)
==
1
{
if
len
(
pod
.
Spec
.
Containers
)
==
1
{
container
=
pod
.
Spec
.
Containers
[
0
]
.
Name
container
=
pod
.
Spec
.
Containers
[
0
]
.
Name
}
else
{
}
else
{
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"a container name must be specified for pod %s"
,
name
))
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"a container name must be specified for pod %s"
,
name
))
}
}
}
else
{
if
!
podHasContainerWithName
(
pod
,
container
)
{
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"container %s is not valid for pod %s"
,
container
,
name
))
}
}
}
nodeHost
:=
pod
.
Spec
.
NodeName
nodeHost
:=
pod
.
Spec
.
NodeName
if
len
(
nodeHost
)
==
0
{
if
len
(
nodeHost
)
==
0
{
...
@@ -282,12 +287,21 @@ func LogLocation(getter ResourceGetter, connInfo client.ConnectionInfoGetter, ct
...
@@ -282,12 +287,21 @@ func LogLocation(getter ResourceGetter, connInfo client.ConnectionInfoGetter, ct
loc
:=
&
url
.
URL
{
loc
:=
&
url
.
URL
{
Scheme
:
nodeScheme
,
Scheme
:
nodeScheme
,
Host
:
fmt
.
Sprintf
(
"%s:%d"
,
nodeHost
,
nodePort
),
Host
:
fmt
.
Sprintf
(
"%s:%d"
,
nodeHost
,
nodePort
),
Path
:
fmt
.
Sprintf
(
"/containerLogs/%s/%s/%s"
,
pod
.
Namespace
,
n
ame
,
container
),
Path
:
fmt
.
Sprintf
(
"/containerLogs/%s/%s/%s"
,
pod
.
Namespace
,
pod
.
N
ame
,
container
),
RawQuery
:
params
.
Encode
(),
RawQuery
:
params
.
Encode
(),
}
}
return
loc
,
nodeTransport
,
nil
return
loc
,
nodeTransport
,
nil
}
}
func
podHasContainerWithName
(
pod
*
api
.
Pod
,
containerName
string
)
bool
{
for
_
,
c
:=
range
pod
.
Spec
.
Containers
{
if
c
.
Name
==
containerName
{
return
true
}
}
return
false
}
func
streamParams
(
params
url
.
Values
,
opts
runtime
.
Object
)
error
{
func
streamParams
(
params
url
.
Values
,
opts
runtime
.
Object
)
error
{
switch
opts
:=
opts
.
(
type
)
{
switch
opts
:=
opts
.
(
type
)
{
case
*
api
.
PodExecOptions
:
case
*
api
.
PodExecOptions
:
...
@@ -344,12 +358,17 @@ func streamLocation(getter ResourceGetter, connInfo client.ConnectionInfoGetter,
...
@@ -344,12 +358,17 @@ func streamLocation(getter ResourceGetter, connInfo client.ConnectionInfoGetter,
}
}
// Try to figure out a container
// Try to figure out a container
// If a container was provided, it must be valid
if
container
==
""
{
if
container
==
""
{
if
len
(
pod
.
Spec
.
Containers
)
==
1
{
if
len
(
pod
.
Spec
.
Containers
)
==
1
{
container
=
pod
.
Spec
.
Containers
[
0
]
.
Name
container
=
pod
.
Spec
.
Containers
[
0
]
.
Name
}
else
{
}
else
{
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"a container name must be specified for pod %s"
,
name
))
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"a container name must be specified for pod %s"
,
name
))
}
}
}
else
{
if
!
podHasContainerWithName
(
pod
,
container
)
{
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"container %s is not valid for pod %s"
,
container
,
name
))
}
}
}
nodeHost
:=
pod
.
Spec
.
NodeName
nodeHost
:=
pod
.
Spec
.
NodeName
if
len
(
nodeHost
)
==
0
{
if
len
(
nodeHost
)
==
0
{
...
@@ -367,7 +386,7 @@ func streamLocation(getter ResourceGetter, connInfo client.ConnectionInfoGetter,
...
@@ -367,7 +386,7 @@ func streamLocation(getter ResourceGetter, connInfo client.ConnectionInfoGetter,
loc
:=
&
url
.
URL
{
loc
:=
&
url
.
URL
{
Scheme
:
nodeScheme
,
Scheme
:
nodeScheme
,
Host
:
fmt
.
Sprintf
(
"%s:%d"
,
nodeHost
,
nodePort
),
Host
:
fmt
.
Sprintf
(
"%s:%d"
,
nodeHost
,
nodePort
),
Path
:
fmt
.
Sprintf
(
"/%s/%s/%s/%s"
,
path
,
pod
.
Namespace
,
n
ame
,
container
),
Path
:
fmt
.
Sprintf
(
"/%s/%s/%s/%s"
,
path
,
pod
.
Namespace
,
pod
.
N
ame
,
container
),
RawQuery
:
params
.
Encode
(),
RawQuery
:
params
.
Encode
(),
}
}
return
loc
,
nodeTransport
,
nil
return
loc
,
nodeTransport
,
nil
...
@@ -392,7 +411,7 @@ func PortForwardLocation(getter ResourceGetter, connInfo client.ConnectionInfoGe
...
@@ -392,7 +411,7 @@ func PortForwardLocation(getter ResourceGetter, connInfo client.ConnectionInfoGe
loc
:=
&
url
.
URL
{
loc
:=
&
url
.
URL
{
Scheme
:
nodeScheme
,
Scheme
:
nodeScheme
,
Host
:
fmt
.
Sprintf
(
"%s:%d"
,
nodeHost
,
nodePort
),
Host
:
fmt
.
Sprintf
(
"%s:%d"
,
nodeHost
,
nodePort
),
Path
:
fmt
.
Sprintf
(
"/portForward/%s/%s"
,
pod
.
Namespace
,
n
ame
),
Path
:
fmt
.
Sprintf
(
"/portForward/%s/%s"
,
pod
.
Namespace
,
pod
.
N
ame
),
}
}
return
loc
,
nodeTransport
,
nil
return
loc
,
nodeTransport
,
nil
}
}
pkg/registry/pod/strategy_test.go
View file @
afd56495
...
@@ -17,9 +17,12 @@ limitations under the License.
...
@@ -17,9 +17,12 @@ limitations under the License.
package
pod
package
pod
import
(
import
(
"reflect"
"testing"
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/runtime"
)
)
func
TestCheckGracefulDelete
(
t
*
testing
.
T
)
{
func
TestCheckGracefulDelete
(
t
*
testing
.
T
)
{
...
@@ -76,3 +79,91 @@ func TestCheckGracefulDelete(t *testing.T) {
...
@@ -76,3 +79,91 @@ func TestCheckGracefulDelete(t *testing.T) {
}
}
}
}
}
}
type
mockPodGetter
struct
{
pod
*
api
.
Pod
}
func
(
g
mockPodGetter
)
Get
(
api
.
Context
,
string
)
(
runtime
.
Object
,
error
)
{
return
g
.
pod
,
nil
}
func
TestCheckLogLocation
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
tcs
:=
[]
struct
{
in
*
api
.
Pod
opts
*
api
.
PodLogOptions
expectedErr
error
}{
{
in
:
&
api
.
Pod
{
Spec
:
api
.
PodSpec
{},
Status
:
api
.
PodStatus
{},
},
opts
:
&
api
.
PodLogOptions
{},
expectedErr
:
errors
.
NewBadRequest
(
"a container name must be specified for pod test"
),
},
{
in
:
&
api
.
Pod
{
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"mycontainer"
},
},
},
Status
:
api
.
PodStatus
{},
},
opts
:
&
api
.
PodLogOptions
{},
expectedErr
:
nil
,
},
{
in
:
&
api
.
Pod
{
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"container1"
},
{
Name
:
"container2"
},
},
},
Status
:
api
.
PodStatus
{},
},
opts
:
&
api
.
PodLogOptions
{},
expectedErr
:
errors
.
NewBadRequest
(
"a container name must be specified for pod test"
),
},
{
in
:
&
api
.
Pod
{
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"container1"
},
{
Name
:
"container2"
},
},
},
Status
:
api
.
PodStatus
{},
},
opts
:
&
api
.
PodLogOptions
{
Container
:
"unknown"
,
},
expectedErr
:
errors
.
NewBadRequest
(
"container unknown is not valid for pod test"
),
},
{
in
:
&
api
.
Pod
{
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"container1"
},
{
Name
:
"container2"
},
},
},
Status
:
api
.
PodStatus
{},
},
opts
:
&
api
.
PodLogOptions
{
Container
:
"container2"
,
},
expectedErr
:
nil
,
},
}
for
_
,
tc
:=
range
tcs
{
getter
:=
&
mockPodGetter
{
tc
.
in
}
_
,
_
,
err
:=
LogLocation
(
getter
,
nil
,
ctx
,
"test"
,
tc
.
opts
)
if
!
reflect
.
DeepEqual
(
err
,
tc
.
expectedErr
)
{
t
.
Errorf
(
"expected %v, got %v"
,
tc
.
expectedErr
,
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