-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'sebastian/prod-2439-retry-w-no-terraform-state-if-a-413…
…-error-code-is-returned' of github.com:pluralsh/deployment-operator into sebastian/prod-2439-retry-w-no-terraform-state-if-a-413-error-code-is-returned
- Loading branch information
Showing
6 changed files
with
470 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: E2E | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
jobs: | ||
create-cluster: | ||
name: Create Kind cluster | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Install GO | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: go.mod | ||
cache: false | ||
- name: Create kind cluster | ||
uses: helm/[email protected] | ||
- run: kind get clusters | ||
- run: go test -v -race ./pkg/cache/... -tags="e2e" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//go:build cache | ||
|
||
package cache | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
func TestCache(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Test cache") | ||
} | ||
|
||
var _ = Describe("Resource cache", Ordered, func() { | ||
Context("Resource cache", func() { | ||
const ( | ||
resourceName = "default" | ||
namespace = "default" | ||
key = "key" | ||
) | ||
rce := &ResourceCacheEntry{} | ||
pod := v1.Pod{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: resourceName, | ||
Namespace: namespace, | ||
}, | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "test", | ||
Image: "test", | ||
}, | ||
}, | ||
}, | ||
} | ||
cache := NewCache[*ResourceCacheEntry](context.Background(), time.Second) | ||
|
||
It("check cache", func() { | ||
res, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&pod) | ||
Expect(err).ToNot(HaveOccurred()) | ||
unstructuredPod := unstructured.Unstructured{Object: res} | ||
Expect(rce.SetSHA(unstructuredPod, ApplySHA)).ToNot(HaveOccurred()) | ||
Expect(rce.SetSHA(unstructuredPod, ManifestSHA)).ToNot(HaveOccurred()) | ||
Expect(rce.SetSHA(unstructuredPod, ServerSHA)).ToNot(HaveOccurred()) | ||
|
||
cache.Set(key, rce) | ||
cachedResource, ok := cache.Get(key) | ||
Expect(ok).To(BeTrue()) | ||
Expect(cachedResource).To(Equal(rce)) | ||
// should expire and clean applySHA and manifestSHA | ||
time.Sleep(1 * time.Second) | ||
cachedResource, ok = cache.Get(key) | ||
Expect(ok).To(BeTrue()) | ||
Expect(cachedResource.applySHA).Should(BeNil()) | ||
Expect(cachedResource.manifestSHA).Should(BeNil()) | ||
Expect(cachedResource.serverSHA).ShouldNot(BeNil()) | ||
}) | ||
|
||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//go:build cache | ||
|
||
package cache | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
var _ = Describe("Resource cache entry", Ordered, func() { | ||
Context("Resource cache entry", func() { | ||
const ( | ||
resourceName = "default" | ||
namespace = "default" | ||
) | ||
rce := ResourceCacheEntry{} | ||
pod := v1.Pod{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: resourceName, | ||
Namespace: namespace, | ||
}, | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "test", | ||
Image: "test", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
It("check ResourceCacheEntry", func() { | ||
res, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&pod) | ||
Expect(err).ToNot(HaveOccurred()) | ||
unstructuredPod := unstructured.Unstructured{Object: res} | ||
Expect(rce.SetSHA(unstructuredPod, ApplySHA)).ToNot(HaveOccurred()) | ||
Expect(rce.SetSHA(unstructuredPod, ManifestSHA)).ToNot(HaveOccurred()) | ||
Expect(rce.SetSHA(unstructuredPod, ServerSHA)).ToNot(HaveOccurred()) | ||
|
||
Expect(rce.RequiresApply("test")).Should(BeTrue()) | ||
Expect(rce.RequiresApply("U33NQLAAPDEC5RDDKQ2KUHCUHIQUOC4PLMCQ5QVBYZ53B6V5UI5A====")).Should(BeFalse()) | ||
|
||
rce.Expire() | ||
Expect(rce.applySHA).Should(BeNil()) | ||
Expect(rce.manifestSHA).Should(BeNil()) | ||
Expect(rce.serverSHA).ShouldNot(BeNil()) | ||
}) | ||
|
||
}) | ||
|
||
}) |
Oops, something went wrong.