Skip to content
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
1 change: 0 additions & 1 deletion pkg/apiserver/filter/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ var (
"/metrics",
"/debug",
"/openapi",
"/version",
"/swagger",
"/favicon.ico",
"/healthz",
Expand Down
9 changes: 0 additions & 9 deletions pkg/apiserver/openapi/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"strings"

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

// version
genericAPIServerConfig.Version = &version.Info{
GitVersion: appVersion.GitVersion,
BuildDate: appVersion.BuildDate,
GoVersion: appVersion.GoVersion,
Compiler: appVersion.Compiler,
Platform: appVersion.Platform,
}
}

func postProcessOpenAPISpec(host string, port int) func(*spec.Swagger) (*spec.Swagger, error) {
Expand Down
5 changes: 5 additions & 0 deletions pkg/platform/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import (
schedulingrest "tkestack.io/tke/pkg/platform/proxy/scheduling/rest"
settingsrest "tkestack.io/tke/pkg/platform/proxy/settings/rest"
storagerest "tkestack.io/tke/pkg/platform/proxy/storage/rest"
versionrest "tkestack.io/tke/pkg/platform/proxy/version/rest"
platformrest "tkestack.io/tke/pkg/platform/registry/rest"
"tkestack.io/tke/pkg/util/log"
)
Expand Down Expand Up @@ -203,6 +204,10 @@ func (m *APIServer) InstallAPIs(apiResourceConfigSource serverstorage.APIResourc
apiGroupsInfo = append(apiGroupsInfo, apiGroupInfo)
}

// install /version route
versionHandler := versionrest.NewVersionProxyHandler(m.GenericAPIServer.LoopbackClientConfig)
versionHandler.Install(m.GenericAPIServer.Handler.GoRestfulContainer)

for i := range apiGroupsInfo {
if err := m.GenericAPIServer.InstallAPIGroup(&apiGroupsInfo[i]); err != nil {
log.Fatalf("Error in registering group versions: %v", err)
Expand Down
72 changes: 72 additions & 0 deletions pkg/platform/proxy/version/rest/rest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Tencent is pleased to support the open source community by making TKEStack
* available.
*
* Copyright (C) 2012-2021 Tencent. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://opensource.org/licenses/Apache-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package rest

import (
"net/http"

"github.com/emicklei/go-restful"
"k8s.io/client-go/rest"
platforminternalclient "tkestack.io/tke/api/client/clientset/internalversion/typed/platform/internalversion"
"tkestack.io/tke/pkg/platform/proxy"
)

type VersionProxyHandler struct {
config *rest.Config
}

func NewVersionProxyHandler(config *rest.Config) *VersionProxyHandler {
return &VersionProxyHandler{
config: config,
}
}

// Install install /version route
// Please confirm /version is not in pkg/apiserver/filter/authentication.go defaultIgnoreAuthPathPrefixes
func (s *VersionProxyHandler) Install(c *restful.Container) {
versionWS := new(restful.WebService)
versionWS.Path("/version")
versionWS.Doc("git code version from which this is built")
versionWS.Route(
versionWS.GET("/").To(s.handle).
Doc("get the code version").
Operation("getVersion").
Produces(restful.MIME_JSON).
Consumes(restful.MIME_JSON))

c.Add(versionWS)
}

// /version route process
func (s *VersionProxyHandler) handle(req *restful.Request, resp *restful.Response) {
platformClient := platforminternalclient.NewForConfigOrDie(s.config)
client, err := proxy.ClientSet(req.Request.Context(), platformClient)
if err != nil {
resp.WriteHeaderAndEntity(http.StatusBadRequest, err.Error())
return
}
version, err := client.Discovery().ServerVersion()

if err != nil {
resp.WriteHeaderAndEntity(http.StatusInternalServerError, err.Error())
return
}

resp.WriteHeaderAndEntity(http.StatusOK, version)
}