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 d5980c343 fix(ctrl): use builtin command kill
d5980c343 is described below
commit d5980c343e888659a51efee76cb443458fb7c819
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Thu Apr 13 10:53:24 2023 +0200
fix(ctrl): use builtin command kill
The builder Pods may not have a /bin/kill command, but do have a builtin
shell kill command available.
Closes #4241
---
e2e/commonwithcustominstall/builder_test.go | 42 +++++++++++++++++++++++++++++
e2e/support/test_support.go | 30 +++++++++++++++++++++
pkg/controller/build/monitor_pod.go | 2 +-
3 files changed, 73 insertions(+), 1 deletion(-)
diff --git a/e2e/commonwithcustominstall/builder_test.go
b/e2e/commonwithcustominstall/builder_test.go
index a55c43a56..05c6d188d 100644
--- a/e2e/commonwithcustominstall/builder_test.go
+++ b/e2e/commonwithcustominstall/builder_test.go
@@ -25,9 +25,11 @@ package commonwithcustominstall
import (
"fmt"
"testing"
+ "time"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
. "github.com/apache/camel-k/v2/e2e/support"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
@@ -52,3 +54,43 @@ func TestBuilderPodFallback(t *testing.T) {
})
})
}
+
+func TestBuilderTimeout(t *testing.T) {
+ WithNewTestNamespace(t, func(ns string) {
+ operatorID := fmt.Sprintf("camel-k-%s", ns)
+ Expect(KamelInstallWithID(operatorID,
ns).Execute()).To(Succeed())
+ Eventually(OperatorPod(ns)).ShouldNot(BeNil())
+ Eventually(Platform(ns)).ShouldNot(BeNil())
+ Eventually(PlatformConditionStatus(ns,
v1.IntegrationPlatformConditionReady), TestTimeoutShort).
+ Should(Equal(corev1.ConditionTrue))
+
+ pl := Platform(ns)()
+ // set a short timeout to simulate the build timeout
+ pl.Spec.Build.Timeout = &metav1.Duration{
+ Duration: 10 * time.Second,
+ }
+ TestClient().Update(TestContext, pl)
+ Eventually(Platform(ns)).ShouldNot(BeNil())
+ Eventually(PlatformTimeout(ns)).Should(Equal(
+ &metav1.Duration{
+ Duration: 10 * time.Second,
+ },
+ ))
+
+ t.Run("run yaml", func(t *testing.T) {
+ name := "yaml"
+ Expect(KamelRunWithID(operatorID, ns,
"files/yaml.yaml").Execute()).To(Succeed())
+ // As the build hits timeout, it keeps trying building
+ Eventually(IntegrationPhase(ns,
name)).Should(Equal(v1.IntegrationPhaseBuildingKit))
+ integrationKitName := IntegrationKit(ns, name)()
+ builderKitName := fmt.Sprintf("camel-k-%s-builder",
integrationKitName)
+ Eventually(BuilderPodPhase(ns,
builderKitName)).Should(Equal(corev1.PodPending))
+ Eventually(BuildPhase(ns,
integrationKitName)).Should(Equal(v1.BuildPhaseRunning))
+ // After a few minutes (5 max retries), this has to be
in error state
+ Eventually(BuildPhase(ns, integrationKitName),
TestTimeoutMedium).Should(Equal(v1.BuildPhaseError))
+ Eventually(IntegrationPhase(ns, name),
TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseError))
+ Eventually(BuildFailureRecovery(ns,
integrationKitName), TestTimeoutMedium).Should(Equal(5))
+ Eventually(BuilderPodPhase(ns, builderKitName),
TestTimeoutMedium).Should(Equal(corev1.PodFailed))
+ })
+ })
+}
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index bc058c843..5aab97ddf 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -1374,6 +1374,16 @@ func BuilderPod(ns string, name string) func()
*corev1.Pod {
}
}
+func BuilderPodPhase(ns string, name string) func() corev1.PodPhase {
+ return func() corev1.PodPhase {
+ pod := BuilderPod(ns, name)()
+ if pod == nil {
+ return ""
+ }
+ return pod.Status.Phase
+ }
+}
+
func BuilderPodsCount(ns string) func() int {
return func() int {
lst := corev1.PodList{
@@ -1590,6 +1600,16 @@ func BuildPhase(ns, name string) func() v1.BuildPhase {
}
}
+func BuildFailureRecovery(ns, name string) func() int {
+ return func() int {
+ build := Build(ns, name)()
+ if build != nil {
+ return build.Status.Failure.Recovery.Attempt
+ }
+ return 0
+ }
+}
+
func HasPlatform(ns string) func() bool {
return func() bool {
lst := v1.NewIntegrationPlatformList()
@@ -1789,6 +1809,16 @@ func PlatformBuildCatalogToolTimeout(ns string) func()
*metav1.Duration {
}
}
+func PlatformTimeout(ns string) func() *metav1.Duration {
+ return func() *metav1.Duration {
+ p := Platform(ns)()
+ if p == nil {
+ return &metav1.Duration{}
+ }
+ return p.Status.Build.Timeout
+ }
+}
+
func AssignPlatformToOperator(ns, operator string) error {
pl := Platform(ns)()
if pl == nil {
diff --git a/pkg/controller/build/monitor_pod.go
b/pkg/controller/build/monitor_pod.go
index 7a3e6829b..d75353dba 100644
--- a/pkg/controller/build/monitor_pod.go
+++ b/pkg/controller/build/monitor_pod.go
@@ -216,7 +216,7 @@ func (action *monitorPodAction) sigterm(pod *corev1.Pod)
error {
r.VersionedParams(&corev1.PodExecOptions{
Container: container.Name,
- Command: []string{"kill", "-SIGTERM", "1"},
+ Command: []string{"/bin/bash", "-c", "kill -SIGTERM
1"},
Stdout: true,
Stderr: true,
TTY: false,