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

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

commit dd88ebad6cd0f24a4e5015b15f20feab036aa8c6
Author: Keerthan <[email protected]>
AuthorDate: Wed Sep 16 23:13:06 2026 +0530

    refactor: Default cert-manager discovery to enabled in the shared fake test 
client, matching the Knative default, and exclude cert-manager duck types from 
the generic fake Kubernetes clientset (they are only ever accessed via the 
typed controller-runtime client).added types to prevent unstructured, 
ingress_test made it enabled by default and added a function to disable it
---
 pkg/cmd/operator/operator.go    |  2 ++
 pkg/platform/operator.go        |  4 ++++
 pkg/trait/ingress.go            | 10 +++-------
 pkg/trait/ingress_test.go       | 21 +++++++++++++++++++--
 pkg/util/certmanager/enabled.go | 17 -----------------
 5 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/pkg/cmd/operator/operator.go b/pkg/cmd/operator/operator.go
index f606fcac2..1ec490d77 100644
--- a/pkg/cmd/operator/operator.go
+++ b/pkg/cmd/operator/operator.go
@@ -202,6 +202,8 @@ func Run(healthPort, monitoringPort int32, leaderElection 
bool, leaderElectionID
                selectors[&batchv1.CronJob{}] = selector
        }
 
+       platform.CertManagerInstalled, _ = 
kubernetes.IsAPIResourceInstalled(bootstrapClient, "cert-manager.io/v1", 
"ClusterIssuer")
+
        options := cache.Options{
                ByObject: selectors,
        }
diff --git a/pkg/platform/operator.go b/pkg/platform/operator.go
index abe3432fa..7b29f5596 100644
--- a/pkg/platform/operator.go
+++ b/pkg/platform/operator.go
@@ -44,6 +44,10 @@ const OperatorLockName = "camel-k-lock"
 
 var OperatorImage string
 
+// CertManagerInstalled is computed once at operator bootstrap and reports 
whether
+// cert-manager's ClusterIssuer CRD is available on the cluster.
+var CertManagerInstalled bool
+
 // IsCurrentOperatorGlobal returns true if the operator is configured to watch 
