From 3292991c5a286967fe7b7e12a1c1a7ed0334d982 Mon Sep 17 00:00:00 2001 From: Florian Hopfensperger Date: Wed, 30 Aug 2023 00:03:33 +0200 Subject: [PATCH 1/4] fix(crd): kindConfig type (#477) Signed-off-by: Florian Hopfensperger --- crds/testsuite-json-schema.yaml | 2 +- crds/testsuite_crd.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crds/testsuite-json-schema.yaml b/crds/testsuite-json-schema.yaml index 5001f7e3..d78c21b6 100644 --- a/crds/testsuite-json-schema.yaml +++ b/crds/testsuite-json-schema.yaml @@ -30,7 +30,7 @@ properties: default: false kindConfig: description: Path to the KIND configuration file to use. - type: boolean + type: string kindContext: description: KIND context to use. type: string diff --git a/crds/testsuite_crd.yaml b/crds/testsuite_crd.yaml index 98ed2f79..ee77a069 100644 --- a/crds/testsuite_crd.yaml +++ b/crds/testsuite_crd.yaml @@ -46,7 +46,7 @@ spec: default: false kindConfig: description: Path to the KIND configuration file to use. - type: boolean + type: string kindContext: description: KIND context to use. type: string From abc00ee6274bf44cc155f9edcf2831a0aacbada7 Mon Sep 17 00:00:00 2001 From: Ken Sipe Date: Thu, 31 Aug 2023 09:40:56 -0500 Subject: [PATCH 2/4] Upgrade to Go 1.21, requires update to linter, and fixes to new lint failures (#485) Signed-off-by: Ken Sipe --- .github/workflows/integration-test.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/unittest.yml | 2 +- Dockerfile | 2 +- Makefile | 2 +- go.mod | 2 +- go.sum | 21 +++++++++++++++++++++ pkg/kuttlctl/cmd/version.go | 2 +- pkg/test/assert.go | 2 +- pkg/test/harness_test.go | 6 +++--- pkg/test/kind_logger.go | 4 ++-- pkg/test/step.go | 10 +++++----- pkg/test/step_test.go | 8 ++++---- pkg/test/utils/kubernetes.go | 2 +- pkg/test/utils/testing.go | 2 +- test/Dockerfile | 2 +- 16 files changed, 46 insertions(+), 25 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 00069a94..98c96637 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -16,7 +16,7 @@ jobs: steps: - uses: actions/setup-go@v2.1.4 with: - go-version: 1.18 + go-version: 1.21 - uses: actions/checkout@v2.4.0 - name: "Run integration tests" run: make integration-test INTEGRATION_OUTPUT_JUNIT="true" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 9d1a0e8a..353e1c36 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,7 +16,7 @@ jobs: steps: - uses: actions/setup-go@v2.1.4 with: - go-version: 1.18 + go-version: 1.21 - uses: actions/checkout@v2.4.0 - name: "Lint the code" run: make lint diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 1b982b8a..05c190b8 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -16,7 +16,7 @@ jobs: steps: - uses: actions/setup-go@v2.1.4 with: - go-version: 1.18 + go-version: 1.21 - uses: actions/checkout@v2.4.0 - name: "Run unit tests" run: make test diff --git a/Dockerfile b/Dockerfile index fa2ce68e..a57a7c2b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ # artifacts by default will land in the root of the mount point. # kuttl builder -FROM golang:1.18 as builder +FROM golang:1.21 as builder WORKDIR /go/src/kuttl COPY . . diff --git a/Makefile b/Makefile index 2fba08a5..c5f992df 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ BUILD_DATE_PATH := github.com/kudobuilder/kuttl/pkg/version.buildDate DATE_FMT := "%Y-%m-%dT%H:%M:%SZ" BUILD_DATE := $(shell date -u -d "@$SOURCE_DATE_EPOCH" "+${DATE_FMT}" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "+${DATE_FMT}" 2>/dev/null || date -u "+${DATE_FMT}") LDFLAGS := -X ${GIT_VERSION_PATH}=${GIT_VERSION} -X ${GIT_COMMIT_PATH}=${GIT_COMMIT} -X ${BUILD_DATE_PATH}=${BUILD_DATE} -GOLANGCI_LINT_VER = "1.50.1" +GOLANGCI_LINT_VER = "1.54.2" # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. ENVTEST_K8S_VERSION ?= 1.25.0 diff --git a/go.mod b/go.mod index e8185be3..5b529e8f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/kudobuilder/kuttl -go 1.18 +go 1.21 require ( github.com/Masterminds/semver/v3 v3.1.1 diff --git a/go.sum b/go.sum index 69a9bf17..d099af02 100644 --- a/go.sum +++ b/go.sum @@ -44,8 +44,10 @@ github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpz github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= +github.com/cespare/xxhash/v2 v2.1.2/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= @@ -84,6 +86,7 @@ github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2Vvl github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= +github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -92,6 +95,7 @@ github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/zapr v1.2.3 h1:a9vnzlIBPQBBkeaR9IuMUfmVOrQlkoC4YfPoFkX3T7A= +github.com/go-logr/zapr v1.2.3/go.mod h1:eIauM6P8qSvTw5o2ez6UEAfGjQKrxQTl5EoK+Qa2oG4= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= @@ -109,6 +113,7 @@ github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4er github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= @@ -202,6 +207,7 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/matttproud/golang_protobuf_extensions v1.0.2 h1:hAHbPm5IJGijwng3PWk09JkG9WeqChjprR5s9bBZ+OM= +github.com/matttproud/golang_protobuf_extensions v1.0.2/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae h1:O4SWKdcHVCvYqyDV+9CJA1fcDN2L11Bule0iFy3YlAI= github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -216,9 +222,13 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= 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 v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.6.0 h1:9t9b9vRUbFq3C4qKFCGkVuq/fIHji802N1nrtkh1mNc= +github.com/onsi/ginkgo/v2 v2.6.0/go.mod h1:63DOGlLAH8+REH8jUGdL3YpCpu7JODesutUjdENfUAc= github.com/onsi/gomega v1.24.2 h1:J/tulyYK6JwBldPViHJReihxxZ+22FHs0piGjQAvoUE= +github.com/onsi/gomega v1.24.2/go.mod h1:gs3J10IS7Z7r7eXRoNJIrNqU4ToQukCJhFtKrWgHWnk= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM= @@ -231,10 +241,14 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw= +github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4= +github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= github.com/prometheus/common v0.37.0 h1:ccBbHCgIiT9uSoFY0vX8H3zsNR5eLt17/RQLUvn8pXE= +github.com/prometheus/common v0.37.0/go.mod h1:phzohg0JFMnBEFGxTDbfu3QyL5GI8gTQJFhYO5B3mfA= github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo= +github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= @@ -271,8 +285,11 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= +go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -357,6 +374,7 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/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-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -462,6 +480,7 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gomodules.xyz/jsonpatch/v2 v2.2.0 h1:4pT439QV83L+G9FkcCriY6EkpcK6r6bK+A5FBUMI7qY= +gomodules.xyz/jsonpatch/v2 v2.2.0/go.mod h1:WXp+iVDkoLQqPudfQ9GBlwB2eZ5DKOnjQZCYdOS8GPY= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= @@ -552,6 +571,7 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= 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.2/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= @@ -582,6 +602,7 @@ k8s.io/client-go v0.26.0/go.mod h1:I2Sh57A79EQsDmn7F7ASpmru1cceh3ocVT9KlX2jEZg= k8s.io/code-generator v0.26.0 h1:ZDY+7Gic9p/lACgD1G72gQg2CvNGeAYZTPIncv+iALM= k8s.io/code-generator v0.26.0/go.mod h1:OMoJ5Dqx1wgaQzKgc+ZWaZPfGjdRq/Y3WubFrZmeI3I= k8s.io/component-base v0.26.0 h1:0IkChOCohtDHttmKuz+EP3j3+qKmV55rM9gIFTXA7Vs= +k8s.io/component-base v0.26.0/go.mod h1:lqHwlfV1/haa14F/Z5Zizk5QmzaVf23nQzCwVOQpfC8= k8s.io/gengo v0.0.0-20220902162205-c0856e24416d h1:U9tB195lKdzwqicbJvyJeOXV7Klv+wNAWENRnXEGi08= k8s.io/gengo v0.0.0-20220902162205-c0856e24416d/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= diff --git a/pkg/kuttlctl/cmd/version.go b/pkg/kuttlctl/cmd/version.go index 5051a3e0..1f28da89 100644 --- a/pkg/kuttlctl/cmd/version.go +++ b/pkg/kuttlctl/cmd/version.go @@ -27,7 +27,7 @@ func newVersionCmd() *cobra.Command { } // VersionCmd performs the version sub command -func VersionCmd(cmd *cobra.Command, args []string) error { +func VersionCmd(_ *cobra.Command, _ []string) error { kuttlVersion := version.Get() fmt.Printf("KUTTL Version: %s\n", fmt.Sprintf("%#v", kuttlVersion)) return nil diff --git a/pkg/test/assert.go b/pkg/test/assert.go index 8c8a4082..8d371937 100644 --- a/pkg/test/assert.go +++ b/pkg/test/assert.go @@ -104,7 +104,7 @@ func Errors(namespace string, timeout int, errorFiles ...string) error { return errors.New("error asserts not valid") } -func Client(forceNew bool) (client.Client, error) { +func Client(_ bool) (client.Client, error) { cfg, err := config.GetConfig() if err != nil { return nil, err diff --git a/pkg/test/harness_test.go b/pkg/test/harness_test.go index 6eed8d93..87b14b94 100644 --- a/pkg/test/harness_test.go +++ b/pkg/test/harness_test.go @@ -42,15 +42,15 @@ func newDockerMock() *dockerMock { } } -func (d *dockerMock) VolumeCreate(ctx context.Context, body volumetypes.VolumeCreateBody) (dockertypes.Volume, error) { +func (d *dockerMock) VolumeCreate(_ context.Context, body volumetypes.VolumeCreateBody) (dockertypes.Volume, error) { return dockertypes.Volume{ Mountpoint: fmt.Sprintf("/var/lib/docker/data/%s", body.Name), }, nil } -func (d *dockerMock) NegotiateAPIVersion(ctx context.Context) {} +func (d *dockerMock) NegotiateAPIVersion(_ context.Context) {} -func (d *dockerMock) ImageSave(ctx context.Context, imageIDs []string) (io.ReadCloser, error) { +func (d *dockerMock) ImageSave(_ context.Context, _ []string) (io.ReadCloser, error) { return d.imageReader, nil } diff --git a/pkg/test/kind_logger.go b/pkg/test/kind_logger.go index 4b9b9151..844d3354 100644 --- a/pkg/test/kind_logger.go +++ b/pkg/test/kind_logger.go @@ -86,6 +86,6 @@ func (n *nopLogger) Enabled() bool { return false } -func (n *nopLogger) Info(message string) {} +func (n *nopLogger) Info(_ string) {} -func (n *nopLogger) Infof(format string, args ...interface{}) {} +func (n *nopLogger) Infof(_ string, _ ...interface{}) {} diff --git a/pkg/test/step.go b/pkg/test/step.go index 7c930003..fa3fb555 100644 --- a/pkg/test/step.go +++ b/pkg/test/step.go @@ -142,12 +142,12 @@ func (s *Step) DeleteExisting(namespace string) error { } for _, obj := range toDelete { - delete := &unstructured.Unstructured{} - delete.SetGroupVersionKind(obj.GetObjectKind().GroupVersionKind()) - delete.SetName(obj.GetName()) - delete.SetNamespace(obj.GetNamespace()) + del := &unstructured.Unstructured{} + del.SetGroupVersionKind(obj.GetObjectKind().GroupVersionKind()) + del.SetName(obj.GetName()) + del.SetNamespace(obj.GetNamespace()) - err := cl.Delete(context.TODO(), delete) + err := cl.Delete(context.TODO(), del) if err != nil && !k8serrors.IsNotFound(err) { return err } diff --git a/pkg/test/step_test.go b/pkg/test/step_test.go index 843ee901..6a97745a 100644 --- a/pkg/test/step_test.go +++ b/pkg/test/step_test.go @@ -260,15 +260,15 @@ func TestCheckResourceAbsent(t *testing.T) { DiscoveryClient: func() (discovery.DiscoveryInterface, error) { return fakeDiscovery, nil }, } - error := step.CheckResourceAbsent(test.expected, testNamespace) + err := step.CheckResourceAbsent(test.expected, testNamespace) if test.shouldError { - assert.Error(t, error) + assert.Error(t, err) if test.expectedErr != "" { - assert.EqualError(t, error, test.expectedErr) + assert.EqualError(t, err, test.expectedErr) } } else { - assert.NoError(t, error) + assert.NoError(t, err) } }) } diff --git a/pkg/test/utils/kubernetes.go b/pkg/test/utils/kubernetes.go index 38603ba1..ebcdcce7 100644 --- a/pkg/test/utils/kubernetes.go +++ b/pkg/test/utils/kubernetes.go @@ -245,7 +245,7 @@ func (r *RetryClient) List(ctx context.Context, list client.ObjectList, opts ... } // Watch watches a specific object and returns all events for it. -func (r *RetryClient) Watch(ctx context.Context, obj runtime.Object) (watch.Interface, error) { +func (r *RetryClient) Watch(_ context.Context, obj runtime.Object) (watch.Interface, error) { meta, err := meta.Accessor(obj) if err != nil { return nil, err diff --git a/pkg/test/utils/testing.go b/pkg/test/utils/testing.go index d61782c5..3961e5c1 100644 --- a/pkg/test/utils/testing.go +++ b/pkg/test/utils/testing.go @@ -86,7 +86,7 @@ func (testDeps) ImportPath() string { return "" } -func (testDeps) StartTestLog(w io.Writer) {} +func (testDeps) StartTestLog(_ io.Writer) {} func (testDeps) StopTestLog() error { return nil diff --git a/test/Dockerfile b/test/Dockerfile index 47dc6ed5..8e3240dc 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -1,4 +1,4 @@ -FROM kudobuilder/golang:1.18 +FROM kudobuilder/golang:1.21 WORKDIR $GOPATH/src/github.com/kudobuilder/kuttl From 1f3096ab1eae5f80c05bc9e2f03375c809c99cf3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 31 Aug 2023 09:45:38 -0500 Subject: [PATCH 3/4] Bump github.com/docker/distribution (#472) Bumps [github.com/docker/distribution](https://github.com/docker/distribution) from 2.8.1+incompatible to 2.8.2+incompatible. - [Release notes](https://github.com/docker/distribution/releases) - [Commits](https://github.com/docker/distribution/compare/v2.8.1...v2.8.2) --- updated-dependencies: - dependency-name: github.com/docker/distribution dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ken Sipe --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5b529e8f..bb92967f 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( github.com/Microsoft/go-winio v0.5.1 // indirect github.com/alessio/shellescape v1.4.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/docker/distribution v2.8.1+incompatible // indirect + github.com/docker/distribution v2.8.2+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.4.0 // indirect github.com/emicklei/go-restful/v3 v3.9.0 // indirect diff --git a/go.sum b/go.sum index d099af02..e8aa78dd 100644 --- a/go.sum +++ b/go.sum @@ -60,8 +60,8 @@ github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= -github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8= +github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/docker v20.10.21+incompatible h1:UTLdBmHk3bEY+w8qeO5KttOhy6OmXWsl/FEet9Uswog= github.com/docker/docker v20.10.21+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= From 7e783766c9b15837934f8f98137140cf87929f2c Mon Sep 17 00:00:00 2001 From: Marcin Owsiany Date: Thu, 31 Aug 2023 18:45:49 +0200 Subject: [PATCH 4/4] Support for test run labels/selectors (#483) Add TestFile type and support for running tests which filters on labels. Signed-off-by: Marcin Owsiany Co-authored-by: Ken Sipe --- pkg/apis/testharness/v1beta1/test_types.go | 13 ++ .../v1beta1/zz_generated.deepcopy.go | 32 +++++ pkg/kuttlctl/cmd/test.go | 3 + pkg/kuttlctl/cmd/values.go | 30 ++++ pkg/test/case.go | 17 ++- pkg/test/case_test.go | 128 ++++++++++++++++-- pkg/test/harness.go | 3 + pkg/test/step.go | 43 +++++- .../test-run-labels/01-assert-a.yaml | 12 ++ .../test-run-labels/01-assert-b.yaml | 12 ++ .../test-run-labels/01-create-a.yaml | 12 ++ .../test-run-labels/01-create-b.yaml | 12 ++ pkg/test/utils/kubernetes.go | 2 + 13 files changed, 296 insertions(+), 23 deletions(-) create mode 100644 pkg/kuttlctl/cmd/values.go create mode 100644 pkg/test/test_data/test-run-labels/01-assert-a.yaml create mode 100644 pkg/test/test_data/test-run-labels/01-assert-b.yaml create mode 100644 pkg/test/test_data/test-run-labels/01-create-a.yaml create mode 100644 pkg/test/test_data/test-run-labels/01-create-b.yaml diff --git a/pkg/apis/testharness/v1beta1/test_types.go b/pkg/apis/testharness/v1beta1/test_types.go index 92981426..675fd299 100644 --- a/pkg/apis/testharness/v1beta1/test_types.go +++ b/pkg/apis/testharness/v1beta1/test_types.go @@ -13,6 +13,19 @@ type RestConfig struct { // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// TestFile contains attributes of a single test file. +type TestFile struct { + // The type meta object, should always be a GVK of kuttl.dev/v1beta1/TestFile. + metav1.TypeMeta `json:",inline"` + // Set labels or the test suite name. + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Which test runs should this file be used in. Empty selector matches all test runs. + TestRunSelector *metav1.LabelSelector `json:"testRunSelector,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + // TestSuite configures which tests should be loaded. type TestSuite struct { // The type meta object, should always be a GVK of kuttl.dev/v1beta1/TestSuite or kuttl.dev/v1beta1/TestSuite. diff --git a/pkg/apis/testharness/v1beta1/zz_generated.deepcopy.go b/pkg/apis/testharness/v1beta1/zz_generated.deepcopy.go index 68f8d6c1..4698a0c6 100644 --- a/pkg/apis/testharness/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/testharness/v1beta1/zz_generated.deepcopy.go @@ -20,6 +20,7 @@ limitations under the License. package v1beta1 import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -147,6 +148,37 @@ func (in *TestCollector) DeepCopy() *TestCollector { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TestFile) DeepCopyInto(out *TestFile) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + if in.TestRunSelector != nil { + in, out := &in.TestRunSelector, &out.TestRunSelector + *out = new(v1.LabelSelector) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestFile. +func (in *TestFile) DeepCopy() *TestFile { + if in == nil { + return nil + } + out := new(TestFile) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TestFile) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TestStep) DeepCopyInto(out *TestStep) { *out = *in diff --git a/pkg/kuttlctl/cmd/test.go b/pkg/kuttlctl/cmd/test.go index a54698db..9b80db6d 100644 --- a/pkg/kuttlctl/cmd/test.go +++ b/pkg/kuttlctl/cmd/test.go @@ -61,6 +61,7 @@ func newTestCmd() *cobra.Command { //nolint:gocyclo reportName := "kuttl-report" namespace := "" suppress := []string{} + var runLabels labelSetValue options := harness.TestSuite{} @@ -229,6 +230,7 @@ For more detailed documentation, visit: https://kuttl.dev`, harness := test.Harness{ TestSuite: options, T: t, + RunLabels: runLabels.AsLabelSet(), } harness.Run() @@ -257,6 +259,7 @@ For more detailed documentation, visit: https://kuttl.dev`, testCmd.Flags().StringVar(&reportName, "report-name", "kuttl-report", "Name for the report. Report location determined by --artifacts-dir and report file type determined by --report.") testCmd.Flags().StringVarP(&namespace, "namespace", "n", "", "Namespace to use for tests. Provided namespaces must exist prior to running tests.") testCmd.Flags().StringSliceVar(&suppress, "suppress-log", []string{}, "Suppress logging for these kinds of logs (events).") + testCmd.Flags().Var(&runLabels, "test-run-labels", "Labels to use for this test run.") // This cannot be a global flag because pkg/test/utils.RunTests calls flag.Parse which barfs on unknown top-level flags. // Putting it here at least does not advertise it on a level where using it is impossible. test.SetFlags(testCmd.Flags()) diff --git a/pkg/kuttlctl/cmd/values.go b/pkg/kuttlctl/cmd/values.go new file mode 100644 index 00000000..244891de --- /dev/null +++ b/pkg/kuttlctl/cmd/values.go @@ -0,0 +1,30 @@ +package cmd + +import ( + "fmt" + + "k8s.io/apimachinery/pkg/labels" +) + +type labelSetValue labels.Set + +func (v *labelSetValue) String() string { + return labels.Set(*v).String() +} + +func (v *labelSetValue) Set(s string) error { + l, err := labels.ConvertSelectorToLabelsMap(s) + if err != nil { + return fmt.Errorf("cannot parse label set: %w", err) + } + *v = labelSetValue(l) + return nil +} + +func (v *labelSetValue) Type() string { + return "labelSet" +} + +func (v labelSetValue) AsLabelSet() labels.Set { + return labels.Set(v) +} diff --git a/pkg/test/case.go b/pkg/test/case.go index 97814b0d..b7093259 100644 --- a/pkg/test/case.go +++ b/pkg/test/case.go @@ -18,6 +18,7 @@ import ( eventsbeta1 "k8s.io/api/events/v1beta1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/discovery" "sigs.k8s.io/controller-runtime/pkg/client" @@ -40,6 +41,7 @@ type Case struct { SkipDelete bool Timeout int PreferredNamespace string + RunLabels labels.Set Client func(forceNew bool) (client.Client, error) DiscoveryClient func() (discovery.DiscoveryInterface, error) @@ -458,13 +460,14 @@ func (t *Case) LoadTestSteps() error { for index, files := range testStepFiles { testStep := &Step{ - Timeout: t.Timeout, - Index: int(index), - SkipDelete: t.SkipDelete, - Dir: t.Dir, - Asserts: []client.Object{}, - Apply: []client.Object{}, - Errors: []client.Object{}, + Timeout: t.Timeout, + Index: int(index), + SkipDelete: t.SkipDelete, + Dir: t.Dir, + TestRunLabels: t.RunLabels, + Asserts: []client.Object{}, + Apply: []client.Object{}, + Errors: []client.Object{}, } for _, file := range files { diff --git a/pkg/test/case_test.go b/pkg/test/case_test.go index 0f479451..21a9a064 100644 --- a/pkg/test/case_test.go +++ b/pkg/test/case_test.go @@ -1,12 +1,14 @@ package test import ( + "fmt" "testing" "github.com/stretchr/testify/assert" corev1 "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/labels" "sigs.k8s.io/controller-runtime/pkg/client" harness "github.com/kudobuilder/kuttl/pkg/apis/testharness/v1beta1" @@ -18,10 +20,12 @@ import ( func TestLoadTestSteps(t *testing.T) { for _, tt := range []struct { path string + runLabels labels.Set testSteps []Step }{ { - "test_data/with-overrides/", + "test_data/with-overrides", + labels.Set{}, []Step{ { Name: "with-test-step-name-override", @@ -52,7 +56,8 @@ func TestLoadTestSteps(t *testing.T) { "qosClass": "BestEffort", }), }, - Errors: []client.Object{}, + Errors: []client.Object{}, + TestRunLabels: labels.Set{}, }, { Name: "test-assert", @@ -96,7 +101,8 @@ func TestLoadTestSteps(t *testing.T) { "qosClass": "BestEffort", }), }, - Errors: []client.Object{}, + Errors: []client.Object{}, + TestRunLabels: labels.Set{}, }, { Name: "pod", @@ -124,7 +130,8 @@ func TestLoadTestSteps(t *testing.T) { "qosClass": "BestEffort", }), }, - Errors: []client.Object{}, + Errors: []client.Object{}, + TestRunLabels: labels.Set{}, }, { Name: "name-overridden", @@ -164,12 +171,14 @@ func TestLoadTestSteps(t *testing.T) { "restartPolicy": "Never", }), }, - Errors: []client.Object{}, + Errors: []client.Object{}, + TestRunLabels: labels.Set{}, }, }, }, { "test_data/list-pods", + labels.Set{}, []Step{ { Name: "pod", @@ -217,6 +226,101 @@ func TestLoadTestSteps(t *testing.T) { }, }, }, + Errors: []client.Object{}, + TestRunLabels: labels.Set{}, + }, + }, + }, + { + "test_data/test-run-labels", + labels.Set{}, + []Step{ + { + Name: "", + Index: 1, + TestRunLabels: labels.Set{}, + Apply: []client.Object{}, + Asserts: []client.Object{}, + Errors: []client.Object{}, + }, + }, + }, + { + "test_data/test-run-labels", + labels.Set{"flavor": "a"}, + []Step{ + { + Name: "create-a", + Index: 1, + TestRunLabels: labels.Set{"flavor": "a"}, + Apply: []client.Object{ + &unstructured.Unstructured{ + Object: map[string]interface{}{ + "apiVersion": "v1", + "kind": "ConfigMap", + "metadata": map[string]interface{}{ + "name": "test", + }, + "data": map[string]interface{}{ + "flavor": "a", + }, + }, + }, + }, + Asserts: []client.Object{ + &unstructured.Unstructured{ + Object: map[string]interface{}{ + "apiVersion": "v1", + "kind": "ConfigMap", + "metadata": map[string]interface{}{ + "name": "test", + }, + "data": map[string]interface{}{ + "flavor": "a", + }, + }, + }, + }, + Errors: []client.Object{}, + }, + }, + }, + { + "test_data/test-run-labels", + labels.Set{"flavor": "b"}, + []Step{ + { + Name: "create-b", + Index: 1, + TestRunLabels: labels.Set{"flavor": "b"}, + Apply: []client.Object{ + &unstructured.Unstructured{ + Object: map[string]interface{}{ + "apiVersion": "v1", + "kind": "ConfigMap", + "metadata": map[string]interface{}{ + "name": "test", + }, + "data": map[string]interface{}{ + "flavor": "b", + }, + }, + }, + }, + Asserts: []client.Object{ + &unstructured.Unstructured{ + Object: map[string]interface{}{ + "apiVersion": "v1", + "kind": "ConfigMap", + "metadata": map[string]interface{}{ + "name": "test", + }, + "data": map[string]interface{}{ + "flavor": "b", + }, + }, + }, + }, Errors: []client.Object{}, }, }, @@ -224,8 +328,8 @@ func TestLoadTestSteps(t *testing.T) { } { tt := tt - t.Run(tt.path, func(t *testing.T) { - test := &Case{Dir: tt.path, Logger: testutils.NewTestLogger(t, tt.path)} + t.Run(fmt.Sprintf("%s/%s", tt.path, tt.runLabels), func(t *testing.T) { + test := &Case{Dir: tt.path, Logger: testutils.NewTestLogger(t, tt.path), RunLabels: tt.runLabels} err := test.LoadTestSteps() assert.Nil(t, err) @@ -238,11 +342,11 @@ func TestLoadTestSteps(t *testing.T) { assert.Equal(t, len(tt.testSteps), len(testStepsVal)) for index := range tt.testSteps { tt.testSteps[index].Dir = tt.path - assert.Equal(t, tt.testSteps[index].Apply, testStepsVal[index].Apply) - assert.Equal(t, tt.testSteps[index].Asserts, testStepsVal[index].Asserts) - assert.Equal(t, tt.testSteps[index].Errors, testStepsVal[index].Errors) - assert.Equal(t, tt.testSteps[index].Step, testStepsVal[index].Step) - assert.Equal(t, tt.testSteps[index].Dir, testStepsVal[index].Dir) + assert.Equal(t, tt.testSteps[index].Apply, testStepsVal[index].Apply, "apply objects need to match") + assert.Equal(t, tt.testSteps[index].Asserts, testStepsVal[index].Asserts, "assert objects need to match") + assert.Equal(t, tt.testSteps[index].Errors, testStepsVal[index].Errors, "error objects need to match") + assert.Equal(t, tt.testSteps[index].Step, testStepsVal[index].Step, "step object needs to match") + assert.Equal(t, tt.testSteps[index].Dir, testStepsVal[index].Dir, "dir needs to match") assert.Equal(t, tt.testSteps[index], testStepsVal[index]) } }) diff --git a/pkg/test/harness.go b/pkg/test/harness.go index b221a5bf..379ae6a5 100644 --- a/pkg/test/harness.go +++ b/pkg/test/harness.go @@ -18,6 +18,7 @@ import ( volumetypes "github.com/docker/docker/api/types/volume" docker "github.com/docker/docker/client" "gopkg.in/yaml.v2" + "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/discovery" "k8s.io/client-go/rest" @@ -53,6 +54,7 @@ type Harness struct { stopping bool bgProcesses []*exec.Cmd report *report.Testsuites + RunLabels labels.Set } // LoadTests loads all of the tests in a given directory. @@ -85,6 +87,7 @@ func (h *Harness) LoadTests(dir string) ([]*Case, error) { Dir: filepath.Join(dir, file.Name()), SkipDelete: h.TestSuite.SkipDelete, Suppress: h.TestSuite.Suppress, + RunLabels: h.RunLabels, }) } diff --git a/pkg/test/step.go b/pkg/test/step.go index fa3fb555..ba73c9bc 100644 --- a/pkg/test/step.go +++ b/pkg/test/step.go @@ -11,7 +11,9 @@ import ( "time" k8serrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/wait" @@ -36,7 +38,8 @@ type Step struct { Index int SkipDelete bool - Dir string + Dir string + TestRunLabels labels.Set Step *harness.TestStep Assert *harness.TestAssert @@ -495,9 +498,9 @@ func (s *Step) String() string { // if seen, mark a test immediately failed. // - All other YAML files are considered resources to create. func (s *Step) LoadYAML(file string) error { - objects, err := testutils.LoadYAMLFromFile(file) - if err != nil { - return fmt.Errorf("loading %s: %s", file, err) + skipFile, objects, err := s.loadOrSkipFile(file) + if skipFile || err != nil { + return err } if err = s.populateObjectsByFileName(filepath.Base(file), objects); err != nil { @@ -579,6 +582,38 @@ func (s *Step) LoadYAML(file string) error { return nil } +func (s *Step) loadOrSkipFile(file string) (bool, []client.Object, error) { + loadedObjects, err := testutils.LoadYAMLFromFile(file) + if err != nil { + return false, nil, fmt.Errorf("loading %s: %s", file, err) + } + + var objects []client.Object + shouldSkip := false + testFileObjEncountered := false + + for i, object := range loadedObjects { + if testFileObject, ok := object.(*harness.TestFile); ok { + if testFileObjEncountered { + return false, nil, fmt.Errorf("more than one TestFile object encountered in file %q", file) + } + testFileObjEncountered = true + selector, err := metav1.LabelSelectorAsSelector(testFileObject.TestRunSelector) + if err != nil { + return false, nil, fmt.Errorf("unrecognized test run selector in object %d of %q: %w", i, file, err) + } + if selector.Empty() || selector.Matches(s.TestRunLabels) { + continue + } + fmt.Printf("Skipping file %q, label selector does not match test run labels.\n", file) + shouldSkip = true + } else { + objects = append(objects, object) + } + } + return shouldSkip, objects, nil +} + // populateObjectsByFileName populates s.Asserts, s.Errors, and/or s.Apply for files containing // "assert", "errors", or no special string, respectively. func (s *Step) populateObjectsByFileName(fileName string, objects []client.Object) error { diff --git a/pkg/test/test_data/test-run-labels/01-assert-a.yaml b/pkg/test/test_data/test-run-labels/01-assert-a.yaml new file mode 100644 index 00000000..46faf4f2 --- /dev/null +++ b/pkg/test/test_data/test-run-labels/01-assert-a.yaml @@ -0,0 +1,12 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestFile +testRunSelector: + matchLabels: + flavor: a +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: test +data: + flavor: a diff --git a/pkg/test/test_data/test-run-labels/01-assert-b.yaml b/pkg/test/test_data/test-run-labels/01-assert-b.yaml new file mode 100644 index 00000000..5d8e7be8 --- /dev/null +++ b/pkg/test/test_data/test-run-labels/01-assert-b.yaml @@ -0,0 +1,12 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestFile +testRunSelector: + matchLabels: + flavor: b +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: test +data: + flavor: b diff --git a/pkg/test/test_data/test-run-labels/01-create-a.yaml b/pkg/test/test_data/test-run-labels/01-create-a.yaml new file mode 100644 index 00000000..559453e5 --- /dev/null +++ b/pkg/test/test_data/test-run-labels/01-create-a.yaml @@ -0,0 +1,12 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestFile +testRunSelector: + matchLabels: + flavor: a +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: test +data: + flavor: a \ No newline at end of file diff --git a/pkg/test/test_data/test-run-labels/01-create-b.yaml b/pkg/test/test_data/test-run-labels/01-create-b.yaml new file mode 100644 index 00000000..ece5b5f5 --- /dev/null +++ b/pkg/test/test_data/test-run-labels/01-create-b.yaml @@ -0,0 +1,12 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestFile +testRunSelector: + matchLabels: + flavor: b +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: test +data: + flavor: b \ No newline at end of file diff --git a/pkg/test/utils/kubernetes.go b/pkg/test/utils/kubernetes.go index ebcdcce7..b7706de7 100644 --- a/pkg/test/utils/kubernetes.go +++ b/pkg/test/utils/kubernetes.go @@ -400,6 +400,8 @@ func ConvertUnstructured(in client.Object) (client.Object, error) { return in, nil } switch { + case kind == "TestFile": + converted = &harness.TestFile{} case kind == "TestStep": converted = &harness.TestStep{} case kind == "TestAssert":