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

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

commit bf77dc8b8c31aa4804831e62647848d9f58a2e3d
Author: Antonin Stefanutti <[email protected]>
AuthorDate: Wed Oct 23 12:06:25 2019 +0200

    feat(quarkus): Only load catalogs matching the specified runtime provider
---
 pkg/trait/gc.go                 | 11 ++---------
 pkg/util/camel/camel_runtime.go | 10 +++++++++-
 pkg/util/controller/util.go     | 31 +++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/pkg/trait/gc.go b/pkg/trait/gc.go
index 07deb52..3d60852 100644
--- a/pkg/trait/gc.go
+++ b/pkg/trait/gc.go
@@ -33,6 +33,7 @@ import (
        "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
        "github.com/apache/camel-k/pkg/client"
        "github.com/apache/camel-k/pkg/util"
+       controllerUtil "github.com/apache/camel-k/pkg/util/controller"
 )
 
 type garbageCollectorTrait struct {
@@ -153,7 +154,7 @@ func lookUpResources(ctx context.Context, client 
client.Client, namespace string
                }
                options := []controller.ListOption{
                        controller.InNamespace(namespace),
-                       matchingSelector{selector: selector},
+                       controllerUtil.MatchingSelector{Selector: selector},
                }
                if err := client.List(ctx, &list, options...); err != nil {
                        if k8serrors.IsNotFound(err) || 
k8serrors.IsForbidden(err) {
@@ -192,11 +193,3 @@ func getDiscoveryTypesWithVerbs(client client.Client, 
verbs []string) ([]metav1.
 
        return types, nil
 }
-
-type matchingSelector struct {
-       selector labels.Selector
-}
-
-func (s matchingSelector) ApplyToList(opts *controller.ListOptions) {
-       opts.LabelSelector = s.selector
-}
diff --git a/pkg/util/camel/camel_runtime.go b/pkg/util/camel/camel_runtime.go
index 331d648..b62b967 100644
--- a/pkg/util/camel/camel_runtime.go
+++ b/pkg/util/camel/camel_runtime.go
@@ -21,10 +21,14 @@ import (
        "context"
        "fmt"
 
+       "k8s.io/apimachinery/pkg/labels"
+       "k8s.io/apimachinery/pkg/selection"
+
        k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
 
        "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
        "github.com/apache/camel-k/pkg/client"
+       controllerUtil "github.com/apache/camel-k/pkg/util/controller"
 )
 
 // LoadCatalog --
@@ -33,7 +37,11 @@ func LoadCatalog(ctx context.Context, client client.Client, 
namespace string, ca
                k8sclient.InNamespace(namespace),
        }
 
-       if _, ok := provider.(v1alpha1.QuarkusRuntimeProvider); ok {
+       if provider == nil {
+               integration, _ := 
labels.NewRequirement("camel.apache.org/runtime.provider", 
selection.DoesNotExist, []string{})
+               selector := labels.NewSelector().Add(*integration)
+               options = append(options, 
controllerUtil.MatchingSelector{Selector: selector})
+       } else if _, ok := provider.(v1alpha1.QuarkusRuntimeProvider); ok {
                options = append(options, k8sclient.MatchingLabels{
                        "camel.apache.org/runtime.provider": "quarkus",
                })
diff --git a/pkg/util/controller/util.go b/pkg/util/controller/util.go
new file mode 100644
index 0000000..007abf6
--- /dev/null
+++ b/pkg/util/controller/util.go
@@ -0,0 +1,31 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package controller
+
+import (
+       "k8s.io/apimachinery/pkg/labels"
+       "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+type MatchingSelector struct {
+       Selector labels.Selector
+}
+
+func (s MatchingSelector) ApplyToList(opts *client.ListOptions) {
+       opts.LabelSelector = s.Selector
+}

Reply via email to