mirror of https://github.com/k3s-io/k3s
Merge pull request #58940 from hanxiaoshuai/bugfix
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. pass listener in apiextentions-apiserver test to prevent port in use … **What this PR does / why we need it**: pass listener to SecureServingOptions to prevent port in use flake. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # partially fix [58936](https://github.com/kubernetes/kubernetes/issues/58936) **Special notes for your reviewer**: /assign @hzxuzhonghu @liggitt @sttts @caesarxuchaopull/6/head
commit
5d457dbd3c
|
@ -26,6 +26,7 @@ go_library(
|
|||
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
|
||||
"//vendor/k8s.io/apiserver/pkg/server:go_default_library",
|
||||
"//vendor/k8s.io/apiserver/pkg/server/options:go_default_library",
|
||||
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
|
||||
"//vendor/k8s.io/client-go/dynamic:go_default_library",
|
||||
],
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/pborman/uuid"
|
||||
|
@ -31,11 +30,12 @@ import (
|
|||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
genericapiserver "k8s.io/apiserver/pkg/server"
|
||||
genericapiserveroptions "k8s.io/apiserver/pkg/server/options"
|
||||
"k8s.io/client-go/dynamic"
|
||||
)
|
||||
|
||||
func DefaultServerConfig() (*extensionsapiserver.Config, error) {
|
||||
port, err := FindFreeLocalPort()
|
||||
listener, port, err := genericapiserveroptions.CreateListener("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ func DefaultServerConfig() (*extensionsapiserver.Config, error) {
|
|||
options.RecommendedOptions.Authorization = nil // disable
|
||||
options.RecommendedOptions.Admission = nil // disable
|
||||
options.RecommendedOptions.SecureServing.BindAddress = net.ParseIP("127.0.0.1")
|
||||
options.RecommendedOptions.SecureServing.Listener = listener
|
||||
etcdURL, ok := os.LookupEnv("KUBE_INTEGRATION_ETCD_URL")
|
||||
if !ok {
|
||||
etcdURL = "http://127.0.0.1:2379"
|
||||
|
@ -145,25 +146,3 @@ func StartDefaultServer() (chan struct{}, clientset.Interface, dynamic.ClientPoo
|
|||
|
||||
return StartServer(config)
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue