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

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

commit 0120ccddad07445d0a4bc3e1e8511481f3da4428
Author: Gregorius Bima Kharisma Wicaksana 
<[email protected]>
AuthorDate: Sun Dec 14 12:36:39 2025 +0700

    refactor: consolidate getIntegrationKit into kubernetes utility
    
    Refactored duplicate getIntegrationKit implementations to use the
    existing kubernetes.GetIntegrationKit utility function. This reduces
    code duplication and centralizes the IntegrationKit retrieval logic.
    
    Changes:
    - pkg/trait/util.go: Use kubernetes.GetIntegrationKit, remove unused ctrl 
import
    - pkg/trait/jvm.go: Use kubernetes.GetIntegrationKit, remove unused ctrl 
import
    - pkg/cmd/promote.go: Simplify to use kubernetes.GetIntegrationKit
    
    Fixes: #6413
---
 pkg/cmd/promote.go | 11 +----------
 pkg/trait/jvm.go   | 15 +++++++++------
 pkg/trait/util.go  |  8 ++------
 3 files changed, 12 insertions(+), 22 deletions(-)

diff --git a/pkg/cmd/promote.go b/pkg/cmd/promote.go
index e7990a081..88d3dd6d0 100644
--- a/pkg/cmd/promote.go
+++ b/pkg/cmd/promote.go
@@ -227,16 +227,7 @@ func (o *promoteCmdOptions) getIntegrationKit(c 
client.Client, ref *corev1.Objec
        if ref == nil {
                return nil, nil
        }
-       ik := v1.NewIntegrationKit(ref.Namespace, ref.Name)
-       key := k8sclient.ObjectKey{
-               Name:      ref.Name,
-               Namespace: ref.Namespace,
-       }
-       if err := c.Get(o.Context, key, ik); err != nil {
-               return nil, err
-       }
-
-       return ik, nil
+       return kubernetes.GetIntegrationKit(o.Context, c, ref.Name, 
ref.Namespace)
 }
 
 func (o *promoteCmdOptions) editIntegration(it *v1.Integration, kit 
*v1.IntegrationKit) *v1.Integration {
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index f71dfbdb5..6fa104123 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -28,7 +28,6 @@ import (
        "k8s.io/apimachinery/pkg/api/resource"
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
        "k8s.io/utils/ptr"
-       ctrl "sigs.k8s.io/controller-runtime/pkg/client"
 
        v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
        traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait"
@@ -36,6 +35,7 @@ import (
        "github.com/apache/camel-k/v2/pkg/util"
        "github.com/apache/camel-k/v2/pkg/util/camel"
        "github.com/apache/camel-k/v2/pkg/util/envvar"
+       "github.com/apache/camel-k/v2/pkg/util/kubernetes"
        "github.com/apache/camel-k/v2/pkg/util/sets"
 )
 
@@ -221,18 +221,21 @@ func getClasspathSet(cps string) *sets.Set {
 }
 
 func (t *jvmTrait) getIntegrationKit(e *Environment) (*v1.IntegrationKit, 
error) {
-       kit := e.IntegrationKit
+       if e.IntegrationKit != nil {
+               return e.IntegrationKit, nil
+       }
 
-       if kit == nil && e.Integration.Status.IntegrationKit != nil {
+       if e.Integration.Status.IntegrationKit != nil {
                name := e.Integration.Status.IntegrationKit.Name
                ns := e.Integration.GetIntegrationKitNamespace(e.Platform)
-               kit = v1.NewIntegrationKit(ns, name)
-               if err := t.Client.Get(e.Ctx, ctrl.ObjectKeyFromObject(kit), 
kit); err != nil {
+               kit, err := kubernetes.GetIntegrationKit(e.Ctx, t.Client, name, 
ns)
+               if err != nil {
                        return nil, fmt.Errorf("unable to find integration kit 
%s/%s: %w", ns, name, err)
                }
+               return kit, nil
        }
 
-       return kit, nil
+       return nil, nil
 }
 
 func (t *jvmTrait) enableDebug(e *Environment) string {
diff --git a/pkg/trait/util.go b/pkg/trait/util.go
index e35dfc169..b87bfcf1c 100644
--- a/pkg/trait/util.go
+++ b/pkg/trait/util.go
@@ -26,12 +26,11 @@ import (
        "regexp"
        "strings"
 
-       ctrl "sigs.k8s.io/controller-runtime/pkg/client"
-
        v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
        "github.com/apache/camel-k/v2/pkg/client"
        "github.com/apache/camel-k/v2/pkg/util"
        "github.com/apache/camel-k/v2/pkg/util/camel"
+       "github.com/apache/camel-k/v2/pkg/util/kubernetes"
        "github.com/apache/camel-k/v2/pkg/util/property"
        "github.com/apache/camel-k/v2/pkg/util/sets"
 )
@@ -53,10 +52,7 @@ func getIntegrationKit(ctx context.Context, c client.Client, 
integration *v1.Int
        if integration.Status.IntegrationKit == nil {
                return nil, nil
        }
-       kit := 
v1.NewIntegrationKit(integration.Status.IntegrationKit.Namespace, 
integration.Status.IntegrationKit.Name)
-       err := c.Get(ctx, ctrl.ObjectKeyFromObject(kit), kit)
-
-       return kit, err
+       return kubernetes.GetIntegrationKit(ctx, c, 
integration.Status.IntegrationKit.Name, 
integration.Status.IntegrationKit.Namespace)
 }
 
 func collectConfigurationPairs(configurationType string, configurable 
...v1.Configurable) []variable {

Reply via email to