Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not wait for initContainer to exit when it is a sidecar #2866

Merged
merged 9 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ jobs:
echo "environment-kubeconfig:" ${KUBECONFIG}

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.22"

- name: Build devspacehelper
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.22"
- uses: actions/checkout@v3
- name: Run golangci-lint
uses: golangci/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ jobs:
runs-on: macos-11
steps:
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.22"
- id: get_version
run: |
RELEASE_VERSION=$(echo $GITHUB_REF | sed -nE 's!refs/tags/!!p')
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ jobs:

steps:
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.22"

- name: Check out code into the Go module directory
uses: actions/checkout@v1
Expand All @@ -43,9 +43,9 @@ jobs:

steps:
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.22"

- name: Check out code into the Go module directory
uses: actions/checkout@v1
Expand Down
18 changes: 9 additions & 9 deletions e2e/framework/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func ExpectNamespace(namespace string) {
kubeClient, err := kube.NewKubeHelper()
ExpectNoErrorWithOffset(1, err)

err = wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
ns, err := kubeClient.Client().KubeClient().CoreV1().Namespaces().Get(context.TODO(), namespace, metav1.GetOptions{})
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(ctx context.Context) (done bool, err error) {
ns, err := kubeClient.Client().KubeClient().CoreV1().Namespaces().Get(ctx, namespace, metav1.GetOptions{})
if err != nil {
return false, nil
}
Expand All @@ -81,7 +81,7 @@ func ExpectRemoteFileContents(imageSelector string, namespace string, filePath s
kubeClient, err := kube.NewKubeHelper()
ExpectNoErrorWithOffset(1, err)

err = wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(_ context.Context) (done bool, err error) {
out, err := kubeClient.ExecByImageSelector(imageSelector, namespace, []string{"cat", filePath})
if err != nil {
return false, nil
Expand All @@ -94,7 +94,7 @@ func ExpectRemoteFileContents(imageSelector string, namespace string, filePath s

func ExpectLocalCurlContents(urlString string, contents string) {
client := resty.New()
err := wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
err := wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(_ context.Context) (done bool, err error) {
resp, _ := client.R().
EnableTrace().
Get(urlString)
Expand All @@ -106,7 +106,7 @@ func ExpectLocalCurlContents(urlString string, contents string) {
func ExpectContainerNameAndImageEqual(namespace, deploymentName, containerImage, containerName string) {
kubeClient, err := kube.NewKubeHelper()
ExpectNoErrorWithOffset(1, err)
err = wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(_ context.Context) (done bool, err error) {
deploy, err := kubeClient.RawClient().AppsV1().Deployments(namespace).Get(context.TODO(),
deploymentName, metav1.GetOptions{})
if err != nil {
Expand All @@ -121,7 +121,7 @@ func ExpectContainerNameAndImageEqual(namespace, deploymentName, containerImage,
func ExpectRemoteCurlContents(imageSelector string, namespace string, urlString string, contents string) {
kubeClient, err := kube.NewKubeHelper()
ExpectNoErrorWithOffset(1, err)
err = wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(_ context.Context) (done bool, err error) {
out, err := kubeClient.ExecByImageSelector(imageSelector, namespace, []string{"curl", urlString})
if err != nil {
return false, nil
Expand All @@ -137,7 +137,7 @@ func ExpectRemoteFileNotFound(imageSelector string, namespace string, filePath s

fileExists := "file exists"
fileNotFound := "file not found"
err = wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(_ context.Context) (done bool, err error) {
test := []string{"sh", "-c", fmt.Sprintf("test -e %s && echo %s || echo %s", filePath, fileExists, fileNotFound)}
out, err := kubeClient.ExecByImageSelector(imageSelector, namespace, test)
if err != nil {
Expand All @@ -159,7 +159,7 @@ func ExpectRemoteContainerFileContents(labelSelector, container string, namespac
kubeClient, err := kube.NewKubeHelper()
ExpectNoErrorWithOffset(1, err)

err = wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(_ context.Context) (done bool, err error) {
out, err := kubeClient.ExecByContainer(labelSelector, container, namespace, []string{"cat", filePath})
if err != nil {
return false, nil
Expand All @@ -182,7 +182,7 @@ func ExpectLocalFileContainSubstringImmediately(filePath string, contents string
}

func ExpectLocalFileContents(filePath string, contents string) {
err := wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
err := wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(_ context.Context) (done bool, err error) {
out, err := os.ReadFile(filePath)
if err != nil {
if !os.IsNotExist(err) {
Expand Down
8 changes: 4 additions & 4 deletions e2e/tests/dependencies/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ dep2dep2wait

// wait until a pod has started
var pods *corev1.PodList
err = wait.Poll(time.Second, time.Minute, func() (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{LabelSelector: selector.ReplacedLabel})
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, false, func(ctx context.Context) (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: selector.ReplacedLabel})
if err != nil {
return false, err
}
Expand All @@ -515,8 +515,8 @@ dep2dep2wait
framework.ExpectNoError(err)

// wait until all pods are killed
err = wait.Poll(time.Second, time.Minute, func() (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{LabelSelector: selector.ReplacedLabel})
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, false, func(ctx context.Context) (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: selector.ReplacedLabel})
if err != nil {
return false, err
}
Expand Down
11 changes: 6 additions & 5 deletions e2e/tests/devspacehelper/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package devspacehelper

import (
"context"
"github.com/onsi/ginkgo/v2"
"os"
"time"

"github.com/onsi/ginkgo/v2"

"github.com/loft-sh/devspace/cmd"
"github.com/loft-sh/devspace/cmd/flags"
"github.com/loft-sh/devspace/e2e/framework"
Expand Down Expand Up @@ -65,8 +66,8 @@ var _ = DevSpaceDescribe("devspacehelper", func() {

// wait until nginx pod is reachable
var pods *corev1.PodList
err = wait.Poll(time.Second, time.Minute, func() (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{LabelSelector: "app=curl-container"})
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, false, func(ctx context.Context) (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: "app=curl-container"})
if err != nil {
return false, err
} else if len(pods.Items) == 0 || len(pods.Items[0].Status.ContainerStatuses) == 0 {
Expand Down Expand Up @@ -116,8 +117,8 @@ var _ = DevSpaceDescribe("devspacehelper", func() {

// wait until nginx pod is reachable
var pods *corev1.PodList
err = wait.Poll(time.Second, time.Minute, func() (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{LabelSelector: "app=non-curl-container"})
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, false, func(ctx context.Context) (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: "app=non-curl-container"})
if err != nil {
return false, err
}
Expand Down
11 changes: 6 additions & 5 deletions e2e/tests/hooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package hooks

import (
"context"
"github.com/onsi/ginkgo/v2"
"os"
"sync"
"time"

"github.com/onsi/ginkgo/v2"

"github.com/loft-sh/devspace/cmd"
"github.com/loft-sh/devspace/cmd/flags"
"github.com/loft-sh/devspace/e2e/framework"
Expand Down Expand Up @@ -147,7 +148,7 @@ var _ = DevSpaceDescribe("hooks", func() {

// Read the 'once' hook output
onceOutput1 := ""
err = wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(_ context.Context) (done bool, err error) {
onceOutput1, err = kubeClient.ExecByImageSelector("node", ns, []string{"cat", "/app/once.out"})
if err != nil {
return false, nil
Expand All @@ -159,7 +160,7 @@ var _ = DevSpaceDescribe("hooks", func() {

// Read the 'each' hook output
eachOutput1 := ""
err = wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(_ context.Context) (done bool, err error) {
eachOutput1, err = kubeClient.ExecByImageSelector("node", ns, []string{"cat", "/app/each.out"})
if err != nil {
return false, nil
Expand Down Expand Up @@ -196,7 +197,7 @@ var _ = DevSpaceDescribe("hooks", func() {

// Wait for 'each' hook output to change
eachOutput2 := ""
err = wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(_ context.Context) (done bool, err error) {
eachOutput2, err = kubeClient.ExecByImageSelector("node", ns, []string{"cat", "/app/each.out"})
if err != nil {
return false, nil
Expand All @@ -208,7 +209,7 @@ var _ = DevSpaceDescribe("hooks", func() {

// Read the 'once' hook output again
onceOutput2 := ""
err = wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(_ context.Context) (done bool, err error) {
onceOutput2, err = kubeClient.ExecByImageSelector("node", ns, []string{"cat", "/app/once.out"})
if err != nil {
return false, nil
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/proxycommands/proxycommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ var _ = DevSpaceDescribe("proxyCommands", func() {

// Get the expected Pod hostname
var pods *corev1.PodList
err = wait.Poll(time.Second, time.Minute, func() (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{LabelSelector: "app.kubernetes.io/component=test"})
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, false, func(ctx context.Context) (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: "app.kubernetes.io/component=test"})
if err != nil {
return false, err
}
Expand Down
27 changes: 14 additions & 13 deletions e2e/tests/replacepods/replacepods.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package replacepods

import (
"context"
"github.com/onsi/ginkgo/v2"
"os"
"strings"
"time"

"github.com/onsi/ginkgo/v2"

"github.com/loft-sh/devspace/cmd"
"github.com/loft-sh/devspace/cmd/flags"
"github.com/loft-sh/devspace/e2e/framework"
Expand Down Expand Up @@ -115,8 +116,8 @@ var _ = DevSpaceDescribe("replacepods", func() {

// wait until a pod has started
var pods *corev1.PodList
err = wait.Poll(time.Second, time.Minute*3, func() (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{LabelSelector: selector.ReplacedLabel})
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*3, false, func(ctx context.Context) (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: selector.ReplacedLabel})
if err != nil {
return false, err
}
Expand Down Expand Up @@ -156,8 +157,8 @@ var _ = DevSpaceDescribe("replacepods", func() {
framework.ExpectEqual(len(list.Items), 1)

// wait until a pod has started
err = wait.Poll(time.Second, time.Minute*3, func() (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{LabelSelector: selector.ReplacedLabel})
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*3, false, func(ctx context.Context) (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: selector.ReplacedLabel})
if err != nil {
return false, err
}
Expand All @@ -179,8 +180,8 @@ var _ = DevSpaceDescribe("replacepods", func() {
framework.ExpectNoError(err)

// wait until all pods are killed
err = wait.Poll(time.Second, time.Minute*3, func() (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{LabelSelector: selector.ReplacedLabel})
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*3, false, func(ctx context.Context) (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: selector.ReplacedLabel})
if err != nil {
return false, err
}
Expand Down Expand Up @@ -222,8 +223,8 @@ var _ = DevSpaceDescribe("replacepods", func() {

// wait until a pod has started
var pods *corev1.PodList
err = wait.Poll(time.Second, time.Minute, func() (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{LabelSelector: selector.ReplacedLabel})
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, false, func(ctx context.Context) (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: selector.ReplacedLabel})
if err != nil {
return false, err
}
Expand Down Expand Up @@ -258,8 +259,8 @@ var _ = DevSpaceDescribe("replacepods", func() {
framework.ExpectEqual(len(list.Items), 1)

// wait until a pod has started
err = wait.Poll(time.Second, time.Minute, func() (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{LabelSelector: selector.ReplacedLabel})
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, false, func(ctx context.Context) (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: selector.ReplacedLabel})
if err != nil {
return false, err
}
Expand Down Expand Up @@ -312,8 +313,8 @@ var _ = DevSpaceDescribe("replacepods", func() {
framework.ExpectNoError(err)

// wait until all pods are killed
err = wait.Poll(time.Second, time.Minute, func() (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{LabelSelector: selector.ReplacedLabel})
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, false, func(ctx context.Context) (done bool, err error) {
pods, err = kubeClient.RawClient().CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: selector.ReplacedLabel})
if err != nil {
return false, err
}
Expand Down
16 changes: 9 additions & 7 deletions e2e/tests/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ var _ = DevSpaceDescribe("sync", func() {
}()

// wait until files were synced
err = wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(_ context.Context) (done bool, err error) {
out, err := kubeClient.ExecByImageSelector("node", ns, []string{"cat", "/app/file1.txt"})
if err != nil {
return false, nil
Expand All @@ -236,7 +236,7 @@ var _ = DevSpaceDescribe("sync", func() {
framework.ExpectNoError(err)

// wait for sync
err = wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(_ context.Context) (done bool, err error) {
out, err := kubeClient.ExecByImageSelector("node", ns, []string{"cat", "/app/file3.txt"})
if err != nil {
return false, nil
Expand All @@ -252,7 +252,7 @@ var _ = DevSpaceDescribe("sync", func() {
framework.ExpectEqual(os.IsNotExist(err), true)

// check if file was downloaded through after hook
err = wait.PollImmediate(time.Second, time.Minute, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, true, func(_ context.Context) (done bool, err error) {
out, err := os.ReadFile(filepath.Join(tempDir, "file5.txt"))
if err != nil {
if !os.IsNotExist(err) {
Expand Down Expand Up @@ -311,7 +311,7 @@ var _ = DevSpaceDescribe("sync", func() {
}()

// wait until files were synced
err = wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(_ context.Context) (done bool, err error) {
out, err := kubeClient.ExecByImageSelector("node", ns, []string{"cat", "/watch/app/file1.txt"})
if err != nil {
return false, nil
Expand All @@ -335,7 +335,7 @@ var _ = DevSpaceDescribe("sync", func() {
err = os.WriteFile(filepath.Join(tempDir, "/project1/app/file3.txt"), []byte(payload1), 0666)
framework.ExpectNoError(err)

err = wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(_ context.Context) (done bool, err error) {
out, err := kubeClient.ExecByImageSelector("node", ns, []string{"cat", "/watch/app/file3.txt"})
if err != nil {
return false, nil
Expand All @@ -350,7 +350,7 @@ var _ = DevSpaceDescribe("sync", func() {
err = os.WriteFile(filepath.Join(tempDir, "/project2/file4.txt"), []byte(payload2), 0666)
framework.ExpectNoError(err)

err = wait.PollImmediate(time.Second, time.Minute*2, func() (done bool, err error) {
err = wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute*2, true, func(_ context.Context) (done bool, err error) {
out, err := kubeClient.ExecByImageSelector("node", ns, []string{"cat", "/watch/app/file4.txt"})
if err != nil {
return false, nil
Expand Down Expand Up @@ -821,7 +821,9 @@ var _ = DevSpaceDescribe("sync", func() {
defer ginkgo.GinkgoRecover()
defer waitGroup.Done()
err = syncCmd.Run(f)
framework.ExpectNoError(err)
if !errors.Is(err, context.Canceled) {
framework.ExpectNoError(err)
}
}()

// check that node_modules folder was not synced
Expand Down
Loading
Loading