diff --git a/pkg/api-server/server.go b/pkg/api-server/server.go index 0cb81b2e5079..c70aace62fae 100644 --- a/pkg/api-server/server.go +++ b/pkg/api-server/server.go @@ -113,6 +113,8 @@ func NewApiServer(resManager manager.ResourceManager, wsManager customization.AP } container.Add(configWs) + container.Add(versionsWs()) + zonesWs := zonesWs(resManager) container.Add(zonesWs) diff --git a/pkg/api-server/versions_ws.go b/pkg/api-server/versions_ws.go new file mode 100644 index 000000000000..603550655371 --- /dev/null +++ b/pkg/api-server/versions_ws.go @@ -0,0 +1,50 @@ +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" + } + } +}`) + +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 { + log.Error(err, "Could not write the index response") + } + })) + + return ws +} diff --git a/pkg/api-server/versions_ws_test.go b/pkg/api-server/versions_ws_test.go new file mode 100644 index 000000000000..9450c2bc90b1 --- /dev/null +++ b/pkg/api-server/versions_ws_test.go @@ -0,0 +1,104 @@ +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")) + }) +})