Skip to content

Commit

Permalink
Use uncached client (kubernetes-sigs#1682)
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik-K-N committed Mar 25, 2024
1 parent 1c025ce commit aa44df2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion controllers/ibmpowervscluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
// IBMPowerVSClusterReconciler reconciles a IBMPowerVSCluster object.
type IBMPowerVSClusterReconciler struct {
client.Client
UncachedClient client.Client
Recorder record.EventRecorder
ServiceEndpoint []endpoints.ServiceEndpoint
Scheme *runtime.Scheme
Expand All @@ -65,7 +66,7 @@ func (r *IBMPowerVSClusterReconciler) Reconcile(ctx context.Context, req ctrl.Re

// Fetch the IBMPowerVSCluster instance.
ibmCluster := &infrav1beta2.IBMPowerVSCluster{}
err := r.Get(ctx, req.NamespacedName, ibmCluster)
err := r.UncachedClient.Get(ctx, req.NamespacedName, ibmCluster)
if err != nil {
if apierrors.IsNotFound(err) {
return ctrl.Result{}, nil
Expand Down
9 changes: 6 additions & 3 deletions controllers/ibmpowervscluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ func TestIBMPowerVSClusterReconciler_Reconcile(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
reconciler := &IBMPowerVSClusterReconciler{
Client: testEnv.Client,
Client: testEnv.Client,
UncachedClient: testEnv.Client,
}

ns, err := testEnv.CreateNamespace(ctx, fmt.Sprintf("namespace-%s", util.RandomString(5)))
Expand Down Expand Up @@ -157,7 +158,8 @@ func TestIBMPowerVSClusterReconciler_reconcile(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
reconciler := &IBMPowerVSClusterReconciler{
Client: testEnv.Client,
Client: testEnv.Client,
UncachedClient: testEnv.Client,
}
_, _ = reconciler.reconcile(tc.powervsClusterScope)
g.Expect(tc.powervsClusterScope.IBMPowerVSCluster.Status.Ready).To(Equal(tc.clusterStatus))
Expand All @@ -172,7 +174,8 @@ func TestIBMPowerVSClusterReconciler_delete(t *testing.T) {
clusterScope *scope.PowerVSClusterScope
)
reconciler = IBMPowerVSClusterReconciler{
Client: testEnv.Client,
Client: testEnv.Client,
UncachedClient: testEnv.Client,
}
t.Run("Reconciling delete IBMPowerVSCluster", func(t *testing.T) {
t.Run("Should reconcile successfully if no descendants are found", func(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (

ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/webhook"

capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -242,8 +243,14 @@ func setupReconcilers(mgr ctrl.Manager, serviceEndpoint []endpoints.ServiceEndpo
os.Exit(1)
}

cfg := ctrl.GetConfigOrDie()
uncachedClient, err := client.New(cfg, client.Options{Scheme: mgr.GetScheme(), Mapper: mgr.GetRESTMapper()})
if err != nil {
setupLog.Error(err, "unable to set up uncached client")
}
if err := (&controllers.IBMPowerVSClusterReconciler{
Client: mgr.GetClient(),
UncachedClient: uncachedClient,
Recorder: mgr.GetEventRecorderFor("ibmpowervscluster-controller"),
ServiceEndpoint: serviceEndpoint,
Scheme: mgr.GetScheme(),
Expand Down

0 comments on commit aa44df2

Please sign in to comment.