This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit acfd3ec35bfdfe49abe37a38eeb978c8f1d97d34
Author: Antonin Stefanutti <anto...@stefanutti.fr>
AuthorDate: Thu Sep 30 18:36:51 2021 +0200

    fix: Do not use cached client to get Kaniko warmer Pod
---
 .../integrationplatform/integrationplatform_controller.go    |  7 +++++--
 pkg/controller/integrationplatform/warm.go                   | 12 ++++++++----
 pkg/controller/integrationplatform/warm_test.go              |  6 +++---
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git 
a/pkg/controller/integrationplatform/integrationplatform_controller.go 
b/pkg/controller/integrationplatform/integrationplatform_controller.go
index 5fa590e..264ae4d 100644
--- a/pkg/controller/integrationplatform/integrationplatform_controller.go
+++ b/pkg/controller/integrationplatform/integrationplatform_controller.go
@@ -57,6 +57,7 @@ func newReconciler(mgr manager.Manager, c client.Client) 
reconcile.Reconciler {
        return monitoring.NewInstrumentedReconciler(
                &reconcileIntegrationPlatform{
                        client:   c,
+                       reader:   mgr.GetAPIReader(),
                        scheme:   mgr.GetScheme(),
                        recorder: 
mgr.GetEventRecorderFor("camel-k-integration-platform-controller"),
                },
@@ -108,7 +109,9 @@ var _ reconcile.Reconciler = &reconcileIntegrationPlatform{}
 type reconcileIntegrationPlatform struct {
        // This client, initialized using mgr.Client() above, is a split client
        // that reads objects from the cache and writes to the API server
-       client   client.Client
+       client client.Client
+       // Non-caching client
+       reader   ctrl.Reader
        scheme   *runtime.Scheme
        recorder record.EventRecorder
 }
@@ -148,7 +151,7 @@ func (r *reconcileIntegrationPlatform) Reconcile(ctx 
context.Context, request re
 
        actions := []Action{
                NewInitializeAction(),
-               NewWarmAction(),
+               NewWarmAction(r.reader),
                NewCreateAction(),
                NewMonitorAction(),
        }
diff --git a/pkg/controller/integrationplatform/warm.go 
b/pkg/controller/integrationplatform/warm.go
index 7fd48aa..21f6608 100644
--- a/pkg/controller/integrationplatform/warm.go
+++ b/pkg/controller/integrationplatform/warm.go
@@ -25,16 +25,20 @@ import (
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
        "k8s.io/apimachinery/pkg/types"
 
+       ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+
        v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 )
 
-// NewWarmAction returns a action that creates resources needed by the platform
-func NewWarmAction() Action {
-       return &warmAction{}
+func NewWarmAction(reader ctrl.Reader) Action {
+       return &warmAction{
+               reader: reader,
+       }
 }
 
 type warmAction struct {
        baseAction
+       reader ctrl.Reader
 }
 
 func (action *warmAction) Name() string {
@@ -58,7 +62,7 @@ func (action *warmAction) Handle(ctx context.Context, 
platform *v1.IntegrationPl
                },
        }
 
-       err := action.client.Get(ctx, types.NamespacedName{Namespace: 
pod.Namespace, Name: pod.Name}, &pod)
+       err := action.reader.Get(ctx, types.NamespacedName{Namespace: 
pod.Namespace, Name: pod.Name}, &pod)
        if err != nil {
                return nil, err
        }
diff --git a/pkg/controller/integrationplatform/warm_test.go 
b/pkg/controller/integrationplatform/warm_test.go
index d580a2d..3c5a6c4 100644
--- a/pkg/controller/integrationplatform/warm_test.go
+++ b/pkg/controller/integrationplatform/warm_test.go
@@ -58,7 +58,7 @@ func TestWarm_Succeeded(t *testing.T) {
 
        assert.Nil(t, platform.ConfigureDefaults(context.TODO(), c, &ip, false))
 
-       h := NewWarmAction()
+       h := NewWarmAction(c)
        h.InjectLogger(log.Log)
        h.InjectClient(c)
 
@@ -93,7 +93,7 @@ func TestWarm_Failing(t *testing.T) {
 
        assert.Nil(t, platform.ConfigureDefaults(context.TODO(), c, &ip, false))
 
-       h := NewWarmAction()
+       h := NewWarmAction(c)
        h.InjectLogger(log.Log)
        h.InjectClient(c)
 
@@ -128,7 +128,7 @@ func TestWarm_WarmingUp(t *testing.T) {
 
        assert.Nil(t, platform.ConfigureDefaults(context.TODO(), c, &ip, false))
 
-       h := NewWarmAction()
+       h := NewWarmAction(c)
        h.InjectLogger(log.Log)
        h.InjectClient(c)
 

Reply via email to