@@ -28,8 +28,10 @@ import (
28
28
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
29
29
"k8s.io/apiserver/pkg/admission"
30
30
genericapifilters "k8s.io/apiserver/pkg/endpoints/filters"
31
+ "k8s.io/apiserver/pkg/reconcilers"
31
32
genericapiserver "k8s.io/apiserver/pkg/server"
32
33
genericoptions "k8s.io/apiserver/pkg/server/options"
34
+ serverstorage "k8s.io/apiserver/pkg/server/storage"
33
35
"k8s.io/apiserver/pkg/storage/storagebackend"
34
36
utilfeature "k8s.io/apiserver/pkg/util/feature"
35
37
"k8s.io/apiserver/pkg/util/notfoundhandler"
@@ -46,10 +48,12 @@ import (
46
48
aggregatorscheme "k8s.io/kube-aggregator/pkg/apiserver/scheme"
47
49
"k8s.io/kube-openapi/pkg/common"
48
50
"k8s.io/kubernetes/pkg/api/legacyscheme"
51
+ api "k8s.io/kubernetes/pkg/apis/core"
49
52
"k8s.io/kubernetes/pkg/features"
50
53
51
54
"github.com/onexstack/onex/cmd/onex-apiserver/app/options"
52
55
"github.com/onexstack/onex/internal/controlplane"
56
+ "github.com/onexstack/onex/internal/controlplane/apiserver"
53
57
controlplaneapiserver "github.com/onexstack/onex/internal/controlplane/apiserver"
54
58
"github.com/onexstack/onex/pkg/apiserver/storage"
55
59
"github.com/onexstack/onexstack/pkg/version"
@@ -59,8 +63,10 @@ func init() {
59
63
utilruntime .Must (logsapi .AddFeatureGates (utilfeature .DefaultMutableFeatureGate ))
60
64
}
61
65
62
- type Option func (* options.ServerRunOptions )
63
- type RegisterFunc func (plugins * admission.Plugins )
66
+ type (
67
+ Option func (* options.ServerRunOptions )
68
+ RegisterFunc func (plugins * admission.Plugins )
69
+ )
64
70
65
71
// WithLegacyCode returns an Option that sets the external group versions in the ServerRunOptions.
66
72
func WithEtcdOptions (prefix string , versions ... schema.GroupVersion ) Option {
@@ -112,13 +118,6 @@ func WithPostStartHook(name string, hook genericapiserver.PostStartHookFunc) Opt
112
118
}
113
119
}
114
120
115
- // WithSharedInformerFactory returns an Option function that sets the external SharedInformerFactory in the ServerRunOptions.
116
- func WithSharedInformerFactory (informers controlplane.ExternalSharedInformerFactory ) Option {
117
- return func (s * options.ServerRunOptions ) {
118
- s .ExternalVersionedInformers = informers
119
- }
120
- }
121
-
122
121
// WithRESTStorageProviders returns an Option function that sets the external REST storage providers in the ServerRunOptions.
123
122
func WithRESTStorageProviders (providers ... storage.RESTStorageProvider ) Option {
124
123
return func (s * options.ServerRunOptions ) {
@@ -238,7 +237,7 @@ func Run(ctx context.Context, opts options.CompletedOptions) error {
238
237
239
238
// CreateServerChain creates the apiservers connected via delegation.
240
239
func CreateServerChain (config CompletedConfig ) (* aggregatorapiserver.APIAggregator , error ) {
241
- notFoundHandler := notfoundhandler .New (config .KubeAPIs .GenericConfig .Serializer , genericapifilters .NoMuxAndDiscoveryIncompleteKey )
240
+ notFoundHandler := notfoundhandler .New (config .KubeAPIs .Generic .Serializer , genericapifilters .NoMuxAndDiscoveryIncompleteKey )
242
241
apiExtensionsServer , err := config .ApiExtensions .New (genericapiserver .NewEmptyDelegateWithCustomHandler (notFoundHandler ))
243
242
if err != nil {
244
243
return nil , err
@@ -292,43 +291,41 @@ func CreateOneXAPIServerConfig(opts options.CompletedOptions) (
292
291
opts .Metrics .Apply ()
293
292
294
293
config := & controlplane.Config {
295
- GenericConfig : genericConfig ,
296
- ExtraConfig : controlplane.ExtraConfig {
294
+ Generic : genericConfig ,
295
+ Extra : controlplane.Extra {
297
296
APIResourceConfigSource : storageFactory .APIResourceConfigSource ,
298
297
StorageFactory : storageFactory ,
299
298
EventTTL : opts .EventTTL ,
300
299
EnableLogsSupport : opts .EnableLogsHandler ,
301
300
ProxyTransport : proxyTransport ,
302
- //ExternalGroupResources: opts.ExternalGroupResources,
301
+ // ExternalGroupResources: opts.ExternalGroupResources,
303
302
ExternalRESTStorageProviders : opts .ExternalRESTStorageProviders ,
304
303
MasterCount : opts .MasterCount ,
305
- //VersionedInformers: opts.SharedInformerFactory,
304
+ // VersionedInformers: opts.SharedInformerFactory,
306
305
// Here we will use the config file of "onex" to create a client-go informers.
307
- //KubeVersionedInformers: kubeSharedInformers,
306
+ // KubeVersionedInformers: kubeSharedInformers,
308
307
InternalVersionedInformers : opts .InternalVersionedInformers ,
309
- ExternalVersionedInformers : opts .ExternalVersionedInformers ,
310
308
ExternalPostStartHooks : opts .ExternalPostStartHooks ,
311
309
},
312
310
}
313
311
314
312
if utilfeature .DefaultFeatureGate .Enabled (features .UnknownVersionInteroperabilityProxy ) {
315
- config .ExtraConfig .PeerEndpointLeaseReconciler , err = controlplaneapiserver .CreatePeerEndpointLeaseReconciler (genericConfig .Config , storageFactory )
313
+ var err error
314
+ config .PeerEndpointLeaseReconciler , err = CreatePeerEndpointLeaseReconciler (* genericConfig , storageFactory )
316
315
if err != nil {
317
316
return nil , nil , err
318
317
}
319
- // build peer proxy config only if peer ca file exists
320
318
if opts .PeerCAFile != "" {
321
- config .ExtraConfig .PeerProxy , err = controlplaneapiserver .BuildPeerProxy (
322
- kubeSharedInformers ,
323
- genericConfig .StorageVersionManager ,
319
+ leaseInformer := kubeSharedInformers .Coordination ().V1 ().Leases ()
320
+ config .PeerProxy , err = apiserver .BuildPeerProxy (
321
+ leaseInformer ,
322
+ genericConfig .LoopbackClientConfig ,
324
323
opts .ProxyClientCertFile ,
325
- opts .ProxyClientKeyFile ,
326
- opts .PeerCAFile ,
324
+ opts .ProxyClientKeyFile , opts .PeerCAFile ,
327
325
opts .PeerAdvertiseAddress ,
328
326
genericConfig .APIServerID ,
329
- config .ExtraConfig .PeerEndpointLeaseReconciler ,
330
- config .GenericConfig .Serializer ,
331
- )
327
+ config .Extra .PeerEndpointLeaseReconciler ,
328
+ config .Generic .Serializer )
332
329
if err != nil {
333
330
return nil , nil , err
334
331
}
@@ -385,3 +382,15 @@ func buildServiceResolver(enabledAggregatorRouting bool, hostname string, inform
385
382
}
386
383
return serviceResolver
387
384
}
385
+
386
+ // CreatePeerEndpointLeaseReconciler creates a apiserver endpoint lease reconciliation loop
387
+ // The peer endpoint leases are used to find network locations of apiservers for peer proxy
388
+ func CreatePeerEndpointLeaseReconciler (c genericapiserver.RecommendedConfig , storageFactory serverstorage.StorageFactory ) (reconcilers.PeerEndpointLeaseReconciler , error ) {
389
+ ttl := apiserver .DefaultPeerEndpointReconcilerTTL
390
+ config , err := storageFactory .NewConfig (api .Resource ("apiServerPeerIPInfo" ), & api.Endpoints {})
391
+ if err != nil {
392
+ return nil , fmt .Errorf ("error creating storage factory config: %w" , err )
393
+ }
394
+ reconciler , err := reconcilers .NewPeerEndpointLeaseReconciler (config , "/peerserverleases/" , ttl )
395
+ return reconciler , err
396
+ }
0 commit comments