Skip to content

Commit d0ead81

Browse files
committed
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.
1 parent 9d3345d commit d0ead81

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

pkg/envtest/server.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ func defaultAssetPath(binary string) string {
5353

5454
}
5555

56-
// APIServerDefaultArgs are flags necessary to bring up apiserver.
57-
// TODO: create test framework interface to append flag to default flags.
58-
var defaultKubeAPIServerFlags = []string{
56+
// DefaultKubeAPIServerFlags are default flags necessary to bring up apiserver.
57+
var DefaultKubeAPIServerFlags = []string{
5958
"--etcd-servers={{ if .EtcdURL }}{{ .EtcdURL.String }}{{ end }}",
6059
"--cert-dir={{ .CertDir }}",
6160
"--insecure-port={{ if .URL }}{{ .URL.Port }}{{ end }}",
@@ -93,6 +92,9 @@ type Environment struct {
9392
// may take to stop. It defaults to the KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT
9493
// environment variable or 20 seconds if unspecified
9594
ControlPlaneStopTimeout time.Duration
95+
96+
// KubeAPIServerFlags is the set of flags passed while starting the api server.
97+
KubeAPIServerFlags []string
9698
}
9799

98100
// Stop stops a running server
@@ -103,6 +105,15 @@ func (te *Environment) Stop() error {
103105
return te.ControlPlane.Stop()
104106
}
105107

108+
// getAPIServerFlags returns flags to be used with the Kubernetes API server.
109+
func (te Environment) getAPIServerFlags() []string {
110+
// Set default API server flags if not set.
111+
if len(te.KubeAPIServerFlags) == 0 {
112+
return DefaultKubeAPIServerFlags
113+
}
114+
return te.KubeAPIServerFlags
115+
}
116+
106117
// Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on
107118
func (te *Environment) Start() (*rest.Config, error) {
108119
if te.UseExistingCluster {
@@ -118,7 +129,7 @@ func (te *Environment) Start() (*rest.Config, error) {
118129
}
119130
} else {
120131
te.ControlPlane = integration.ControlPlane{}
121-
te.ControlPlane.APIServer = &integration.APIServer{Args: defaultKubeAPIServerFlags}
132+
te.ControlPlane.APIServer = &integration.APIServer{Args: te.getAPIServerFlags()}
122133
te.ControlPlane.Etcd = &integration.Etcd{}
123134

124135
if os.Getenv(envKubeAPIServerBin) == "" {

0 commit comments

Comments
 (0)