This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push:
new b7ff260de fix(ctrl): include image status after custom publishing task
b7ff260de is described below
commit b7ff260de965d9829d74c9dcac6a45b75c48cb97
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Sat Mar 28 09:07:14 2026 +0100
fix(ctrl): include image status after custom publishing task
Closes #6534
---
e2e/common/traits/builder_test.go | 20 ++++
pkg/controller/build/build_pod_test.go | 1 -
pkg/controller/build/monitor_pod.go | 23 ++++-
pkg/controller/build/monitor_pod_test.go | 164 +++++++++++++++++++++++++++++++
pkg/event/manager.go | 4 +
5 files changed, 210 insertions(+), 2 deletions(-)
diff --git a/e2e/common/traits/builder_test.go
b/e2e/common/traits/builder_test.go
index 2a0b44a5a..9377af043 100644
--- a/e2e/common/traits/builder_test.go
+++ b/e2e/common/traits/builder_test.go
@@ -231,3 +231,23 @@ func TestBuilderTrait(t *testing.T) {
})
})
}
+
+func TestCustomPipelineBuildah(t *testing.T) {
+ t.Parallel()
+ WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
+ t.Run("Run Buildah custom publish task", func(t *testing.T) {
+ name := RandomizedSuffixName("java")
+ g.Expect(KamelRun(t, ctx, ns, "files/Java.java",
+ "--name", name,
+ "-t", "builder.strategy=pod",
+ "-t",
"builder.base-image=docker.io/library/eclipse-temurin:17",
+ "-t",
`builder.tasks=my-buildah;quay.io/buildah/stable;/bin/bash -c \"cd context &&
buildah bud --storage-driver=vfs --tls-verify=false -t $(INTEGRATION_KIT_IMAGE)
. && buildah push --storage-driver=vfs --digestfile=/dev/termination-log
--tls-verify=false $(INTEGRATION_KIT_IMAGE)
docker://$(INTEGRATION_KIT_IMAGE)";0`,
+ "-t",
"builder.tasks-filter=builder,package,my-buildah",
+ ).Execute()).To(Succeed())
+
+ g.Eventually(IntegrationConditionStatus(t, ctx, ns,
name, v1.IntegrationConditionReady),
TestTimeoutMedium).Should(Equal(corev1.ConditionTrue))
+ g.Eventually(IntegrationPodPhase(t, ctx, ns,
name)).Should(Equal(corev1.PodRunning))
+ g.Eventually(IntegrationLogs(t, ctx, ns,
name)).Should(ContainSubstring("Magicstring!"))
+ })
+ })
+}
diff --git a/pkg/controller/build/build_pod_test.go
b/pkg/controller/build/build_pod_test.go
index 7a41d3923..8467e6e31 100644
--- a/pkg/controller/build/build_pod_test.go
+++ b/pkg/controller/build/build_pod_test.go
@@ -29,7 +29,6 @@ import (
)
func TestNewBuildPodConfiguration(t *testing.T) {
-
ctx := context.TODO()
c, err := internal.NewFakeClient()
require.NoError(t, err)
diff --git a/pkg/controller/build/monitor_pod.go
b/pkg/controller/build/monitor_pod.go
index 4cd1e8dd2..8cf352635 100644
--- a/pkg/controller/build/monitor_pod.go
+++ b/pkg/controller/build/monitor_pod.go
@@ -144,8 +144,20 @@ func (action *monitorPodAction) Handle(ctx
context.Context, build *v1.Build) (*v
// Account for the Build metrics
observeBuildResult(build, build.Status.Phase, buildCreator,
duration)
- // operator supported publishing tasks should provide the
digest in the builder command process execution
+ // operator supported publishing tasks should provide the image
name and digest in the builder command process execution
if !operatorSupportedPublishingStrategy(build.Spec.Tasks) {
+ build.Status.Image = publishTaskImage(build.Spec.Tasks)
+ if build.Status.Image == "" {
+ // Image not available
+ build.Status.Phase = v1.BuildPhaseError
+ build.Status.SetCondition(
+ "ContainerImageAvailable",
+ corev1.ConditionFalse,
+ "ContainerImageAvailable",
+ publishTaskName(build.Spec.Tasks)+
+ " publishing task completed but
no image is available",
+ )
+ }
build.Status.Digest =
publishTaskDigest(build.Spec.Tasks, pod.Status.ContainerStatuses)
if build.Status.Digest == "" {
// Likely to happen for users provided
publishing tasks and not providing the digest image among statuses
@@ -380,6 +392,15 @@ func publishTaskDigest(tasks []v1.Task, cntStates
[]corev1.ContainerStatus) stri
return ""
}
+func publishTaskImage(tasks []v1.Task) string {
+ t := publishTask(tasks)
+ if t != nil && t.Custom != nil {
+ return t.Custom.PublishingImage
+ }
+
+ return ""
+}
+
func operatorSupportedPublishingStrategy(tasks []v1.Task) bool {
taskName := publishTaskName(tasks)
diff --git a/pkg/controller/build/monitor_pod_test.go
b/pkg/controller/build/monitor_pod_test.go
new file mode 100644
index 000000000..27295416b
--- /dev/null
+++ b/pkg/controller/build/monitor_pod_test.go
@@ -0,0 +1,164 @@
+/*
+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"
+ "time"
+
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+ v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
+ "github.com/apache/camel-k/v2/pkg/internal"
+ "github.com/apache/camel-k/v2/pkg/util/log"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+ corev1 "k8s.io/api/core/v1"
+)
+
+func TestHandle_PodSucceeded(t *testing.T) {
+ now := time.Now()
+ start := metav1.NewTime(now.Add(-2 * time.Minute))
+ end := metav1.NewTime(now.Add(2 * time.Minute))
+
+ build := &v1.Build{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "test-build",
+ Namespace: "default",
+ },
+ Spec: v1.BuildSpec{
+ Timeout: metav1.Duration{Duration: 5 * time.Minute},
+ Tasks: []v1.Task{
+ {
+ Custom: &v1.UserTask{
+ BaseTask: v1.BaseTask{
+ Configuration:
v1.BuildConfiguration{
+
BuilderPodNamespace: "default",
+ },
+ },
+ PublishingImage:
"my-camel-k-container-image",
+ },
+ },
+ },
+ },
+ Status: v1.BuildStatus{
+ Phase: v1.BuildPhaseRunning,
+ StartedAt: &start,
+ },
+ }
+
+ pod := &corev1.Pod{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: buildPodName(build),
+ Namespace: build.BuilderPodNamespace(),
+ Annotations: map[string]string{},
+ },
+ Status: corev1.PodStatus{
+ Phase: corev1.PodSucceeded,
+ ContainerStatuses: []corev1.ContainerStatus{
+ {
+ State: corev1.ContainerState{
+ Terminated:
&corev1.ContainerStateTerminated{
+ ExitCode: 0,
+ FinishedAt: end,
+ Message:
"sha:123456",
+ },
+ },
+ },
+ },
+ },
+ }
+
+ c, err := internal.NewFakeClient(build, pod)
+ require.NoError(t, err)
+
+ a := monitorPodAction{
+ reader: c,
+ }
+ a.InjectLogger(log.Log)
+ a.InjectClient(c)
+
+ result, err := a.Handle(context.Background(), build)
+
+ require.NoError(t, err)
+ require.NotNil(t, result)
+
+ assert.Equal(t, v1.BuildPhaseSucceeded, result.Status.Phase)
+ assert.Equal(t, "sha:123456", result.Status.Digest)
+ assert.Equal(t, "my-camel-k-container-image", result.Status.Image)
+}
+
+func TestHandle_PodFailed(t *testing.T) {
+ now := time.Now()
+ start := metav1.NewTime(now.Add(-2 * time.Minute))
+
+ build := &v1.Build{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "test-build",
+ Namespace: "default",
+ },
+ Spec: v1.BuildSpec{
+ Timeout: metav1.Duration{Duration: 5 * time.Minute},
+ Tasks: []v1.Task{
+ {
+ Custom: &v1.UserTask{
+ BaseTask: v1.BaseTask{
+ Configuration:
v1.BuildConfiguration{
+
BuilderPodNamespace: "default",
+ },
+ },
+ PublishingImage:
"my-camel-k-container-image",
+ },
+ },
+ },
+ },
+ Status: v1.BuildStatus{
+ Phase: v1.BuildPhaseRunning,
+ StartedAt: &start,
+ },
+ }
+
+ pod := &corev1.Pod{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: buildPodName(build),
+ Namespace: build.BuilderPodNamespace(),
+ Annotations: map[string]string{},
+ },
+ Status: corev1.PodStatus{
+ Phase: corev1.PodFailed,
+ },
+ }
+
+ c, err := internal.NewFakeClient(build, pod)
+ require.NoError(t, err)
+
+ a := monitorPodAction{
+ reader: c,
+ }
+ a.InjectLogger(log.Log)
+ a.InjectClient(c)
+
+ result, err := a.Handle(context.Background(), build)
+
+ require.NoError(t, err)
+ require.NotNil(t, result)
+
+ assert.Equal(t, v1.BuildPhaseFailed, result.Status.Phase)
+ assert.Equal(t, "Builder Pod camel-k-test-build-builder failed (see
conditions for more details)", result.Status.Error)
+}
diff --git a/pkg/event/manager.go b/pkg/event/manager.go
index 633e383bb..7cb048b37 100644
--- a/pkg/event/manager.go
+++ b/pkg/event/manager.go
@@ -309,6 +309,10 @@ func notifyIfConditionUpdated(recorder
events.EventRecorder, newResource runtime
tail := ""
if cond.GetMessage() != "" {
tail = ": " + cond.GetMessage()
+ // NOTE: Kubernetes events does not allow more than
1024 chars, we cut the trailing part.
+ if len(tail) > 800 { // leave room for prefix
+ tail = tail[:800] + "..."
+ }
}
recorder.Eventf(newResource, nil, corev1.EventTypeNormal,
reason, "Condition %q is %q for %s %s%s",
cond.GetType(), cond.GetStatus(), resourceType, name,
tail)