Skip to content

Commit

Permalink
wip: Update the integration tests to run with kubernetes 1.28 and lat…
Browse files Browse the repository at this point in the history
…est versions.
  • Loading branch information
hessjcg committed Nov 21, 2024
1 parent 5994d62 commit 9d27065
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ build: generate build_push_docker ## Builds and pushes the docker image to tag d
@echo "TIME: $(shell date) end make build"

.PHONY: test
test: generate go_test ## Run tests (but not internal/teste2e)
test: generate go_test go_test_k8s_1_28 ## Run tests (but not internal/teste2e)
@echo "TIME: $(shell date) end make test"

.PHONY: deploy
Expand Down Expand Up @@ -167,6 +167,11 @@ go_test: ctrl_manifests envtest # Run tests (but not internal/teste2e)
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" \
go test ./internal/.../. -coverprofile cover.out -race | tee test_results.txt

.PHONY: go_test_k8s_1_28
go_test_k8s_1_28: ctrl_manifests envtest # Run tests using older kubernetes version 1.28 (but not internal/teste2e)
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use 1.28.x -p path)" \
go test ./internal/.../. -coverprofile cover.out -race | tee test_results.txt

##
# 3rd Party License Checks
.PHONY: license_check
Expand Down Expand Up @@ -445,8 +450,6 @@ GO_LICENSES_VERSION=v1.6.0# renovate datasource=go depName=github.com/google/go-

KUSTOMIZE_VERSION=v4.5.2# don't manage with renovate, this repo has non-standard tags

ENVTEST_K8S_VERSION=1.28.x

GOOS?=$(shell go env GOOS | tr -d '\n')
GOARCH?=$(shell go env GOARCH | tr -d '\n')

Expand Down
6 changes: 5 additions & 1 deletion internal/testhelpers/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,11 @@ func (cc *TestCaseClient) ExpectPodContainerCount(ctx context.Context, podSelect
return fmt.Errorf("got 0 pods, want at least 1 pod")
}
for _, pod := range pods.Items {
got := len(pod.Spec.Containers)
// The use len(Containers) + len(InitContainers) as the total number
// of containers on the pod. This way the assertion works the same
// when it runs with k8s <= 1.28 using regular containers for the proxy
// as well as with k8s >= 1.29 using init containers for the proxy.
got := len(pod.Spec.Containers) + len(pod.Spec.InitContainers)
if got != count {
countBadPods++
}
Expand Down
19 changes: 17 additions & 2 deletions internal/testintegration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,14 @@ func TestUpdateWorkloadContainerWhenDefaultProxyImageChanges(t *testing.T) {
// Check that the pods have the expected default proxy image
pods, err := testhelpers.ListPods(ctx, tcc.Client, tcc.Namespace, d.Spec.Selector)
for _, p := range pods.Items {
if got, want := p.Spec.Containers[1].Image, workload.DefaultProxyImage; got != want {
want := workload.DefaultProxyImage
var got string
if len(p.Spec.Containers) > 1 {
got = p.Spec.Containers[1].Image
} else {
got = p.Spec.InitContainers[0].Image
}
if got != want {
t.Errorf("got %v, want %v image before operator upgrade", got, want)
}
}
Expand Down Expand Up @@ -305,7 +312,15 @@ func TestUpdateWorkloadContainerWhenDefaultProxyImageChanges(t *testing.T) {
// Check that the new pods have the new default proxy image
pods, err = testhelpers.ListPods(ctx, tcc.Client, tcc.Namespace, d.Spec.Selector)
for _, p := range pods.Items {
if got, want := p.Spec.Containers[1].Image, newDefault; got != want {
want := newDefault
var got string
if len(p.Spec.Containers) > 1 {
got = p.Spec.Containers[1].Image
} else {
got = p.Spec.InitContainers[0].Image
}

if got != want {
t.Errorf("got %v, want %v image before operator upgrade", got, want)
}
}
Expand Down

0 comments on commit 9d27065

Please sign in to comment.