Skip to content

Commit

Permalink
Merge branch 'sebastian/prod-2439-retry-w-no-terraform-state-if-a-413…
Browse files Browse the repository at this point in the history
…-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
floreks committed Jul 23, 2024
2 parents a3faaf6 + 02c7214 commit 9bb3756
Show file tree
Hide file tree
Showing 6 changed files with 470 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .github/workflows/e2e.yaml
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"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ velero-crds:

.PHONY: test
test: envtest ## run tests
@KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(GOPATH)/bin -p path)" go test $$(go list ./... | grep -v /e2e) -v
@KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(GOPATH)/bin -p path)" go test $$(go list ./... | grep -v /e2e) -v -tags="cache"

.PHONY: lint
lint: $(PRE) ## run linters
Expand Down
70 changes: 70 additions & 0 deletions pkg/cache/cache_test.go
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())
})

})

})
55 changes: 55 additions & 0 deletions pkg/cache/resource_cache_entry_test.go
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())
})

})

})
Loading

0 comments on commit 9bb3756

Please sign in to comment.