From cd1e810c4f29f89e557d949f81c100b14c78c2c6 Mon Sep 17 00:00:00 2001 From: Mathieu Cesbron <45229023+MathieuCesbron@users.noreply.github.com> Date: Mon, 15 Jan 2024 06:35:37 +0100 Subject: [PATCH] test: add envtest for redis standalone (#748) Signed-off-by: Mathieu Cesbron --- .github/workflows/operator-ci.yaml | 39 +++---- Makefile | 6 +- controllers/redis_controller_test.go | 147 +++++++++++++++++++++++++++ controllers/suite_test.go | 76 +++++++++----- go.mod | 7 +- go.sum | 25 ++--- hack/integrationSetup.sh | 40 ++++++++ 7 files changed, 274 insertions(+), 66 deletions(-) create mode 100644 controllers/redis_controller_test.go create mode 100755 hack/integrationSetup.sh diff --git a/.github/workflows/operator-ci.yaml b/.github/workflows/operator-ci.yaml index f32f67757..8d055d1bd 100644 --- a/.github/workflows/operator-ci.yaml +++ b/.github/workflows/operator-ci.yaml @@ -13,7 +13,7 @@ env: DockerImagName: docker.io/opstree/redis-operator BuildDocs: true AppVersion: "v0.15.2" - DOCKERFILE_PATH: '**/Dockerfile' + DOCKERFILE_PATH: "**/Dockerfile" jobs: gofmt: @@ -54,6 +54,8 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ env.GOLANG_VERSION }} + - name: Install integration test dependencies + run: make integration-test-setup - name: Run Go Tests with coverage run: go test ./... -coverprofile=coverage.txt -covermode=atomic - name: Upload coverage to Codecov @@ -62,7 +64,7 @@ jobs: file: ./coverage.txt fail_ci_if_error: false verbose: true - + code_quality_golang_ci_lint: needs: [gofmt, govet] runs-on: ubuntu-latest @@ -72,16 +74,16 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ env.GOLANG_VERSION }} - + - name: Download Go modules run: go mod download - + - name: Check disk space run: df -h - + - name: List Go module cache run: ls -la $(go env GOPATH)/pkg/mod - + - name: Run GolangCI-Lint uses: golangci/golangci-lint-action@v3 with: @@ -105,7 +107,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - arch: ['amd64', 'arm64'] + arch: ["amd64", "arm64"] steps: - name: Checkout Code uses: actions/checkout@v2 @@ -125,19 +127,19 @@ jobs: needs: [container_quality_dockerfile_lint] runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 - - name: Build multi-arch image - uses: docker/build-push-action@v2 - with: - context: . - platforms: linux/arm64,linux/amd64 - push: false - tags: ${{ env.DockerImagName }}:latest + - name: Build multi-arch image + uses: docker/build-push-action@v2 + with: + context: . + platforms: linux/arm64,linux/amd64 + push: false + tags: ${{ env.DockerImagName }}:latest gosec_scan: needs: [build_go_binary] @@ -152,4 +154,3 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GOSEC_OUTPUT: "junit-xml:/github/workspace/gosec-results.xml" - diff --git a/Makefile b/Makefile index 66849fd86..49695e5cc 100644 --- a/Makefile +++ b/Makefile @@ -148,4 +148,8 @@ e2e-kind-setup: .PHONY: e2e-test e2e-test: e2e-kind-setup install-kuttl - $(shell pwd)/bin/kuttl test --config tests/_config/kuttl-test.yaml \ No newline at end of file + $(shell pwd)/bin/kuttl test --config tests/_config/kuttl-test.yaml + +.PHONY: integration-test-setup +integration-test-setup: + ./hack/integrationSetup.sh \ No newline at end of file diff --git a/controllers/redis_controller_test.go b/controllers/redis_controller_test.go new file mode 100644 index 000000000..3b9ff9870 --- /dev/null +++ b/controllers/redis_controller_test.go @@ -0,0 +1,147 @@ +package controllers + +import ( + "context" + "fmt" + "time" + + appsv1 "k8s.io/api/apps/v1" + + redisv1beta2 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta2" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + corev1 "k8s.io/api/core/v1" + + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" +) + +const ( + ns = "default" + + timeout = time.Second * 5 + interval = time.Millisecond * 250 +) + +var _ = Describe("Redis standalone test", func() { + var ( + redisCR redisv1beta2.Redis + redisCRName string + // Used to create unique name for each test + testCount int + ) + + JustBeforeEach(func() { + redisCR = redisv1beta2.Redis{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "redisv1beta2/apiVersion", + Kind: "Redis", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: redisCRName, + Namespace: ns, + }, + } + Expect(k8sClient.Create(context.TODO(), &redisCR)).Should(Succeed()) + testCount++ + }) + + BeforeEach(func() { + redisCRName = fmt.Sprintf("redis-%d", testCount) + }) + + Context("When creating a redis standalone CR", func() { + It("should create a statefulset", func() { + var sts *appsv1.StatefulSet + Eventually(func() error { + sts = &appsv1.StatefulSet{} + return k8sClient.Get(context.TODO(), types.NamespacedName{ + Name: redisCRName, + Namespace: ns, + }, sts) + }, timeout, interval).Should(BeNil()) + + Expect(sts.Labels).To(Equal(map[string]string{ + "app": redisCRName, + "redis_setup_type": "standalone", + "role": "standalone", + })) + + Expect(*sts.Spec.Replicas).To(BeEquivalentTo(1)) + Expect(sts.Spec.ServiceName).To(Equal(redisCRName + "-headless")) + }) + + It("should create a service", func() { + var svc *corev1.Service + Eventually(func() error { + svc = &corev1.Service{} + return k8sClient.Get(context.TODO(), types.NamespacedName{ + Name: redisCR.Name, + Namespace: ns, + }, svc) + }, timeout, interval).Should(BeNil()) + + Expect(svc.Labels).To(Equal(map[string]string{ + "app": redisCRName, + "redis_setup_type": "standalone", + "role": "standalone", + })) + }) + + It("should create a headless service", func() { + var svc *corev1.Service + Eventually(func() error { + svc = &corev1.Service{} + return k8sClient.Get(context.TODO(), types.NamespacedName{ + Name: redisCR.Name + "-headless", + Namespace: ns, + }, svc) + }, timeout, interval).Should(BeNil()) + + Expect(svc.Labels).To(Equal(map[string]string{ + "app": redisCRName, + "redis_setup_type": "standalone", + "role": "standalone", + })) + }) + + It("should create additional service", func() { + var svc *corev1.Service + Eventually(func() error { + svc = &corev1.Service{} + return k8sClient.Get(context.TODO(), types.NamespacedName{ + Name: redisCR.Name + "-additional", + Namespace: ns, + }, svc) + }, timeout, interval).Should(BeNil()) + + Expect(svc.Labels).To(Equal(map[string]string{ + "app": redisCRName, + "redis_setup_type": "standalone", + "role": "standalone", + })) + }) + + Context("then deleting the redis standalone CR", func() { + It("should delete the statefulset", func() { + redisCR := &redisv1beta2.Redis{ + ObjectMeta: metav1.ObjectMeta{ + Name: redisCRName, + Namespace: ns, + }, + } + Expect(k8sClient.Delete(context.TODO(), redisCR)).To(BeNil()) + + Eventually(func() bool { + sts := &appsv1.StatefulSet{} + err := k8sClient.Get(context.TODO(), types.NamespacedName{ + Name: redisCRName, + Namespace: ns, + }, sts) + return errors.IsNotFound(err) + }, timeout, interval).Should(BeTrue()) + }) + }) + }) +}) diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 88aea5083..3bc2b13c7 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -18,13 +18,19 @@ package controllers import ( "path/filepath" + "testing" + "time" + // redisv1beta1 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta1" redisv1beta2 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta2" - . "github.com/onsi/ginkgo" + + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/onsi/gomega/gexec" + "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/scheme" + ctrl "sigs.k8s.io/controller-runtime" - // "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest" logf "sigs.k8s.io/controller-runtime/pkg/log" @@ -32,49 +38,67 @@ import ( // +kubebuilder:scaffold:imports ) -// These tests use Ginkgo (BDD-style Go testing framework). Refer to -// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. - -// var cfg *rest.Config var k8sClient client.Client var testEnv *envtest.Environment -// func TestAPIs(t *testing.T) { -// RegisterFailHandler(Fail) +func TestAPIs(t *testing.T) { + RegisterFailHandler(Fail) -// RunSpecsWithDefaultAndCustomReporters(t, -// "Controller Suite", -// []Reporter{printer.NewlineReporter{}}) -// } + RunSpecs(t, "Controller suite") +} var _ = BeforeSuite(func() { logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) By("bootstrapping test environment") testEnv = &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")}, + CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")}, + ErrorIfCRDPathMissing: true, + CRDInstallOptions: envtest.CRDInstallOptions{ + MaxTime: 60 * time.Second, + }, } cfg, err := testEnv.Start() - Expect(err).NotTo(HaveOccurred()) - Expect(cfg).NotTo(BeNil()) + Expect(err).ToNot(HaveOccurred()) + Expect(cfg).ToNot(BeNil()) - err = redisv1beta2.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) + // err = redisv1beta1.AddToScheme(scheme.Scheme) + // Expect(err).ToNot(HaveOccurred()) err = redisv1beta2.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) + Expect(err).ToNot(HaveOccurred()) // +kubebuilder:scaffold:scheme k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) - Expect(err).NotTo(HaveOccurred()) - Expect(k8sClient).NotTo(BeNil()) - -}, 60) + Expect(err).ToNot(HaveOccurred()) + Expect(k8sClient).ToNot(BeNil()) + + k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{ + Scheme: scheme.Scheme, + }) + Expect(err).ToNot(HaveOccurred()) + + k8sClient, err := kubernetes.NewForConfig(cfg) + Expect(err).ToNot(HaveOccurred()) + + err = (&RedisReconciler{ + Client: k8sManager.GetClient(), + K8sClient: k8sClient, + Scheme: k8sManager.GetScheme(), + }).SetupWithManager(k8sManager) + Expect(err).ToNot(HaveOccurred()) + + go func() { + defer GinkgoRecover() + err = k8sManager.Start(ctrl.SetupSignalHandler()) + Expect(err).ToNot(HaveOccurred(), "failed to run manager") + gexec.KillAndWait(4 * time.Second) + + // Teardown the test environment once controller is fnished. + err := testEnv.Stop() + Expect(err).ToNot(HaveOccurred()) + }() -var _ = AfterSuite(func() { - By("tearing down the test environment") - err := testEnv.Stop() - Expect(err).NotTo(HaveOccurred()) }) diff --git a/go.mod b/go.mod index b8210b8c2..eff13a616 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/banzaicloud/k8s-objectmatcher v1.7.0 github.com/go-logr/logr v1.2.4 - github.com/onsi/ginkgo v1.16.5 + github.com/onsi/ginkgo/v2 v2.11.0 github.com/onsi/gomega v1.27.10 github.com/pkg/errors v0.9.1 github.com/redis/go-redis/v9 v9.2.1 @@ -31,12 +31,14 @@ require ( github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/swag v0.22.3 // indirect + github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/google/gofuzz v1.2.0 // indirect + github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect github.com/google/uuid v1.3.0 // indirect github.com/imdario/mergo v0.3.12 // indirect github.com/josharian/intern v1.0.0 // indirect @@ -47,7 +49,6 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/nxadm/tail v1.4.8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.16.0 // indirect github.com/prometheus/client_model v0.4.0 // indirect @@ -63,11 +64,11 @@ require ( golang.org/x/term v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect golang.org/x/time v0.3.0 // indirect + golang.org/x/tools v0.9.3 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/apiextensions-apiserver v0.28.0 // indirect diff --git a/go.sum b/go.sum index cbee05b11..0aec70c41 100644 --- a/go.sum +++ b/go.sum @@ -21,6 +21,9 @@ github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0 github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -63,7 +66,6 @@ github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nA github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I= github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g= github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= @@ -110,6 +112,7 @@ github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3i github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -150,21 +153,13 @@ github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8m github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= -github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -193,7 +188,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= @@ -226,6 +221,8 @@ golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= +golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -236,7 +233,6 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= @@ -256,14 +252,12 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -288,7 +282,6 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM= @@ -330,11 +323,9 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= diff --git a/hack/integrationSetup.sh b/hack/integrationSetup.sh new file mode 100755 index 000000000..666a71b5e --- /dev/null +++ b/hack/integrationSetup.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +set -euo pipefail + +K8S_VERSION="${K8S_VERSION:="1.28.x"}" +KUBEBUILDER_ASSETS="/usr/local/kubebuilder/bin" + +main() { + tools + kubebuilder +} + +tools() { + go install github.com/google/go-licenses@latest + go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + go install github.com/google/ko@latest + go install github.com/mikefarah/yq/v4@latest + go install github.com/norwoodj/helm-docs/cmd/helm-docs@latest + go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest + go install sigs.k8s.io/controller-tools/cmd/controller-gen@latest + go install github.com/sigstore/cosign/v2/cmd/cosign@latest + go install -tags extended github.com/gohugoio/hugo@v0.110.0 + go install golang.org/x/vuln/cmd/govulncheck@latest + go install github.com/onsi/ginkgo/v2/ginkgo@latest + go install github.com/rhysd/actionlint/cmd/actionlint@latest + go install github.com/mattn/goveralls@latest + + if ! echo "$PATH" | grep -q "${GOPATH:-undefined}/bin\|$HOME/go/bin"; then + echo "Go workspace's \"bin\" directory is not in PATH. Run 'export PATH=\"\$PATH:\${GOPATH:-\$HOME/go}/bin\"'." + fi +} + +kubebuilder() { + sudo mkdir -p ${KUBEBUILDER_ASSETS} + sudo chown "${USER}" ${KUBEBUILDER_ASSETS} + arch=$(go env GOARCH) + ln -sf $(setup-envtest use -p path "${K8S_VERSION}" --arch="${arch}" --bin-dir="${KUBEBUILDER_ASSETS}")/* ${KUBEBUILDER_ASSETS} + find $KUBEBUILDER_ASSETS +} + +main "$@" \ No newline at end of file