Skip to content

Commit

Permalink
Add test for new annotation on build pod
Browse files Browse the repository at this point in the history
  • Loading branch information
rodcloutier authored and squakez committed Jan 26, 2024
1 parent ab6217d commit ec9406b
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/apis/camel/v1/trait/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ type BuilderTrait struct {
TasksLimitMemory []string `property:"tasks-limit-memory" json:"tasksLimitMemory,omitempty"`
// Defines a set of nodes the builder pod is eligible to be scheduled on, based on labels on the node.
NodeSelector map[string]string `property:"node-selector" json:"nodeSelector,omitempty"`
// When using `pod` strategy, annotation to use for the builder pod.
Annotations map[string]string `property:"annotations" json:"annotations,omitempty"`
}
68 changes: 68 additions & 0 deletions pkg/controller/build/build_pod_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
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 build

import (
"context"
"testing"

v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
"github.com/apache/camel-k/v2/pkg/util/test"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestNewBuildPodConfiguration(t *testing.T) {

ctx := context.TODO()
c, err := test.NewFakeClient()
assert.Nil(t, err)

build := v1.Build{
ObjectMeta: metav1.ObjectMeta{
Name: "theBuildName",
},
Spec: v1.BuildSpec{
Tasks: []v1.Task{
{
Builder: &v1.BuilderTask{
BaseTask: v1.BaseTask{
Name: "builder",
Configuration: v1.BuildConfiguration{
BuilderPodNamespace: "theNamespace",
NodeSelector: map[string]string{"node": "selector"},
Annotations: map[string]string{"annotation": "value"},
},
},
},
},
},
},
}

pod := newBuildPod(ctx, c, &build)

assert.Equal(t, "Pod", pod.Kind)
assert.Equal(t, "theNamespace", pod.Namespace)
assert.Equal(t, map[string]string{
"camel.apache.org/build": "theBuildName",
"camel.apache.org/component": "builder",
}, pod.Labels)
assert.Equal(t, map[string]string{"node": "selector"}, pod.Spec.NodeSelector)
assert.Equal(t, map[string]string{"annotation": "value"}, pod.Annotations)
}
1 change: 1 addition & 0 deletions pkg/trait/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (t *builderTrait) Apply(e *Environment) error {
return nil
}
builderTask.Configuration.NodeSelector = t.NodeSelector
builderTask.Configuration.Annotations = t.Annotations
pipelineTasks = append(pipelineTasks, v1.Task{Builder: builderTask})

// Custom tasks
Expand Down
20 changes: 20 additions & 0 deletions pkg/trait/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,26 @@ func TestBuilderWithNodeSelector(t *testing.T) {
assert.Equal(t, map[string]string{"size": "large"}, builderTrait.NodeSelector)
}

func TestBuilderWithAnnotations(t *testing.T) {
env := createBuilderTestEnv(v1.IntegrationPlatformClusterKubernetes, v1.IntegrationPlatformBuildPublishStrategyJib, v1.BuildStrategyRoutine)
builderTrait := createNominalBuilderTraitTest()
builderTrait.Annotations = map[string]string{
"annotation": "value",
}

active, condition, err := builderTrait.Configure(env)
assert.Nil(t, err)

err = builderTrait.Apply(env)
assert.Nil(t, err)

assert.True(t, active)
assert.Nil(t, condition)

assert.Equal(t, map[string]string{"annotation": "value"}, env.Pipeline[0].Builder.Configuration.Annotations)
assert.Equal(t, map[string]string{"annotation": "value"}, builderTrait.Annotations)
}

func TestBuilderNoTasksFilter(t *testing.T) {
env := createBuilderTestEnv(v1.IntegrationPlatformClusterKubernetes, v1.IntegrationPlatformBuildPublishStrategyJib, v1.BuildStrategyPod)
builderTrait := createNominalBuilderTraitTest()
Expand Down

0 comments on commit ec9406b

Please sign in to comment.