Skip to content

Commit

Permalink
fix(ctrl): use builtin command kill
Browse files Browse the repository at this point in the history
The builder Pods may not have a /bin/kill command, but do have a builtin shell kill command available.

Closes apache#4241
  • Loading branch information
squakez committed Apr 13, 2023
1 parent 0855491 commit 0bf1456
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
42 changes: 42 additions & 0 deletions e2e/commonwithcustominstall/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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))
})
})
}
30 changes: 30 additions & 0 deletions e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/build/monitor_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0bf1456

Please sign in to comment.