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
a6c43c6a
Commit
a6c43c6a
authored
Jan 29, 2018
by
hzxuzhonghu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pass listener in integration test to prevent port in use flake
parent
84408378
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
53 additions
and
71 deletions
+53
-71
serving.go
staging/src/k8s.io/apiserver/pkg/server/options/serving.go
+9
-2
main.go
staging/src/k8s.io/kube-aggregator/main.go
+2
-1
start.go
staging/src/k8s.io/kube-aggregator/pkg/cmd/server/start.go
+3
-3
main.go
staging/src/k8s.io/sample-apiserver/main.go
+2
-1
start.go
staging/src/k8s.io/sample-apiserver/pkg/cmd/server/start.go
+3
-3
etcd_storage_path_test.go
test/integration/etcd/etcd_storage_path_test.go
+29
-34
apiserver_test.go
test/integration/examples/apiserver_test.go
+0
-0
master_utils.go
test/integration/framework/master_utils.go
+0
-23
ciphers_test.go
test/integration/tls/ciphers_test.go
+5
-4
No files found.
staging/src/k8s.io/apiserver/pkg/server/options/serving.go
View file @
a6c43c6a
...
@@ -35,7 +35,8 @@ import (
...
@@ -35,7 +35,8 @@ import (
type
SecureServingOptions
struct
{
type
SecureServingOptions
struct
{
BindAddress
net
.
IP
BindAddress
net
.
IP
BindPort
int
// BindPort is ignored when Listener is set, will serve https even with 0.
BindPort
int
// BindNetwork is the type of network to bind to - defaults to "tcp", accepts "tcp",
// BindNetwork is the type of network to bind to - defaults to "tcp", accepts "tcp",
// "tcp4", and "tcp6".
// "tcp4", and "tcp6".
BindNetwork
string
BindNetwork
string
...
@@ -160,7 +161,7 @@ func (s *SecureServingOptions) ApplyTo(c *server.Config) error {
...
@@ -160,7 +161,7 @@ func (s *SecureServingOptions) ApplyTo(c *server.Config) error {
if
s
==
nil
{
if
s
==
nil
{
return
nil
return
nil
}
}
if
s
.
BindPort
<=
0
{
if
s
.
BindPort
<=
0
&&
s
.
Listener
==
nil
{
return
nil
return
nil
}
}
...
@@ -171,6 +172,12 @@ func (s *SecureServingOptions) ApplyTo(c *server.Config) error {
...
@@ -171,6 +172,12 @@ func (s *SecureServingOptions) ApplyTo(c *server.Config) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to create listener: %v"
,
err
)
return
fmt
.
Errorf
(
"failed to create listener: %v"
,
err
)
}
}
}
else
{
if
_
,
ok
:=
s
.
Listener
.
Addr
()
.
(
*
net
.
TCPAddr
);
!
ok
{
return
fmt
.
Errorf
(
"failed to parse ip and port from listener"
)
}
s
.
BindPort
=
s
.
Listener
.
Addr
()
.
(
*
net
.
TCPAddr
)
.
Port
s
.
BindAddress
=
s
.
Listener
.
Addr
()
.
(
*
net
.
TCPAddr
)
.
IP
}
}
if
err
:=
s
.
applyServingInfoTo
(
c
);
err
!=
nil
{
if
err
:=
s
.
applyServingInfoTo
(
c
);
err
!=
nil
{
...
...
staging/src/k8s.io/kube-aggregator/main.go
View file @
a6c43c6a
...
@@ -44,7 +44,8 @@ func main() {
...
@@ -44,7 +44,8 @@ func main() {
}
}
stopCh
:=
genericapiserver
.
SetupSignalHandler
()
stopCh
:=
genericapiserver
.
SetupSignalHandler
()
cmd
:=
server
.
NewCommandStartAggregator
(
os
.
Stdout
,
os
.
Stderr
,
stopCh
)
options
:=
server
.
NewDefaultOptions
(
os
.
Stdout
,
os
.
Stderr
)
cmd
:=
server
.
NewCommandStartAggregator
(
options
,
stopCh
)
cmd
.
Flags
()
.
AddGoFlagSet
(
flag
.
CommandLine
)
cmd
.
Flags
()
.
AddGoFlagSet
(
flag
.
CommandLine
)
if
err
:=
cmd
.
Execute
();
err
!=
nil
{
if
err
:=
cmd
.
Execute
();
err
!=
nil
{
glog
.
Fatal
(
err
)
glog
.
Fatal
(
err
)
...
...
staging/src/k8s.io/kube-aggregator/pkg/cmd/server/start.go
View file @
a6c43c6a
...
@@ -49,9 +49,9 @@ type AggregatorOptions struct {
...
@@ -49,9 +49,9 @@ type AggregatorOptions struct {
}
}
// NewCommandStartAggregator provides a CLI handler for 'start master' command
// NewCommandStartAggregator provides a CLI handler for 'start master' command
func
NewCommandStartAggregator
(
out
,
err
io
.
Writer
,
stopCh
<-
chan
struct
{})
*
cobra
.
Command
{
// with a default AggregatorOptions.
o
:=
NewDefaultOptions
(
out
,
err
)
func
NewCommandStartAggregator
(
defaults
*
AggregatorOptions
,
stopCh
<-
chan
struct
{})
*
cobra
.
Command
{
o
:=
*
defaults
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Short
:
"Launch a API aggregator and proxy server"
,
Short
:
"Launch a API aggregator and proxy server"
,
Long
:
"Launch a API aggregator and proxy server"
,
Long
:
"Launch a API aggregator and proxy server"
,
...
...
staging/src/k8s.io/sample-apiserver/main.go
View file @
a6c43c6a
...
@@ -37,7 +37,8 @@ func main() {
...
@@ -37,7 +37,8 @@ func main() {
}
}
stopCh
:=
genericapiserver
.
SetupSignalHandler
()
stopCh
:=
genericapiserver
.
SetupSignalHandler
()
cmd
:=
server
.
NewCommandStartWardleServer
(
os
.
Stdout
,
os
.
Stderr
,
stopCh
)
options
:=
server
.
NewWardleServerOptions
(
os
.
Stdout
,
os
.
Stderr
)
cmd
:=
server
.
NewCommandStartWardleServer
(
options
,
stopCh
)
cmd
.
Flags
()
.
AddGoFlagSet
(
flag
.
CommandLine
)
cmd
.
Flags
()
.
AddGoFlagSet
(
flag
.
CommandLine
)
if
err
:=
cmd
.
Execute
();
err
!=
nil
{
if
err
:=
cmd
.
Execute
();
err
!=
nil
{
glog
.
Fatal
(
err
)
glog
.
Fatal
(
err
)
...
...
staging/src/k8s.io/sample-apiserver/pkg/cmd/server/start.go
View file @
a6c43c6a
...
@@ -57,9 +57,9 @@ func NewWardleServerOptions(out, errOut io.Writer) *WardleServerOptions {
...
@@ -57,9 +57,9 @@ func NewWardleServerOptions(out, errOut io.Writer) *WardleServerOptions {
}
}
// NewCommandStartWardleServer provides a CLI handler for 'start master' command
// NewCommandStartWardleServer provides a CLI handler for 'start master' command
func
NewCommandStartWardleServer
(
out
,
errOut
io
.
Writer
,
stopCh
<-
chan
struct
{})
*
cobra
.
Command
{
// with a default WardleServerOptions.
o
:=
NewWardleServerOptions
(
out
,
errOut
)
func
NewCommandStartWardleServer
(
defaults
*
WardleServerOptions
,
stopCh
<-
chan
struct
{})
*
cobra
.
Command
{
o
:=
*
defaults
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Short
:
"Launch a wardle API server"
,
Short
:
"Launch a wardle API server"
,
Long
:
"Launch a wardle API server"
,
Long
:
"Launch a wardle API server"
,
...
...
test/integration/etcd/etcd_storage_path_test.go
View file @
a6c43c6a
...
@@ -41,6 +41,7 @@ import (
...
@@ -41,6 +41,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/util/wait"
genericapiserver
"k8s.io/apiserver/pkg/server"
genericapiserver
"k8s.io/apiserver/pkg/server"
genericapiserveroptions
"k8s.io/apiserver/pkg/server/options"
"k8s.io/apiserver/pkg/storage/storagebackend"
"k8s.io/apiserver/pkg/storage/storagebackend"
clientset
"k8s.io/client-go/kubernetes"
clientset
"k8s.io/client-go/kubernetes"
restclient
"k8s.io/client-go/rest"
restclient
"k8s.io/client-go/rest"
...
@@ -704,47 +705,41 @@ func startRealMasterOrDie(t *testing.T, certDir string) (*allClient, clientv3.KV
...
@@ -704,47 +705,41 @@ func startRealMasterOrDie(t *testing.T, certDir string) (*allClient, clientv3.KV
}
}
}()
}()
for
{
listener
,
_
,
err
:=
genericapiserveroptions
.
CreateListener
(
"tcp"
,
"127.0.0.1:0"
)
kubeAPIServerOptions
:=
options
.
NewServerRunOptions
()
if
err
!=
nil
{
kubeAPIServerOptions
.
SecureServing
.
BindAddress
=
net
.
ParseIP
(
"127.0.0.1"
)
t
.
Fatal
(
err
)
kubeAPIServerOptions
.
SecureServing
.
ServerCert
.
CertDirectory
=
certDir
}
kubeAPIServerOptions
.
Etcd
.
StorageConfig
.
ServerList
=
[]
string
{
framework
.
GetEtcdURL
()}
kubeAPIServerOptions
.
Etcd
.
DefaultStorageMediaType
=
runtime
.
ContentTypeJSON
// TODO use protobuf?
kubeAPIServerOptions
.
ServiceClusterIPRange
=
*
defaultServiceClusterIPRange
kubeAPIServerOptions
.
Authorization
.
Mode
=
"RBAC"
// always get a fresh port in case something claimed the old one
kubePort
,
err
:=
framework
.
FindFreeLocalPort
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
kubeAPIServerOptions
.
SecureServing
.
BindPort
=
kubePort
kubeAPIServerOptions
:=
options
.
NewServerRunOptions
()
tunneler
,
proxyTransport
,
err
:=
app
.
CreateNodeDialer
(
kubeAPIServerOptions
)
kubeAPIServerOptions
.
SecureServing
.
Listener
=
listener
if
err
!=
nil
{
kubeAPIServerOptions
.
SecureServing
.
ServerCert
.
CertDirectory
=
certDir
t
.
Fatal
(
err
)
kubeAPIServerOptions
.
Etcd
.
StorageConfig
.
ServerList
=
[]
string
{
framework
.
GetEtcdURL
()}
}
kubeAPIServerOptions
.
Etcd
.
DefaultStorageMediaType
=
runtime
.
ContentTypeJSON
// TODO use protobuf?
kubeAPIServerConfig
,
sharedInformers
,
versionedInformers
,
_
,
_
,
err
:=
app
.
CreateKubeAPIServerConfig
(
kubeAPIServerOptions
,
tunneler
,
proxyTransport
)
kubeAPIServerOptions
.
ServiceClusterIPRange
=
*
defaultServiceClusterIPRange
if
err
!=
nil
{
kubeAPIServerOptions
.
Authorization
.
Mode
=
"RBAC"
t
.
Fatal
(
err
)
}
kubeAPIServerConfig
.
ExtraConfig
.
APIResourceConfigSource
=
&
allResourceSource
{}
// force enable all resources
tunneler
,
proxyTransport
,
err
:=
app
.
CreateNodeDialer
(
kubeAPIServerOptions
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
kubeAPIServerConfig
,
sharedInformers
,
versionedInformers
,
_
,
_
,
err
:=
app
.
CreateKubeAPIServerConfig
(
kubeAPIServerOptions
,
tunneler
,
proxyTransport
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
kubeAPIServer
,
err
:=
app
.
CreateKubeAPIServer
(
kubeAPIServerConfig
,
genericapiserver
.
EmptyDelegate
,
sharedInformers
,
versionedInformers
)
kubeAPIServerConfig
.
ExtraConfig
.
APIResourceConfigSource
=
&
allResourceSource
{}
// force enable all resources
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
kubeClientConfigValue
.
Store
(
kubeAPIServerConfig
.
GenericConfig
.
LoopbackClientConfig
)
kubeAPIServer
,
err
:=
app
.
CreateKubeAPIServer
(
kubeAPIServerConfig
,
genericapiserver
.
EmptyDelegate
,
sharedInformers
,
versionedInformers
)
storageConfigValue
.
Store
(
kubeAPIServerOptions
.
Etcd
.
StorageConfig
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
kubeAPIServer
.
GenericAPIServer
.
PrepareRun
()
.
Run
(
wait
.
NeverStop
);
err
!=
nil
{
kubeClientConfigValue
.
Store
(
kubeAPIServerConfig
.
GenericConfig
.
LoopbackClientConfig
)
t
.
Log
(
err
)
storageConfigValue
.
Store
(
kubeAPIServerOptions
.
Etcd
.
StorageConfig
)
}
time
.
Sleep
(
time
.
Second
)
if
err
:=
kubeAPIServer
.
GenericAPIServer
.
PrepareRun
()
.
Run
(
wait
.
NeverStop
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
}()
}()
...
...
test/integration/examples/apiserver_test.go
View file @
a6c43c6a
This diff is collapsed.
Click to expand it.
test/integration/framework/master_utils.go
View file @
a6c43c6a
...
@@ -21,7 +21,6 @@ import (
...
@@ -21,7 +21,6 @@ import (
"net/http"
"net/http"
"net/http/httptest"
"net/http/httptest"
"path"
"path"
"strconv"
"time"
"time"
"github.com/go-openapi/spec"
"github.com/go-openapi/spec"
...
@@ -328,28 +327,6 @@ func RunAMasterUsingServer(masterConfig *master.Config, s *httptest.Server, mast
...
@@ -328,28 +327,6 @@ func RunAMasterUsingServer(masterConfig *master.Config, s *httptest.Server, mast
return
startMasterOrDie
(
masterConfig
,
s
,
masterReceiver
)
return
startMasterOrDie
(
masterConfig
,
s
,
masterReceiver
)
}
}
// FindFreeLocalPort returns the number of an available port number on
// the loopback interface. Useful for determining the port to launch
// a server on. Error handling required - there is a non-zero chance
// that the returned port number will be bound by another process
// after this function returns.
func
FindFreeLocalPort
()
(
int
,
error
)
{
l
,
err
:=
net
.
Listen
(
"tcp"
,
":0"
)
if
err
!=
nil
{
return
0
,
err
}
defer
l
.
Close
()
_
,
portStr
,
err
:=
net
.
SplitHostPort
(
l
.
Addr
()
.
String
())
if
err
!=
nil
{
return
0
,
err
}
port
,
err
:=
strconv
.
Atoi
(
portStr
)
if
err
!=
nil
{
return
0
,
err
}
return
port
,
nil
}
// SharedEtcd creates a storage config for a shared etcd instance, with a unique prefix.
// SharedEtcd creates a storage config for a shared etcd instance, with a unique prefix.
func
SharedEtcd
()
*
storagebackend
.
Config
{
func
SharedEtcd
()
*
storagebackend
.
Config
{
cfg
:=
storagebackend
.
NewDefaultConfig
(
path
.
Join
(
uuid
.
New
(),
"registry"
),
nil
)
cfg
:=
storagebackend
.
NewDefaultConfig
(
path
.
Join
(
uuid
.
New
(),
"registry"
),
nil
)
...
...
test/integration/tls/ciphers_test.go
View file @
a6c43c6a
...
@@ -29,6 +29,7 @@ import (
...
@@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/util/wait"
genericapiserver
"k8s.io/apiserver/pkg/server"
genericapiserver
"k8s.io/apiserver/pkg/server"
genericapiserveroptions
"k8s.io/apiserver/pkg/server/options"
client
"k8s.io/client-go/kubernetes"
client
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/rest"
"k8s.io/kubernetes/cmd/kube-apiserver/app"
"k8s.io/kubernetes/cmd/kube-apiserver/app"
...
@@ -44,17 +45,17 @@ func runBasicSecureAPIServer(t *testing.T, ciphers []string) (uint32, error) {
...
@@ -44,17 +45,17 @@ func runBasicSecureAPIServer(t *testing.T, ciphers []string) (uint32, error) {
var
kubePort
uint32
var
kubePort
uint32
go
func
()
{
go
func
()
{
// always get a fresh port in case something claimed the old one
listener
,
port
,
err
:=
genericapiserveroptions
.
CreateListener
(
"tcp"
,
"127.0.0.1:0"
)
freePort
,
err
:=
framework
.
FindFreeLocalPort
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
atomic
.
StoreUint32
(
&
kubePort
,
uint32
(
freeP
ort
))
atomic
.
StoreUint32
(
&
kubePort
,
uint32
(
p
ort
))
kubeAPIServerOptions
:=
options
.
NewServerRunOptions
()
kubeAPIServerOptions
:=
options
.
NewServerRunOptions
()
kubeAPIServerOptions
.
SecureServing
.
BindAddress
=
net
.
ParseIP
(
"127.0.0.1"
)
kubeAPIServerOptions
.
SecureServing
.
BindAddress
=
net
.
ParseIP
(
"127.0.0.1"
)
kubeAPIServerOptions
.
SecureServing
.
BindPort
=
freePort
kubeAPIServerOptions
.
SecureServing
.
BindPort
=
port
kubeAPIServerOptions
.
SecureServing
.
Listener
=
listener
kubeAPIServerOptions
.
SecureServing
.
ServerCert
.
CertDirectory
=
certDir
kubeAPIServerOptions
.
SecureServing
.
ServerCert
.
CertDirectory
=
certDir
kubeAPIServerOptions
.
SecureServing
.
CipherSuites
=
ciphers
kubeAPIServerOptions
.
SecureServing
.
CipherSuites
=
ciphers
kubeAPIServerOptions
.
InsecureServing
.
BindPort
=
0
kubeAPIServerOptions
.
InsecureServing
.
BindPort
=
0
...
...
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