From 6d08efb84912fce7b60377174d42ce2c0a7228d0 Mon Sep 17 00:00:00 2001 From: Sunny Date: Sun, 30 Sep 2018 15:09:53 +0530 Subject: [PATCH] envtest: export DefaultKubeAPIServerFlags & make it configurable This change exports DefaultKubeAPIServerFlags, allowing a user to append the default flags with other custom flags and set it to Environment.KubeAPIServerFlags. If KubeAPIServerFlags is not set, DefaultKubeAPIServerFlags is used when the API server starts. --- pkg/envtest/server.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/envtest/server.go b/pkg/envtest/server.go index 0d7da68855..b5f25850ec 100644 --- a/pkg/envtest/server.go +++ b/pkg/envtest/server.go @@ -46,9 +46,8 @@ func defaultAssetPath(binary string) string { } -// APIServerDefaultArgs are flags necessary to bring up apiserver. -// TODO: create test framework interface to append flag to default flags. -var defaultKubeAPIServerFlags = []string{ +// DefaultKubeAPIServerFlags are default flags necessary to bring up apiserver. +var DefaultKubeAPIServerFlags = []string{ "--etcd-servers={{ if .EtcdURL }}{{ .EtcdURL.String }}{{ end }}", "--cert-dir={{ .CertDir }}", "--insecure-port={{ if .URL }}{{ .URL.Port }}{{ end }}", @@ -76,6 +75,9 @@ type Environment struct { // existing kubeconfig, instead of trying to stand up a new control plane. // This is useful in cases that need aggregated API servers and the like. UseExistingCluster bool + + // KubeAPIServerFlags is the set of flags passed while starting the api server. + KubeAPIServerFlags []string } // Stop stops a running server @@ -88,6 +90,11 @@ func (te *Environment) Stop() error { // Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on func (te *Environment) Start() (*rest.Config, error) { + // Set default API server flags if not set. + if len(te.KubeAPIServerFlags) == 0 { + te.KubeAPIServerFlags = DefaultKubeAPIServerFlags + } + if te.UseExistingCluster { if te.Config == nil { // we want to allow people to pass in their own config, so @@ -101,7 +108,7 @@ func (te *Environment) Start() (*rest.Config, error) { } } else { te.ControlPlane = integration.ControlPlane{} - te.ControlPlane.APIServer = &integration.APIServer{Args: defaultKubeAPIServerFlags} + te.ControlPlane.APIServer = &integration.APIServer{Args: te.KubeAPIServerFlags} if os.Getenv(envKubeAPIServerBin) == "" { te.ControlPlane.APIServer.Path = defaultAssetPath("kube-apiserver") }