Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kuma-cp) test versions compatibility on the release #2707

Merged
merged 4 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,11 @@ jobs:
test:
executor: golang
resource_class: medium
parameters:
target:
description: The test make target.
type: string
default: test
steps:
- checkout
- restore_cache:
Expand All @@ -804,7 +809,7 @@ jobs:
command: make dev/tools
- run:
name: "Run unit tests"
command: GO_TEST_OPTS='-p 2' make test
command: GO_TEST_OPTS='-p 2' make << parameters.target >>
- store_artifacts:
path: build/coverage
destination: /coverage
Expand Down Expand Up @@ -1492,6 +1497,12 @@ workflows:
<<: *release_workflow_filters
requires:
- build
- test:
<<: *helm_release_workflow_filters
requires:
- go_cache
name: test-release
target: test/release
- test:
<<: *release_workflow_filters
requires:
Expand All @@ -1506,6 +1517,7 @@ workflows:
- api_check
- check
- test
- test-release
- integration
- helm-release:
<<: *helm_release_workflow_filters
Expand Down
4 changes: 4 additions & 0 deletions mk/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ test/kumactl: test/kuma ## Dev: Run `kumactl` tests only
${COVERAGE_INTEGRATION_PROFILE}:
mkdir -p "$(shell dirname "$(COVERAGE_INTEGRATION_PROFILE)")"

.PHONY: test/release
test/release: # Dev: Run release tests
$(GO_TEST) $(GO_TEST_OPTS) -tags=release ./test/release/...

.PHONY: integration
integration: ${COVERAGE_INTEGRATION_PROFILE} ## Dev: Run integration tests
tools/test/run-integration-tests.sh '$(GO_TEST) -tags=integration,gateway -race -covermode=atomic -count=1 -coverpkg=./... -coverprofile=$(COVERAGE_INTEGRATION_PROFILE) $(PKG_LIST)'
Expand Down
40 changes: 40 additions & 0 deletions pkg/api-server/testdata/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"kumaDp": {
"1.0.0": {
"envoy": "1.16.0"
},
"1.0.1": {
"envoy": "1.16.0"
},
"1.0.2": {
"envoy": "1.16.1"
},
"1.0.3": {
"envoy": "1.16.1"
},
"1.0.4": {
"envoy": "1.16.1"
},
"1.0.5": {
"envoy": "1.16.2"
},
"1.0.6": {
"envoy": "1.16.2"
},
"1.0.7": {
"envoy": "1.16.2"
},
"1.0.8": {
"envoy": "1.16.2"
},
"~1.1.0": {
"envoy": "~1.17.0"
},
"~1.2.0": {
"envoy": "~1.18.0"
},
"~1.3.0": {
"envoy": "~1.18.4"
}
}
}
42 changes: 3 additions & 39 deletions pkg/api-server/versions_ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,16 @@ package api_server

import (
"github.com/emicklei/go-restful"
)

var Versions = []byte(`{
"kumaDp": {
"1.0.0": {
"envoy": "1.16.0"
},
"1.0.1": {
"envoy": "1.16.0"
},
"1.0.2": {
"envoy": "1.16.1"
},
"1.0.3": {
"envoy": "1.16.1"
},
"1.0.4": {
"envoy": "1.16.1"
},
"1.0.5": {
"envoy": "1.16.2"
},
"1.0.6": {
"envoy": "1.16.2"
},
"1.0.7": {
"envoy": "1.16.2"
},
"1.0.8": {
"envoy": "1.16.2"
},
"~1.1.0": {
"envoy": "~1.17.0"
},
"~1.2.0": {
"envoy": "~1.18.0"
}
}
}`)
"github.com/kumahq/kuma/pkg/version"
)

