Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 KCP: cache unstructured #8913

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions controlplane/kubeadm/controllers/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ import (

// KubeadmControlPlaneReconciler reconciles a KubeadmControlPlane object.
type KubeadmControlPlaneReconciler struct {
Client client.Client
APIReader client.Reader
Tracker *remote.ClusterCacheTracker
Client client.Client
Tracker *remote.ClusterCacheTracker

EtcdDialTimeout time.Duration
EtcdCallTimeout time.Duration
Expand All @@ -45,7 +44,6 @@ type KubeadmControlPlaneReconciler struct {
func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
return (&kubeadmcontrolplanecontrollers.KubeadmControlPlaneReconciler{
Client: r.Client,
APIReader: r.APIReader,
Tracker: r.Tracker,
EtcdDialTimeout: r.EtcdDialTimeout,
EtcdCallTimeout: r.EtcdCallTimeout,
Expand Down
10 changes: 5 additions & 5 deletions controlplane/kubeadm/internal/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ const (

// KubeadmControlPlaneReconciler reconciles a KubeadmControlPlane object.
type KubeadmControlPlaneReconciler struct {
Client client.Client
APIReader client.Reader
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APIReader was never read by production code (only tests) so I got rid of it

controller controller.Controller
recorder record.EventRecorder
Tracker *remote.ClusterCacheTracker
Client client.Client
controller controller.Controller
recorder record.EventRecorder
Tracker *remote.ClusterCacheTracker

EtcdDialTimeout time.Duration
EtcdCallTimeout time.Duration

Expand Down
13 changes: 4 additions & 9 deletions controlplane/kubeadm/internal/controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ func TestKubeadmControlPlaneReconciler_adoption(t *testing.T) {
fmc.Reader = fakeClient
r := &KubeadmControlPlaneReconciler{
Client: fakeClient,
APIReader: fakeClient,
managementCluster: fmc,
managementClusterUncached: fmc,
}
Expand Down Expand Up @@ -611,7 +610,6 @@ func TestKubeadmControlPlaneReconciler_adoption(t *testing.T) {
fmc.Reader = fakeClient
r := &KubeadmControlPlaneReconciler{
Client: fakeClient,
APIReader: fakeClient,
managementCluster: fmc,
managementClusterUncached: fmc,
}
Expand Down Expand Up @@ -697,7 +695,6 @@ func TestKubeadmControlPlaneReconciler_adoption(t *testing.T) {
fmc.Reader = fakeClient
r := &KubeadmControlPlaneReconciler{
Client: fakeClient,
APIReader: fakeClient,
managementCluster: fmc,
managementClusterUncached: fmc,
}
Expand Down Expand Up @@ -750,7 +747,6 @@ func TestKubeadmControlPlaneReconciler_adoption(t *testing.T) {
recorder := record.NewFakeRecorder(32)
r := &KubeadmControlPlaneReconciler{
Client: fakeClient,
APIReader: fakeClient,
recorder: recorder,
managementCluster: fmc,
managementClusterUncached: fmc,
Expand Down Expand Up @@ -1281,9 +1277,8 @@ kubernetesVersion: metav1.16.1`,

expectedLabels := map[string]string{clusterv1.ClusterNameLabel: "foo"}
r := &KubeadmControlPlaneReconciler{
Client: env,
APIReader: env.GetAPIReader(),
recorder: record.NewFakeRecorder(32),
Client: env,
recorder: record.NewFakeRecorder(32),
managementCluster: &fakeManagementCluster{
Management: &internal.Management{Client: env},
Workload: fakeWorkloadCluster{
Expand All @@ -1309,13 +1304,13 @@ kubernetesVersion: metav1.16.1`,
g.Expect(err).NotTo(HaveOccurred())
// this first requeue is to add finalizer
g.Expect(result).To(Equal(ctrl.Result{}))
g.Expect(r.APIReader.Get(ctx, util.ObjectKey(kcp), kcp)).To(Succeed())
g.Expect(env.GetAPIReader().Get(ctx, util.ObjectKey(kcp), kcp)).To(Succeed())
g.Expect(kcp.Finalizers).To(ContainElement(controlplanev1.KubeadmControlPlaneFinalizer))

g.Eventually(func(g Gomega) {
_, err = r.Reconcile(ctx, ctrl.Request{NamespacedName: util.ObjectKey(kcp)})
g.Expect(err).NotTo(HaveOccurred())
g.Expect(r.APIReader.Get(ctx, client.ObjectKey{Name: kcp.Name, Namespace: kcp.Namespace}, kcp)).To(Succeed())
g.Expect(env.GetAPIReader().Get(ctx, client.ObjectKey{Name: kcp.Name, Namespace: kcp.Namespace}, kcp)).To(Succeed())
// Expect the referenced infrastructure template to have a Cluster Owner Reference.
g.Expect(env.GetAPIReader().Get(ctx, util.ObjectKey(genericInfrastructureMachineTemplate), genericInfrastructureMachineTemplate)).To(Succeed())
g.Expect(genericInfrastructureMachineTemplate.GetOwnerReferences()).To(ContainElement(metav1.OwnerReference{
Expand Down
3 changes: 1 addition & 2 deletions controlplane/kubeadm/internal/controllers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,7 @@ func TestKubeadmControlPlaneReconciler_adoptKubeconfigSecret(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
fakeClient := newFakeClient(kcp, tt.configSecret)
r := &KubeadmControlPlaneReconciler{
APIReader: fakeClient,
Client: fakeClient,
Client: fakeClient,
}
g.Expect(r.adoptKubeconfigSecret(ctx, tt.configSecret, kcp)).To(Succeed())
actualSecret := &corev1.Secret{}
Expand Down
1 change: 0 additions & 1 deletion controlplane/kubeadm/internal/controllers/scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ func TestKubeadmControlPlaneReconciler_scaleUpControlPlane(t *testing.T) {

r := &KubeadmControlPlaneReconciler{
Client: env,
APIReader: env.GetAPIReader(),
managementCluster: fmc,
managementClusterUncached: fmc,
recorder: record.NewFakeRecorder(32),
Expand Down
6 changes: 2 additions & 4 deletions controlplane/kubeadm/internal/controllers/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleUp(t *testing.T) {
setKCPHealthy(kcp)

r := &KubeadmControlPlaneReconciler{
Client: env,
APIReader: env.GetAPIReader(),
recorder: record.NewFakeRecorder(32),
Client: env,
recorder: record.NewFakeRecorder(32),
managementCluster: &fakeManagementCluster{
Management: &internal.Management{Client: env},
Workload: fakeWorkloadCluster{
Expand Down Expand Up @@ -227,7 +226,6 @@ func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleDown(t *testing.T) {
fakeClient := newFakeClient(objs...)
fmc.Reader = fakeClient
r := &KubeadmControlPlaneReconciler{
APIReader: fakeClient,
Client: fakeClient,
managementCluster: fmc,
managementClusterUncached: fmc,
Expand Down
6 changes: 5 additions & 1 deletion controlplane/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ func main() {
&corev1.ConfigMap{},
&corev1.Secret{},
},
// This config ensures that the default client caches Unstructured objects.
// KCP is only using Unstructured to retrieve InfraMachines and InfraMachineTemplates.
// As the cache should be used in those cases, caching is configured globally instead of
// creating a separate client that caches Unstructured.
Unstructured: true,
sbueringer marked this conversation as resolved.
Show resolved Hide resolved
},
},
WebhookServer: webhook.NewServer(
Expand Down Expand Up @@ -283,7 +288,6 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {

if err := (&kubeadmcontrolplanecontrollers.KubeadmControlPlaneReconciler{
Client: mgr.GetClient(),
APIReader: mgr.GetAPIReader(),
Tracker: tracker,
WatchFilterValue: watchFilterValue,
EtcdDialTimeout: etcdDialTimeout,
Expand Down