fix: application api

Signed-off-by: hongming <talonwan@yunify.com>
This commit is contained in:
hongming
2019-05-14 16:03:10 +08:00
committed by zryfish
parent 4c111533b1
commit 4ae7d3256e
11 changed files with 267 additions and 209 deletions

View File

@@ -1,33 +0,0 @@
/*
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 install
import (
"github.com/emicklei/go-restful"
urlruntime "k8s.io/apimachinery/pkg/util/runtime"
metrcisv1alpha2 "kubesphere.io/kubesphere/pkg/apis/metrics/v1alpha2"
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
)
func init() {
Install(runtime.Container)
}
func Install(container *restful.Container) {
urlruntime.Must(metrcisv1alpha2.AddToContainer(container))
}

View File

@@ -1,58 +0,0 @@
/*
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 v1alpha2
import (
"github.com/emicklei/go-restful"
"github.com/emicklei/go-restful-openapi"
"k8s.io/apimachinery/pkg/runtime/schema"
"kubesphere.io/kubesphere/pkg/apiserver/metrics"
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
)
const GroupName = "metrics.kubesphere.io"
var GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"}
var (
WebServiceBuilder = runtime.NewContainerBuilder(addWebService)
AddToContainer = WebServiceBuilder.AddToContainer
)
func addWebService(c *restful.Container) error {
webservice := runtime.NewWebService(GroupVersion)
tags := []string{"metrics"}
webservice.Route(webservice.GET("/storageclasses/{storageclass}").
To(metrics.GetScMetrics).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("").
Param(webservice.PathParameter("storageclass", "storageclass's name")).
Writes(metrics.ScMetricsItem{}))
webservice.Route(webservice.GET("/storageclasses").
To(metrics.GetScMetricsList).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("").
Writes([]metrics.ScMetricsItem{}))
c.Add(webservice)
return nil
}

View File

@@ -34,8 +34,10 @@ import (
"kubesphere.io/kubesphere/pkg/apiserver/workloadstatuses"
"kubesphere.io/kubesphere/pkg/errors"
"kubesphere.io/kubesphere/pkg/models"
"kubesphere.io/kubesphere/pkg/models/applications"
gitmodel "kubesphere.io/kubesphere/pkg/models/git"
"kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
)
const GroupName = "resources.kubesphere.io"
@@ -88,7 +90,7 @@ func addWebService(c *restful.Container) error {
tags = []string{"Applications"}
webservice.Route(webservice.GET("/applications").
To(resources.ApplicationHandler).
To(resources.ListApplication).
Writes(models.PageableResponse{}).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("List applications in cluster").
@@ -104,7 +106,7 @@ func addWebService(c *restful.Container) error {
DefaultValue("limit=10,page=1")))
webservice.Route(webservice.GET("/namespaces/{namespace}/applications").
To(resources.NamespacedApplicationHandler).
To(resources.ListNamespacedApplication).
Writes(models.PageableResponse{}).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("List applications").
@@ -118,11 +120,26 @@ func addWebService(c *restful.Container) error {
DataFormat("limit=%d,page=%d").
DefaultValue("limit=10,page=1")))
webservice.Route(webservice.GET("/storageclasses/{storageclass}/persistentvolumeclaims").
To(resources.GetPvcListBySc).
Doc("query persistent volume claims by storageclass").
Param(webservice.PathParameter("username", "username")).
Metadata(restfulspec.KeyOpenAPITags, tags))
webservice.Route(webservice.GET("/namespaces/{namespace}/applications/{cluster_id}").
To(resources.DescribeApplication).
Writes(applications.Application{}).
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Describe application").
Param(webservice.PathParameter("namespace", "namespace name")).
Param(webservice.PathParameter("cluster_id", "openpitrix cluster id")))
webservice.Route(webservice.POST("/namespaces/{namespace}/applications").
To(resources.DeployApplication).
Doc("Deploy application").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(openpitrix.CreateClusterRequest{}).
Param(webservice.PathParameter("namespace", "namespace name")))
webservice.Route(webservice.DELETE("/namespaces/{namespace}/applications/{cluster_id}").
To(resources.DeleteApplication).
Doc("Delete application").
Metadata(restfulspec.KeyOpenAPITags, tags).
Param(webservice.PathParameter("namespace", "namespace name")))
tags = []string{"User resources"}