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
7f900daa
Commit
7f900daa
authored
Sep 22, 2015
by
Andy Goldstein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add port-forward-tester image
parent
bd8ee1c4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
140 additions
and
0 deletions
+140
-0
.gitignore
test/images/port-forward-tester/.gitignore
+1
-0
Dockerfile
test/images/port-forward-tester/Dockerfile
+18
-0
Makefile
test/images/port-forward-tester/Makefile
+15
-0
portforwardtester.go
test/images/port-forward-tester/portforwardtester.go
+106
-0
No files found.
test/images/port-forward-tester/.gitignore
0 → 100644
View file @
7f900daa
portforwardtester
test/images/port-forward-tester/Dockerfile
0 → 100644
View file @
7f900daa
# Copyright 2015 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM
scratch
ADD
portforwardtester portforwardtester
ADD
portforwardtester.go portforwardtester.go
ENTRYPOINT
["/portforwardtester"]
test/images/port-forward-tester/Makefile
0 → 100644
View file @
7f900daa
all
:
push
TAG
=
1.0
portforwardtester
:
portforwardtester.go
CGO_ENABLED
=
0
GOOS
=
linux go build
-a
-installsuffix
cgo
-ldflags
'-w'
./portforwardtester.go
image
:
portforwardtester
docker build
-t
gcr.io/google_containers/portforwardtester:
$(TAG)
.
push
:
image
gcloud docker push gcr.io/google_containers/portforwardtester:
$(TAG)
clean
:
rm
-f
portforwardtester
test/images/port-forward-tester/portforwardtester.go
0 → 100644
View file @
7f900daa
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// A tiny binary for testing port forwarding. The following environment variables
// control the binary's logic:
//
// BIND_PORT - the TCP port to use for the listener
// EXPECTED_CLIENT_DATA - data that we expect to receive from the client; may be "".
// CHUNKS - how many chunks of data we should send to the client
// CHUNK_SIZE - how large each chunk should be
// CHUNK_INTERVAL - the delay in between sending each chunk
//
// Log messages are written to stdout at various stages of the binary's execution.
// Test code can retrieve this container's log and validate that the expected
// behavior is taking place.
package
main
import
(
"fmt"
"net"
"os"
"strconv"
"strings"
"time"
)
func
getEnvInt
(
name
string
)
int
{
s
:=
os
.
Getenv
(
name
)
value
,
err
:=
strconv
.
Atoi
(
s
)
if
err
!=
nil
{
fmt
.
Printf
(
"Error parsing %s %q: %v
\n
"
,
name
,
s
,
err
)
os
.
Exit
(
1
)
}
return
value
}
func
main
()
{
bindPort
:=
os
.
Getenv
(
"BIND_PORT"
)
listener
,
err
:=
net
.
Listen
(
"tcp"
,
fmt
.
Sprintf
(
"localhost:%s"
,
bindPort
))
if
err
!=
nil
{
fmt
.
Printf
(
"Error listening: %v
\n
"
,
err
)
os
.
Exit
(
1
)
}
conn
,
err
:=
listener
.
Accept
()
if
err
!=
nil
{
fmt
.
Printf
(
"Error accepting connection: %v
\n
"
,
err
)
os
.
Exit
(
1
)
}
defer
conn
.
Close
()
fmt
.
Println
(
"Accepted client connection"
)
expectedClientData
:=
os
.
Getenv
(
"EXPECTED_CLIENT_DATA"
)
if
len
(
expectedClientData
)
>
0
{
buf
:=
make
([]
byte
,
len
(
expectedClientData
))
read
,
err
:=
conn
.
Read
(
buf
)
if
read
!=
len
(
expectedClientData
)
{
fmt
.
Printf
(
"Expected to read %d bytes from client, but got %d instead. err=%v
\n
"
,
len
(
expectedClientData
),
read
,
err
)
os
.
Exit
(
2
)
}
if
expectedClientData
!=
string
(
buf
)
{
fmt
.
Printf
(
"Expect to read %q, but got %q. err=%v
\n
"
,
expectedClientData
,
string
(
buf
),
err
)
os
.
Exit
(
3
)
}
if
err
!=
nil
{
fmt
.
Printf
(
"Read err: %v
\n
"
,
err
)
}
fmt
.
Println
(
"Received expected client data"
)
}
chunks
:=
getEnvInt
(
"CHUNKS"
)
chunkSize
:=
getEnvInt
(
"CHUNK_SIZE"
)
chunkInterval
:=
getEnvInt
(
"CHUNK_INTERVAL"
)
stringData
:=
strings
.
Repeat
(
"x"
,
chunkSize
)
data
:=
[]
byte
(
stringData
)
for
i
:=
0
;
i
<
chunks
;
i
++
{
written
,
err
:=
conn
.
Write
(
data
)
if
written
!=
chunkSize
{
fmt
.
Printf
(
"Expected to write %d bytes from client, but wrote %d instead. err=%v
\n
"
,
chunkSize
,
written
,
err
)
os
.
Exit
(
4
)
}
if
err
!=
nil
{
fmt
.
Printf
(
"Write err: %v
\n
"
,
err
)
}
if
i
+
1
<
chunks
{
time
.
Sleep
(
time
.
Duration
(
chunkInterval
)
*
time
.
Millisecond
)
}
}
fmt
.
Println
(
"Done"
)
}
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