Skip to content

Commit 2245c64

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 4376e6e commit 2245c64

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pkg/envtest/server.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ func defaultAssetPath(binary string) string {
5252

5353
}
5454

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

9799
// Stop stops a running server
@@ -104,6 +106,11 @@ func (te *Environment) Stop() error {
104106

105107
// Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on
106108
func (te *Environment) Start() (*rest.Config, error) {
109+
// Set default API server flags if not set.
110+
if len(te.KubeAPIServerFlags) == 0 {
111+
te.KubeAPIServerFlags = DefaultKubeAPIServerFlags
112+
}
113+
107114
if te.UseExistingCluster {
108115
if te.Config == nil {
109116
// we want to allow people to pass in their own config, so
@@ -117,8 +124,7 @@ func (te *Environment) Start() (*rest.Config, error) {
117124
}
118125
} else {
119126
te.ControlPlane = integration.ControlPlane{}
120-
te.ControlPlane.APIServer = &integration.APIServer{Args: defaultKubeAPIServerFlags}
121-
127+
te.ControlPlane.APIServer = &integration.APIServer{Args: te.KubeAPIServerFlags}
122128
if os.Getenv(envKubeAPIServerBin) == "" {
123129
te.ControlPlane.APIServer.Path = defaultAssetPath("kube-apiserver")
124130
}

0 commit comments

Comments
 (0)