@@ -30,6 +30,7 @@ import (
30
30
"k8s.io/client-go/pkg/version"
31
31
openapicommon "k8s.io/kube-openapi/pkg/common"
32
32
33
+ "k8s.io/apiserver/pkg/server/dynamiccertificates"
33
34
v1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
34
35
v1helper "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1/helper"
35
36
"k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1"
@@ -64,8 +65,8 @@ const legacyAPIServiceName = "v1."
64
65
type ExtraConfig struct {
65
66
// ProxyClientCert/Key are the client cert used to identify this proxy. Backing APIServices use
66
67
// this to confirm the proxy's identity
67
- ProxyClientCert [] byte
68
- ProxyClientKey [] byte
68
+ ProxyClientCertFile string
69
+ ProxyClientKeyFile string
69
70
70
71
// If present, the Dial method will be used for dialing out to delegate
71
72
// apiservers.
@@ -108,11 +109,9 @@ type APIAggregator struct {
108
109
109
110
delegateHandler http.Handler
110
111
111
- // proxyClientCert/Key are the client cert used to identify this proxy. Backing APIServices use
112
- // this to confirm the proxy's identity
113
- proxyClientCert []byte
114
- proxyClientKey []byte
115
- proxyTransport * http.Transport
112
+ // proxyCurrentCertKeyContent holds he client cert used to identify this proxy. Backing APIServices use this to confirm the proxy's identity
113
+ proxyCurrentCertKeyContent certKeyFunc
114
+ proxyTransport * http.Transport
116
115
117
116
// proxyHandlers are the proxy handlers that are currently registered, keyed by apiservice.name
118
117
proxyHandlers map [string ]* proxyHandler
@@ -178,18 +177,17 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
178
177
)
179
178
180
179
s := & APIAggregator {
181
- GenericAPIServer : genericServer ,
182
- delegateHandler : delegationTarget .UnprotectedHandler (),
183
- proxyClientCert : c .ExtraConfig .ProxyClientCert ,
184
- proxyClientKey : c .ExtraConfig .ProxyClientKey ,
185
- proxyTransport : c .ExtraConfig .ProxyTransport ,
186
- proxyHandlers : map [string ]* proxyHandler {},
187
- handledGroups : sets.String {},
188
- lister : informerFactory .Apiregistration ().V1 ().APIServices ().Lister (),
189
- APIRegistrationInformers : informerFactory ,
190
- serviceResolver : c .ExtraConfig .ServiceResolver ,
191
- openAPIConfig : openAPIConfig ,
192
- egressSelector : c .GenericConfig .EgressSelector ,
180
+ GenericAPIServer : genericServer ,
181
+ delegateHandler : delegationTarget .UnprotectedHandler (),
182
+ proxyTransport : c .ExtraConfig .ProxyTransport ,
183
+ proxyHandlers : map [string ]* proxyHandler {},
184
+ handledGroups : sets.String {},
185
+ lister : informerFactory .Apiregistration ().V1 ().APIServices ().Lister (),
186
+ APIRegistrationInformers : informerFactory ,
187
+ serviceResolver : c .ExtraConfig .ServiceResolver ,
188
+ openAPIConfig : openAPIConfig ,
189
+ egressSelector : c .GenericConfig .EgressSelector ,
190
+ proxyCurrentCertKeyContent : func () (bytes []byte , bytes2 []byte ) { return nil , nil },
193
191
}
194
192
195
193
apiGroupInfo := apiservicerest .NewRESTStorage (c .GenericConfig .MergedResourceConfig , c .GenericConfig .RESTOptionsGetter )
@@ -214,14 +212,30 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
214
212
s .GenericAPIServer .Handler .NonGoRestfulMux .UnlistedHandle ("/apis/" , apisHandler )
215
213
216
214
apiserviceRegistrationController := NewAPIServiceRegistrationController (informerFactory .Apiregistration ().V1 ().APIServices (), s )
215
+ if len (c .ExtraConfig .ProxyClientCertFile ) > 0 && len (c .ExtraConfig .ProxyClientKeyFile ) > 0 {
216
+ aggregatorProxyCerts , err := dynamiccertificates .NewDynamicServingContentFromFiles ("aggregator-proxy-cert" , c .ExtraConfig .ProxyClientCertFile , c .ExtraConfig .ProxyClientKeyFile )
217
+ if err != nil {
218
+ return nil , err
219
+ }
220
+ if err := aggregatorProxyCerts .RunOnce (); err != nil {
221
+ return nil , err
222
+ }
223
+ aggregatorProxyCerts .AddListener (apiserviceRegistrationController )
224
+ s .proxyCurrentCertKeyContent = aggregatorProxyCerts .CurrentCertKeyContent
225
+
226
+ s .GenericAPIServer .AddPostStartHookOrDie ("aggregator-reload-proxy-client-cert" , func (context genericapiserver.PostStartHookContext ) error {
227
+ go aggregatorProxyCerts .Run (1 , context .StopCh )
228
+ return nil
229
+ })
230
+ }
231
+
217
232
availableController , err := statuscontrollers .NewAvailableConditionController (
218
233
informerFactory .Apiregistration ().V1 ().APIServices (),
219
234
c .GenericConfig .SharedInformerFactory .Core ().V1 ().Services (),
220
235
c .GenericConfig .SharedInformerFactory .Core ().V1 ().Endpoints (),
221
236
apiregistrationClient .ApiregistrationV1 (),
222
237
c .ExtraConfig .ProxyTransport ,
223
- c .ExtraConfig .ProxyClientCert ,
224
- c .ExtraConfig .ProxyClientKey ,
238
+ (func () ([]byte , []byte ))(s .proxyCurrentCertKeyContent ),
225
239
s .serviceResolver ,
226
240
c .GenericConfig .EgressSelector ,
227
241
)
@@ -309,12 +323,11 @@ func (s *APIAggregator) AddAPIService(apiService *v1.APIService) error {
309
323
310
324
// register the proxy handler
311
325
proxyHandler := & proxyHandler {
312
- localDelegate : s .delegateHandler ,
313
- proxyClientCert : s .proxyClientCert ,
314
- proxyClientKey : s .proxyClientKey ,
315
- proxyTransport : s .proxyTransport ,
316
- serviceResolver : s .serviceResolver ,
317
- egressSelector : s .egressSelector ,
326
+ localDelegate : s .delegateHandler ,
327
+ proxyCurrentCertKeyContent : s .proxyCurrentCertKeyContent ,
328
+ proxyTransport : s .proxyTransport ,
329
+ serviceResolver : s .serviceResolver ,
330
+ egressSelector : s .egressSelector ,
318
331
}
319
332
proxyHandler .updateAPIService (apiService )
320
333
if s .openAPIAggregationController != nil {
0 commit comments