Fix L0 test to make it more reliable. (#2178)
This commit is contained in:
parent
6da1cde09c
commit
4932412cd6
|
|
@ -310,6 +310,7 @@ func (r *EphemeralRunnerReconciler) cleanupRunnerLinkedPods(ctx context.Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(runnerLinkedPodList.Items) == 0 {
|
if len(runnerLinkedPodList.Items) == 0 {
|
||||||
|
log.Info("Runner-linked pods are deleted")
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -344,6 +345,7 @@ func (r *EphemeralRunnerReconciler) cleanupRunnerLinkedSecrets(ctx context.Conte
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(runnerLinkedSecretList.Items) == 0 {
|
if len(runnerLinkedSecretList.Items) == 0 {
|
||||||
|
log.Info("Runner-linked secrets are deleted")
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package actionsgithubcom
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -22,7 +23,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
gh_token = "gh_token"
|
gh_token = "gh_token"
|
||||||
timeout = time.Second * 30
|
timeout = time.Second * 10
|
||||||
interval = time.Millisecond * 250
|
interval = time.Millisecond * 250
|
||||||
runnerImage = "ghcr.io/actions/actions-runner:latest"
|
runnerImage = "ghcr.io/actions/actions-runner:latest"
|
||||||
)
|
)
|
||||||
|
|
@ -344,19 +345,6 @@ var _ = Describe("EphemeralRunner", func() {
|
||||||
interval,
|
interval,
|
||||||
).Should(BeEquivalentTo(true))
|
).Should(BeEquivalentTo(true))
|
||||||
|
|
||||||
Eventually(
|
|
||||||
func() (bool, error) {
|
|
||||||
secret := new(corev1.Secret)
|
|
||||||
err = k8sClient.Get(ctx, client.ObjectKey{Name: ephemeralRunner.Name, Namespace: ephemeralRunner.Namespace}, secret)
|
|
||||||
if err == nil {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
return kerrors.IsNotFound(err), nil
|
|
||||||
},
|
|
||||||
timeout,
|
|
||||||
interval,
|
|
||||||
).Should(BeEquivalentTo(true))
|
|
||||||
|
|
||||||
Eventually(
|
Eventually(
|
||||||
func() (bool, error) {
|
func() (bool, error) {
|
||||||
updated := new(v1alpha1.EphemeralRunner)
|
updated := new(v1alpha1.EphemeralRunner)
|
||||||
|
|
@ -458,20 +446,43 @@ var _ = Describe("EphemeralRunner", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("It should not re-create pod indefinitely", func() {
|
It("It should not re-create pod indefinitely", func() {
|
||||||
|
updated := new(v1alpha1.EphemeralRunner)
|
||||||
pod := new(corev1.Pod)
|
pod := new(corev1.Pod)
|
||||||
failures := 0
|
|
||||||
for i := 0; i < 6; i++ {
|
|
||||||
Eventually(
|
Eventually(
|
||||||
func() (bool, error) {
|
func() (bool, error) {
|
||||||
if err := k8sClient.Get(ctx, client.ObjectKey{Name: ephemeralRunner.Name, Namespace: ephemeralRunner.Namespace}, pod); err != nil {
|
err := k8sClient.Get(ctx, client.ObjectKey{Name: ephemeralRunner.Name, Namespace: ephemeralRunner.Namespace}, updated)
|
||||||
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = k8sClient.Get(ctx, client.ObjectKey{Name: ephemeralRunner.Name, Namespace: ephemeralRunner.Namespace}, pod)
|
||||||
|
if err != nil {
|
||||||
|
if kerrors.IsNotFound(err) && len(updated.Status.Failures) > 5 {
|
||||||
return true, nil
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
pod.Status.ContainerStatuses = append(pod.Status.ContainerStatuses, corev1.ContainerStatus{
|
||||||
|
Name: EphemeralRunnerContainerName,
|
||||||
|
State: corev1.ContainerState{
|
||||||
|
Terminated: &corev1.ContainerStateTerminated{
|
||||||
|
ExitCode: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
err = k8sClient.Status().Update(ctx, pod)
|
||||||
|
Expect(err).To(BeNil(), "Failed to update pod status")
|
||||||
|
return false, fmt.Errorf("pod haven't failed for 5 times.")
|
||||||
},
|
},
|
||||||
timeout,
|
timeout,
|
||||||
interval,
|
interval,
|
||||||
).Should(BeEquivalentTo(true))
|
).Should(BeEquivalentTo(true), "we should stop creating pod after 5 failures")
|
||||||
|
|
||||||
|
// In case we still have pod created due to controller-runtime cache delay, mark the container as exited
|
||||||
|
err := k8sClient.Get(ctx, client.ObjectKey{Name: ephemeralRunner.Name, Namespace: ephemeralRunner.Namespace}, pod)
|
||||||
|
if err == nil {
|
||||||
pod.Status.ContainerStatuses = append(pod.Status.ContainerStatuses, corev1.ContainerStatus{
|
pod.Status.ContainerStatuses = append(pod.Status.ContainerStatuses, corev1.ContainerStatus{
|
||||||
Name: EphemeralRunnerContainerName,
|
Name: EphemeralRunnerContainerName,
|
||||||
State: corev1.ContainerState{
|
State: corev1.ContainerState{
|
||||||
|
|
@ -482,19 +493,18 @@ var _ = Describe("EphemeralRunner", func() {
|
||||||
})
|
})
|
||||||
err := k8sClient.Status().Update(ctx, pod)
|
err := k8sClient.Status().Update(ctx, pod)
|
||||||
Expect(err).To(BeNil(), "Failed to update pod status")
|
Expect(err).To(BeNil(), "Failed to update pod status")
|
||||||
|
}
|
||||||
|
|
||||||
failures++
|
// EphemeralRunner should failed with reason TooManyPodFailures
|
||||||
|
Eventually(func() (string, error) {
|
||||||
updated := new(v1alpha1.EphemeralRunner)
|
|
||||||
Eventually(func() (bool, error) {
|
|
||||||
err := k8sClient.Get(ctx, client.ObjectKey{Name: ephemeralRunner.Name, Namespace: ephemeralRunner.Namespace}, updated)
|
err := k8sClient.Get(ctx, client.ObjectKey{Name: ephemeralRunner.Name, Namespace: ephemeralRunner.Namespace}, updated)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return "", err
|
||||||
}
|
|
||||||
return len(updated.Status.Failures) == failures, nil
|
|
||||||
}, timeout, interval).Should(BeEquivalentTo(true))
|
|
||||||
}
|
}
|
||||||
|
return updated.Status.Reason, nil
|
||||||
|
}, timeout, interval).Should(BeEquivalentTo("TooManyPodFailures"), "Reason should be TooManyPodFailures")
|
||||||
|
|
||||||
|
// EphemeralRunner should not have any pod
|
||||||
Eventually(func() (bool, error) {
|
Eventually(func() (bool, error) {
|
||||||
err := k8sClient.Get(ctx, client.ObjectKey{Name: ephemeralRunner.Name, Namespace: ephemeralRunner.Namespace}, pod)
|
err := k8sClient.Get(ctx, client.ObjectKey{Name: ephemeralRunner.Name, Namespace: ephemeralRunner.Namespace}, pod)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ephemeralRunnerSetTestTimeout = time.Second * 5
|
ephemeralRunnerSetTestTimeout = time.Second * 10
|
||||||
ephemeralRunnerSetTestInterval = time.Millisecond * 250
|
ephemeralRunnerSetTestInterval = time.Millisecond * 250
|
||||||
ephemeralRunnerSetTestGitHubToken = "gh_token"
|
ephemeralRunnerSetTestGitHubToken = "gh_token"
|
||||||
)
|
)
|
||||||
|
|
@ -172,6 +172,26 @@ var _ = Describe("Test EphemeralRunnerSet controller", func() {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set status to simulate a configured EphemeralRunner
|
||||||
|
refetch := false
|
||||||
|
for i, runner := range runnerList.Items {
|
||||||
|
if runner.Status.RunnerId == 0 {
|
||||||
|
updatedRunner := runner.DeepCopy()
|
||||||
|
updatedRunner.Status.Phase = corev1.PodRunning
|
||||||
|
updatedRunner.Status.RunnerId = i + 100
|
||||||
|
err = k8sClient.Status().Patch(ctx, updatedRunner, client.MergeFrom(&runner))
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to update EphemeralRunner")
|
||||||
|
refetch = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if refetch {
|
||||||
|
err := k8sClient.List(ctx, runnerList, client.InNamespace(ephemeralRunnerSet.Namespace))
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return len(runnerList.Items), nil
|
return len(runnerList.Items), nil
|
||||||
},
|
},
|
||||||
ephemeralRunnerSetTestTimeout,
|
ephemeralRunnerSetTestTimeout,
|
||||||
|
|
@ -214,6 +234,26 @@ var _ = Describe("Test EphemeralRunnerSet controller", func() {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set status to simulate a configured EphemeralRunner
|
||||||
|
refetch := false
|
||||||
|
for i, runner := range runnerList.Items {
|
||||||
|
if runner.Status.RunnerId == 0 {
|
||||||
|
updatedRunner := runner.DeepCopy()
|
||||||
|
updatedRunner.Status.Phase = corev1.PodRunning
|
||||||
|
updatedRunner.Status.RunnerId = i + 100
|
||||||
|
err = k8sClient.Status().Patch(ctx, updatedRunner, client.MergeFrom(&runner))
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to update EphemeralRunner")
|
||||||
|
refetch = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if refetch {
|
||||||
|
err := k8sClient.List(ctx, runnerList, client.InNamespace(ephemeralRunnerSet.Namespace))
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return len(runnerList.Items), nil
|
return len(runnerList.Items), nil
|
||||||
},
|
},
|
||||||
ephemeralRunnerSetTestTimeout,
|
ephemeralRunnerSetTestTimeout,
|
||||||
|
|
@ -278,19 +318,30 @@ var _ = Describe("Test EphemeralRunnerSet controller", func() {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return len(runnerList.Items), nil
|
|
||||||
},
|
|
||||||
ephemeralRunnerSetTestTimeout,
|
|
||||||
ephemeralRunnerSetTestInterval).Should(BeEquivalentTo(5), "5 EphemeralRunner should be created")
|
|
||||||
|
|
||||||
// Set status to simulate a configured EphemeralRunner
|
// Set status to simulate a configured EphemeralRunner
|
||||||
|
refetch := false
|
||||||
for i, runner := range runnerList.Items {
|
for i, runner := range runnerList.Items {
|
||||||
|
if runner.Status.RunnerId == 0 {
|
||||||
updatedRunner := runner.DeepCopy()
|
updatedRunner := runner.DeepCopy()
|
||||||
updatedRunner.Status.Phase = corev1.PodRunning
|
updatedRunner.Status.Phase = corev1.PodRunning
|
||||||
updatedRunner.Status.RunnerId = i + 100
|
updatedRunner.Status.RunnerId = i + 100
|
||||||
err = k8sClient.Status().Patch(ctx, updatedRunner, client.MergeFrom(&runner))
|
err = k8sClient.Status().Patch(ctx, updatedRunner, client.MergeFrom(&runner))
|
||||||
Expect(err).NotTo(HaveOccurred(), "failed to update EphemeralRunner")
|
Expect(err).NotTo(HaveOccurred(), "failed to update EphemeralRunner")
|
||||||
|
refetch = true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if refetch {
|
||||||
|
err := k8sClient.List(ctx, runnerList, client.InNamespace(ephemeralRunnerSet.Namespace))
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return len(runnerList.Items), nil
|
||||||
|
},
|
||||||
|
ephemeralRunnerSetTestTimeout,
|
||||||
|
ephemeralRunnerSetTestInterval).Should(BeEquivalentTo(5), "5 EphemeralRunner should be created")
|
||||||
|
|
||||||
// Mark one of the EphemeralRunner as finished
|
// Mark one of the EphemeralRunner as finished
|
||||||
finishedRunner := runnerList.Items[4].DeepCopy()
|
finishedRunner := runnerList.Items[4].DeepCopy()
|
||||||
|
|
@ -327,19 +378,30 @@ var _ = Describe("Test EphemeralRunnerSet controller", func() {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return len(runnerList.Items), nil
|
|
||||||
},
|
|
||||||
ephemeralRunnerSetTestTimeout,
|
|
||||||
ephemeralRunnerSetTestInterval).Should(BeEquivalentTo(5), "5 EphemeralRunner should be created")
|
|
||||||
|
|
||||||
// Set status to simulate a configured EphemeralRunner
|
// Set status to simulate a configured EphemeralRunner
|
||||||
|
refetch := false
|
||||||
for i, runner := range runnerList.Items {
|
for i, runner := range runnerList.Items {
|
||||||
|
if runner.Status.RunnerId == 0 {
|
||||||
updatedRunner := runner.DeepCopy()
|
updatedRunner := runner.DeepCopy()
|
||||||
updatedRunner.Status.Phase = corev1.PodRunning
|
updatedRunner.Status.Phase = corev1.PodRunning
|
||||||
updatedRunner.Status.RunnerId = i + 100
|
updatedRunner.Status.RunnerId = i + 100
|
||||||
err = k8sClient.Status().Patch(ctx, updatedRunner, client.MergeFrom(&runner))
|
err = k8sClient.Status().Patch(ctx, updatedRunner, client.MergeFrom(&runner))
|
||||||
Expect(err).NotTo(HaveOccurred(), "failed to update EphemeralRunner")
|
Expect(err).NotTo(HaveOccurred(), "failed to update EphemeralRunner")
|
||||||
|
refetch = true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if refetch {
|
||||||
|
err := k8sClient.List(ctx, runnerList, client.InNamespace(ephemeralRunnerSet.Namespace))
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return len(runnerList.Items), nil
|
||||||
|
},
|
||||||
|
ephemeralRunnerSetTestTimeout,
|
||||||
|
ephemeralRunnerSetTestInterval).Should(BeEquivalentTo(5), "5 EphemeralRunner should be created")
|
||||||
|
|
||||||
// Scale down the EphemeralRunnerSet
|
// Scale down the EphemeralRunnerSet
|
||||||
updated = created.DeepCopy()
|
updated = created.DeepCopy()
|
||||||
|
|
@ -356,6 +418,26 @@ var _ = Describe("Test EphemeralRunnerSet controller", func() {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set status to simulate a configured EphemeralRunner
|
||||||
|
refetch := false
|
||||||
|
for i, runner := range runnerList.Items {
|
||||||
|
if runner.Status.RunnerId == 0 {
|
||||||
|
updatedRunner := runner.DeepCopy()
|
||||||
|
updatedRunner.Status.Phase = corev1.PodRunning
|
||||||
|
updatedRunner.Status.RunnerId = i + 100
|
||||||
|
err = k8sClient.Status().Patch(ctx, updatedRunner, client.MergeFrom(&runner))
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to update EphemeralRunner")
|
||||||
|
refetch = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if refetch {
|
||||||
|
err := k8sClient.List(ctx, runnerList, client.InNamespace(ephemeralRunnerSet.Namespace))
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return len(runnerList.Items), nil
|
return len(runnerList.Items), nil
|
||||||
},
|
},
|
||||||
ephemeralRunnerSetTestTimeout,
|
ephemeralRunnerSetTestTimeout,
|
||||||
|
|
@ -387,6 +469,26 @@ var _ = Describe("Test EphemeralRunnerSet controller", func() {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set status to simulate a configured EphemeralRunner
|
||||||
|
refetch := false
|
||||||
|
for i, runner := range runnerList.Items {
|
||||||
|
if runner.Status.RunnerId == 0 {
|
||||||
|
updatedRunner := runner.DeepCopy()
|
||||||
|
updatedRunner.Status.Phase = corev1.PodRunning
|
||||||
|
updatedRunner.Status.RunnerId = i + 100
|
||||||
|
err = k8sClient.Status().Patch(ctx, updatedRunner, client.MergeFrom(&runner))
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to update EphemeralRunner")
|
||||||
|
refetch = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if refetch {
|
||||||
|
err := k8sClient.List(ctx, runnerList, client.InNamespace(ephemeralRunnerSet.Namespace))
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return len(runnerList.Items), nil
|
return len(runnerList.Items), nil
|
||||||
},
|
},
|
||||||
ephemeralRunnerSetTestTimeout,
|
ephemeralRunnerSetTestTimeout,
|
||||||
|
|
@ -413,6 +515,26 @@ var _ = Describe("Test EphemeralRunnerSet controller", func() {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set status to simulate a configured EphemeralRunner
|
||||||
|
refetch := false
|
||||||
|
for i, runner := range runnerList.Items {
|
||||||
|
if runner.Status.RunnerId == 0 {
|
||||||
|
updatedRunner := runner.DeepCopy()
|
||||||
|
updatedRunner.Status.Phase = corev1.PodRunning
|
||||||
|
updatedRunner.Status.RunnerId = i + 100
|
||||||
|
err = k8sClient.Status().Patch(ctx, updatedRunner, client.MergeFrom(&runner))
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to update EphemeralRunner")
|
||||||
|
refetch = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if refetch {
|
||||||
|
err := k8sClient.List(ctx, runnerList, client.InNamespace(ephemeralRunnerSet.Namespace))
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return len(runnerList.Items), nil
|
return len(runnerList.Items), nil
|
||||||
},
|
},
|
||||||
ephemeralRunnerSetTestTimeout,
|
ephemeralRunnerSetTestTimeout,
|
||||||
|
|
@ -436,6 +558,26 @@ var _ = Describe("Test EphemeralRunnerSet controller", func() {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set status to simulate a configured EphemeralRunner
|
||||||
|
refetch := false
|
||||||
|
for i, runner := range runnerList.Items {
|
||||||
|
if runner.Status.RunnerId == 0 {
|
||||||
|
updatedRunner := runner.DeepCopy()
|
||||||
|
updatedRunner.Status.Phase = corev1.PodRunning
|
||||||
|
updatedRunner.Status.RunnerId = i + 100
|
||||||
|
err = k8sClient.Status().Patch(ctx, updatedRunner, client.MergeFrom(&runner))
|
||||||
|
Expect(err).NotTo(HaveOccurred(), "failed to update EphemeralRunner")
|
||||||
|
refetch = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if refetch {
|
||||||
|
err := k8sClient.List(ctx, runnerList, client.InNamespace(ephemeralRunnerSet.Namespace))
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return len(runnerList.Items), nil
|
return len(runnerList.Items), nil
|
||||||
},
|
},
|
||||||
ephemeralRunnerSetTestTimeout,
|
ephemeralRunnerSetTestTimeout,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue