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
bb460c04
Commit
bb460c04
authored
Jan 30, 2016
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
netexec: Add / and /echo handlers, bump to 1.4
Add some logs, allow simple "cmd" arg for shell.
parent
fd5cbdf7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
62 additions
and
14 deletions
+62
-14
kubelet_etc_hosts.go
test/e2e/kubelet_etc_hosts.go
+3
-2
kubeproxy.go
test/e2e/kubeproxy.go
+1
-1
privileged.go
test/e2e/privileged.go
+3
-2
netexecrc.yaml
test/e2e/testing-manifests/netexecrc.yaml
+1
-1
Makefile
test/images/netexec/Makefile
+1
-1
netexec.go
test/images/netexec/netexec.go
+50
-6
pod.yaml
test/images/netexec/pod.yaml
+3
-1
No files found.
test/e2e/kubelet_etc_hosts.go
View file @
bb460c04
...
@@ -18,16 +18,17 @@ package e2e
...
@@ -18,16 +18,17 @@ package e2e
import
(
import
(
"fmt"
"fmt"
"strings"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/ginkgo"
api
"k8s.io/kubernetes/pkg/api"
api
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apimachinery/registered"
"k8s.io/kubernetes/pkg/apimachinery/registered"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"strings"
)
)
const
(
const
(
kubeletEtcHostsImageName
=
"gcr.io/google_containers/netexec:1.
0
"
kubeletEtcHostsImageName
=
"gcr.io/google_containers/netexec:1.
4
"
kubeletEtcHostsPodName
=
"test-pod"
kubeletEtcHostsPodName
=
"test-pod"
kubeletEtcHostsHostNetworkPodName
=
"test-host-network-pod"
kubeletEtcHostsHostNetworkPodName
=
"test-host-network-pod"
etcHostsPartialContent
=
"# Kubernetes-managed hosts file."
etcHostsPartialContent
=
"# Kubernetes-managed hosts file."
...
...
test/e2e/kubeproxy.go
View file @
bb460c04
...
@@ -46,7 +46,7 @@ const (
...
@@ -46,7 +46,7 @@ const (
nodeHttpPort
=
32080
nodeHttpPort
=
32080
nodeUdpPort
=
32081
nodeUdpPort
=
32081
loadBalancerHttpPort
=
100
loadBalancerHttpPort
=
100
netexecImageName
=
"gcr.io/google_containers/netexec:1.
0
"
netexecImageName
=
"gcr.io/google_containers/netexec:1.
4
"
testPodName
=
"test-container-pod"
testPodName
=
"test-container-pod"
hostTestPodName
=
"host-test-container-pod"
hostTestPodName
=
"host-test-container-pod"
nodePortServiceName
=
"node-port-service"
nodePortServiceName
=
"node-port-service"
...
...
test/e2e/privileged.go
View file @
bb460c04
...
@@ -19,13 +19,14 @@ package e2e
...
@@ -19,13 +19,14 @@ package e2e
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"net/url"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
.
"github.com/onsi/gomega"
"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/apimachinery/registered"
"k8s.io/kubernetes/pkg/apimachinery/registered"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"net/url"
)
)
const
(
const
(
...
@@ -36,7 +37,7 @@ const (
...
@@ -36,7 +37,7 @@ const (
notPrivilegedHttpPort
=
9090
notPrivilegedHttpPort
=
9090
notPrivilegedUdpPort
=
9091
notPrivilegedUdpPort
=
9091
notPrivilegedContainerName
=
"not-privileged-container"
notPrivilegedContainerName
=
"not-privileged-container"
privilegedContainerImage
=
"gcr.io/google_containers/netexec:1.
1
"
privilegedContainerImage
=
"gcr.io/google_containers/netexec:1.
4
"
privilegedCommand
=
"ip link add dummy1 type dummy"
privilegedCommand
=
"ip link add dummy1 type dummy"
)
)
...
...
test/e2e/testing-manifests/netexecrc.yaml
View file @
bb460c04
...
@@ -12,7 +12,7 @@ spec:
...
@@ -12,7 +12,7 @@ spec:
spec
:
spec
:
containers
:
containers
:
-
name
:
netexec
-
name
:
netexec
image
:
gcr.io/google_containers/netexec:1.
0
image
:
gcr.io/google_containers/netexec:1.
4
ports
:
ports
:
-
containerPort
:
8080
-
containerPort
:
8080
# This is to force these pods to land on different hosts.
# This is to force these pods to land on different hosts.
...
...
test/images/netexec/Makefile
View file @
bb460c04
.PHONY
:
all netexec image push clean
.PHONY
:
all netexec image push clean
TAG
=
1.
3.1
TAG
=
1.
4
PREFIX
=
gcr.io/google_containers
PREFIX
=
gcr.io/google_containers
...
...
test/images/netexec/netexec.go
View file @
bb460c04
...
@@ -56,15 +56,45 @@ func main() {
...
@@ -56,15 +56,45 @@ func main() {
}
}
func
startHTTPServer
(
httpPort
int
)
{
func
startHTTPServer
(
httpPort
int
)
{
http
.
HandleFunc
(
"/shutdown"
,
shutdownHandler
)
http
.
HandleFunc
(
"/"
,
rootHandler
)
http
.
HandleFunc
(
"/hostName"
,
hostNameHandler
)
http
.
HandleFunc
(
"/echo"
,
echoHandler
)
http
.
HandleFunc
(
"/exit"
,
exitHandler
)
http
.
HandleFunc
(
"/hostname"
,
hostnameHandler
)
http
.
HandleFunc
(
"/shell"
,
shellHandler
)
http
.
HandleFunc
(
"/shell"
,
shellHandler
)
http
.
HandleFunc
(
"/upload"
,
uploadHandler
)
http
.
HandleFunc
(
"/upload"
,
uploadHandler
)
http
.
HandleFunc
(
"/dial"
,
dialHandler
)
http
.
HandleFunc
(
"/dial"
,
dialHandler
)
// older handlers
http
.
HandleFunc
(
"/hostName"
,
hostNameHandler
)
http
.
HandleFunc
(
"/shutdown"
,
shutdownHandler
)
log
.
Fatal
(
http
.
ListenAndServe
(
fmt
.
Sprintf
(
":%d"
,
httpPort
),
nil
))
log
.
Fatal
(
http
.
ListenAndServe
(
fmt
.
Sprintf
(
":%d"
,
httpPort
),
nil
))
}
}
func
rootHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
log
.
Printf
(
"GET /"
)
fmt
.
Fprintf
(
w
,
"NOW: %v"
,
time
.
Now
())
}
func
echoHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
log
.
Printf
(
"GET /echo?msg=%s"
,
r
.
FormValue
(
"msg"
))
fmt
.
Fprintf
(
w
,
"%s"
,
r
.
FormValue
(
"msg"
))
}
func
exitHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
log
.
Printf
(
"GET /exit?code=%s"
,
r
.
FormValue
(
"code"
))
code
,
err
:=
strconv
.
Atoi
(
r
.
FormValue
(
"code"
))
if
err
==
nil
||
r
.
FormValue
(
"code"
)
==
""
{
os
.
Exit
(
code
)
}
fmt
.
Fprintf
(
w
,
"argument 'code' must be an integer [0-127] or empty, got %q"
,
r
.
FormValue
(
"code"
))
}
func
hostnameHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
log
.
Printf
(
"GET /hostname"
)
fmt
.
Fprintf
(
w
,
getHostName
())
}
func
shutdownHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
shutdownHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
log
.
Printf
(
"GET /shutdown"
)
os
.
Exit
(
0
)
os
.
Exit
(
0
)
}
}
...
@@ -80,6 +110,7 @@ func dialHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -80,6 +110,7 @@ func dialHandler(w http.ResponseWriter, r *http.Request) {
request
:=
values
.
Query
()
.
Get
(
"request"
)
// hostName
request
:=
values
.
Query
()
.
Get
(
"request"
)
// hostName
protocol
:=
values
.
Query
()
.
Get
(
"protocol"
)
protocol
:=
values
.
Query
()
.
Get
(
"protocol"
)
tryParam
:=
values
.
Query
()
.
Get
(
"tries"
)
tryParam
:=
values
.
Query
()
.
Get
(
"tries"
)
log
.
Printf
(
"GET /dial?host=%s&protocol=%s&port=%s&request=%s&tries=%s"
,
host
,
protocol
,
port
,
request
,
tryParam
)
tries
:=
1
tries
:=
1
if
len
(
tryParam
)
>
0
{
if
len
(
tryParam
)
>
0
{
tries
,
err
=
strconv
.
Atoi
(
tryParam
)
tries
,
err
=
strconv
.
Atoi
(
tryParam
)
...
@@ -192,9 +223,12 @@ func dialUDP(request string, remoteAddress *net.UDPAddr) (string, error) {
...
@@ -192,9 +223,12 @@ func dialUDP(request string, remoteAddress *net.UDPAddr) (string, error) {
}
}
func
shellHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
shellHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
log
.
Println
(
r
.
FormValue
(
"shellCommand"
))
cmd
:=
r
.
FormValue
(
"shellCommand"
)
log
.
Printf
(
"%s %s %s
\n
"
,
shellPath
,
"-c"
,
r
.
FormValue
(
"shellCommand"
))
if
cmd
==
""
{
cmdOut
,
err
:=
exec
.
Command
(
shellPath
,
"-c"
,
r
.
FormValue
(
"shellCommand"
))
.
CombinedOutput
()
cmd
=
r
.
FormValue
(
"cmd"
)
}
log
.
Printf
(
"GET /shell?cmd=%s"
,
cmd
)
cmdOut
,
err
:=
exec
.
Command
(
shellPath
,
"-c"
,
cmd
)
.
CombinedOutput
()
output
:=
map
[
string
]
string
{}
output
:=
map
[
string
]
string
{}
if
len
(
cmdOut
)
>
0
{
if
len
(
cmdOut
)
>
0
{
output
[
"output"
]
=
string
(
cmdOut
)
output
[
"output"
]
=
string
(
cmdOut
)
...
@@ -212,6 +246,7 @@ func shellHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -212,6 +246,7 @@ func shellHandler(w http.ResponseWriter, r *http.Request) {
}
}
func
uploadHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
uploadHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
log
.
Printf
(
"GET /upload"
)
result
:=
map
[
string
]
string
{}
result
:=
map
[
string
]
string
{}
file
,
_
,
err
:=
r
.
FormFile
(
"file"
)
file
,
_
,
err
:=
r
.
FormFile
(
"file"
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -287,10 +322,19 @@ func startUDPServer(udpPort int) {
...
@@ -287,10 +322,19 @@ func startUDPServer(udpPort int) {
n
,
clientAddress
,
err
:=
serverConn
.
ReadFromUDP
(
buf
)
n
,
clientAddress
,
err
:=
serverConn
.
ReadFromUDP
(
buf
)
assertNoError
(
err
)
assertNoError
(
err
)
receivedText
:=
strings
.
TrimSpace
(
string
(
buf
[
0
:
n
]))
receivedText
:=
strings
.
TrimSpace
(
string
(
buf
[
0
:
n
]))
if
receivedText
==
"hostName"
{
if
receivedText
==
"hostName"
||
receivedText
==
"hostname"
{
log
.
Println
(
"Sending udp hostName response"
)
log
.
Println
(
"Sending udp hostName response"
)
_
,
err
=
serverConn
.
WriteToUDP
([]
byte
(
getHostName
()),
clientAddress
)
_
,
err
=
serverConn
.
WriteToUDP
([]
byte
(
getHostName
()),
clientAddress
)
assertNoError
(
err
)
assertNoError
(
err
)
}
else
if
strings
.
HasPrefix
(
receivedText
,
"echo "
)
{
parts
:=
strings
.
SplitN
(
receivedText
,
" "
,
2
)
resp
:=
""
if
len
(
parts
)
==
2
{
resp
=
parts
[
1
]
}
log
.
Println
(
"Echoing %q"
)
_
,
err
=
serverConn
.
WriteToUDP
([]
byte
(
resp
),
clientAddress
)
assertNoError
(
err
)
}
else
if
len
(
receivedText
)
>
0
{
}
else
if
len
(
receivedText
)
>
0
{
log
.
Println
(
"Unknown udp command received. "
,
receivedText
)
log
.
Println
(
"Unknown udp command received. "
,
receivedText
)
}
}
...
...
test/images/netexec/pod.yaml
View file @
bb460c04
...
@@ -7,7 +7,9 @@ metadata:
...
@@ -7,7 +7,9 @@ metadata:
spec
:
spec
:
containers
:
containers
:
-
name
:
netexec
-
name
:
netexec
image
:
gcr.io/google_containers/netexec:1.
3.1
image
:
gcr.io/google_containers/netexec:1.
4
ports
:
ports
:
-
containerPort
:
8080
-
containerPort
:
8080
protocol
:
TCP
-
containerPort
:
8081
-
containerPort
:
8081
protocol
:
UDP
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