Skip to content

Commit f9485ff

Browse files
perdasilvaPer Goncalves da Silva
and
Per Goncalves da Silva
authored
🌱 update unit test gha to test against the k8s version of client-go (#3272)
* add setup-envtest to tools Signed-off-by: Per Goncalves da Silva <[email protected]> * pin setup_envtest environment to client-go version Signed-off-by: Per Goncalves da Silva <[email protected]> * make installplan test case more robust to update conflict errors Signed-off-by: Per Goncalves da Silva <[email protected]> * fix subscription e2e test flake Signed-off-by: Per Goncalves da Silva <[email protected]> --------- Signed-off-by: Per Goncalves da Silva <[email protected]> Co-authored-by: Per Goncalves da Silva <[email protected]>
1 parent 618aac7 commit f9485ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+7295
-36
lines changed

.github/workflows/unit.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
name: unit
2-
env:
3-
K8S_VERSION: 1.19.2
42
on:
53
push:
64
branches:
@@ -20,9 +18,5 @@ jobs:
2018
- uses: actions/setup-go@v5
2119
with:
2220
go-version-file: "go.mod"
23-
- name: Envtest setup
24-
run: |
25-
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
26-
setup-envtest use ${K8S_VERSION}
2721
- name: Run unit tests
28-
run: KUBEBUILDER_ASSETS=$(setup-envtest use -i -p path ${K8S_VERSION}) make unit
22+
run: make unit

Makefile

+15-23
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,28 @@ export GO111MODULE=on
2828
YQ_INTERNAL := go run $(MOD_FLAGS) ./vendor/github.com/mikefarah/yq/v3/
2929
HELM := go run $(MOD_FLAGS) ./vendor/helm.sh/helm/v3/cmd/helm
3030
KIND := go run $(MOD_FLAGS) ./vendor/sigs.k8s.io/kind
31-
KUBEBUILDER_ASSETS := $(or $(or $(KUBEBUILDER_ASSETS),$(dir $(shell command -v kubebuilder))),/usr/local/kubebuilder/bin)
32-
export KUBEBUILDER_ASSETS
3331
GO := GO111MODULE=on GOFLAGS="$(MOD_FLAGS)" go
3432
GINKGO := $(GO) run github.com/onsi/ginkgo/v2/ginkgo
3533
BINDATA := $(GO) run github.com/go-bindata/go-bindata/v3/go-bindata
34+
SETUP_ENVTEST := $(GO) run sigs.k8s.io/controller-runtime/tools/setup-envtest
3635
GIT_COMMIT := $(shell git rev-parse HEAD)
3736
ifeq ($(shell arch), arm64)
3837
ARCH := arm64
3938
else
4039
ARCH := amd64
4140
endif
4241

42+
# Track the minor version of kubernetes we are building against by looking at the client-go dependency version
43+
# For example, a client-go version of v0.28.5 will map to kube version 1.28
44+
KUBE_MINOR ?= $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1/')
45+
46+
# Unit test against the latest available version for the minor version of kubernetes we are building against e.g. 1.30.x
47+
ENVTEST_KUBE_VERSION ?= $(KUBE_MINOR).x
48+
49+
# Kind node image tags are in the format x.y.z we pin to version x.y.0 because patch releases and node images
50+
# are not guaranteed to be available when a new version of the kube apis is released
51+
KIND_NODE_VERSION ?= $(KUBE_MINOR).0
4352
KIND_CLUSTER_NAME ?= kind-olmv0
44-
# Not guaranteed to have patch releases available and node image tags are full versions (i.e v1.28.0 - no v1.28, v1.29, etc.)
45-
# The KIND_NODE_VERSION is set by getting the version of the k8s.io/client-go dependency from the go.mod
46-
# and sets major version to "1" and the patch version to "0". For example, a client-go version of v0.28.5
47-
# will map to a KIND_NODE_VERSION of 1.28.0
48-
KIND_NODE_VERSION := $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.0/')
4953
KIND_CLUSTER_IMAGE := kindest/node:v$(KIND_NODE_VERSION)
5054

5155
# Phony prerequisite for targets that rely on the go build cache to determine staleness.
@@ -63,24 +67,12 @@ vet:
6367
all: test build
6468

6569
test: clean cover.out
66-
67-
unit: kubebuilder
70+
.PHONY: unit
71+
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use -p path $(ENVTEST_KUBE_VERSION))
72+
unit:
73+
@echo "Running unit tests with setup_envtest for kubernetes $(ENVTEST_KUBE_VERSION)"
6874
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test $(MOD_FLAGS) $(SPECIFIC_UNIT_TEST) -tags "json1" -race -count=1 ./pkg/... ./test/e2e/split/...
6975

