feat: kubesphere 4.0 (#6115)
* feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> * feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> --------- Signed-off-by: ci-bot <ci-bot@kubesphere.io> Co-authored-by: ks-ci-bot <ks-ci-bot@example.com> Co-authored-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
committed by
GitHub
parent
b5015ec7b9
commit
447a51f08b
108
pkg/kapis/config/v1alpha2/handler.go
Normal file
108
pkg/kapis/config/v1alpha2/handler.go
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Please refer to the LICENSE file in the root directory of the project.
|
||||
* https://github.com/kubesphere/kubesphere/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package v1alpha2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/emicklei/go-restful/v3"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/api"
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/authentication/identityprovider"
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/authentication/oauth"
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/options"
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/rest"
|
||||
"kubesphere.io/kubesphere/pkg/constants"
|
||||
)
|
||||
|
||||
const (
|
||||
themeConfigurationName = "platform-configuration-theme"
|
||||
)
|
||||
|
||||
func NewHandler(config *options.Options, client client.Client) rest.Handler {
|
||||
return &handler{
|
||||
config: config,
|
||||
client: client,
|
||||
oauthClientConfigurationGetter: oauth.NewOAuthClientGetter(client),
|
||||
}
|
||||
}
|
||||
|
||||
func NewFakeHandler() rest.Handler {
|
||||
return &handler{}
|
||||
}
|
||||
|
||||
type handler struct {
|
||||
config *options.Options
|
||||
client client.Client
|
||||
oauthClientConfigurationGetter oauth.ClientGetter
|
||||
}
|
||||
|
||||
type ThemeConfiguration map[string]string
|
||||
|
||||
func (h *handler) updateThemeConfiguration(req *restful.Request, resp *restful.Response) {
|
||||
platformInformation := ThemeConfiguration{}
|
||||
if err := req.ReadEntity(&platformInformation); err != nil {
|
||||
api.HandleBadRequest(resp, req, err)
|
||||
return
|
||||
}
|
||||
configMap := corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: themeConfigurationName,
|
||||
Namespace: constants.KubeSphereNamespace,
|
||||
},
|
||||
}
|
||||
_, err := ctrl.CreateOrUpdate(req.Request.Context(), h.client, &configMap, func() error {
|
||||
configMap.Data = platformInformation
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
api.HandleInternalError(resp, req, err)
|
||||
return
|
||||
}
|
||||
_ = resp.WriteEntity(platformInformation)
|
||||
}
|
||||
|
||||
func (h *handler) getThemeConfiguration(req *restful.Request, resp *restful.Response) {
|
||||
var configMap corev1.ConfigMap
|
||||
themeConfiguration := ThemeConfiguration{}
|
||||
configName := types.NamespacedName{Namespace: constants.KubeSphereNamespace, Name: themeConfigurationName}
|
||||
if err := h.client.Get(req.Request.Context(), configName, &configMap); err != nil {
|
||||
if apierrors.IsNotFound(err) {
|
||||
_ = resp.WriteEntity(themeConfiguration)
|
||||
return
|
||||
}
|
||||
api.HandleInternalError(resp, req, err)
|
||||
return
|
||||
}
|
||||
_ = resp.WriteEntity(configMap.Data)
|
||||
}
|
||||
|
||||
type OAuthConfiguration struct {
|
||||
Issuer *oauth.IssuerOptions `json:"issuer"`
|
||||
IdentityProviders []*identityprovider.Configuration `json:"identityProviders"`
|
||||
Clients []*oauth.Client `json:"clients"`
|
||||
}
|
||||
|
||||
func (h *handler) getOAuthConfiguration(req *restful.Request, resp *restful.Response) {
|
||||
providers := identityprovider.SharedIdentityProviderController.ListConfigurations()
|
||||
clients, err := h.oauthClientConfigurationGetter.ListOAuthClients(req.Request.Context())
|
||||
if err != nil {
|
||||
api.HandleInternalError(resp, req, fmt.Errorf("failed to list OAuth clients: %s", err))
|
||||
return
|
||||
}
|
||||
configuration := OAuthConfiguration{
|
||||
Issuer: h.config.AuthenticationOptions.Issuer,
|
||||
IdentityProviders: providers,
|
||||
Clients: clients,
|
||||
}
|
||||
_ = resp.WriteEntity(configuration)
|
||||
}
|
||||
@@ -1,28 +1,16 @@
|
||||
/*
|
||||
Copyright 2020 The KubeSphere Authors.
|
||||
|
||||
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
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-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 OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
* Please refer to the LICENSE file in the root directory of the project.
|
||||
* https://github.com/kubesphere/kubesphere/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package v1alpha2
|
||||
|
||||
import (
|
||||
restfulspec "github.com/emicklei/go-restful-openapi/v2"
|
||||
"github.com/emicklei/go-restful/v3"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/gpu"
|
||||
|
||||
kubesphereconfig "kubesphere.io/kubesphere/pkg/apiserver/config"
|
||||
"kubesphere.io/kubesphere/pkg/api"
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
|
||||
)
|
||||
|
||||
@@ -32,30 +20,39 @@ const (
|
||||
|
||||
var GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"}
|
||||
|
||||
func AddToContainer(c *restful.Container, config *kubesphereconfig.Config) error {
|
||||
func (h *handler) AddToContainer(c *restful.Container) error {
|
||||
webservice := runtime.NewWebService(GroupVersion)
|
||||
|
||||
webservice.Route(webservice.GET("/configs/oauth").
|
||||
Doc("Information about the authorization server are published.").
|
||||
To(func(request *restful.Request, response *restful.Response) {
|
||||
response.WriteEntity(config.AuthenticationOptions.OAuthOptions)
|
||||
}))
|
||||
Doc("OAuth configurations").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{api.TagPlatformConfigurations}).
|
||||
Notes("Information about the authorization server are published.").
|
||||
Operation("oauth-config").
|
||||
To(h.getOAuthConfiguration))
|
||||
|
||||
webservice.Route(webservice.GET("/configs/configz").
|
||||
Doc("Information about the server configuration").
|
||||
Deprecate().
|
||||
Doc("Component configurations").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{api.TagPlatformConfigurations}).
|
||||
Notes("Information about the components configuration").
|
||||
Operation("component-config").
|
||||
To(func(request *restful.Request, response *restful.Response) {
|
||||
response.WriteAsJson(config.ToMap())
|
||||
_ = response.WriteAsJson(h.config)
|
||||
}))
|
||||
|
||||
webservice.Route(webservice.GET("/configs/gpu/kinds").
|
||||
Doc("Get all supported GPU kinds.").
|
||||
To(func(request *restful.Request, response *restful.Response) {
|
||||
var kinds []gpu.GPUKind
|
||||
if config.GPUOptions != nil {
|
||||
kinds = config.GPUOptions.Kinds
|
||||
}
|
||||
response.WriteAsJson(kinds)
|
||||
}))
|
||||
webservice.Route(webservice.GET("/configs/theme").
|
||||
Doc("Retrieve theme configurations").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{api.TagPlatformConfigurations}).
|
||||
Notes("Retrieve theme configuration settings.").
|
||||
Operation("get-theme-config").
|
||||
To(h.getThemeConfiguration))
|
||||
|
||||
webservice.Route(webservice.POST("/configs/theme").
|
||||
Doc("Update theme configurations").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{api.TagPlatformConfigurations}).
|
||||
Notes("Update theme configuration settings.").
|
||||
Operation("update-theme-config").
|
||||
To(h.updateThemeConfiguration))
|
||||
|
||||
c.Add(webservice)
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user