diff --git a/Gopkg.lock b/Gopkg.lock index c9ce2f8cab..622557b36c 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -891,14 +891,16 @@ revision = "e3762e86a74c878ffed47484592986685639c2cd" [[projects]] - digest = "1:16c26aad2883eddb0caa103f510401b468e71ae8854b93c340de63bd57015002" + digest = "1:9070222ca967d09b3966552a161dd4420d62315964bf5e1efd8cc4c7c30ebca8" name = "sigs.k8s.io/testing_frameworks" packages = [ "integration", + "integration/addr", "integration/internal", ] pruneopts = "UT" - revision = "f53464b8b84b4507805a0b033a8377b225163fea" + revision = "d348cb12705b516376e0c323bacca72b00a78425" + version = "v0.1.1" [solve-meta] analyzer-name = "dep" diff --git a/Gopkg.toml b/Gopkg.toml index b92ddd0d65..f75ea91105 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -44,6 +44,10 @@ required = ["sigs.k8s.io/testing_frameworks/integration", name = "k8s.io/client-go" version = "kubernetes-1.12.3" +[[constraint]] + name = "sigs.k8s.io/testing_frameworks" + version = "v0.1.1" + [[constraint]] name = "github.com/onsi/ginkgo" version = "v1.5.0" @@ -67,9 +71,6 @@ required = ["sigs.k8s.io/testing_frameworks/integration", # these are not listed explicitly until we get version tags, # since dep doesn't like bare revision dependencies -# [[constraint]] -# name = "sigs.k8s.io/testing_frameworks" -# # [[constraint]] # name = "github.com/go-logr/logr" # diff --git a/vendor/sigs.k8s.io/testing_frameworks/integration/addr/manager.go b/vendor/sigs.k8s.io/testing_frameworks/integration/addr/manager.go new file mode 100644 index 0000000000..7523ce860c --- /dev/null +++ b/vendor/sigs.k8s.io/testing_frameworks/integration/addr/manager.go @@ -0,0 +1,24 @@ +package addr + +import ( + "net" +) + +// Suggest suggests a address a process can listen on. It returns +// a tuple consisting of a free port and the hostname resolved to its IP. +func Suggest() (port int, resolvedHost string, err error) { + addr, err := net.ResolveTCPAddr("tcp", "localhost:0") + if err != nil { + return + } + l, err := net.ListenTCP("tcp", addr) + if err != nil { + return + } + port = l.Addr().(*net.TCPAddr).Port + defer func() { + err = l.Close() + }() + resolvedHost = addr.IP.String() + return +} diff --git a/vendor/sigs.k8s.io/testing_frameworks/integration/apiserver.go b/vendor/sigs.k8s.io/testing_frameworks/integration/apiserver.go index 3bf2d81b6c..4f1e28267d 100644 --- a/vendor/sigs.k8s.io/testing_frameworks/integration/apiserver.go +++ b/vendor/sigs.k8s.io/testing_frameworks/integration/apiserver.go @@ -6,6 +6,7 @@ import ( "net/url" "time" + "sigs.k8s.io/testing_frameworks/integration/addr" "sigs.k8s.io/testing_frameworks/integration/internal" ) @@ -16,6 +17,9 @@ type APIServer struct { // If this is not specified, we default to a random free port on localhost. URL *url.URL + // SecurePort is the additional secure port that the APIServer should listen on. + SecurePort int + // Path is the path to the apiserver binary. // // If this is left as the empty string, we will attempt to locate a binary, @@ -87,6 +91,14 @@ func (s *APIServer) Start() error { return err } + // Defaulting the secure port + if s.SecurePort == 0 { + s.SecurePort, _, err = addr.Suggest() + if err != nil { + return err + } + } + s.processState.HealthCheckEndpoint = "/healthz" s.URL = &s.processState.URL @@ -110,3 +122,10 @@ func (s *APIServer) Start() error { func (s *APIServer) Stop() error { return s.processState.Stop() } + +// APIServerDefaultArgs exposes the default args for the APIServer so that you +// can use those to append your own additional arguments. +// +// The internal default arguments are explicitely copied here, we don't want to +// allow users to change the internal ones. +var APIServerDefaultArgs = append([]string{}, internal.APIServerDefaultArgs...) diff --git a/vendor/sigs.k8s.io/testing_frameworks/integration/doc.go b/vendor/sigs.k8s.io/testing_frameworks/integration/doc.go index 01bc5ce558..bbd88d94a9 100644 --- a/vendor/sigs.k8s.io/testing_frameworks/integration/doc.go +++ b/vendor/sigs.k8s.io/testing_frameworks/integration/doc.go @@ -78,7 +78,7 @@ location (`${FRAMEWORK_DIR}/assets/bin/`). Arguments for Etcd and APIServer -Those components will start without any configuration. However, if you want our +Those components will start without any configuration. However, if you want or need to, you can override certain configuration -- one of which are the arguments used when calling the binary. @@ -86,6 +86,13 @@ When you choose to specify your own set of arguments, those won't be appended to the default set of arguments, it is your responsibility to provide all the arguments needed for the binary to start successfully. +However, the default arguments for APIServer and Etcd are exported as +`APIServerDefaultArgs` and `EtcdDefaultArgs` from this package. Treat those +variables as read-only constants. Internally we have a set of default +arguments for defaulting, the `APIServerDefaultArgs` and `EtcdDefaultArgs` are +just copies of those. So when you override them you loose access to the actual +internal default arguments, but your override won't affect the defaulting. + All arguments are interpreted as go templates. Those templates have access to all exported fields of the `APIServer`/`Etcd` struct. It does not matter if those fields where explicitly set up or if they were defaulted by calling the @@ -93,19 +100,18 @@ those fields where explicitly set up or if they were defaulted by calling the executed and right after the defaulting of all the struct's fields has happened. - // All arguments needed for a successful start must be specified - etcdArgs := []string{ - "--listen-peer-urls=http://localhost:0", - "--advertise-client-urls={{ .URL.String }}", - "--listen-client-urls={{ .URL.String }}", - "--data-dir={{ .DataDir }}", - // add some custom arguments - "--this-is-my-very-important-custom-argument", - "--arguments-dont-have-to-be-templates=but they can", + // When you want to append additional arguments ... + etcd := &Etcd{ + // Additional custom arguments will appended to the set of default + // arguments + Args: append(EtcdDefaultArgs, "--additional=arg"), + DataDir: "/my/special/data/dir", } + // When you want to use a custom set of arguments ... etcd := &Etcd{ - Args: etcdArgs, + // Only custom arguments will be passed to the binary + Args: []string{"--one=1", "--two=2", "--three=3"}, DataDir: "/my/special/data/dir", } diff --git a/vendor/sigs.k8s.io/testing_frameworks/integration/etcd.go b/vendor/sigs.k8s.io/testing_frameworks/integration/etcd.go index 7bfa758e29..43cb314d7b 100644 --- a/vendor/sigs.k8s.io/testing_frameworks/integration/etcd.go +++ b/vendor/sigs.k8s.io/testing_frameworks/integration/etcd.go @@ -100,3 +100,10 @@ func (e *Etcd) Start() error { func (e *Etcd) Stop() error { return e.processState.Stop() } + +// EtcdDefaultArgs exposes the default args for Etcd so that you +// can use those to append your own additional arguments. +// +// The internal default arguments are explicitely copied here, we don't want to +// allow users to change the internal ones. +var EtcdDefaultArgs = append([]string{}, internal.EtcdDefaultArgs...) diff --git a/vendor/sigs.k8s.io/testing_frameworks/integration/internal/address_manager.go b/vendor/sigs.k8s.io/testing_frameworks/integration/internal/address_manager.go deleted file mode 100644 index 7ad4ab7eaa..0000000000 --- a/vendor/sigs.k8s.io/testing_frameworks/integration/internal/address_manager.go +++ /dev/null @@ -1,53 +0,0 @@ -package internal - -import ( - "fmt" - "net" -) - -// AddressManager allocates a new address (interface & port) a process -// can bind and keeps track of that. -type AddressManager struct { - port int - host string -} - -// Initialize returns a address a process can listen on. It returns -// a tuple consisting of a free port and the hostname resolved to its IP. -func (d *AddressManager) Initialize() (port int, resolvedHost string, err error) { - if d.port != 0 { - return 0, "", fmt.Errorf("this AddressManager is already initialized") - } - addr, err := net.ResolveTCPAddr("tcp", "localhost:0") - if err != nil { - return - } - l, err := net.ListenTCP("tcp", addr) - if err != nil { - return - } - d.port = l.Addr().(*net.TCPAddr).Port - defer func() { - err = l.Close() - }() - d.host = addr.IP.String() - return d.port, d.host, nil -} - -// Port returns the port that this AddressManager is managing. Port returns an -// error if this AddressManager has not yet been initialized. -func (d *AddressManager) Port() (int, error) { - if d.port == 0 { - return 0, fmt.Errorf("this AdressManager is not initialized yet") - } - return d.port, nil -} - -// Host returns the host that this AddressManager is managing. Host returns an -// error if this AddressManager has not yet been initialized. -func (d *AddressManager) Host() (string, error) { - if d.host == "" { - return "", fmt.Errorf("this AdressManager is not initialized yet") - } - return d.host, nil -} diff --git a/vendor/sigs.k8s.io/testing_frameworks/integration/internal/apiserver.go b/vendor/sigs.k8s.io/testing_frameworks/integration/internal/apiserver.go index a5256aee08..68a54dc751 100644 --- a/vendor/sigs.k8s.io/testing_frameworks/integration/internal/apiserver.go +++ b/vendor/sigs.k8s.io/testing_frameworks/integration/internal/apiserver.go @@ -5,7 +5,7 @@ var APIServerDefaultArgs = []string{ "--cert-dir={{ .CertDir }}", "--insecure-port={{ if .URL }}{{ .URL.Port }}{{ end }}", "--insecure-bind-address={{ if .URL }}{{ .URL.Hostname }}{{ end }}", - "--secure-port=0", + "--secure-port={{ if .SecurePort }}{{ .SecurePort }}{{ end }}", } func DoAPIServerArgDefaulting(args []string) []string { diff --git a/vendor/sigs.k8s.io/testing_frameworks/integration/internal/process.go b/vendor/sigs.k8s.io/testing_frameworks/integration/internal/process.go index 620c6a99c5..d7a0885668 100644 --- a/vendor/sigs.k8s.io/testing_frameworks/integration/internal/process.go +++ b/vendor/sigs.k8s.io/testing_frameworks/integration/internal/process.go @@ -13,6 +13,8 @@ import ( "github.com/onsi/gomega/gbytes" "github.com/onsi/gomega/gexec" + + "sigs.k8s.io/testing_frameworks/integration/addr" ) type ProcessState struct { @@ -63,8 +65,7 @@ func DoDefaulting( } if listenUrl == nil { - am := &AddressManager{} - port, host, err := am.Initialize() + port, host, err := addr.Suggest() if err != nil { return DefaultedProcessInput{}, err }