70-
# Ensure kubectl installed before continuing
71-
KUBEBUILDER_ASSETS_ERR := not detected in $(KUBEBUILDER_ASSETS), to override the assets path set the KUBEBUILDER_ASSETS environment variable, for install instructions see https://pkg.go.dev/sigs.k8s.io/controller-runtime/tools/setup-envtest
72-
KUBECTL_ASSETS_ERR := kubectl not detected.
73-
kubebuilder:
74-
ifeq (, $(shell which kubectl))
75-
$(error $(KUBECTL_ASSETS_ERR))
76-
endif
77-
ifeq (, $(wildcard $(KUBEBUILDER_ASSETS)/etcd))
78-
$(error etcd $(KUBEBUILDER_ASSETS_ERR))
79-
endif
80-
ifeq (, $(wildcard $(KUBEBUILDER_ASSETS)/kube-apiserver))
81-
$(error kube-apiserver $(KUBEBUILDER_ASSETS_ERR))
82-
endif
83-
8476
cover.out:
8577
go test $(MOD_FLAGS) -tags "json1" -race -coverprofile=cover.out -covermode=atomic \
8678
-coverpkg ./pkg/controller/... ./pkg/...

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ require (
5555
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340
5656
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
5757
sigs.k8s.io/controller-runtime v0.18.0
58+
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20240522175850-2e9781e9fc60
5859
sigs.k8s.io/controller-tools v0.15.0
5960
sigs.k8s.io/kind v0.23.0
6061
)
@@ -187,6 +188,7 @@ require (
187188
github.com/rubenv/sql-migrate v1.5.2 // indirect
188189
github.com/russross/blackfriday/v2 v2.1.0 // indirect
189190
github.com/shopspring/decimal v1.3.1 // indirect
191+
github.com/spf13/afero v1.6.0 // indirect
190192
github.com/spf13/cast v1.5.0 // indirect
191193
github.com/stoewer/go-strcase v1.3.0 // indirect
192194
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect

go.sum

+8
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ib
366366
github.com/klauspost/pgzip v1.2.6 h1:8RXeL5crjEUFnR2/Sn6GJNWtSQ3Dk8pq4CL3jvdDyjU=
367367
github.com/klauspost/pgzip v1.2.6/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
368368
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
369+
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
369370
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
370371
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
371372
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
@@ -496,8 +497,10 @@ github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR
496497
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 h1:Ii+DKncOVM8Cu1Hc+ETb5K+23HdAMvESYE3ZJ5b5cMI=
497498
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE=
498499
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
500+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
499501
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
500502
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
503+
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
501504
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
502505
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
503506
github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY=
@@ -559,6 +562,8 @@ github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js=
559562
github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0=
560563
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
561564
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
565+
github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
566+
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
562567
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
563568
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
564569
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
@@ -686,6 +691,7 @@ go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
686691
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
687692
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
688693
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
694+
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
689695
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
690696
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
691697
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
@@ -920,6 +926,8 @@ sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0 h1:/U5vjBbQn3RCh
920926
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0/go.mod h1:z7+wmGM2dfIiLRfrC6jb5kV2Mq/sK1ZP303cxzkV5Y4=
921927
sigs.k8s.io/controller-runtime v0.18.0 h1:Z7jKuX784TQSUL1TIyeuF7j8KXZ4RtSX0YgtjKcSTME=
922928
sigs.k8s.io/controller-runtime v0.18.0/go.mod h1:tuAt1+wbVsXIT8lPtk5RURxqAnq7xkpv2Mhttslg7Hw=
929+
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20240522175850-2e9781e9fc60 h1:ihaeBTCFuEYPL1T1/FqAavDY7z5UcKSnWpnb+I3DYeM=
930+
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20240522175850-2e9781e9fc60/go.mod h1:4+4tM2Es0ycqPedATtzPer5RTrUq3Xab59BYogt0mCE=
923931
sigs.k8s.io/controller-tools v0.15.0 h1:4dxdABXGDhIa68Fiwaif0vcu32xfwmgQ+w8p+5CxoAI=
924932
sigs.k8s.io/controller-tools v0.15.0/go.mod h1:8zUSS2T8Hx0APCNRhJWbS3CAQEbIxLa07khzh7pZmXM=
925933
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=

test/e2e/installplan_e2e_test.go

+20-6
Original file line numberDiff line numberDiff line change
@@ -2263,12 +2263,26 @@ var _ = Describe("Install Plan", func() {
22632263
Permissions: permissions,
22642264
ClusterPermissions: clusterPermissions,
22652265
}
2266-
csv.Spec.InstallStrategy = operatorsv1alpha1.NamedInstallStrategy{
2267-
StrategyName: operatorsv1alpha1.InstallStrategyNameDeployment,
2268-
StrategySpec: modifiedDetails,
2269-
}
2270-
_, err = crc.OperatorsV1alpha1().ClusterServiceVersions(generatedNamespace.GetName()).Update(context.Background(), csv, metav1.UpdateOptions{})
2271-
require.NoError(GinkgoT(), err)
2266+
2267+
// wrapping the csv update in an eventually helps eliminate a flake in this test
2268+
// it can happen that the csv changes in the meantime (e.g. reconciler adds a condition)
2269+
// and the update fails with a conflict
2270+
Eventually(func() error {
2271+
csv, err := crc.OperatorsV1alpha1().ClusterServiceVersions(generatedNamespace.GetName()).Get(context.Background(), csv.GetName(), metav1.GetOptions{})
2272+
if err != nil {
2273+
return nil
2274+
}
2275+
2276+
// update spec
2277+
csv.Spec.InstallStrategy = operatorsv1alpha1.NamedInstallStrategy{
2278+
StrategyName: operatorsv1alpha1.InstallStrategyNameDeployment,
2279+
StrategySpec: modifiedDetails,
2280+
}
2281+
2282+
// update csv
2283+
_, err = crc.OperatorsV1alpha1().ClusterServiceVersions(generatedNamespace.GetName()).Update(context.Background(), csv, metav1.UpdateOptions{})
2284+
return err
2285+
}).Should(Succeed())
22722286

22732287
By(`Wait for csv to update`)
22742288
_, err = fetchCSV(crc, generatedNamespace.GetName(), csv.GetName(), csvSucceededChecker)

test/e2e/subscription_e2e_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -2840,6 +2840,24 @@ properties:
28402840
_, err = fetchCSV(crc, generatedNamespace.GetName(), subscription.Status.CurrentCSV, buildCSVConditionChecker(operatorsv1alpha1.CSVPhaseSucceeded))
28412841
Expect(err).ShouldNot(HaveOccurred())
28422842

2843+
By("waiting for the subscription bundle unpack conditions to be scrubbed")
2844+
// This step removes flakes from this test where the conditions on the subscription haven't been
2845+
// updated by the time the Consistently block executed a couple of steps below to ensure that the unpack
2846+
// job has not been retried
2847+
Eventually(func() error {
2848+
fetched, err := crc.OperatorsV1alpha1().Subscriptions(generatedNamespace.GetName()).Get(context.Background(), subName, metav1.GetOptions{})
2849+
if err != nil {
2850+
return err
2851+
}
2852+
if cond := fetched.Status.GetCondition(operatorsv1alpha1.SubscriptionBundleUnpacking); cond.Status == corev1.ConditionTrue {
2853+
return fmt.Errorf("unexpected condition status for %s on subscription %s", operatorsv1alpha1.SubscriptionBundleUnpacking, subName)
2854+
}
2855+
if cond := fetched.Status.GetCondition(operatorsv1alpha1.SubscriptionBundleUnpackFailed); cond.Status == corev1.ConditionTrue {
2856+
return fmt.Errorf("unexpected condition status for %s on subscription %s", operatorsv1alpha1.SubscriptionBundleUnpackFailed, subName)
2857+
}
2858+
return nil
2859+
}).Should(Succeed())
2860+
28432861
By("patching operator group to enable unpack retries")
28442862
ogNN := types.NamespacedName{Name: operatorGroup.GetName(), Namespace: generatedNamespace.GetName()}
28452863
setBundleUnpackRetryMinimumIntervalAnnotation(context.Background(), ctx.Ctx().Client(), ogNN, "1s")

tools.go

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
_ "helm.sh/helm/v3/cmd/helm"
1515
_ "k8s.io/code-generator"
1616
_ "k8s.io/kube-openapi/cmd/openapi-gen"
17+
_ "sigs.k8s.io/controller-runtime/tools/setup-envtest"
1718
_ "sigs.k8s.io/controller-tools/cmd/controller-gen"
1819
_ "sigs.k8s.io/kind"
1920
)

vendor/github.com/spf13/afero/.gitignore

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/spf13/afero/.travis.yml

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)