Skip to content

Commit 034f8e3

Browse files
committed
envtest expose 'SecureConfig' for user conveinience.
Please note that this just contains secure endpoint itself and its CA certs. User will have to set authentication information by themselves and configure some authn module in kube-apiserver.
1 parent b231ddb commit 034f8e3

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

pkg/envtest/server.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,34 @@ type Environment struct {
8787
// ControlPlane is the ControlPlane including the apiserver and etcd
8888
ControlPlane integration.ControlPlane
8989

90-
// Config can be used to talk to the apiserver. It's automatically
91-
// populated if not set using the standard controller-runtime config
90+
// Config can be used to talk to the apiserver (insecure endpoint).
91+
// It's automatically populated if not set using the standard controller-runtime config
9292
// loading.
9393
Config *rest.Config
9494

95+
// SecureConfig can be used to talk to the apiserver (secure endpoint).
96+
// It's automatically populated if not set using the standard controller-runtime config
97+
// loading. This just contains secure endpoint and tlsconfig (no authn info).
98+
// To use this config, you have to configure kube-apiserver with some authn module(static token, basic auth, etc.)
99+
// and set your authentication info to this config. For example:
100+
//
101+
// // basic authn plugin case
102+
// te := &envtest.Environment{
103+
// KubeAPIServerFlags: append(
104+
// envtest.DefaultKubeAPIServerFlags,
105+
// "--basic-auth-file=my-file", "--authorization-mode=RBAC",
106+
// ),
107+
// }
108+
// te.Start()
109+
//
110+
// cfg := rest.CopyConfig(te.SecureConfig)
111+
// cfg.Username = "myname"
112+
// cfg.Password = "mypassword"
113+
//
114+
// // This client can send a request as "myname" user.
115+
// cli := client.New(cfg)
116+
SecureConfig *rest.Config
117+
95118
// CRDInstallOptions are the options for installing CRDs.
96119
CRDInstallOptions CRDInstallOptions
97120

@@ -249,6 +272,13 @@ func (te *Environment) Start() (*rest.Config, error) {
249272
QPS: 1000.0,
250273
Burst: 2000.0,
251274
}
275+
te.SecureConfig = &rest.Config{
276+
Host: fmt.Sprintf("%s:%d", te.ControlPlane.APIURL().Hostname(), te.ControlPlane.APIServer.SecurePort),
277+
TLSClientConfig: te.ControlPlane.APIServer.TLSClientConfig,
278+
// gotta go fast during tests -- we don't really care about overwhelming our test API server
279+
QPS: 1000.0,
280+
Burst: 2000.0,
281+
}
252282
}
253283

254284
log.V(1).Info("installing CRDs")

pkg/internal/testing/integration/apiserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type APIServer struct {
2525
SecurePort int
2626

2727
// TLSconfig is tls configuration to connect to its secure endpoint.
28-
TlsClientConfig rest.TLSClientConfig
28+
TLSClientConfig rest.TLSClientConfig
2929

3030
// Path is the path to the apiserver binary.
3131
//
@@ -161,7 +161,7 @@ func (s *APIServer) populateAPIServerCerts() error {
161161
return err
162162
}
163163

164-
s.TlsClientConfig = rest.TLSClientConfig{
164+
s.TLSClientConfig = rest.TLSClientConfig{
165165
CAData: ca.CA.CertBytes(),
166166
}
167167

0 commit comments

Comments
 (0)