Merge pull request #4880 from iawia002/workspace-detail-api

Add get workspace API
This commit is contained in:
KubeSphere CI Bot
2022-05-16 17:17:05 +08:00
committed by GitHub
10 changed files with 98 additions and 7 deletions

View File

@@ -13167,6 +13167,35 @@
}
}
},
"/kapis/tenant.kubesphere.io/v1alpha3/workspaces/{workspace}": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Workspace"
],
"summary": "Get workspace.",
"operationId": "GetWorkspace",
"parameters": [
{
"type": "string",
"description": "workspace name",
"name": "workspace",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "ok",
"schema": {
"$ref": "#/definitions/v1alpha1.Workspace"
}
}
}
}
},
"/kapis/tenant.kubesphere.io/v1alpha3/workspacetemplates": {
"get": {
"produces": [
@@ -14280,14 +14309,14 @@
},
"metering.OpenPitrixStatistic": {
"required": [
"memory_usage_wo_cache",
"net_bytes_transmitted",
"net_bytes_received",
"pvc_bytes_total",
"deployments",
"statefulsets",
"daemonsets",
"cpu_usage",
"memory_usage_wo_cache",
"net_bytes_transmitted",
"net_bytes_received"
"cpu_usage"
],
"properties": {
"cpu_usage": {
@@ -20810,6 +20839,27 @@
}
}
},
"v1alpha1.Workspace": {
"properties": {
"apiVersion": {
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
"type": "string"
},
"kind": {
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
"type": "string"
},
"metadata": {
"$ref": "#/definitions/v1.ObjectMeta"
},
"spec": {
"$ref": "#/definitions/v1alpha1.WorkspaceSpec"
},
"status": {
"$ref": "#/definitions/v1alpha1.WorkspaceStatus"
}
}
},
"v1alpha1.WorkspaceSpec": {
"properties": {
"manager": {
@@ -20820,6 +20870,7 @@
}
}
},
"v1alpha1.WorkspaceStatus": {},
"v1alpha2.APIResponse": {
"properties": {
"histogram": {
@@ -21337,8 +21388,8 @@
},
"v1alpha2.Node": {
"required": [
"id",
"labelMinor",
"id",
"label",
"rank",
"controls"
@@ -21448,10 +21499,10 @@
},
"v1alpha2.NodeSummary": {
"required": [
"rank",
"id",
"label",
"labelMinor"
"labelMinor",
"rank"
],
"properties": {
"adjacency": {

View File

@@ -20,6 +20,7 @@ import (
"fmt"
"github.com/emicklei/go-restful"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/kubernetes"
"k8s.io/klog"
@@ -78,3 +79,18 @@ func (h *tenantHandler) ListWorkspaces(req *restful.Request, resp *restful.Respo
resp.WriteEntity(result)
}
func (h *tenantHandler) GetWorkspace(request *restful.Request, response *restful.Response) {
workspace, err := h.tenant.GetWorkspace(request.PathParameter("workspace"))
if err != nil {
klog.Error(err)
if errors.IsNotFound(err) {
api.HandleNotFound(response, request, err)
return
}
api.HandleInternalError(response, request, err)
return
}
response.WriteEntity(workspace)
}

View File

@@ -23,6 +23,7 @@ import (
restfulspec "github.com/emicklei/go-restful-openapi"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"
tenantv1alpha1 "kubesphere.io/api/tenant/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/cache"
tenantv1alpha2 "kubesphere.io/api/tenant/v1alpha2"
@@ -115,6 +116,13 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, k8s
Doc("List all workspaces that belongs to the current user").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.WorkspaceTag}))
ws.Route(ws.GET("/workspaces/{workspace}").
To(handler.GetWorkspace).
Param(ws.PathParameter("workspace", "workspace name")).
Returns(http.StatusOK, api.StatusOK, tenantv1alpha1.Workspace{}).
Doc("Get workspace.").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.WorkspaceTag}))
c.Add(ws)
return nil
}

View File

@@ -72,6 +72,7 @@ const orphanFinalizer = "orphan.finalizers.kubesphere.io"
type Interface interface {
ListWorkspaces(user user.Info, queryParam *query.Query) (*api.ListResult, error)
GetWorkspace(workspace string) (*tenantv1alpha1.Workspace, error)
ListWorkspaceTemplates(user user.Info, query *query.Query) (*api.ListResult, error)
CreateWorkspaceTemplate(workspace *tenantv1alpha2.WorkspaceTemplate) (*tenantv1alpha2.WorkspaceTemplate, error)
DeleteWorkspaceTemplate(workspace string, opts metav1.DeleteOptions) error
@@ -196,6 +197,15 @@ func (t *tenantOperator) ListWorkspaces(user user.Info, queryParam *query.Query)
return result, nil
}
func (t *tenantOperator) GetWorkspace(workspace string) (*tenantv1alpha1.Workspace, error) {
obj, err := t.resourceGetter.Get(tenantv1alpha1.ResourcePluralWorkspace, "", workspace)
if err != nil {
klog.Error(err)
return nil, err
}
return obj.(*tenantv1alpha1.Workspace), nil
}
func (t *tenantOperator) ListWorkspaceTemplates(user user.Info, queryParam *query.Query) (*api.ListResult, error) {
listWS := authorizer.AttributesRecord{

View File

@@ -1,3 +1,4 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
/*

View File

@@ -1,3 +1,4 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
/*

View File

@@ -1,3 +1,4 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
/*

View File

@@ -1,3 +1,4 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
/*

View File

@@ -1,3 +1,4 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
/*

View File

@@ -1,3 +1,4 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
/*