func versionsWs() *restful.WebService {
ws := new(restful.WebService).Path("/versions")

ws.Route(ws.GET("").To(func(req *restful.Request, resp *restful.Response) {
resp.AddHeader("content-type", "application/json")
if _, err := resp.Write(Versions); err != nil {
if err := resp.WriteAsJson(version.CompatibilityMatrix); err != nil {
log.Error(err, "Could not write the index response")
}
}))
Expand Down
153 changes: 9 additions & 144 deletions pkg/api-server/versions_ws_test.go
Original file line number Diff line number Diff line change
@@ -1,92 +1,20 @@
package api_server_test

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
"path"

"github.com/Masterminds/semver/v3"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pkg/errors"

config "github.com/kumahq/kuma/pkg/config/api-server"
"github.com/kumahq/kuma/pkg/metrics"
"github.com/kumahq/kuma/pkg/plugins/resources/memory"
"github.com/kumahq/kuma/pkg/test/matchers"
)

func buildConstraints(versions map[string]envoyVersion) ([]*semver.Constraints, error) {
var errs []string
var constraints []*semver.Constraints

for c := range versions {
constraint, err := semver.NewConstraint(c)
if err != nil {
errs = append(errs, err.Error())
continue
}

constraints = append(constraints, constraint)
}

if len(errs) > 0 {
return nil, errors.Errorf("couldn't build constraints:\n%s", strings.Join(errs, "\n"))
}

return constraints, nil
}

func getConstraint(constraints []*semver.Constraints, version string) (*semver.Constraints, error) {
v, err := semver.NewVersion(version)
if err != nil {
return nil, err
}

var matchedConstrain []*semver.Constraints

for _, constraint := range constraints {
if constraint.Check(v) {
matchedConstrain = append(matchedConstrain, constraint)
}
}

if len(matchedConstrain) == 0 {
return nil, errors.Errorf("no constraints for version: %s found", version)
}

if len(matchedConstrain) > 1 {
var matched []string
for _, c := range matchedConstrain {
matched = append(matched, c.String())
}

return nil, errors.Errorf(
"more than one constraint for version: %s\n%s",
version,
strings.Join(matched, "\n"),
)
}

return matchedConstrain[0], nil
}

func validateConstrainForEnvoy(constrain string, version string) error {
if constrain != version {
return errors.Errorf("envoy version in constrain: %s doesn't equal expected one: %s", constrain, version)
}

return nil
}

type envoyVersion struct {
Envoy string
}

type versions struct {
KumaDp map[string]envoyVersion
}

var _ = Describe("Versions WS", func() {
It("should return the supported versions", func() {
// setup
Expand All @@ -102,80 +30,17 @@ var _ = Describe("Versions WS", func() {
Expect(err).ToNot(HaveOccurred())
}()

// wait for the server
// when
var resp *http.Response
Eventually(func() error {
_, err := http.Get(fmt.Sprintf("http://%s/versions", apiServer.Address()))
r, err := http.Get(fmt.Sprintf("http://%s/versions", apiServer.Address()))
resp = r
return err
}, "3s").ShouldNot(HaveOccurred())

// when
resp, err := http.Get(fmt.Sprintf("http://%s/versions", apiServer.Address()))
Expect(err).ToNot(HaveOccurred())

// then
var data versions

Expect(json.NewDecoder(resp.Body).Decode(&data)).ToNot(HaveOccurred())

constraints, err := buildConstraints(data.KumaDp)
bytes, err := ioutil.ReadAll(resp.Body)
Expect(err).ToNot(HaveOccurred())

Expect(data).ToNot(BeNil())
Expect(data.KumaDp).ToNot(BeNil())

// 1.0.0
constrain, err := getConstraint(constraints, "1.0.0")
Expect(err).NotTo(HaveOccurred())
Expect(validateConstrainForEnvoy(data.KumaDp[constrain.String()].Envoy, "1.16.0")).To(Succeed())

// 1.0.1
constrain, err = getConstraint(constraints, "1.0.1")
Expect(err).NotTo(HaveOccurred())
Expect(validateConstrainForEnvoy(data.KumaDp[constrain.String()].Envoy, "1.16.0")).To(Succeed())

// 1.0.2
constrain, err = getConstraint(constraints, "1.0.2")
Expect(err).NotTo(HaveOccurred())
Expect(validateConstrainForEnvoy(data.KumaDp[constrain.String()].Envoy, "1.16.1")).To(Succeed())

// 1.0.3
constrain, err = getConstraint(constraints, "1.0.3")
Expect(err).NotTo(HaveOccurred())
Expect(validateConstrainForEnvoy(data.KumaDp[constrain.String()].Envoy, "1.16.1")).To(Succeed())

// 1.0.4
constrain, err = getConstraint(constraints, "1.0.4")
Expect(err).NotTo(HaveOccurred())
Expect(validateConstrainForEnvoy(data.KumaDp[constrain.String()].Envoy, "1.16.1")).To(Succeed())

// 1.0.5
constrain, err = getConstraint(constraints, "1.0.5")
Expect(err).NotTo(HaveOccurred())
Expect(validateConstrainForEnvoy(data.KumaDp[constrain.String()].Envoy, "1.16.2")).To(Succeed())

// 1.0.6
constrain, err = getConstraint(constraints, "1.0.6")
Expect(err).NotTo(HaveOccurred())
Expect(validateConstrainForEnvoy(data.KumaDp[constrain.String()].Envoy, "1.16.2")).To(Succeed())

// 1.0.7
constrain, err = getConstraint(constraints, "1.0.7")
Expect(err).NotTo(HaveOccurred())
Expect(validateConstrainForEnvoy(data.KumaDp[constrain.String()].Envoy, "1.16.2")).To(Succeed())

// 1.0.8
constrain, err = getConstraint(constraints, "1.0.8")
Expect(err).NotTo(HaveOccurred())
Expect(validateConstrainForEnvoy(data.KumaDp[constrain.String()].Envoy, "1.16.2")).To(Succeed())

// ~1.1.0
constrain, err = getConstraint(constraints, "1.1.0")
Expect(err).NotTo(HaveOccurred())
Expect(validateConstrainForEnvoy(data.KumaDp[constrain.String()].Envoy, "~1.17.0")).To(Succeed())

// ~1.2.0
constrain, err = getConstraint(constraints, "1.2.0")
Expect(err).NotTo(HaveOccurred())
Expect(validateConstrainForEnvoy(data.KumaDp[constrain.String()].Envoy, "~1.18.0")).To(Succeed())
Expect(bytes).To(matchers.MatchGoldenJSON(path.Join("testdata", "versions.json")))
})
})
Loading