Skip to content

Commit 5fc64a1

Browse files
committed
feat(platform): proxy cluster version api
1 parent 9c8d339 commit 5fc64a1

File tree

4 files changed

+77
-10
lines changed

4 files changed

+77
-10
lines changed

pkg/apiserver/filter/authentication.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ var (
7575
"/metrics",
7676
"/debug",
7777
"/openapi",
78-
"/version",
7978
"/swagger",
8079
"/favicon.ico",
8180
"/healthz",

pkg/apiserver/openapi/openapi.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"strings"
2626

2727
"github.com/go-openapi/spec"
28-
"k8s.io/apimachinery/pkg/version"
2928
openapinamer "k8s.io/apiserver/pkg/endpoints/openapi"
3029
genericapiserver "k8s.io/apiserver/pkg/server"
3130
openapicommon "k8s.io/kube-openapi/pkg/common"
@@ -44,14 +43,6 @@ func SetupOpenAPI(genericAPIServerConfig *genericapiserver.Config, getDefinition
4443
genericAPIServerConfig.OpenAPIConfig.Info.Version = appVersion.GitVersion
4544
genericAPIServerConfig.OpenAPIConfig.PostProcessSpec = postProcessOpenAPISpec(host, port)
4645

47-
// version
48-
genericAPIServerConfig.Version = &version.Info{
49-
GitVersion: appVersion.GitVersion,
50-
BuildDate: appVersion.BuildDate,
51-
GoVersion: appVersion.GoVersion,
52-
Compiler: appVersion.Compiler,
53-
Platform: appVersion.Platform,
54-
}
5546
}
5647

5748
func postProcessOpenAPISpec(host string, port int) func(*spec.Swagger) (*spec.Swagger, error) {

pkg/platform/apiserver/apiserver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import (
7171
schedulingrest "tkestack.io/tke/pkg/platform/proxy/scheduling/rest"
7272
settingsrest "tkestack.io/tke/pkg/platform/proxy/settings/rest"
7373
storagerest "tkestack.io/tke/pkg/platform/proxy/storage/rest"
74+
versionrest "tkestack.io/tke/pkg/platform/proxy/version/rest"
7475
platformrest "tkestack.io/tke/pkg/platform/registry/rest"
7576
"tkestack.io/tke/pkg/util/log"
7677
)
@@ -203,6 +204,10 @@ func (m *APIServer) InstallAPIs(apiResourceConfigSource serverstorage.APIResourc
203204
apiGroupsInfo = append(apiGroupsInfo, apiGroupInfo)
204205
}
205206

207+
// install /version route
208+
versionHandler := versionrest.NewVersionProxyHandler(m.GenericAPIServer.LoopbackClientConfig)
209+
versionHandler.Install(m.GenericAPIServer.Handler.GoRestfulContainer)
210+
206211
for i := range apiGroupsInfo {
207212
if err := m.GenericAPIServer.InstallAPIGroup(&apiGroupsInfo[i]); err != nil {
208213
log.Fatalf("Error in registering group versions: %v", err)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making TKEStack
3+
* available.
4+
*
5+
* Copyright (C) 2012-2021 Tencent. All Rights Reserved.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use
8+
* this file except in compliance with the License. You may obtain a copy of the
9+
* License at
10+
*
11+
* https://opensource.org/licenses/Apache-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations under the License.
17+
*/
18+
19+
package rest
20+
21+
import (
22+
"net/http"
23+
24+
"github.com/emicklei/go-restful"
25+
"k8s.io/client-go/rest"
26+
platforminternalclient "tkestack.io/tke/api/client/clientset/internalversion/typed/platform/internalversion"
27+
"tkestack.io/tke/pkg/platform/proxy"
28+
)
29+
30+
type VersionProxyHandler struct {
31+
config *rest.Config
32+
}
33+
34+
func NewVersionProxyHandler(config *rest.Config) *VersionProxyHandler {
35+
return &VersionProxyHandler{
36+
config: config,
37+
}
38+
}
39+
40+
// Install install /version route
41+
// Please confirm /version is not in pkg/apiserver/filter/authentication.go defaultIgnoreAuthPathPrefixes
42+
func (s *VersionProxyHandler) Install(c *restful.Container) {
43+
versionWS := new(restful.WebService)
44+
versionWS.Path("/version")
45+
versionWS.Doc("git code version from which this is built")
46+
versionWS.Route(
47+
versionWS.GET("/").To(s.handle).
48+
Doc("get the code version").
49+
Operation("getVersion").
50+
Produces(restful.MIME_JSON).
51+
Consumes(restful.MIME_JSON))
52+
53+
c.Add(versionWS)
54+
}
55+
56+
// /version route process
57+
func (s *VersionProxyHandler) handle(req *restful.Request, resp *restful.Response) {
58+
platformClient := platforminternalclient.NewForConfigOrDie(s.config)
59+
client, err := proxy.ClientSet(req.Request.Context(), platformClient)
60+
if err != nil {
61+
resp.WriteHeaderAndEntity(http.StatusBadRequest, err.Error())
62+
return
63+
}
64+
version, err := client.Discovery().ServerVersion()
65+
66+
if err != nil {
67+
resp.WriteHeaderAndEntity(http.StatusInternalServerError, err.Error())
68+
return
69+
}
70+
71+
resp.WriteHeaderAndEntity(http.StatusOK, version)
72+
}

0 commit comments

Comments
 (0)