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/04/03 08:38:55 UTC

[camel-k] branch master updated: context with status error should not be included when looking up suitable context for an integration #584

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


The following commit(s) were added to refs/heads/master by this push:
     new 9416251  context with status error should not be included when looking up suitable context for an integration #584
9416251 is described below

commit 9416251124b309aa90d95605f5c2217471bae43e
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Tue Apr 2 15:01:27 2019 +0200

    context with status error should not be included when looking up suitable context for an integration #584
---
 pkg/builder/builder_steps.go            |   3 +
 pkg/builder/builder_steps_test.go       |  78 ++++++++++++++++++++
 pkg/controller/integration/util.go      |   7 ++
 pkg/controller/integration/util_test.go | 124 ++++++++++++++++++++++++++++++++
 pkg/util/test/client.go                 |  60 ++++++++++++++++
 5 files changed, 272 insertions(+)

diff --git a/pkg/builder/builder_steps.go b/pkg/builder/builder_steps.go
index dd465a5..e2a7c04 100644
--- a/pkg/builder/builder_steps.go
+++ b/pkg/builder/builder_steps.go
@@ -323,6 +323,9 @@ func ListPublishedImages(context *Context) ([]PublishedImage, error) {
 	for _, item := range list.Items {
 		ctx := item
 
+		if ctx.Status.Phase != v1alpha1.IntegrationContextPhaseReady {
+			continue
+		}
 		if ctx.Status.CamelVersion != context.Catalog.Version {
 			continue
 		}
diff --git a/pkg/builder/builder_steps_test.go b/pkg/builder/builder_steps_test.go
index e85bc55..00addc3 100644
--- a/pkg/builder/builder_steps_test.go
+++ b/pkg/builder/builder_steps_test.go
@@ -27,6 +27,7 @@ import (
 	"github.com/apache/camel-k/pkg/util/defaults"
 	"github.com/apache/camel-k/pkg/util/maven"
 	"github.com/apache/camel-k/pkg/util/test"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 
 	"github.com/stretchr/testify/assert"
 )
@@ -346,3 +347,80 @@ func TestFailure(t *testing.T) {
 	assert.NotNil(t, res)
 	assert.Equal(t, StatusError, res.Status)
 }
+
+func TestListPublishedImages(t *testing.T) {
+	catalog, err := test.DefaultCatalog()
+	assert.Nil(t, err)
+
+	c, err := test.NewFakeClient(
+		&v1alpha1.IntegrationContext{
+			TypeMeta: metav1.TypeMeta{
+				APIVersion: v1alpha1.SchemeGroupVersion.String(),
+				Kind:       v1alpha1.IntegrationContextKind,
+			},
+			ObjectMeta: metav1.ObjectMeta{
+				Namespace: "ns",
+				Name:      "my-context-1",
+				Labels: map[string]string{
+					"camel.apache.org/context.type": v1alpha1.IntegrationContextTypePlatform,
+				},
+			},
+			Status: v1alpha1.IntegrationContextStatus{
+				Phase:        v1alpha1.IntegrationContextPhaseError,
+				Image:        "image-1",
+				CamelVersion: catalog.Version,
+			},
+		},
+		&v1alpha1.IntegrationContext{
+			TypeMeta: metav1.TypeMeta{
+				APIVersion: v1alpha1.SchemeGroupVersion.String(),
+				Kind:       v1alpha1.IntegrationContextKind,
+			},
+			ObjectMeta: metav1.ObjectMeta{
+				Namespace: "ns",
+				Name:      "my-context-2",
+				Labels: map[string]string{
+					"camel.apache.org/context.type": v1alpha1.IntegrationContextTypePlatform,
+				},
+			},
+			Status: v1alpha1.IntegrationContextStatus{
+				Phase:        v1alpha1.IntegrationContextPhaseBuildFailureRecovery,
+				Image:        "image-3",
+				CamelVersion: catalog.Version,
+			},
+		},
+		&v1alpha1.IntegrationContext{
+			TypeMeta: metav1.TypeMeta{
+				APIVersion: v1alpha1.SchemeGroupVersion.String(),
+				Kind:       v1alpha1.IntegrationContextKind,
+			},
+			ObjectMeta: metav1.ObjectMeta{
+				Namespace: "ns",
+				Name:      "my-context-3",
+				Labels: map[string]string{
+					"camel.apache.org/context.type": v1alpha1.IntegrationContextTypePlatform,
+				},
+			},
+			Status: v1alpha1.IntegrationContextStatus{
+				Phase:        v1alpha1.IntegrationContextPhaseReady,
+				Image:        "image-3",
+				CamelVersion: catalog.Version,
+			},
+		},
+	)
+
+	assert.Nil(t, err)
+	assert.NotNil(t, c)
+
+	i, err := ListPublishedImages(&Context{
+		Client:  c,
+		Catalog: catalog,
+		Request: Request{
+			C: cancellable.NewContext(),
+		},
+	})
+
+	assert.Nil(t, err)
+	assert.Len(t, i, 1)
+	assert.Equal(t, "image-3", i[0].Image)
+}
diff --git a/pkg/controller/integration/util.go b/pkg/controller/integration/util.go
index d471a0b..b66e896 100644
--- a/pkg/controller/integration/util.go
+++ b/pkg/controller/integration/util.go
@@ -55,6 +55,13 @@ func LookupContextForIntegration(ctx context.Context, c k8sclient.Reader, integr
 	for _, ctx := range ctxList.Items {
 		ctx := ctx // pin
 
+		if ctx.Status.Phase == v1alpha1.IntegrationContextPhaseError {
+			continue
+		}
+		if ctx.Status.Phase == v1alpha1.IntegrationContextPhaseBuildFailureRecovery {
+			continue
+		}
+
 		if ctx.Status.CamelVersion != integration.Status.CamelVersion {
 			continue
 		}
diff --git a/pkg/controller/integration/util_test.go b/pkg/controller/integration/util_test.go
new file mode 100644
index 0000000..2205536
--- /dev/null
+++ b/pkg/controller/integration/util_test.go
@@ -0,0 +1,124 @@
+/*
+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 integration
+
+import (
+	"context"
+	"testing"
+
+	"github.com/apache/camel-k/pkg/util/test"
+
+	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+
+	"github.com/stretchr/testify/assert"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+)
+
+func TestLookupContextForIntegration(t *testing.T) {
+	c, err := test.NewFakeClient(
+		&v1alpha1.IntegrationContext{
+			TypeMeta: metav1.TypeMeta{
+				APIVersion: v1alpha1.SchemeGroupVersion.String(),
+				Kind:       v1alpha1.IntegrationContextKind,
+			},
+			ObjectMeta: metav1.ObjectMeta{
+				Namespace: "ns",
+				Name:      "my-context-1",
+				Labels: map[string]string{
+					"camel.apache.org/context.type": v1alpha1.IntegrationContextTypePlatform,
+				},
+			},
+			Spec: v1alpha1.IntegrationContextSpec{
+				Dependencies: []string{
+					"camel-core",
+					"camel-irc",
+				},
+			},
+			Status: v1alpha1.IntegrationContextStatus{
+				Phase: v1alpha1.IntegrationContextPhaseError,
+			},
+		},
+		&v1alpha1.IntegrationContext{
+			TypeMeta: metav1.TypeMeta{
+				APIVersion: v1alpha1.SchemeGroupVersion.String(),
+				Kind:       v1alpha1.IntegrationContextKind,
+			},
+			ObjectMeta: metav1.ObjectMeta{
+				Namespace: "ns",
+				Name:      "my-context-2",
+				Labels: map[string]string{
+					"camel.apache.org/context.type": v1alpha1.IntegrationContextTypePlatform,
+				},
+			},
+			Spec: v1alpha1.IntegrationContextSpec{
+				Dependencies: []string{
+					"camel-core",
+					"camel-irc",
+				},
+			},
+			Status: v1alpha1.IntegrationContextStatus{
+				Phase: v1alpha1.IntegrationContextPhaseBuildFailureRecovery,
+			},
+		},
+		&v1alpha1.IntegrationContext{
+			TypeMeta: metav1.TypeMeta{
+				APIVersion: v1alpha1.SchemeGroupVersion.String(),
+				Kind:       v1alpha1.IntegrationContextKind,
+			},
+			ObjectMeta: metav1.ObjectMeta{
+				Namespace: "ns",
+				Name:      "my-context-3",
+				Labels: map[string]string{
+					"camel.apache.org/context.type": v1alpha1.IntegrationContextTypePlatform,
+				},
+			},
+			Spec: v1alpha1.IntegrationContextSpec{
+				Dependencies: []string{
+					"camel-core",
+					"camel-irc",
+				},
+			},
+			Status: v1alpha1.IntegrationContextStatus{
+				Phase: v1alpha1.IntegrationContextPhaseReady,
+			},
+		},
+	)
+
+	assert.Nil(t, err)
+
+	i, err := LookupContextForIntegration(context.TODO(), c, &v1alpha1.Integration{
+		TypeMeta: metav1.TypeMeta{
+			APIVersion: v1alpha1.SchemeGroupVersion.String(),
+			Kind:       v1alpha1.IntegrationKind,
+		},
+		ObjectMeta: metav1.ObjectMeta{
+			Namespace: "ns",
+			Name:      "my-integration",
+		},
+		Status: v1alpha1.IntegrationStatus{
+			Dependencies: []string{
+				"camel-core",
+				"camel-irc",
+			},
+		},
+	})
+
+	assert.Nil(t, err)
+	assert.NotNil(t, i)
+	assert.Equal(t, "my-context-3", i.Name)
+}
diff --git a/pkg/util/test/client.go b/pkg/util/test/client.go
new file mode 100644
index 0000000..10c9e93
--- /dev/null
+++ b/pkg/util/test/client.go
@@ -0,0 +1,60 @@
+/*
+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 test
+
+import (
+	"github.com/apache/camel-k/pkg/apis"
+	"github.com/apache/camel-k/pkg/client"
+
+	"k8s.io/apimachinery/pkg/runtime"
+	"k8s.io/client-go/kubernetes"
+
+	"sigs.k8s.io/controller-runtime/pkg/client/fake"
+
+	clientscheme "k8s.io/client-go/kubernetes/scheme"
+	controller "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+// NewFakeClient ---
+func NewFakeClient(initObjs ...runtime.Object) (client.Client, error) {
+	scheme := clientscheme.Scheme
+
+	// Setup Scheme for all resources
+	if err := apis.AddToScheme(scheme); err != nil {
+		return nil, err
+	}
+
+	c := fake.NewFakeClientWithScheme(scheme, initObjs...)
+
+	return &FakeClient{
+		Client:    c,
+		Interface: nil,
+	}, nil
+
+}
+
+// FakeClient ---
+type FakeClient struct {
+	controller.Client
+	kubernetes.Interface
+}
+
+// GetScheme ---
+func (c *FakeClient) GetScheme() *runtime.Scheme {
+	return nil
+}