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
@@ -1,18 +1,7 @@
|
||||
/*
|
||||
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 main
|
||||
|
||||
@@ -23,31 +12,17 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
urlruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
|
||||
applicationv1alpha1 "kubesphere.io/api/application/v1alpha1"
|
||||
clusterv1alpha1 "kubesphere.io/api/cluster/v1alpha1"
|
||||
devopsv1alpha3 "kubesphere.io/api/devops/v1alpha3"
|
||||
|
||||
kubespec "k8s.io/kube-openapi/pkg/validation/spec"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/version"
|
||||
"kubesphere.io/kubesphere/tools/lib"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||
urlruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/kube-openapi/pkg/common"
|
||||
kubespec "k8s.io/kube-openapi/pkg/validation/spec"
|
||||
clusterv1alpha1 "kubesphere.io/api/cluster/v1alpha1"
|
||||
tenantv1beta1 "kubesphere.io/api/tenant/v1beta1"
|
||||
|
||||
applicationinstall "kubesphere.io/api/application/crdinstall"
|
||||
devopsinstall "kubesphere.io/api/devops/crdinstall"
|
||||
devopsv1alpha1 "kubesphere.io/api/devops/v1alpha1"
|
||||
networkinstall "kubesphere.io/api/network/crdinstall"
|
||||
networkv1alpha1 "kubesphere.io/api/network/v1alpha1"
|
||||
servicemeshinstall "kubesphere.io/api/servicemesh/crdinstall"
|
||||
servicemeshv1alpha2 "kubesphere.io/api/servicemesh/v1alpha2"
|
||||
tenantinstall "kubesphere.io/api/tenant/crdinstall"
|
||||
tenantv1alpha1 "kubesphere.io/api/tenant/v1alpha1"
|
||||
"kubesphere.io/kubesphere/pkg/version"
|
||||
"kubesphere.io/kubesphere/tools/lib"
|
||||
)
|
||||
|
||||
var output string
|
||||
@@ -63,57 +38,15 @@ func main() {
|
||||
Codecs = serializer.NewCodecFactory(Scheme)
|
||||
)
|
||||
|
||||
servicemeshinstall.Install(Scheme)
|
||||
tenantinstall.Install(Scheme)
|
||||
networkinstall.Install(Scheme)
|
||||
devopsinstall.Install(Scheme)
|
||||
applicationinstall.Install(Scheme)
|
||||
|
||||
urlruntime.Must(clusterv1alpha1.AddToScheme(Scheme))
|
||||
urlruntime.Must(tenantv1beta1.AddToScheme(Scheme))
|
||||
urlruntime.Must(Scheme.SetVersionPriority(clusterv1alpha1.SchemeGroupVersion))
|
||||
|
||||
mapper := meta.NewDefaultRESTMapper(nil)
|
||||
|
||||
mapper.AddSpecific(servicemeshv1alpha2.SchemeGroupVersion.WithKind(servicemeshv1alpha2.ResourceKindServicePolicy),
|
||||
servicemeshv1alpha2.SchemeGroupVersion.WithResource(servicemeshv1alpha2.ResourcePluralServicePolicy),
|
||||
servicemeshv1alpha2.SchemeGroupVersion.WithResource(servicemeshv1alpha2.ResourceSingularServicePolicy), meta.RESTScopeRoot)
|
||||
|
||||
mapper.AddSpecific(servicemeshv1alpha2.SchemeGroupVersion.WithKind(servicemeshv1alpha2.ResourceKindStrategy),
|
||||
servicemeshv1alpha2.SchemeGroupVersion.WithResource(servicemeshv1alpha2.ResourcePluralStrategy),
|
||||
servicemeshv1alpha2.SchemeGroupVersion.WithResource(servicemeshv1alpha2.ResourceSingularStrategy), meta.RESTScopeRoot)
|
||||
|
||||
mapper.AddSpecific(tenantv1alpha1.SchemeGroupVersion.WithKind(tenantv1alpha1.ResourceKindWorkspace),
|
||||
tenantv1alpha1.SchemeGroupVersion.WithResource(tenantv1alpha1.ResourcePluralWorkspace),
|
||||
tenantv1alpha1.SchemeGroupVersion.WithResource(tenantv1alpha1.ResourceSingularWorkspace), meta.RESTScopeRoot)
|
||||
|
||||
mapper.AddSpecific(devopsv1alpha1.SchemeGroupVersion.WithKind(devopsv1alpha1.ResourceKindS2iBuilder),
|
||||
devopsv1alpha1.SchemeGroupVersion.WithResource(devopsv1alpha1.ResourcePluralS2iBuilder),
|
||||
devopsv1alpha1.SchemeGroupVersion.WithResource(devopsv1alpha1.ResourceSingularS2iBuilder), meta.RESTScopeRoot)
|
||||
|
||||
mapper.AddSpecific(devopsv1alpha1.SchemeGroupVersion.WithKind(devopsv1alpha1.ResourceKindS2iBuilderTemplate),
|
||||
devopsv1alpha1.SchemeGroupVersion.WithResource(devopsv1alpha1.ResourcePluralS2iBuilderTemplate),
|
||||
devopsv1alpha1.SchemeGroupVersion.WithResource(devopsv1alpha1.ResourceSingularS2iBuilderTemplate), meta.RESTScopeRoot)
|
||||
|
||||
mapper.AddSpecific(devopsv1alpha1.SchemeGroupVersion.WithKind(devopsv1alpha1.ResourceKindS2iRun),
|
||||
devopsv1alpha1.SchemeGroupVersion.WithResource(devopsv1alpha1.ResourcePluralS2iRun),
|
||||
devopsv1alpha1.SchemeGroupVersion.WithResource(devopsv1alpha1.ResourceSingularS2iRun), meta.RESTScopeRoot)
|
||||
mapper.AddSpecific(devopsv1alpha1.SchemeGroupVersion.WithKind(devopsv1alpha1.ResourceKindS2iBinary),
|
||||
devopsv1alpha1.SchemeGroupVersion.WithResource(devopsv1alpha1.ResourceSingularS2iBinary),
|
||||
devopsv1alpha1.SchemeGroupVersion.WithResource(devopsv1alpha1.ResourcePluralS2iBinary), meta.RESTScopeRoot)
|
||||
|
||||
mapper.AddSpecific(networkv1alpha1.SchemeGroupVersion.WithKind(networkv1alpha1.ResourceKindNamespaceNetworkPolicy),
|
||||
networkv1alpha1.SchemeGroupVersion.WithResource(networkv1alpha1.ResourcePluralNamespaceNetworkPolicy),
|
||||
networkv1alpha1.SchemeGroupVersion.WithResource(networkv1alpha1.ResourceSingularNamespaceNetworkPolicy), meta.RESTScopeRoot)
|
||||
mapper.AddSpecific(networkv1alpha1.SchemeGroupVersion.WithKind(networkv1alpha1.ResourceKindIPPool),
|
||||
networkv1alpha1.SchemeGroupVersion.WithResource(networkv1alpha1.ResourcePluralIPPool),
|
||||
networkv1alpha1.SchemeGroupVersion.WithResource(networkv1alpha1.ResourceSingularIPPool), meta.RESTScopeRoot)
|
||||
|
||||
mapper.AddSpecific(devopsv1alpha3.SchemeGroupVersion.WithKind(devopsv1alpha3.ResourceKindDevOpsProject),
|
||||
devopsv1alpha3.SchemeGroupVersion.WithResource(devopsv1alpha3.ResourcePluralDevOpsProject),
|
||||
devopsv1alpha3.SchemeGroupVersion.WithResource(devopsv1alpha3.ResourceSingularDevOpsProject), meta.RESTScopeRoot)
|
||||
mapper.AddSpecific(devopsv1alpha3.SchemeGroupVersion.WithKind(devopsv1alpha3.ResourceKindPipeline),
|
||||
devopsv1alpha3.SchemeGroupVersion.WithResource(devopsv1alpha3.ResourcePluralPipeline),
|
||||
devopsv1alpha3.SchemeGroupVersion.WithResource(devopsv1alpha3.ResourceSingularPipeline), meta.RESTScopeRoot)
|
||||
mapper.AddSpecific(tenantv1beta1.SchemeGroupVersion.WithKind(tenantv1beta1.ResourceKindWorkspace),
|
||||
tenantv1beta1.SchemeGroupVersion.WithResource(tenantv1beta1.ResourcePluralWorkspace),
|
||||
tenantv1beta1.SchemeGroupVersion.WithResource(tenantv1beta1.ResourceSingularWorkspace), meta.RESTScopeRoot)
|
||||
|
||||
mapper.AddSpecific(clusterv1alpha1.SchemeGroupVersion.WithKind(clusterv1alpha1.ResourceKindCluster),
|
||||
clusterv1alpha1.SchemeGroupVersion.WithResource(clusterv1alpha1.ResourcesPluralCluster),
|
||||
@@ -123,26 +56,6 @@ func main() {
|
||||
clusterv1alpha1.SchemeGroupVersion.WithResource(clusterv1alpha1.ResourcesPluralCluster),
|
||||
clusterv1alpha1.SchemeGroupVersion.WithResource(clusterv1alpha1.ResourcesSingularCluster), meta.RESTScopeRoot)
|
||||
|
||||
mapper.AddSpecific(applicationv1alpha1.SchemeGroupVersion.WithKind(applicationv1alpha1.ResourceKindHelmApplication),
|
||||
applicationv1alpha1.SchemeGroupVersion.WithResource(applicationv1alpha1.ResourcePluralHelmApplication),
|
||||
applicationv1alpha1.SchemeGroupVersion.WithResource(applicationv1alpha1.ResourceSingularHelmApplication), meta.RESTScopeRoot)
|
||||
|
||||
mapper.AddSpecific(applicationv1alpha1.SchemeGroupVersion.WithKind(applicationv1alpha1.ResourceKindHelmApplicationVersion),
|
||||
applicationv1alpha1.SchemeGroupVersion.WithResource(applicationv1alpha1.ResourcePluralHelmApplicationVersion),
|
||||
applicationv1alpha1.SchemeGroupVersion.WithResource(applicationv1alpha1.ResourceSingularHelmApplicationVersion), meta.RESTScopeRoot)
|
||||
|
||||
mapper.AddSpecific(applicationv1alpha1.SchemeGroupVersion.WithKind(applicationv1alpha1.ResourceKindHelmRelease),
|
||||
applicationv1alpha1.SchemeGroupVersion.WithResource(applicationv1alpha1.ResourcePluralHelmRelease),
|
||||
applicationv1alpha1.SchemeGroupVersion.WithResource(applicationv1alpha1.ResourceSingularHelmRelease), meta.RESTScopeRoot)
|
||||
|
||||
mapper.AddSpecific(applicationv1alpha1.SchemeGroupVersion.WithKind(applicationv1alpha1.ResourceKindHelmRepo),
|
||||
applicationv1alpha1.SchemeGroupVersion.WithResource(applicationv1alpha1.ResourcePluralHelmRepo),
|
||||
applicationv1alpha1.SchemeGroupVersion.WithResource(applicationv1alpha1.ResourceSingularHelmRepo), meta.RESTScopeRoot)
|
||||
|
||||
mapper.AddSpecific(applicationv1alpha1.SchemeGroupVersion.WithKind(applicationv1alpha1.ResourceKindHelmCategory),
|
||||
applicationv1alpha1.SchemeGroupVersion.WithResource(applicationv1alpha1.ResourcePluralHelmCategory),
|
||||
applicationv1alpha1.SchemeGroupVersion.WithResource(applicationv1alpha1.ResourceSingularHelmCategory), meta.RESTScopeRoot)
|
||||
|
||||
spec, err := lib.RenderOpenAPISpec(lib.Config{
|
||||
Scheme: Scheme,
|
||||
Codecs: Codecs,
|
||||
@@ -160,28 +73,14 @@ func main() {
|
||||
},
|
||||
},
|
||||
OpenAPIDefinitions: []common.GetOpenAPIDefinitions{
|
||||
servicemeshv1alpha2.GetOpenAPIDefinitions,
|
||||
tenantv1alpha1.GetOpenAPIDefinitions,
|
||||
networkv1alpha1.GetOpenAPIDefinitions,
|
||||
devopsv1alpha1.GetOpenAPIDefinitions,
|
||||
devopsv1alpha3.GetOpenAPIDefinitions,
|
||||
tenantv1beta1.GetOpenAPIDefinitions,
|
||||
clusterv1alpha1.GetOpenAPIDefinitions,
|
||||
},
|
||||
Resources: []schema.GroupVersionResource{
|
||||
//TODO(runzexia) At present, the document generation requires the openapi structure of the go language,
|
||||
// but there is no +k8s:openapi-gen=true in the repository of https://github.com/knative/pkg,
|
||||
// and the api document cannot be generated temporarily.
|
||||
//servicemeshv1alpha2.SchemeGroupVersion.WithResource(servicemeshv1alpha2.ResourcePluralStrategy),
|
||||
//servicemeshv1alpha2.SchemeGroupVersion.WithResource(servicemeshv1alpha2.ResourcePluralServicePolicy),
|
||||
tenantv1alpha1.SchemeGroupVersion.WithResource(tenantv1alpha1.ResourcePluralWorkspace),
|
||||
devopsv1alpha1.SchemeGroupVersion.WithResource(devopsv1alpha1.ResourcePluralS2iBinary),
|
||||
devopsv1alpha1.SchemeGroupVersion.WithResource(devopsv1alpha1.ResourcePluralS2iRun),
|
||||
devopsv1alpha1.SchemeGroupVersion.WithResource(devopsv1alpha1.ResourcePluralS2iBuilderTemplate),
|
||||
devopsv1alpha1.SchemeGroupVersion.WithResource(devopsv1alpha1.ResourcePluralS2iBuilder),
|
||||
networkv1alpha1.SchemeGroupVersion.WithResource(networkv1alpha1.ResourcePluralNamespaceNetworkPolicy),
|
||||
networkv1alpha1.SchemeGroupVersion.WithResource(networkv1alpha1.ResourcePluralIPPool),
|
||||
devopsv1alpha3.SchemeGroupVersion.WithResource(devopsv1alpha3.ResourcePluralDevOpsProject),
|
||||
devopsv1alpha3.SchemeGroupVersion.WithResource(devopsv1alpha3.ResourcePluralPipeline),
|
||||
tenantv1beta1.SchemeGroupVersion.WithResource(tenantv1beta1.ResourcePluralWorkspace),
|
||||
clusterv1alpha1.SchemeGroupVersion.WithResource(clusterv1alpha1.ResourcesPluralCluster),
|
||||
},
|
||||
Mapper: mapper,
|
||||
|
||||
@@ -1,18 +1,7 @@
|
||||
/*
|
||||
Copyright 2019 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 main
|
||||
|
||||
@@ -22,6 +11,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
restfulspec "github.com/emicklei/go-restful-openapi/v2"
|
||||
"github.com/go-openapi/loads"
|
||||
@@ -29,34 +19,27 @@ import (
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/validate"
|
||||
"github.com/pkg/errors"
|
||||
promfake "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned/fake"
|
||||
urlruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/api"
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/rest"
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
|
||||
"kubesphere.io/kubesphere/pkg/client/clientset/versioned/fake"
|
||||
"kubesphere.io/kubesphere/pkg/constants"
|
||||
"kubesphere.io/kubesphere/pkg/informers"
|
||||
alertingv2alpha1 "kubesphere.io/kubesphere/pkg/kapis/alerting/v2alpha1"
|
||||
appv2 "kubesphere.io/kubesphere/pkg/kapis/application/v2"
|
||||
clusterkapisv1alpha1 "kubesphere.io/kubesphere/pkg/kapis/cluster/v1alpha1"
|
||||
kapisdevops "kubesphere.io/kubesphere/pkg/kapis/devops"
|
||||
iamv1alpha2 "kubesphere.io/kubesphere/pkg/kapis/iam/v1alpha2"
|
||||
monitoringv1alpha3 "kubesphere.io/kubesphere/pkg/kapis/monitoring/v1alpha3"
|
||||
networkv1alpha2 "kubesphere.io/kubesphere/pkg/kapis/network/v1alpha2"
|
||||
configv1alpha2 "kubesphere.io/kubesphere/pkg/kapis/config/v1alpha2"
|
||||
gatewayv1alpha2 "kubesphere.io/kubesphere/pkg/kapis/gateway/v1alpha2"
|
||||
iamv1beta1 "kubesphere.io/kubesphere/pkg/kapis/iam/v1beta1"
|
||||
"kubesphere.io/kubesphere/pkg/kapis/oauth"
|
||||
openpitrixv1 "kubesphere.io/kubesphere/pkg/kapis/openpitrix/v1"
|
||||
openpitrixv2 "kubesphere.io/kubesphere/pkg/kapis/openpitrix/v2alpha1"
|
||||
operationsv1alpha2 "kubesphere.io/kubesphere/pkg/kapis/operations/v1alpha2"
|
||||
packagev1alpha1 "kubesphere.io/kubesphere/pkg/kapis/package/v1alpha1"
|
||||
resourcesv1alpha2 "kubesphere.io/kubesphere/pkg/kapis/resources/v1alpha2"
|
||||
resourcesv1alpha3 "kubesphere.io/kubesphere/pkg/kapis/resources/v1alpha3"
|
||||
metricsv1alpha2 "kubesphere.io/kubesphere/pkg/kapis/servicemesh/metrics/v1alpha2"
|
||||
tenantv1alpha2 "kubesphere.io/kubesphere/pkg/kapis/tenant/v1alpha2"
|
||||
"kubesphere.io/kubesphere/pkg/kapis/static"
|
||||
tenantv1alpha3 "kubesphere.io/kubesphere/pkg/kapis/tenant/v1alpha3"
|
||||
tenantv1beta1 "kubesphere.io/kubesphere/pkg/kapis/tenant/v1beta1"
|
||||
terminalv1alpha2 "kubesphere.io/kubesphere/pkg/kapis/terminal/v1alpha2"
|
||||
"kubesphere.io/kubesphere/pkg/models/iam/group"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/alerting"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
|
||||
"kubesphere.io/kubesphere/pkg/version"
|
||||
"kubesphere.io/kubesphere/pkg/kapis/version"
|
||||
)
|
||||
|
||||
var output string
|
||||
@@ -67,23 +50,19 @@ func init() {
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
swaggerSpec := generateSwaggerJson()
|
||||
|
||||
err := validateSpec(swaggerSpec)
|
||||
if err != nil {
|
||||
if err := validateSpec(generateSwaggerJson()); err != nil {
|
||||
klog.Warningf("Swagger specification has errors")
|
||||
}
|
||||
}
|
||||
|
||||
func validateSpec(apiSpec []byte) error {
|
||||
|
||||
swaggerDoc, err := loads.Analyzed(apiSpec, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Attempts to report about all errors
|
||||
validate.SetContinueOnErrors(true)
|
||||
validate.SetContinueOnErrors(false)
|
||||
|
||||
v := validate.NewSpecValidator(swaggerDoc.Schema(), strfmt.Default)
|
||||
result, _ := v.Validate(swaggerDoc)
|
||||
@@ -108,187 +87,128 @@ func validateSpec(apiSpec []byte) error {
|
||||
}
|
||||
|
||||
func generateSwaggerJson() []byte {
|
||||
|
||||
container := runtime.Container
|
||||
clientsets := k8s.NewNullClient()
|
||||
|
||||
informerFactory := informers.NewNullInformerFactory()
|
||||
handlers := []rest.Handler{
|
||||
version.NewFakeHandler(),
|
||||
oauth.FakeHandler(),
|
||||
clusterkapisv1alpha1.NewFakeHandler(),
|
||||
iamv1beta1.NewFakeHandler(),
|
||||
operationsv1alpha2.NewFakeHandler(),
|
||||
packagev1alpha1.NewFakeHandler(),
|
||||
gatewayv1alpha2.NewFakeHandler(),
|
||||
configv1alpha2.NewFakeHandler(),
|
||||
terminalv1alpha2.NewFakeHandler(),
|
||||
resourcesv1alpha2.NewFakeHandler(),
|
||||
resourcesv1alpha3.NewFakeHandler(),
|
||||
tenantv1beta1.NewFakeHandler(),
|
||||
tenantv1alpha3.NewFakeHandler(),
|
||||
appv2.NewFakeHandler(),
|
||||
static.NewFakeHandler(),
|
||||
}
|
||||
|
||||
urlruntime.Must(oauth.AddToContainer(container, nil, nil, nil, nil, nil, nil))
|
||||
urlruntime.Must(clusterkapisv1alpha1.AddToContainer(container, clientsets.KubeSphere(), informerFactory.KubernetesSharedInformerFactory(),
|
||||
informerFactory.KubeSphereSharedInformerFactory(), "", "", ""))
|
||||
urlruntime.Must(kapisdevops.AddToContainer(container, ""))
|
||||
urlruntime.Must(iamv1alpha2.AddToContainer(container, nil, nil, group.New(informerFactory, clientsets.KubeSphere(), clientsets.Kubernetes()), nil))
|
||||
urlruntime.Must(monitoringv1alpha3.AddToContainer(container, clientsets.Kubernetes(), nil, nil, informerFactory, nil, nil))
|
||||
urlruntime.Must(openpitrixv1.AddToContainer(container, informerFactory, fake.NewSimpleClientset(), nil, nil))
|
||||
urlruntime.Must(openpitrixv2.AddToContainer(container, informerFactory, fake.NewSimpleClientset(), nil))
|
||||
urlruntime.Must(operationsv1alpha2.AddToContainer(container, clientsets.Kubernetes()))
|
||||
urlruntime.Must(resourcesv1alpha2.AddToContainer(container, clientsets.Kubernetes(), informerFactory, ""))
|
||||
urlruntime.Must(resourcesv1alpha3.AddToContainer(container, informerFactory, nil))
|
||||
urlruntime.Must(tenantv1alpha2.AddToContainer(container, informerFactory, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil))
|
||||
urlruntime.Must(tenantv1alpha3.AddToContainer(container, informerFactory, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil))
|
||||
urlruntime.Must(terminalv1alpha2.AddToContainer(container, clientsets.Kubernetes(), nil, nil, nil))
|
||||
urlruntime.Must(metricsv1alpha2.AddToContainer(nil, container, clientsets.Kubernetes(), nil))
|
||||
urlruntime.Must(networkv1alpha2.AddToContainer(container, ""))
|
||||
alertingOptions := &alerting.Options{}
|
||||
alertingClient, _ := alerting.NewRuleClient(alertingOptions)
|
||||
urlruntime.Must(alertingv2alpha1.AddToContainer(container, informerFactory, promfake.NewSimpleClientset(), alertingClient, alertingOptions))
|
||||
for _, handler := range handlers {
|
||||
urlruntime.Must(handler.AddToContainer(container))
|
||||
}
|
||||
|
||||
config := restfulspec.Config{
|
||||
WebServices: container.RegisteredWebServices(),
|
||||
PostBuildSwaggerObjectHandler: enrichSwaggerObject}
|
||||
PostBuildSwaggerObjectHandler: enrichSwaggerObject,
|
||||
}
|
||||
|
||||
swagger := restfulspec.BuildSwagger(config)
|
||||
swagger.Info.Extensions = make(spec.Extensions)
|
||||
swagger.Info.Extensions.Add("x-tagGroups", []struct {
|
||||
Name string `json:"name"`
|
||||
Tags []string `json:"tags"`
|
||||
}{
|
||||
{
|
||||
Name: "Authentication",
|
||||
Tags: []string{constants.AuthenticationTag},
|
||||
},
|
||||
{
|
||||
Name: "Identity Management",
|
||||
Tags: []string{
|
||||
constants.UserTag,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Access Management",
|
||||
Tags: []string{
|
||||
constants.ClusterMemberTag,
|
||||
constants.WorkspaceMemberTag,
|
||||
constants.DevOpsProjectMemberTag,
|
||||
constants.NamespaceMemberTag,
|
||||
constants.GlobalRoleTag,
|
||||
constants.ClusterRoleTag,
|
||||
constants.WorkspaceRoleTag,
|
||||
constants.DevOpsProjectRoleTag,
|
||||
constants.NamespaceRoleTag,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Multi-tenancy",
|
||||
Tags: []string{
|
||||
constants.WorkspaceTag,
|
||||
constants.NamespaceTag,
|
||||
constants.UserResourceTag,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Multi-cluster",
|
||||
Tags: []string{
|
||||
constants.MultiClusterTag,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Resources",
|
||||
Tags: []string{
|
||||
constants.ClusterResourcesTag,
|
||||
constants.NamespaceResourcesTag,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "App Store",
|
||||
Tags: []string{
|
||||
constants.OpenpitrixAppInstanceTag,
|
||||
constants.OpenpitrixAppTemplateTag,
|
||||
constants.OpenpitrixCategoryTag,
|
||||
constants.OpenpitrixAttachmentTag,
|
||||
constants.OpenpitrixRepositoryTag,
|
||||
constants.OpenpitrixManagementTag,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Other",
|
||||
Tags: []string{
|
||||
constants.RegistryTag,
|
||||
constants.GitTag,
|
||||
constants.ToolboxTag,
|
||||
constants.TerminalTag,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "DevOps",
|
||||
Tags: []string{
|
||||
constants.DevOpsProjectTag,
|
||||
constants.DevOpsCredentialTag,
|
||||
constants.DevOpsPipelineTag,
|
||||
constants.DevOpsProjectMemberTag,
|
||||
constants.DevOpsWebhookTag,
|
||||
constants.DevOpsJenkinsfileTag,
|
||||
constants.DevOpsScmTag,
|
||||
constants.DevOpsJenkinsTag,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Monitoring",
|
||||
Tags: []string{
|
||||
constants.ClusterMetricsTag,
|
||||
constants.NodeMetricsTag,
|
||||
constants.NamespaceMetricsTag,
|
||||
constants.WorkloadMetricsTag,
|
||||
constants.PodMetricsTag,
|
||||
constants.ContainerMetricsTag,
|
||||
constants.WorkspaceMetricsTag,
|
||||
constants.ComponentMetricsTag,
|
||||
constants.ComponentStatusTag,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Logging",
|
||||
Tags: []string{constants.LogQueryTag},
|
||||
},
|
||||
{
|
||||
Name: "Events",
|
||||
Tags: []string{constants.EventsQueryTag},
|
||||
},
|
||||
{
|
||||
Name: "Auditing",
|
||||
Tags: []string{constants.AuditingQueryTag},
|
||||
},
|
||||
{
|
||||
Name: "Network",
|
||||
Tags: []string{constants.NetworkTopologyTag},
|
||||
},
|
||||
})
|
||||
|
||||
data, _ := json.MarshalIndent(swagger, "", " ")
|
||||
err := os.WriteFile(output, data, 0644)
|
||||
if err != nil {
|
||||
data, _ := json.MarshalIndent(restfulspec.BuildSwagger(config), "", " ")
|
||||
if err := os.WriteFile(output, data, 0644); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("successfully written to %s", output)
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
func enrichSwaggerObject(swo *spec.Swagger) {
|
||||
swo.Info = &spec.Info{
|
||||
InfoProps: spec.InfoProps{
|
||||
Title: "KubeSphere",
|
||||
Title: "KS API",
|
||||
Description: "KubeSphere OpenAPI",
|
||||
Version: version.Get().GitVersion,
|
||||
Version: gitVersion(),
|
||||
Contact: &spec.ContactInfo{
|
||||
ContactInfoProps: spec.ContactInfoProps{
|
||||
Name: "KubeSphere",
|
||||
URL: "https://kubesphere.io/",
|
||||
Email: "kubesphere@yunify.com",
|
||||
},
|
||||
},
|
||||
License: &spec.License{
|
||||
LicenseProps: spec.LicenseProps{
|
||||
Name: "Apache 2.0",
|
||||
URL: "https://www.apache.org/licenses/LICENSE-2.0.html",
|
||||
URL: "https://kubesphere.com.cn",
|
||||
Email: "support@kubesphere.cloud",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// setup security definitions
|
||||
swo.SecurityDefinitions = map[string]*spec.SecurityScheme{
|
||||
"jwt": spec.APIKeyAuth("Authorization", "header"),
|
||||
"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,
|
||||
},
|
||||
},
|
||||
}
|
||||
swo.Security = []map[string][]string{{"jwt": []string{}}}
|
||||
}
|
||||
|
||||
func gitVersion() string {
|
||||
out, err := exec.Command("sh", "-c", "git tag --sort=committerdate | tail -1 | tr -d '\n'").Output()
|
||||
if err != nil {
|
||||
log.Printf("failed to get git version: %s", err)
|
||||
return "v0.0.0"
|
||||
}
|
||||
return string(out)
|
||||
}
|
||||
|
||||
@@ -1,18 +1,7 @@
|
||||
/*
|
||||
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 lib
|
||||
|
||||
@@ -31,6 +20,7 @@ import (
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
genericapiserver "k8s.io/apiserver/pkg/server"
|
||||
genericoptions "k8s.io/apiserver/pkg/server/options"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
"k8s.io/kube-openapi/pkg/common/restfuladapter"
|
||||
|
||||
"k8s.io/kube-openapi/pkg/builder"
|
||||
@@ -78,7 +68,7 @@ func RenderOpenAPISpec(cfg Config) (string, error) {
|
||||
recommendedOptions.Etcd = nil
|
||||
recommendedOptions.Authentication = nil
|
||||
recommendedOptions.Authorization = nil
|
||||
recommendedOptions.CoreAPI = nil
|
||||
recommendedOptions.CoreAPI.CoreAPIKubeconfigPath = clientcmd.NewDefaultPathOptions().GetDefaultFilename()
|
||||
recommendedOptions.Admission = nil
|
||||
|
||||
// TODO have a "real" external address
|
||||
@@ -94,6 +84,8 @@ func RenderOpenAPISpec(cfg Config) (string, error) {
|
||||
}
|
||||
serverConfig.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(cfg.GetOpenAPIDefinitions, apiopenapi.NewDefinitionNamer(cfg.Scheme))
|
||||
serverConfig.OpenAPIConfig.Info.InfoProps = cfg.Info
|
||||
serverConfig.OpenAPIV3Config = genericapiserver.DefaultOpenAPIV3Config(cfg.GetOpenAPIDefinitions, apiopenapi.NewDefinitionNamer(cfg.Scheme))
|
||||
serverConfig.OpenAPIV3Config.Info.InfoProps = cfg.Info
|
||||
|
||||
genericServer, err := serverConfig.Complete().New("stash-server", genericapiserver.NewEmptyDelegate()) // completion is done in Complete, no need for a second time
|
||||
if err != nil {
|
||||
@@ -130,9 +122,10 @@ func RenderOpenAPISpec(cfg Config) (string, error) {
|
||||
}
|
||||
|
||||
resmap[gvr.Resource] = ResourceInfo{
|
||||
gvk: gvk,
|
||||
obj: obj,
|
||||
list: list,
|
||||
gvk: gvk,
|
||||
obj: obj,
|
||||
list: list,
|
||||
singularName: gvr.Resource,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,7 @@
|
||||
/*
|
||||
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 lib
|
||||
|
||||
@@ -28,9 +17,10 @@ import (
|
||||
)
|
||||
|
||||
type ResourceInfo struct {
|
||||
gvk schema.GroupVersionKind
|
||||
obj runtime.Object
|
||||
list runtime.Object
|
||||
gvk schema.GroupVersionKind
|
||||
obj runtime.Object
|
||||
list runtime.Object
|
||||
singularName string
|
||||
}
|
||||
|
||||
type StatusResourceInfo struct {
|
||||
@@ -120,6 +110,10 @@ func (r *StandardStorage) NamespaceScoped() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *StandardStorage) GetSingularName() string {
|
||||
return r.cfg.singularName
|
||||
}
|
||||
|
||||
func (r *StatusStandardStorage) GroupVersionKind(containingGV schema.GroupVersion) schema.GroupVersionKind {
|
||||
return r.cfg.gvk
|
||||
}
|
||||
|
||||
@@ -1,22 +1,6 @@
|
||||
//go:build tools
|
||||
// +build tools
|
||||
|
||||
/*
|
||||
Copyright 2019 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.
|
||||
*/
|
||||
|
||||
package tools
|
||||
|
||||
import (
|
||||
|
||||
Reference in New Issue
Block a user