Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

envtest: export DefaultKubeAPIServerFlags & make flags configurable #165

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need to export this anymore given that we have made KubeAPIServerFlag configurable (change below) ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, because we still want to allow people to make use of the default args if they just want to append.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification.

"--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