You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2019/11/04 16:10:53 UTC
[camel-k] 29/38: feat(quarkus): Use runtime provider label selector
to list kits
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 fb6d63704c972d1186f0b0dd0513f2e85b6f9894
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Oct 28 14:51:35 2019 +0100
feat(quarkus): Use runtime provider label selector to list kits
---
pkg/builder/builder_steps.go | 23 ++++++++++++++++++++---
pkg/controller/integration/build_kit.go | 4 ++++
pkg/controller/integration/util.go | 22 ++++++++++++++++++++--
pkg/util/camel/camel_runtime.go | 4 ++--
4 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/pkg/builder/builder_steps.go b/pkg/builder/builder_steps.go
index 3e08e79..d44d579 100644
--- a/pkg/builder/builder_steps.go
+++ b/pkg/builder/builder_steps.go
@@ -24,9 +24,13 @@ import (
"reflect"
"strings"
+ "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/util/controller"
"github.com/apache/camel-k/pkg/util/kubernetes"
"github.com/apache/camel-k/pkg/util/maven"
"github.com/apache/camel-k/pkg/util/tar"
@@ -329,9 +333,22 @@ func packager(ctx *Context, selector artifactsSelector) error {
}
func listPublishedImages(context *Context) ([]publishedImage, error) {
- list := v1alpha1.NewIntegrationKitList()
+ options := []k8sclient.ListOption{
+ k8sclient.InNamespace(context.Namespace),
+ }
- err := context.Client.List(context.C, &list, k8sclient.InNamespace(context.Namespace))
+ if context.Catalog.RuntimeProvider != nil && context.Catalog.RuntimeProvider.Quarkus != nil {
+ options = append(options, k8sclient.MatchingLabels{
+ "camel.apache.org/runtime.provider": "quarkus",
+ })
+ } else {
+ provider, _ := labels.NewRequirement("camel.apache.org/runtime.provider", selection.DoesNotExist, []string{})
+ selector := labels.NewSelector().Add(*provider)
+ options = append(options, controller.MatchingSelector{Selector: selector})
+ }
+
+ list := v1alpha1.NewIntegrationKitList()
+ err := context.Client.List(context.C, &list, options...)
if err != nil {
return nil, err
}
@@ -350,7 +367,7 @@ func listPublishedImages(context *Context) ([]publishedImage, error) {
continue
}
- // TODO: should ideally be made generic
+ // TODO: should ideally be made generic from the runtime providers
if kit.Status.RuntimeProvider == nil && context.Catalog.RuntimeProvider != nil ||
kit.Status.RuntimeProvider != nil && context.Catalog.RuntimeProvider == nil ||
kit.Status.RuntimeProvider != nil && context.Catalog.RuntimeProvider != nil &&
diff --git a/pkg/controller/integration/build_kit.go b/pkg/controller/integration/build_kit.go
index c2976ee..beb078c 100644
--- a/pkg/controller/integration/build_kit.go
+++ b/pkg/controller/integration/build_kit.go
@@ -113,6 +113,10 @@ func (action *buildKitAction) Handle(ctx context.Context, integration *v1alpha1.
"camel.apache.org/kit.created.by.version": integration.ResourceVersion,
}
+ if integration.Status.RuntimeProvider != nil && integration.Status.RuntimeProvider.Quarkus != nil {
+ platformKit.Labels["camel.apache.org/runtime.provider"] = "quarkus"
+ }
+
// Set the kit to have the same characteristics as the integrations
platformKit.Spec = v1alpha1.IntegrationKitSpec{
Dependencies: integration.Status.Dependencies,
diff --git a/pkg/controller/integration/util.go b/pkg/controller/integration/util.go
index 39e3495..261153a 100644
--- a/pkg/controller/integration/util.go
+++ b/pkg/controller/integration/util.go
@@ -22,10 +22,14 @@ import (
"github.com/pkg/errors"
+ "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/util"
+ "github.com/apache/camel-k/pkg/util/controller"
"github.com/apache/camel-k/pkg/util/kubernetes"
)
@@ -45,8 +49,22 @@ func LookupKitForIntegration(ctx context.Context, c k8sclient.Reader, integratio
return kit, nil
}
+ options := []k8sclient.ListOption{
+ k8sclient.InNamespace(integration.Namespace),
+ }
+
+ if integration.Status.RuntimeProvider != nil && integration.Status.RuntimeProvider.Quarkus != nil {
+ options = append(options, k8sclient.MatchingLabels{
+ "camel.apache.org/runtime.provider": "quarkus",
+ })
+ } else {
+ provider, _ := labels.NewRequirement("camel.apache.org/runtime.provider", selection.DoesNotExist, []string{})
+ selector := labels.NewSelector().Add(*provider)
+ options = append(options, controller.MatchingSelector{Selector: selector})
+ }
+
kits := v1alpha1.NewIntegrationKitList()
- if err := c.List(ctx, &kits, k8sclient.InNamespace(integration.Namespace)); err != nil {
+ if err := c.List(ctx, &kits, options...); err != nil {
return nil, err
}
@@ -66,7 +84,7 @@ func LookupKitForIntegration(ctx context.Context, c k8sclient.Reader, integratio
continue
}
- // TODO: should ideally be made generic
+ // TODO: should ideally be made generic from the runtime providers
if integration.Status.RuntimeProvider == nil && kit.Status.RuntimeProvider != nil ||
integration.Status.RuntimeProvider != nil && kit.Status.RuntimeProvider == nil ||
integration.Status.RuntimeProvider != nil && kit.Status.RuntimeProvider != nil &&
diff --git a/pkg/util/camel/camel_runtime.go b/pkg/util/camel/camel_runtime.go
index c9aea1b..420ebe3 100644
--- a/pkg/util/camel/camel_runtime.go
+++ b/pkg/util/camel/camel_runtime.go
@@ -37,8 +37,8 @@ func LoadCatalog(ctx context.Context, client client.Client, namespace string, ca
}
if provider == nil {
- integration, _ := labels.NewRequirement("camel.apache.org/runtime.provider", selection.DoesNotExist, []string{})
- selector := labels.NewSelector().Add(*integration)
+ requirement, _ := labels.NewRequirement("camel.apache.org/runtime.provider", selection.DoesNotExist, []string{})
+ selector := labels.NewSelector().Add(*requirement)
options = append(options, controller.MatchingSelector{Selector: selector})
} else if _, ok := provider.(v1alpha1.QuarkusRuntimeProvider); ok {
options = append(options, k8sclient.MatchingLabels{