Skip to content

Commit

Permalink
envtest: export DefaultKubeAPIServerFlags & make it configurable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
darkowlzz committed Oct 25, 2018
1 parent 4376e6e commit d04f63b
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/envtest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,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 }}",
Expand Down Expand Up @@ -92,6 +91,9 @@ type Environment struct {
// may take to stop. It defaults to the KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT
// environment variable or 20 seconds if unspecified
ControlPlaneStopTimeout time.Duration

// KubeAPIServerFlags is the set of flags passed while starting the api server.
KubeAPIServerFlags []string
}

// Stop stops a running server
Expand All @@ -102,6 +104,15 @@ func (te *Environment) Stop() error {
return te.ControlPlane.Stop()
}

// getAPIServerFlags returns flags to be used with the Kubernetes API server.
func (te Environment) getAPIServerFlags() []string {
// Set default API server flags if not set.
if len(te.KubeAPIServerFlags) == 0 {
return DefaultKubeAPIServerFlags
}
return te.KubeAPIServerFlags
}

// Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on
func (te *Environment) Start() (*rest.Config, error) {
if te.UseExistingCluster {
Expand All @@ -117,8 +128,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.getAPIServerFlags()}
if os.Getenv(envKubeAPIServerBin) == "" {
te.ControlPlane.APIServer.Path = defaultAssetPath("kube-apiserver")
}
Expand Down

0 comments on commit d04f63b

Please sign in to comment.