Skip to content

Commit b677359

Browse files
authored
Merge pull request #10692 from sbueringer/pr-cache-unstructured
🌱 Cleanup separate unstructuredCachingClient
2 parents 0539a29 + 4714c48 commit b677359

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+193
-371
lines changed

bootstrap/kubeadm/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ func main() {
247247
&corev1.ConfigMap{},
248248
&corev1.Secret{},
249249
},
250+
// Use the cache for all Unstructured get/list calls.
251+
Unstructured: true,
250252
},
251253
},
252254
WebhookServer: webhook.NewServer(

cmd/clusterctl/client/cluster/topology.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,8 @@ func (t *topologyClient) Plan(ctx context.Context, in *TopologyPlanInput) (*Topo
200200

201201
res.ReconciledCluster = targetCluster
202202
reconciler := &clustertopologycontroller.Reconciler{
203-
Client: dryRunClient,
204-
APIReader: dryRunClient,
205-
UnstructuredCachingClient: dryRunClient,
203+
Client: dryRunClient,
204+
APIReader: dryRunClient,
206205
}
207206
reconciler.SetupForDryRun(&noOpRecorder{})
208207
request := reconcile.Request{NamespacedName: *targetCluster}
@@ -515,8 +514,7 @@ func reconcileClusterClass(ctx context.Context, apiReader client.Reader, class c
515514
reconcilerClient := dryrun.NewClient(apiReader, reconciliationObjects)
516515

517516
clusterClassReconciler := &clusterclasscontroller.Reconciler{
518-
Client: reconcilerClient,
519-
UnstructuredCachingClient: reconcilerClient,
517+
Client: reconcilerClient,
520518
}
521519

522520
if _, err := clusterClassReconciler.Reconcile(ctx, reconcile.Request{NamespacedName: targetClusterClass}); err != nil {

controllers/alias.go

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,26 @@ import (
4242

4343
// ClusterReconciler reconciles a Cluster object.
4444
type ClusterReconciler struct {
45-
Client client.Client
46-
UnstructuredCachingClient client.Client
47-
APIReader client.Reader
45+
Client client.Client
46+
APIReader client.Reader
4847

4948
// WatchFilterValue is the label value used to filter events prior to reconciliation.
5049
WatchFilterValue string
5150
}
5251

5352
func (r *ClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
5453
return (&clustercontroller.Reconciler{
55-
Client: r.Client,
56-
UnstructuredCachingClient: r.UnstructuredCachingClient,
57-
APIReader: r.APIReader,
58-
WatchFilterValue: r.WatchFilterValue,
54+
Client: r.Client,
55+
APIReader: r.APIReader,
56+
WatchFilterValue: r.WatchFilterValue,
5957
}).SetupWithManager(ctx, mgr, options)
6058
}
6159

6260
// MachineReconciler reconciles a Machine object.
6361
type MachineReconciler struct {
64-
Client client.Client
65-
UnstructuredCachingClient client.Client
66-
APIReader client.Reader
67-
Tracker *remote.ClusterCacheTracker
62+
Client client.Client
63+
APIReader client.Reader
64+
Tracker *remote.ClusterCacheTracker
6865

6966
// WatchFilterValue is the label value used to filter events prior to reconciliation.
7067
WatchFilterValue string
@@ -75,21 +72,19 @@ type MachineReconciler struct {
7572

7673
func (r *MachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
7774
return (&machinecontroller.Reconciler{
78-
Client: r.Client,
79-
UnstructuredCachingClient: r.UnstructuredCachingClient,
80-
APIReader: r.APIReader,
81-
Tracker: r.Tracker,
82-
WatchFilterValue: r.WatchFilterValue,
83-
NodeDrainClientTimeout: r.NodeDrainClientTimeout,
75+
Client: r.Client,
76+
APIReader: r.APIReader,
77+
Tracker: r.Tracker,
78+
WatchFilterValue: r.WatchFilterValue,
79+
NodeDrainClientTimeout: r.NodeDrainClientTimeout,
8480
}).SetupWithManager(ctx, mgr, options)
8581
}
8682

8783
// MachineSetReconciler reconciles a MachineSet object.
8884
type MachineSetReconciler struct {
89-
Client client.Client
90-
UnstructuredCachingClient client.Client
91-
APIReader client.Reader
92-
Tracker *remote.ClusterCacheTracker
85+
Client client.Client
86+
APIReader client.Reader
87+
Tracker *remote.ClusterCacheTracker
9388

9489
// WatchFilterValue is the label value used to filter events prior to reconciliation.
9590
WatchFilterValue string
@@ -101,7 +96,6 @@ type MachineSetReconciler struct {
10196
func (r *MachineSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
10297
return (&machinesetcontroller.Reconciler{
10398
Client: r.Client,
104-
UnstructuredCachingClient: r.UnstructuredCachingClient,
10599
APIReader: r.APIReader,
106100
Tracker: r.Tracker,
107101
WatchFilterValue: r.WatchFilterValue,
@@ -111,20 +105,18 @@ func (r *MachineSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
111105

112106
// MachineDeploymentReconciler reconciles a MachineDeployment object.
113107
type MachineDeploymentReconciler struct {
114-
Client client.Client
115-
UnstructuredCachingClient client.Client
116-
APIReader client.Reader
108+
Client client.Client
109+
APIReader client.Reader
117110

118111
// WatchFilterValue is the label value used to filter events prior to reconciliation.
119112
WatchFilterValue string
120113
}
121114

122115
func (r *MachineDeploymentReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
123116
return (&machinedeploymentcontroller.Reconciler{
124-
Client: r.Client,
125-
UnstructuredCachingClient: r.UnstructuredCachingClient,
126-
APIReader: r.APIReader,
127-
WatchFilterValue: r.WatchFilterValue,
117+
Client: r.Client,
118+
APIReader: r.APIReader,
119+
WatchFilterValue: r.WatchFilterValue,
128120
}).SetupWithManager(ctx, mgr, options)
129121
}
130122

@@ -157,20 +149,15 @@ type ClusterTopologyReconciler struct {
157149

158150
// WatchFilterValue is the label value used to filter events prior to reconciliation.
159151
WatchFilterValue string
160-
161-
// UnstructuredCachingClient provides a client that forces caching of unstructured objects,
162-
// thus allowing to optimize reads for templates or provider specific objects in a managed topology.
163-
UnstructuredCachingClient client.Client
164152
}
165153

166154
func (r *ClusterTopologyReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
167155
return (&clustertopologycontroller.Reconciler{
168-
Client: r.Client,
169-
APIReader: r.APIReader,
170-
Tracker: r.Tracker,
171-
RuntimeClient: r.RuntimeClient,
172-
UnstructuredCachingClient: r.UnstructuredCachingClient,
173-
WatchFilterValue: r.WatchFilterValue,
156+
Client: r.Client,
157+
APIReader: r.APIReader,
158+
Tracker: r.Tracker,
159+
RuntimeClient: r.RuntimeClient,
160+
WatchFilterValue: r.WatchFilterValue,
174161
}).SetupWithManager(ctx, mgr, options)
175162
}
176163

@@ -227,18 +214,13 @@ type ClusterClassReconciler struct {
227214

228215
// WatchFilterValue is the label value used to filter events prior to reconciliation.
229216
WatchFilterValue string
230-
231-
// UnstructuredCachingClient provides a client that forces caching of unstructured objects,
232-
// thus allowing to optimize reads for templates or provider specific objects.
233-
UnstructuredCachingClient client.Client
234217
}
235218

236219
func (r *ClusterClassReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
237220
r.internalReconciler = &clusterclasscontroller.Reconciler{
238-
Client: r.Client,
239-
RuntimeClient: r.RuntimeClient,
240-
UnstructuredCachingClient: r.UnstructuredCachingClient,
241-
WatchFilterValue: r.WatchFilterValue,
221+
Client: r.Client,
222+
RuntimeClient: r.RuntimeClient,
223+
WatchFilterValue: r.WatchFilterValue,
242224
}
243225
return r.internalReconciler.SetupWithManager(ctx, mgr, options)
244226
}

controlplane/kubeadm/internal/controllers/helpers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func TestCloneConfigsAndGenerateMachine(t *testing.T) {
338338
},
339339
},
340340
}
341-
g.Expect(env.Create(ctx, genericInfrastructureMachineTemplate)).To(Succeed())
341+
g.Expect(env.CreateAndWait(ctx, genericInfrastructureMachineTemplate)).To(Succeed())
342342

343343
kcp := &controlplanev1.KubeadmControlPlane{
344344
ObjectMeta: metav1.ObjectMeta{

controlplane/kubeadm/internal/controllers/upgrade_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleUp(t *testing.T) {
6868
timeout := 30 * time.Second
6969

7070
cluster, kcp, genericInfrastructureMachineTemplate := createClusterWithControlPlane(namespace.Name)
71-
g.Expect(env.Create(ctx, genericInfrastructureMachineTemplate, client.FieldOwner("manager"))).To(Succeed())
71+
g.Expect(env.CreateAndWait(ctx, genericInfrastructureMachineTemplate, client.FieldOwner("manager"))).To(Succeed())
7272
cluster.UID = types.UID(util.RandomString(10))
7373
cluster.Spec.ControlPlaneEndpoint.Host = Host
7474
cluster.Spec.ControlPlaneEndpoint.Port = 6443

controlplane/kubeadm/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func main() {
257257
&corev1.ConfigMap{},
258258
&corev1.Secret{},
259259
},
260-
// This config ensures that the default client caches Unstructured objects.
260+
// This config ensures that the default client uses the cache for all Unstructured get/list calls.
261261
// KCP is only using Unstructured to retrieve InfraMachines and InfraMachineTemplates.
262262
// As the cache should be used in those cases, caching is configured globally instead of
263263
// creating a separate client that caches Unstructured.

docs/proposals/20220221-runtime-SDK.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,6 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
576576
Client: mgr.GetClient(),
577577
APIReader: mgr.GetAPIReader(),
578578
RuntimeClient: runtimeClient,
579-
UnstructuredCachingClient: unstructuredCachingClient,
580579
WatchFilterValue: watchFilterValue,
581580
}).SetupWithManager(ctx, mgr, concurrency(clusterTopologyConcurrency)); err != nil {
582581
setupLog.Error(err, "Unable to create controller", "controller", "ClusterTopology")

internal/controllers/cluster/cluster_controller.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ const (
6666

6767
// Reconciler reconciles a Cluster object.
6868
type Reconciler struct {
69-
Client client.Client
70-
UnstructuredCachingClient client.Client
71-
APIReader client.Reader
69+
Client client.Client
70+
APIReader client.Reader
7271

7372
// WatchFilterValue is the label value used to filter events prior to reconciliation.
7473
WatchFilterValue string
@@ -279,7 +278,7 @@ func (r *Reconciler) reconcileDelete(ctx context.Context, cluster *clusterv1.Clu
279278
}
280279

281280
if cluster.Spec.ControlPlaneRef != nil {
282-
obj, err := external.Get(ctx, r.UnstructuredCachingClient, cluster.Spec.ControlPlaneRef, cluster.Namespace)
281+
obj, err := external.Get(ctx, r.Client, cluster.Spec.ControlPlaneRef, cluster.Namespace)
283282
switch {
284283
case apierrors.IsNotFound(errors.Cause(err)):
285284
// All good - the control plane resource has been deleted
@@ -310,7 +309,7 @@ func (r *Reconciler) reconcileDelete(ctx context.Context, cluster *clusterv1.Clu
310309
}
311310

312311
if cluster.Spec.InfrastructureRef != nil {
313-
obj, err := external.Get(ctx, r.UnstructuredCachingClient, cluster.Spec.InfrastructureRef, cluster.Namespace)
312+
obj, err := external.Get(ctx, r.Client, cluster.Spec.InfrastructureRef, cluster.Namespace)
314313
switch {
315314
case apierrors.IsNotFound(errors.Cause(err)):
316315
// All good - the infra resource has been deleted

internal/controllers/cluster/cluster_controller_phases.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (r *Reconciler) reconcileExternal(ctx context.Context, cluster *clusterv1.C
8383
return external.ReconcileOutput{}, err
8484
}
8585

86-
obj, err := external.Get(ctx, r.UnstructuredCachingClient, ref, cluster.Namespace)
86+
obj, err := external.Get(ctx, r.Client, ref, cluster.Namespace)
8787
if err != nil {
8888
if apierrors.IsNotFound(errors.Cause(err)) {
8989
log.Info("Could not find external object for cluster, requeuing", "refGroupVersionKind", ref.GroupVersionKind(), "refName", ref.Name)

internal/controllers/cluster/cluster_controller_phases_test.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,8 @@ func TestClusterReconcilePhases(t *testing.T) {
137137
Build()
138138
}
139139
r := &Reconciler{
140-
Client: c,
141-
UnstructuredCachingClient: c,
142-
recorder: record.NewFakeRecorder(32),
140+
Client: c,
141+
recorder: record.NewFakeRecorder(32),
143142
}
144143

145144
res, err := r.reconcileInfrastructure(ctx, tt.cluster)
@@ -218,9 +217,8 @@ func TestClusterReconcilePhases(t *testing.T) {
218217
Build()
219218
}
220219
r := &Reconciler{
221-
Client: c,
222-
UnstructuredCachingClient: c,
223-
recorder: record.NewFakeRecorder(32),
220+
Client: c,
221+
recorder: record.NewFakeRecorder(32),
224222
}
225223
res, err := r.reconcileKubeconfig(ctx, tt.cluster)
226224
if tt.wantErr {
@@ -370,9 +368,8 @@ func TestClusterReconciler_reconcilePhase(t *testing.T) {
370368
Build()
371369

372370
r := &Reconciler{
373-
Client: c,
374-
UnstructuredCachingClient: c,
375-
recorder: record.NewFakeRecorder(32),
371+
Client: c,
372+
recorder: record.NewFakeRecorder(32),
376373
}
377374
r.reconcilePhase(ctx, tt.cluster)
378375
g.Expect(tt.cluster.Status.GetTypedPhase()).To(Equal(tt.wantPhase))
@@ -488,9 +485,8 @@ func TestClusterReconcilePhases_reconcileFailureDomains(t *testing.T) {
488485

489486
c := fake.NewClientBuilder().WithObjects(objs...).Build()
490487
r := &Reconciler{
491-
Client: c,
492-
UnstructuredCachingClient: c,
493-
recorder: record.NewFakeRecorder(32),
488+
Client: c,
489+
recorder: record.NewFakeRecorder(32),
494490
}
495491

496492
_, err := r.reconcileInfrastructure(ctx, tt.cluster)

0 commit comments

Comments
 (0)