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
e209b643
Commit
e209b643
authored
Jul 05, 2018
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kube-controller-manager: add test server and test serving
parent
4cc3b2e6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
566 additions
and
0 deletions
+566
-0
BUILD
cmd/kube-controller-manager/app/BUILD
+1
-0
BUILD
cmd/kube-controller-manager/app/testing/BUILD
+31
-0
testserver.go
cmd/kube-controller-manager/app/testing/testserver.go
+175
-0
BUILD
test/integration/BUILD
+1
-0
BUILD
test/integration/kube_controller_manager/BUILD
+40
-0
main_test.go
test/integration/kube_controller_manager/main_test.go
+27
-0
serving_test.go
test/integration/kube_controller_manager/serving_test.go
+291
-0
No files found.
cmd/kube-controller-manager/app/BUILD
View file @
e209b643
...
...
@@ -157,6 +157,7 @@ filegroup(
":package-srcs",
"//cmd/kube-controller-manager/app/config:all-srcs",
"//cmd/kube-controller-manager/app/options:all-srcs",
"//cmd/kube-controller-manager/app/testing:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
...
...
cmd/kube-controller-manager/app/testing/BUILD
0 → 100644
View file @
e209b643
load("@io_bazel_rules_go//go:def.bzl", "go_library")
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
go_library(
name = "go_default_library",
srcs = ["testserver.go"],
importpath = "k8s.io/kubernetes/cmd/kube-controller-manager/app/testing",
visibility = ["//visibility:public"],
deps = [
"//cmd/kube-controller-manager/app:go_default_library",
"//cmd/kube-controller-manager/app/config:go_default_library",
"//cmd/kube-controller-manager/app/options:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//staging/src/k8s.io/client-go/rest:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
],
)
cmd/kube-controller-manager/app/testing/testserver.go
0 → 100644
View file @
e209b643
/*
Copyright 2018 The Kubernetes Authors.
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.
*/
package
testing
import
(
"fmt"
"io/ioutil"
"net"
"os"
"time"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
restclient
"k8s.io/client-go/rest"
"k8s.io/kubernetes/cmd/kube-controller-manager/app"
kubecontrollerconfig
"k8s.io/kubernetes/cmd/kube-controller-manager/app/config"
"k8s.io/kubernetes/cmd/kube-controller-manager/app/options"
)
// TearDownFunc is to be called to tear down a test server.
type
TearDownFunc
func
()
// TestServer return values supplied by kube-test-ApiServer
type
TestServer
struct
{
LoopbackClientConfig
*
restclient
.
Config
// Rest client config using the magic token
Options
*
options
.
KubeControllerManagerOptions
Config
*
kubecontrollerconfig
.
Config
TearDownFn
TearDownFunc
// TearDown function
TmpDir
string
// Temp Dir used, by the apiserver
}
// Logger allows t.Testing and b.Testing to be passed to StartTestServer and StartTestServerOrDie
type
Logger
interface
{
Errorf
(
format
string
,
args
...
interface
{})
Fatalf
(
format
string
,
args
...
interface
{})
Logf
(
format
string
,
args
...
interface
{})
}
// StartTestServer starts a kube-controller-manager. A rest client config and a tear-down func,
// and location of the tmpdir are returned.
//
// Note: we return a tear-down func instead of a stop channel because the later will leak temporary
// files that because Golang testing's call to os.Exit will not give a stop channel go routine
// enough time to remove temporary files.
func
StartTestServer
(
t
Logger
,
customFlags
[]
string
)
(
result
TestServer
,
err
error
)
{
stopCh
:=
make
(
chan
struct
{})
tearDown
:=
func
()
{
close
(
stopCh
)
if
len
(
result
.
TmpDir
)
!=
0
{
os
.
RemoveAll
(
result
.
TmpDir
)
}
}
defer
func
()
{
if
result
.
TearDownFn
==
nil
{
tearDown
()
}
}()
result
.
TmpDir
,
err
=
ioutil
.
TempDir
(
""
,
"kube-controller-manager"
)
if
err
!=
nil
{
return
result
,
fmt
.
Errorf
(
"failed to create temp dir: %v"
,
err
)
}
fs
:=
pflag
.
NewFlagSet
(
"test"
,
pflag
.
PanicOnError
)
s
,
err
:=
options
.
NewKubeControllerManagerOptions
()
if
err
!=
nil
{
return
TestServer
{},
err
}
all
,
disabled
:=
app
.
KnownControllers
(),
app
.
ControllersDisabledByDefault
.
List
()
namedFlagSets
:=
s
.
Flags
(
all
,
disabled
)
for
_
,
f
:=
range
namedFlagSets
.
FlagSets
{
fs
.
AddFlagSet
(
f
)
}
fs
.
Parse
(
customFlags
)
if
s
.
SecureServing
.
BindPort
!=
0
{
s
.
SecureServing
.
Listener
,
s
.
SecureServing
.
BindPort
,
err
=
createListenerOnFreePort
()
if
err
!=
nil
{
return
result
,
fmt
.
Errorf
(
"failed to create listener: %v"
,
err
)
}
s
.
SecureServing
.
ServerCert
.
CertDirectory
=
result
.
TmpDir
t
.
Logf
(
"kube-controller-manager will listen securely on port %d..."
,
s
.
SecureServing
.
BindPort
)
}
if
s
.
InsecureServing
.
BindPort
!=
0
{
s
.
InsecureServing
.
Listener
,
s
.
InsecureServing
.
BindPort
,
err
=
createListenerOnFreePort
()
if
err
!=
nil
{
return
result
,
fmt
.
Errorf
(
"failed to create listener: %v"
,
err
)
}
t
.
Logf
(
"kube-controller-manager will listen insecurely on port %d..."
,
s
.
InsecureServing
.
BindPort
)
}
config
,
err
:=
s
.
Config
(
all
,
disabled
)
if
err
!=
nil
{
return
result
,
fmt
.
Errorf
(
"failed to create config from options: %v"
,
err
)
}
go
func
(
stopCh
<-
chan
struct
{})
{
if
err
:=
app
.
Run
(
config
.
Complete
(),
stopCh
);
err
!=
nil
{
t
.
Errorf
(
"kube-apiserver failed run: %v"
,
err
)
}
}(
stopCh
)
t
.
Logf
(
"Waiting for /healthz to be ok..."
)
client
,
err
:=
kubernetes
.
NewForConfig
(
config
.
LoopbackClientConfig
)
if
err
!=
nil
{
return
result
,
fmt
.
Errorf
(
"failed to create a client: %v"
,
err
)
}
err
=
wait
.
Poll
(
100
*
time
.
Millisecond
,
30
*
time
.
Second
,
func
()
(
bool
,
error
)
{
result
:=
client
.
CoreV1
()
.
RESTClient
()
.
Get
()
.
AbsPath
(
"/healthz"
)
.
Do
()
status
:=
0
result
.
StatusCode
(
&
status
)
if
status
==
200
{
return
true
,
nil
}
return
false
,
nil
})
if
err
!=
nil
{
return
result
,
fmt
.
Errorf
(
"failed to wait for /healthz to return ok: %v"
,
err
)
}
// from here the caller must call tearDown
result
.
LoopbackClientConfig
=
config
.
LoopbackClientConfig
result
.
Options
=
s
result
.
Config
=
config
result
.
TearDownFn
=
tearDown
return
result
,
nil
}
// StartTestServerOrDie calls StartTestServer t.Fatal if it does not succeed.
func
StartTestServerOrDie
(
t
Logger
,
flags
[]
string
)
*
TestServer
{
result
,
err
:=
StartTestServer
(
t
,
flags
)
if
err
==
nil
{
return
&
result
}
t
.
Fatalf
(
"failed to launch server: %v"
,
err
)
return
nil
}
func
createListenerOnFreePort
()
(
net
.
Listener
,
int
,
error
)
{
ln
,
err
:=
net
.
Listen
(
"tcp"
,
":0"
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
// get port
tcpAddr
,
ok
:=
ln
.
Addr
()
.
(
*
net
.
TCPAddr
)
if
!
ok
{
ln
.
Close
()
return
nil
,
0
,
fmt
.
Errorf
(
"invalid listen address: %q"
,
ln
.
Addr
()
.
String
())
}
return
ln
,
tcpAddr
.
Port
,
nil
}
test/integration/BUILD
View file @
e209b643
...
...
@@ -51,6 +51,7 @@ filegroup(
"//test/integration/framework:all-srcs",
"//test/integration/garbagecollector:all-srcs",
"//test/integration/ipamperf:all-srcs",
"//test/integration/kube_controller_manager:all-srcs",
"//test/integration/master:all-srcs",
"//test/integration/metrics:all-srcs",
"//test/integration/objectmeta:all-srcs",
...
...
test/integration/kube_controller_manager/BUILD
0 → 100644
View file @
e209b643
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
)
go_test(
name = "go_default_test",
size = "large",
srcs = [
"main_test.go",
"serving_test.go",
],
tags = [
"etcd",
"integration",
],
deps = [
"//cmd/kube-apiserver/app/testing:go_default_library",
"//cmd/kube-controller-manager/app/testing:go_default_library",
"//staging/src/k8s.io/api/rbac/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//test/integration/framework:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)
test/integration/kube_controller_manager/main_test.go
0 → 100644
View file @
e209b643
/*
Copyright 2017 The Kubernetes Authors.
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.
*/
package
kubecontrollermanager
import
(
"testing"
"k8s.io/kubernetes/test/integration/framework"
)
func
TestMain
(
m
*
testing
.
M
)
{
framework
.
EtcdMain
(
m
.
Run
)
}
test/integration/kube_controller_manager/serving_test.go
0 → 100644
View file @
e209b643
This diff is collapsed.
Click to expand it.
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