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

feat(kuma-cp) add versions endpoint #1602

Merged
merged 4 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
31 changes: 31 additions & 0 deletions pkg/api-server/resources/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"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"
}
}
}
6 changes: 6 additions & 0 deletions pkg/api-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ func NewApiServer(resManager manager.ResourceManager, wsManager customization.AP
}
container.Add(configWs)

versionsWs, err := versionsWs()
if err != nil {
return nil, errors.Wrap(err, "could not create versions webservice")
}
container.Add(versionsWs)

zonesWs := zonesWs(resManager)
container.Add(zonesWs)

Expand Down
28 changes: 28 additions & 0 deletions pkg/api-server/versions_ws.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package api_server

import (
"io/ioutil"

"github.com/emicklei/go-restful"
"github.com/pkg/errors"
)

const VersionsFilePath = "resources/versions.json"

func versionsWs() (*restful.WebService, error) {
bartsmykla marked this conversation as resolved.
Show resolved Hide resolved
json, err := ioutil.ReadFile(VersionsFilePath)
if err != nil {
return nil, errors.Wrap(err, "couldn't read versions.json file")
}

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(json); err != nil {
log.Error(err, "Could not write the index response")
}
}))

return ws, nil
}
105 changes: 105 additions & 0 deletions pkg/api-server/versions_ws_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package api_server_test

import (
"encoding/json"
"fmt"
"net/http"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

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

var _ = Describe("Versions WS", func() {

It("should return the supported versions", func() {
// setup
resourceStore := memory.NewStore()
metrics, err := metrics.NewMetrics("Standalone")
Expect(err).ToNot(HaveOccurred())
apiServer := createTestApiServer(resourceStore, config.DefaultApiServerConfig(), true, metrics)

stop := make(chan struct{})
go func() {
defer GinkgoRecover()
err := apiServer.Start(stop)
Expect(err).ToNot(HaveOccurred())
}()

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

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

// then
var data struct {
KumaDp map[string]struct {
Envoy string
}
}

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

// 1.0.0
Expect(data).ToNot(BeNil())
Expect(data.KumaDp).ToNot(BeNil())
Expect(data.KumaDp["1.0.0"]).ToNot(BeNil())
Expect(data.KumaDp["1.0.0"].Envoy).To(Equal("1.16.0"))

// 1.0.1
Expect(data).ToNot(BeNil())
Expect(data.KumaDp).ToNot(BeNil())
Expect(data.KumaDp["1.0.1"]).ToNot(BeNil())
Expect(data.KumaDp["1.0.1"].Envoy).To(Equal("1.16.0"))

// 1.0.2
Expect(data).ToNot(BeNil())
Expect(data.KumaDp).ToNot(BeNil())
Expect(data.KumaDp["1.0.2"]).ToNot(BeNil())
Expect(data.KumaDp["1.0.2"].Envoy).To(Equal("1.16.1"))

// 1.0.3
Expect(data).ToNot(BeNil())
Expect(data.KumaDp).ToNot(BeNil())
Expect(data.KumaDp["1.0.3"]).ToNot(BeNil())
Expect(data.KumaDp["1.0.3"].Envoy).To(Equal("1.16.1"))

// 1.0.4
Expect(data).ToNot(BeNil())
Expect(data.KumaDp).ToNot(BeNil())
Expect(data.KumaDp["1.0.4"]).ToNot(BeNil())
Expect(data.KumaDp["1.0.4"].Envoy).To(Equal("1.16.1"))

// 1.0.5
Expect(data).ToNot(BeNil())
Expect(data.KumaDp).ToNot(BeNil())
Expect(data.KumaDp["1.0.5"]).ToNot(BeNil())
Expect(data.KumaDp["1.0.5"].Envoy).To(Equal("1.16.2"))

// 1.0.6
Expect(data).ToNot(BeNil())
Expect(data.KumaDp).ToNot(BeNil())
Expect(data.KumaDp["1.0.6"]).ToNot(BeNil())
Expect(data.KumaDp["1.0.6"].Envoy).To(Equal("1.16.2"))

// 1.0.7
Expect(data).ToNot(BeNil())
Expect(data.KumaDp).ToNot(BeNil())
Expect(data.KumaDp["1.0.7"]).ToNot(BeNil())
Expect(data.KumaDp["1.0.7"].Envoy).To(Equal("1.16.2"))

// 1.0.8
Expect(data).ToNot(BeNil())
Expect(data.KumaDp).ToNot(BeNil())
Expect(data.KumaDp["1.0.8"]).ToNot(BeNil())
Expect(data.KumaDp["1.0.8"].Envoy).To(Equal("1.16.2"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is a need to check each and every entry ;) Maybe just first,middle,last?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm checking it as an additional layer for us to be sure we are presenting expected versions

})
})