all namespaces.
 func IsCurrentOperatorGlobal() bool {
        if watchNamespace, envSet := 
os.LookupEnv(OperatorWatchNamespaceEnvVariable); !envSet || 
strings.TrimSpace(watchNamespace) == "" {
diff --git a/pkg/trait/ingress.go b/pkg/trait/ingress.go
index aadcce161..1e3762101 100644
--- a/pkg/trait/ingress.go
+++ b/pkg/trait/ingress.go
@@ -23,6 +23,7 @@ import (
 
        v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
        traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait"
+       "github.com/apache/camel-k/v2/pkg/platform"
        "github.com/apache/camel-k/v2/pkg/util/certmanager"
        corev1 "k8s.io/api/core/v1"
        networkingv1 "k8s.io/api/networking/v1"
@@ -191,13 +192,8 @@ func (t *ingressTrait) Apply(e *Environment) error {
 func (t *ingressTrait) resolveCertManagerIssuer(e *Environment) 
(annotationKey, issuerName string, err error) {
        namespace := e.Integration.Namespace
 
-       installed, err := certmanager.IsInstalled(t.Client)
-       if err != nil {
-               return "", "", err
-       }
-
        if t.TLSIssuerName != "" {
-               if !installed {
+               if !platform.CertManagerInstalled {
                        return "", "", fmt.Errorf("cert-manager is not 
installed but tlsIssuerName %q was set", t.TLSIssuerName)
                }
 
@@ -232,7 +228,7 @@ func (t *ingressTrait) resolveCertManagerIssuer(e 
*Environment) (annotationKey,
                }
        }
 
-       if !ptr.Deref(t.TLSCertManagerAuto, false) || !installed {
+       if !ptr.Deref(t.TLSCertManagerAuto, false) || 
!platform.CertManagerInstalled {
                return "", "", nil
        }
 
diff --git a/pkg/trait/ingress_test.go b/pkg/trait/ingress_test.go
index dd0acd237..859fe73b4 100644
--- a/pkg/trait/ingress_test.go
+++ b/pkg/trait/ingress_test.go
@@ -33,6 +33,7 @@ import (
        v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
        certmanagerv1 
"github.com/apache/camel-k/v2/pkg/apis/duck/certmanager/v1"
        "github.com/apache/camel-k/v2/pkg/internal"
+       "github.com/apache/camel-k/v2/pkg/platform"
        "github.com/apache/camel-k/v2/pkg/util/certmanager"
        "github.com/apache/camel-k/v2/pkg/util/kubernetes"
 )
@@ -340,12 +341,14 @@ func 
TestConfigureTLSWithoutSecretNameIngressTraitWDoesSucceed(t *testing.T) {
 }
 
 func TestApplyIngressTraitCertManagerAutoNotInstalledDoesNoop(t *testing.T) {
+       platform.CertManagerInstalled = false
+       t.Cleanup(func() { platform.CertManagerInstalled = false })
+
        ingressTrait, environment := createNominalIngressTest()
        ingressTrait.TLSCertManagerAuto = ptr.To(true)
        environment.Ctx = context.Background()
        fakeClient, err := internal.NewFakeClient()
        require.NoError(t, err)
-       fakeClient.(*internal.FakeClient).DisableCertManagerDiscovery()
        ingressTrait.Client = fakeClient
 
        _, _, err = ingressTrait.Configure(environment)
@@ -363,6 +366,9 @@ func 
TestApplyIngressTraitCertManagerAutoNotInstalledDoesNoop(t *testing.T) {
 }
 
 func TestApplyIngressTraitCertManagerAutoNoIssuerDoesNoop(t *testing.T) {
+       platform.CertManagerInstalled = true
+       t.Cleanup(func() { platform.CertManagerInstalled = false })
+
        ingressTrait, environment := createNominalIngressTest()
        ingressTrait.TLSCertManagerAuto = ptr.To(true)
        environment.Ctx = context.Background()
@@ -384,6 +390,9 @@ func TestApplyIngressTraitCertManagerAutoNoIssuerDoesNoop(t 
*testing.T) {
 }
 
 func TestApplyIngressTraitCertManagerAutoClusterIssuerFoundDoesSucceed(t 
*testing.T) {
+       platform.CertManagerInstalled = true
+       t.Cleanup(func() { platform.CertManagerInstalled = false })
+
        ingressTrait, environment := createNominalIngressTest()
        ingressTrait.TLSCertManagerAuto = ptr.To(true)
        environment.Ctx = context.Background()
@@ -409,6 +418,9 @@ func 
TestApplyIngressTraitCertManagerAutoClusterIssuerFoundDoesSucceed(t *testin
 }
 
 func TestApplyIngressTraitForcedIssuerExistsDoesSucceed(t *testing.T) {
+       platform.CertManagerInstalled = true
+       t.Cleanup(func() { platform.CertManagerInstalled = false })
+
        ingressTrait, environment := createNominalIngressTest()
        ingressTrait.TLSIssuerName = "my-issuer"
        ingressTrait.TLSIssuerKind = "Issuer"
@@ -435,6 +447,9 @@ func TestApplyIngressTraitForcedIssuerExistsDoesSucceed(t 
*testing.T) {
 }
 
 func TestApplyIngressTraitForcedIssuerMissingDoesNotSucceed(t *testing.T) {
+       platform.CertManagerInstalled = true
+       t.Cleanup(func() { platform.CertManagerInstalled = false })
+
        ingressTrait, environment := createNominalIngressTest()
        ingressTrait.TLSIssuerName = "missing-issuer"
        environment.Ctx = context.Background()
@@ -451,13 +466,15 @@ func 
TestApplyIngressTraitForcedIssuerMissingDoesNotSucceed(t *testing.T) {
 }
 
 func TestApplyIngressTraitForcedIssuerCertManagerNotInstalledDoesNotSucceed(t 
*testing.T) {
+       platform.CertManagerInstalled = false
+       t.Cleanup(func() { platform.CertManagerInstalled = false })
+
        ingressTrait, environment := createNominalIngressTest()
        ingressTrait.TLSIssuerName = "my-issuer"
        environment.Ctx = context.Background()
 
        fakeClient, err := internal.NewFakeClient()
        require.NoError(t, err)
-       fakeClient.(*internal.FakeClient).DisableCertManagerDiscovery()
        ingressTrait.Client = fakeClient
 
        _, _, err = ingressTrait.Configure(environment)
diff --git a/pkg/util/certmanager/enabled.go b/pkg/util/certmanager/enabled.go
index 32b13a7d4..c4d46a0e8 100644
--- a/pkg/util/certmanager/enabled.go
+++ b/pkg/util/certmanager/enabled.go
@@ -23,8 +23,6 @@ import (
 
        k8serrors "k8s.io/apimachinery/pkg/api/errors"
        "k8s.io/apimachinery/pkg/api/meta"
-       "k8s.io/apimachinery/pkg/runtime/schema"
-       "k8s.io/client-go/kubernetes"
        ctrl "sigs.k8s.io/controller-runtime/pkg/client"
 
        certmanagerv1 
"github.com/apache/camel-k/v2/pkg/apis/duck/certmanager/v1"
@@ -46,21 +44,6 @@ func isResourceNotFoundError(err error) bool {
        return k8serrors.IsNotFound(err) || meta.IsNoMatchError(err) || 
kubernetesutil.IsUnknownAPIError(err)
 }
 
-// IsInstalled returns true if connected to a cluster with cert-manager 
installed.
-func IsInstalled(c kubernetes.Interface) (bool, error) {
-       _, err := 
c.Discovery().ServerResourcesForGroupVersion(schema.GroupVersion{
-               Group:   certmanagerv1.CertManagerGroup,
-               Version: certmanagerv1.CertManagerVersion,
-       }.String())
-       if isResourceNotFoundError(err) {
-               return false, nil
-       } else if err != nil {
-               return false, err
-       }
-
-       return true, nil
-}
-
 // ListClusterIssuers returns all ClusterIssuer names available in the cluster.
 func ListClusterIssuers(ctx context.Context, c ctrl.Reader) ([]string, error) {
        list := &certmanagerv1.ClusterIssuerList{}

Reply via email to