Skip to content

Commit

Permalink
Merge pull request #165 from darkowlzz/112-AppendKubeAPIServerFlags
Browse files Browse the repository at this point in the history
envtest: export DefaultKubeAPIServerFlags & make flags configurable
  • Loading branch information
k8s-ci-robot committed Nov 7, 2018
2 parents 86b3a15 + d0ead81 commit 81f67a0
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pkg/envtest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,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 @@ -93,6 +92,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 @@ -103,6 +105,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 @@ -118,7 +129,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()}
te.ControlPlane.Etcd = &integration.Etcd{}

if os.Getenv(envKubeAPIServerBin) == "" {
Expand Down

0 comments on commit 81f67a0

Please sign in to comment.