Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

context with status error should not be included when looking up suitable context for an integration #585

Merged
merged 1 commit into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/builder/builder_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
78 changes: 78 additions & 0 deletions pkg/builder/builder_steps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
7 changes: 7 additions & 0 deletions pkg/controller/integration/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
124 changes: 124 additions & 0 deletions pkg/controller/integration/util_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
60 changes: 60 additions & 0 deletions pkg/util/test/client.go
Original file line number Diff line number Diff line change
@@ -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
}