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
93
pkg/controller/openapi/config.go
Normal file
93
pkg/controller/openapi/config.go
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Please refer to the LICENSE file in the root directory of the project.
|
||||
* https://github.com/kubesphere/kubesphere/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package openapi
|
||||
|
||||
import (
|
||||
"github.com/go-openapi/spec"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/api"
|
||||
ksVersion "kubesphere.io/kubesphere/pkg/version"
|
||||
)
|
||||
|
||||
func EnrichSwaggerObject(swo *spec.Swagger) {
|
||||
swo.Info = &spec.Info{
|
||||
InfoProps: spec.InfoProps{
|
||||
Title: "KubeSphere API",
|
||||
Description: "KubeSphere Enterprise OpenAPI",
|
||||
Version: ksVersion.Get().GitVersion,
|
||||
Contact: &spec.ContactInfo{
|
||||
ContactInfoProps: spec.ContactInfoProps{
|
||||
Name: "KubeSphere",
|
||||
URL: "https://kubesphere.com.cn",
|
||||
Email: "support@kubesphere.cloud",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
// setup security definitions
|
||||
swo.SecurityDefinitions = map[string]*spec.SecurityScheme{
|
||||
"BearerToken": {SecuritySchemeProps: spec.SecuritySchemeProps{
|
||||
Type: "apiKey",
|
||||
Name: "Authorization",
|
||||
In: "header",
|
||||
Description: "Bearer Token Authentication",
|
||||
}},
|
||||
}
|
||||
swo.Security = []map[string][]string{{"BearerToken": []string{}}}
|
||||
swo.Tags = []spec.Tag{
|
||||
|
||||
{
|
||||
TagProps: spec.TagProps{
|
||||
Name: api.TagAuthentication,
|
||||
},
|
||||
},
|
||||
{
|
||||
TagProps: spec.TagProps{
|
||||
Name: api.TagMultiCluster,
|
||||
},
|
||||
},
|
||||
{
|
||||
TagProps: spec.TagProps{
|
||||
Name: api.TagIdentityManagement,
|
||||
},
|
||||
},
|
||||
{
|
||||
TagProps: spec.TagProps{
|
||||
Name: api.TagAccessManagement,
|
||||
},
|
||||
},
|
||||
{
|
||||
TagProps: spec.TagProps{
|
||||
Name: api.TagClusterResources,
|
||||
},
|
||||
},
|
||||
{
|
||||
TagProps: spec.TagProps{
|
||||
Name: api.TagNamespacedResources,
|
||||
},
|
||||
},
|
||||
{
|
||||
TagProps: spec.TagProps{
|
||||
Name: api.TagComponentStatus,
|
||||
},
|
||||
},
|
||||
{
|
||||
TagProps: spec.TagProps{
|
||||
Name: api.TagUserRelatedResources,
|
||||
},
|
||||
},
|
||||
{
|
||||
TagProps: spec.TagProps{
|
||||
Name: api.TagTerminal,
|
||||
},
|
||||
},
|
||||
{
|
||||
TagProps: spec.TagProps{
|
||||
Name: api.TagNonResourceAPI,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
69
pkg/controller/openapi/openapi_controller.go
Normal file
69
pkg/controller/openapi/openapi_controller.go
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Please refer to the LICENSE file in the root directory of the project.
|
||||
* https://github.com/kubesphere/kubesphere/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package openapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
toolscache "k8s.io/client-go/tools/cache"
|
||||
"k8s.io/klog/v2"
|
||||
runtimecache "sigs.k8s.io/controller-runtime/pkg/cache"
|
||||
|
||||
extensionsv1alpha1 "kubesphere.io/api/extensions/v1alpha1"
|
||||
|
||||
"kubesphere.io/kubesphere/kube/pkg/openapi"
|
||||
)
|
||||
|
||||
var SharedOpenAPIController = NewController()
|
||||
|
||||
type Controller struct{}
|
||||
|
||||
func NewController() *Controller {
|
||||
return &Controller{}
|
||||
}
|
||||
|
||||
func (c *Controller) WatchOpenAPIChanges(ctx context.Context, cache runtimecache.Cache, openAPIV2Service openapi.APIServiceManager, openAPIV3Service openapi.APIServiceManager) error {
|
||||
informer, err := cache.GetInformer(ctx, &extensionsv1alpha1.APIService{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("get informer failed: %w", err)
|
||||
}
|
||||
_, err = informer.AddEventHandler(toolscache.FilteringResourceEventHandler{
|
||||
FilterFunc: func(obj interface{}) bool {
|
||||
apiService := obj.(*extensionsv1alpha1.APIService)
|
||||
return apiService.Status.State == extensionsv1alpha1.StateAvailable
|
||||
},
|
||||
Handler: &toolscache.ResourceEventHandlerFuncs{
|
||||
AddFunc: func(obj interface{}) {
|
||||
apiService := obj.(*extensionsv1alpha1.APIService)
|
||||
if err := openAPIV2Service.AddUpdateApiService(apiService); err != nil {
|
||||
klog.Error(err)
|
||||
}
|
||||
if err := openAPIV3Service.AddUpdateApiService(apiService); err != nil {
|
||||
klog.Error(err)
|
||||
}
|
||||
},
|
||||
UpdateFunc: func(old, new interface{}) {
|
||||
apiService := new.(*extensionsv1alpha1.APIService)
|
||||
if err := openAPIV2Service.AddUpdateApiService(apiService); err != nil {
|
||||
klog.Error(err)
|
||||
}
|
||||
if err := openAPIV3Service.AddUpdateApiService(apiService); err != nil {
|
||||
klog.Error(err)
|
||||
}
|
||||
},
|
||||
DeleteFunc: func(obj interface{}) {
|
||||
apiService := obj.(*extensionsv1alpha1.APIService)
|
||||
openAPIV2Service.RemoveApiService(apiService.Name)
|
||||
openAPIV3Service.RemoveApiService(apiService.Name)
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("add event handler failed: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user