register.go 5.1 KB
Newer Older
Z
zryfish 已提交
1
/*
H
hongming 已提交
2
Copyright 2019 The KubeSphere Authors.
Z
zryfish 已提交
3

H
hongming 已提交
4 5 6
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
Z
zryfish 已提交
7

H
hongming 已提交
8
    http://www.apache.org/licenses/LICENSE-2.0
Z
zryfish 已提交
9

H
hongming 已提交
10 11 12 13 14
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.
Z
zryfish 已提交
15
*/
H
hongming 已提交
16

Z
zryfish 已提交
17 18 19 20 21 22 23 24 25 26
package v1alpha3

import (
	"github.com/emicklei/go-restful"
	"github.com/emicklei/go-restful-openapi"
	"k8s.io/apimachinery/pkg/runtime/schema"
	"kubesphere.io/kubesphere/pkg/api"
	"kubesphere.io/kubesphere/pkg/api/resource/v1alpha2"
	"kubesphere.io/kubesphere/pkg/apiserver/query"
	"kubesphere.io/kubesphere/pkg/apiserver/runtime"
27
	"kubesphere.io/kubesphere/pkg/informers"
Z
zryfish 已提交
28 29 30 31 32 33
	"net/http"
)

const (
	GroupName = "resources.kubesphere.io"

Z
zryfish 已提交
34
	tagClusteredResource  = "Clustered Resource"
Z
zryfish 已提交
35 36 37 38 39 40
	tagComponentStatus    = "Component Status"
	tagNamespacedResource = "Namespaced Resource"

	ok = "OK"
)

Z
zryfish 已提交
41
var GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha3"}
Z
zryfish 已提交
42

43
func AddToContainer(c *restful.Container, informerFactory informers.InformerFactory) error {
Z
zryfish 已提交
44 45

	webservice := runtime.NewWebService(GroupVersion)
46
	handler := New(informerFactory)
Z
zryfish 已提交
47

H
hongming 已提交
48 49
	webservice.Route(webservice.GET("/{resources}").
		To(handler.handleListResources).
Z
zryfish 已提交
50
		Metadata(restfulspec.KeyOpenAPITags, []string{tagClusteredResource}).
H
update  
hongming 已提交
51 52
		Doc("Cluster level resources").
		Param(webservice.PathParameter("resources", "cluster level resource type, e.g. pods,jobs,configmaps,services.")).
H
hongming 已提交
53 54 55 56 57 58 59
		Param(webservice.QueryParameter(query.ParameterName, "name used to do filtering").Required(false)).
		Param(webservice.QueryParameter(query.ParameterPage, "page").Required(false).DataFormat("page=%d").DefaultValue("page=1")).
		Param(webservice.QueryParameter(query.ParameterLimit, "limit").Required(false)).
		Param(webservice.QueryParameter(query.ParameterAscending, "sort parameters, e.g. reverse=true").Required(false).DefaultValue("ascending=false")).
		Param(webservice.QueryParameter(query.ParameterOrderBy, "sort parameters, e.g. orderBy=createTime")).
		Returns(http.StatusOK, ok, api.ListResult{}))

Z
zryfish 已提交
60 61 62 63 64 65 66 67
	webservice.Route(webservice.GET("/{resources}/{name}").
		To(handler.handleGetResources).
		Metadata(restfulspec.KeyOpenAPITags, []string{tagClusteredResource}).
		Doc("Cluster level resource").
		Param(webservice.PathParameter("resources", "cluster level resource type, e.g. pods,jobs,configmaps,services.")).
		Param(webservice.PathParameter("name", "the name of the clustered resources")).
		Returns(http.StatusOK, api.StatusOK, nil))

Z
zryfish 已提交
68
	webservice.Route(webservice.GET("/namespaces/{namespace}/{resources}").
H
hongming 已提交
69
		To(handler.handleListResources).
Z
zryfish 已提交
70 71 72 73 74
		Metadata(restfulspec.KeyOpenAPITags, []string{tagNamespacedResource}).
		Doc("Namespace level resource query").
		Param(webservice.PathParameter("namespace", "the name of the project")).
		Param(webservice.PathParameter("resources", "namespace level resource type, e.g. pods,jobs,configmaps,services.")).
		Param(webservice.QueryParameter(query.ParameterName, "name used to do filtering").Required(false)).
H
hongming 已提交
75
		Param(webservice.QueryParameter(query.ParameterPage, "page").Required(false).DataFormat("page=%d").DefaultValue("page=1")).
Z
zryfish 已提交
76 77 78 79 80
		Param(webservice.QueryParameter(query.ParameterLimit, "limit").Required(false)).
		Param(webservice.QueryParameter(query.ParameterAscending, "sort parameters, e.g. reverse=true").Required(false).DefaultValue("ascending=false")).
		Param(webservice.QueryParameter(query.ParameterOrderBy, "sort parameters, e.g. orderBy=createTime")).
		Returns(http.StatusOK, ok, api.ListResult{}))

Z
zhangmin 已提交
81 82 83 84 85 86 87 88 89
	webservice.Route(webservice.GET("/namespaces/{namespace}/{resources}/{name}").
		To(handler.handleGetResources).
		Metadata(restfulspec.KeyOpenAPITags, []string{tagNamespacedResource}).
		Doc("Namespace level get resource query").
		Param(webservice.PathParameter("namespace", "the name of the project")).
		Param(webservice.PathParameter("resources", "namespace level resource type, e.g. pods,jobs,configmaps,services.")).
		Param(webservice.PathParameter("name", "the name of resource")).
		Returns(http.StatusOK, ok, api.ListResult{}))

Z
zryfish 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
	webservice.Route(webservice.GET("/components").
		To(handler.handleGetComponents).
		Metadata(restfulspec.KeyOpenAPITags, []string{tagComponentStatus}).
		Doc("List the system components.").
		Returns(http.StatusOK, ok, []v1alpha2.ComponentStatus{}))
	webservice.Route(webservice.GET("/components/{component}").
		To(handler.handleGetComponentStatus).
		Metadata(restfulspec.KeyOpenAPITags, []string{tagComponentStatus}).
		Doc("Describe the specified system component.").
		Param(webservice.PathParameter("component", "component name")).
		Returns(http.StatusOK, ok, v1alpha2.ComponentStatus{}))
	webservice.Route(webservice.GET("/componenthealth").
		To(handler.handleGetSystemHealthStatus).
		Metadata(restfulspec.KeyOpenAPITags, []string{tagComponentStatus}).
		Doc("Get the health status of system components.").
		Returns(http.StatusOK, ok, v1alpha2.HealthStatus{}))

	c.Add(webservice)

	return nil
}