Skip to content

Commit 6d08efb

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 ddf0390 commit 6d08efb

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

pkg/envtest/server.go

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

4747
}
4848

49-
// APIServerDefaultArgs are flags necessary to bring up apiserver.
50-
// TODO: create test framework interface to append flag to default flags.
51-
var defaultKubeAPIServerFlags = []string{
49+
// DefaultKubeAPIServerFlags are default flags necessary to bring up apiserver.
50+
var DefaultKubeAPIServerFlags = []string{
5251
"--etcd-servers={{ if .EtcdURL }}{{ .EtcdURL.String }}{{ end }}",
5352
"--cert-dir={{ .CertDir }}",
5453
"--insecure-port={{ if .URL }}{{ .URL.Port }}{{ end }}",
@@ -76,6 +75,9 @@ type Environment struct {
7675
// existing kubeconfig, instead of trying to stand up a new control plane.
7776
// This is useful in cases that need aggregated API servers and the like.
7877
UseExistingCluster bool
78+
79+
// KubeAPIServerFlags is the set of flags passed while starting the api server.
80+
KubeAPIServerFlags []string
7981
}
8082

8183
// Stop stops a running server
@@ -88,6 +90,11 @@ func (te *Environment) Stop() error {
8890

8991
// Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on
9092
func (te *Environment) Start() (*rest.Config, error) {
93+
// Set default API server flags if not set.
94+
if len(te.KubeAPIServerFlags) == 0 {
95+
te.KubeAPIServerFlags = DefaultKubeAPIServerFlags
96+
}
97+
9198
if te.UseExistingCluster {
9299
if te.Config == nil {
93100
// we want to allow people to pass in their own config, so
@@ -101,7 +108,7 @@ func (te *Environment) Start() (*rest.Config, error) {
101108
}
102109
} else {
103110
te.ControlPlane = integration.ControlPlane{}
104-
te.ControlPlane.APIServer = &integration.APIServer{Args: defaultKubeAPIServerFlags}
111+
te.ControlPlane.APIServer = &integration.APIServer{Args: te.KubeAPIServerFlags}
105112
if os.Getenv(envKubeAPIServerBin) == "" {
106113
te.ControlPlane.APIServer.Path = defaultAssetPath("kube-apiserver")
107114
}

0 commit comments

Comments
 (0)