-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuilder.go
More file actions
145 lines (128 loc) · 7.26 KB
/
Copy pathbuilder.go
File metadata and controls
145 lines (128 loc) · 7.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"context"
internalautoscaler "k8s.io/gke-autoscaling/cluster-autoscaler/pkg/autoscaler"
"k8s.io/gke-autoscaling/cluster-autoscaler/pkg/cloudprovider/gke/gceclient"
"k8s.io/gke-autoscaling/cluster-autoscaler/pkg/cloudprovider/gke/gceclient/consumablereservations"
"k8s.io/gke-autoscaling/cluster-autoscaler/pkg/cloudprovider/gke/gceclient/flexadvisorclient"
"k8s.io/gke-autoscaling/cluster-autoscaler/pkg/cloudprovider/gke/gceclient/resizablevms"
"k8s.io/gke-autoscaling/cluster-autoscaler/pkg/cloudprovider/gke/gkeclient"
"k8s.io/gke-autoscaling/cluster-autoscaler/pkg/cloudprovider/gke/nodetemplate"
"k8s.io/gke-autoscaling/cluster-autoscaler/pkg/config/options/cli"
optstracking "k8s.io/gke-autoscaling/cluster-autoscaler/pkg/config/options/tracking"
"k8s.io/gke-autoscaling/cluster-autoscaler/pkg/ekvms/nodesizerecommender"
"k8s.io/gke-autoscaling/cluster-autoscaler/pkg/nodequota"
"k8s.io/gke-autoscaling/cluster-autoscaler/pkg/nodesnowflake"
"k8s.io/gke-autoscaling/cluster-autoscaler/pkg/visibility"
ctrl "sigs.k8s.io/controller-runtime"
)
// initBuilder returns the CA Builder without any Google-restricted clients.
// When updating, please reflect the changes in all the initBuilder implementations.
func initBuilder(ctx context.Context, optsTracker *optstracking.OptionsTracker, manager ctrl.Manager) *internalautoscaler.Builder {
options := optsTracker.Options()
experimentsManager := optsTracker.ExperimentsManager()
// K8s client and related objects
kubeConfig, kubeConfigJSON := internalautoscaler.KubeConfig(options)
kubeClient := internalautoscaler.KubeClient(kubeConfig)
informerFactory := internalautoscaler.NewSharedInformerFactory(options, kubeClient, 0)
// GCE config and HTTP client
projectID, location, tokenSource := internalautoscaler.MustCreateGCEConfig(ctx, options)
httpClient := internalautoscaler.MustCreateHttpClient(tokenSource)
// Internal CA caches
nodeTemplateCache := nodetemplate.NewCache()
gceCache, gkeCache := internalautoscaler.MustCreateCaches(nodeTemplateCache)
mccClient := internalautoscaler.CreateMachineConfigClient(kubeConfigJSON)
machineConfigProvider := internalautoscaler.CreateMachineConfigProvider(ctx, options, mccClient, experimentsManager)
// Clients and related objects for GKE-specific CRDs
// UpdateInfo CRD
updateInfoFactory, updateInfoLister := internalautoscaler.MustCreateUpdateInfoLister(kubeConfigJSON)
// NodeProvisioningConfig (NPC) / CustomProvisioningClass (CCC) CRDs
npcCrdClient := internalautoscaler.MustCreateNpcCrdClient(kubeConfigJSON)
npcCrdLister := internalautoscaler.MustCreateNpcCrdLister(ctx, optsTracker, npcCrdClient)
// ProvisioningRequest CRD
prClient := internalautoscaler.MustCreateProvReqClient(ctx, kubeConfigJSON, informerFactory)
prInjector := internalautoscaler.MustCreateProvReqInjector(options, prClient)
prCache := internalautoscaler.MustCreatePRCache(prClient)
// ProviderConfig CRD (related to MultiTenancy)
provConfigInformer := internalautoscaler.MustCreateProviderConfigInformer(options, kubeConfigJSON)
// Main GCE client
gceClient := internalautoscaler.MustCreateGceClient(
projectID, options, httpClient, gkeCache, experimentsManager, provConfigInformer,
)
// Dedicated GCE sub-clients
provReqManager := internalautoscaler.MustCreatePRManager(prClient, httpClient, projectID, options, prCache, experimentsManager, gceClient, gceCache)
atomicRRClient := internalautoscaler.MustCreateAtomicResizeRequestClient(httpClient, projectID, options, provConfigInformer, experimentsManager)
flexRRClient := internalautoscaler.MustCreateFlexResizeRequestClient(httpClient, projectID, options)
// TODO(b/476064174): Move initialization of IO to separate structs.
builder := internalautoscaler.NewBuilder(optsTracker).
WithCAVersion(cli.ComponentVersion()).
WithKubeConfig(kubeConfig).
WithKubeJSON(kubeConfigJSON).
WithKubeClient(kubeClient).
WithInformerFactory(informerFactory).
WithProjectID(projectID).
WithLocation(location).
WithManager(manager).
WithTokenSource(tokenSource).
WithHttpClient(httpClient).
WithNodeTemplateCache(nodeTemplateCache).
WithGCECache(gceCache).
WithGKECache(gkeCache).
WithMachineConfigProvider(machineConfigProvider).
WithUpdateInfoLister(updateInfoLister, updateInfoFactory).
WithNpcCrdClient(npcCrdClient).
WithNpcCrdLister(npcCrdLister).
WithProvReqClient(prClient).
WithProvReqInjector(prInjector).
WithProvReqCache(prCache).
WithProviderConfigInformer(provConfigInformer).
WithGCEClient(gceClient).
WithProvReqManager(provReqManager).
WithAtomicResizeRequestClient(atomicRRClient).
WithFlexResizeRequestClient(flexRRClient)
return configureGKEInternalClients(ctx, builder)
}
// configureGKEInternalClients is used to configure a Builder with the internal clients that are cut out from GKE Cluster Autoscaler in OSS.
// When GKE CA is built in GKE, this function is overwritten in the main pkg init() - with an implementation that builds actual non-stub clients.
var configureGKEInternalClients = configureStubClients
// configureStubClients configures the provided Builder with stub/no-op implementations of the internal clients - so that the code still compiles
// in OSS with the actual internal client code cut out.
func configureStubClients(ctx context.Context, builder *internalautoscaler.Builder) *internalautoscaler.Builder {
// WARN: All the .With() lines below have to be kept in sync with configureActualClients(). If you're adding a new line here, you should
// add a new one there as well.
optsTracker := builder.GetOptionsTracker()
options := optsTracker.Options()
// GKE API client
httpClient := builder.GetHttpClient()
gkeApiClient := internalautoscaler.MustCreateGKEAPIClient(httpClient, options.UserAgent, *gkeclient.GkeAPIEndpoint)
// GKE client
projectID := builder.GetProjectID()
location := builder.GetLocation()
provConfigInformer := builder.GetProviderConfigInformer()
machineConfigProvider := builder.GetMachineConfigProvider()
gkeClient := internalautoscaler.MustCreateGKEClient(gkeApiClient, nil, projectID, location, options, provConfigInformer, machineConfigProvider, optsTracker.ExperimentsManager())
return builder.
WithNodeSizeRecommenderFactory(nodesizerecommender.DefaultFactory).
WithNodeQuotaWatcher(nodequota.NewNoOpWatcher()).
WithSnowflakeWatcher(nodesnowflake.NewNoOpWatcher()).
WithFlexAdvisorClient(flexadvisorclient.NewNoOpFlexAdvisorClient()).
WithRecommendLocationsClient(gceclient.NewAlwaysErrorRecommendLocationsClient()).
WithEventLogger(visibility.NewNoOpEventLogger()).
WithResizableVmClient(resizablevms.NewNoOpClient()).
WithConsumableReservationsClient(consumablereservations.NewNoOpClient()).
WithRecommendationApplier(gceclient.NoOpRecommendationApplier{}).
WithGkeClient(gkeClient)
}