refactor code structure (#1738)
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListResult struct {
|
||||
@@ -158,13 +156,3 @@ const (
|
||||
ResourceKindS2iBuilder = "s2ibuilders"
|
||||
ResourceKindApplication = "applications"
|
||||
)
|
||||
|
||||
func HandleInternalError(response *restful.Response, err error) {
|
||||
statusCode := http.StatusInternalServerError
|
||||
|
||||
response.WriteError(statusCode, err)
|
||||
}
|
||||
|
||||
func HandleBadRequest(response *restful.Response, err error) {
|
||||
|
||||
}
|
||||
|
||||
16
pkg/api/utils.go
Normal file
16
pkg/api/utils.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func HandleInternalError(response *restful.Response, err error) {
|
||||
statusCode := http.StatusInternalServerError
|
||||
|
||||
response.WriteError(statusCode, err)
|
||||
}
|
||||
|
||||
func HandleBadRequest(response *restful.Response, err error) {
|
||||
|
||||
}
|
||||
@@ -69,3 +69,10 @@ type FluentBitList struct {
|
||||
metav1.ListMeta `json:"metadata"`
|
||||
Items []FluentBit `json:"items"`
|
||||
}
|
||||
|
||||
|
||||
type FluentbitOutputsResult struct {
|
||||
Status int `json:"status" description:"response status"`
|
||||
Error string `json:"error,omitempty" description:"debug information"`
|
||||
Outputs []OutputPlugin `json:"outputs,omitempty" description:"array of fluent bit output plugins"`
|
||||
}
|
||||
1
pkg/apis/logging/v1alpha2/fluentbit_types_test.go
Normal file
1
pkg/apis/logging/v1alpha2/fluentbit_types_test.go
Normal file
@@ -0,0 +1 @@
|
||||
package v1alpha2
|
||||
1
pkg/apis/logging/v1alpha2/v1alpha2_suite_test.go
Normal file
1
pkg/apis/logging/v1alpha2/v1alpha2_suite_test.go
Normal file
@@ -0,0 +1 @@
|
||||
package v1alpha2
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/constants"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha2"
|
||||
"kubesphere.io/kubesphere/pkg/server/errors"
|
||||
"kubesphere.io/kubesphere/pkg/server/params"
|
||||
@@ -136,7 +136,7 @@ func DescribeApplication(req *restful.Request, resp *restful.Response) {
|
||||
|
||||
func CreateApplication(req *restful.Request, resp *restful.Response) {
|
||||
namespace := req.PathParameter("namespace")
|
||||
var createClusterRequest openpitrix.CreateClusterRequest
|
||||
var createClusterRequest types.CreateClusterRequest
|
||||
err := req.ReadEntity(&createClusterRequest)
|
||||
if err != nil {
|
||||
resp.WriteHeaderAndEntity(http.StatusBadRequest, errors.Wrap(err))
|
||||
@@ -159,7 +159,7 @@ func CreateApplication(req *restful.Request, resp *restful.Response) {
|
||||
}
|
||||
|
||||
func ModifyApplication(req *restful.Request, resp *restful.Response) {
|
||||
var modifyClusterAttributesRequest openpitrix.ModifyClusterAttributesRequest
|
||||
var modifyClusterAttributesRequest types.ModifyClusterAttributesRequest
|
||||
clusterId := req.PathParameter("application")
|
||||
namespaceName := req.PathParameter("namespace")
|
||||
err := req.ReadEntity(&modifyClusterAttributesRequest)
|
||||
|
||||
@@ -24,7 +24,8 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/constants"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/app"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"kubesphere.io/kubesphere/pkg/server/errors"
|
||||
"kubesphere.io/kubesphere/pkg/server/params"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client"
|
||||
@@ -37,7 +38,7 @@ func GetAppVersionPackage(req *restful.Request, resp *restful.Response) {
|
||||
appId := req.PathParameter("app")
|
||||
versionId := req.PathParameter("version")
|
||||
|
||||
result, err := openpitrix.GetAppVersionPackage(appId, versionId)
|
||||
result, err := app.GetAppVersionPackage(appId, versionId)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -54,7 +55,7 @@ func GetAppVersionPackage(req *restful.Request, resp *restful.Response) {
|
||||
}
|
||||
|
||||
func DoAppAction(req *restful.Request, resp *restful.Response) {
|
||||
var doActionRequest openpitrix.ActionRequest
|
||||
var doActionRequest types.ActionRequest
|
||||
err := req.ReadEntity(&doActionRequest)
|
||||
if err != nil {
|
||||
resp.WriteHeaderAndEntity(http.StatusBadRequest, errors.Wrap(err))
|
||||
@@ -63,7 +64,7 @@ func DoAppAction(req *restful.Request, resp *restful.Response) {
|
||||
|
||||
appId := req.PathParameter("app")
|
||||
|
||||
err = openpitrix.DoAppAction(appId, &doActionRequest)
|
||||
err = app.DoAppAction(appId, &doActionRequest)
|
||||
if status.Code(err) == codes.NotFound {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotFound, errors.Wrap(err))
|
||||
return
|
||||
@@ -84,7 +85,7 @@ func DoAppAction(req *restful.Request, resp *restful.Response) {
|
||||
}
|
||||
|
||||
func DoAppVersionAction(req *restful.Request, resp *restful.Response) {
|
||||
var doActionRequest openpitrix.ActionRequest
|
||||
var doActionRequest types.ActionRequest
|
||||
err := req.ReadEntity(&doActionRequest)
|
||||
if err != nil {
|
||||
resp.WriteHeaderAndEntity(http.StatusBadRequest, errors.Wrap(err))
|
||||
@@ -94,7 +95,7 @@ func DoAppVersionAction(req *restful.Request, resp *restful.Response) {
|
||||
|
||||
versionId := req.PathParameter("version")
|
||||
|
||||
err = openpitrix.DoAppVersionAction(versionId, &doActionRequest)
|
||||
err = app.DoAppVersionAction(versionId, &doActionRequest)
|
||||
if status.Code(err) == codes.NotFound {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotFound, errors.Wrap(err))
|
||||
return
|
||||
@@ -116,12 +117,12 @@ func DoAppVersionAction(req *restful.Request, resp *restful.Response) {
|
||||
|
||||
func GetAppVersionFiles(req *restful.Request, resp *restful.Response) {
|
||||
versionId := req.PathParameter("version")
|
||||
getAppVersionFilesRequest := &openpitrix.GetAppVersionFilesRequest{}
|
||||
getAppVersionFilesRequest := &types.GetAppVersionFilesRequest{}
|
||||
if f := req.QueryParameter("files"); f != "" {
|
||||
getAppVersionFilesRequest.Files = strings.Split(f, ",")
|
||||
}
|
||||
|
||||
result, err := openpitrix.GetAppVersionFiles(versionId, getAppVersionFilesRequest)
|
||||
result, err := app.GetAppVersionFiles(versionId, getAppVersionFilesRequest)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -162,7 +163,7 @@ func ListAppVersionAudits(req *restful.Request, resp *restful.Response) {
|
||||
conditions.Match["version"] = versionId
|
||||
}
|
||||
|
||||
result, err := openpitrix.ListAppVersionAudits(conditions, orderBy, reverse, limit, offset)
|
||||
result, err := app.ListAppVersionAudits(conditions, orderBy, reverse, limit, offset)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -192,7 +193,7 @@ func ListReviews(req *restful.Request, resp *restful.Response) {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := openpitrix.ListAppVersionReviews(conditions, orderBy, reverse, limit, offset)
|
||||
result, err := app.ListAppVersionReviews(conditions, orderBy, reverse, limit, offset)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -225,7 +226,7 @@ func ListAppVersions(req *restful.Request, resp *restful.Response) {
|
||||
}
|
||||
conditions.Match["app"] = appId
|
||||
|
||||
result, err := openpitrix.ListAppVersions(conditions, orderBy, reverse, limit, offset)
|
||||
result, err := app.ListAppVersions(conditions, orderBy, reverse, limit, offset)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -240,7 +241,7 @@ func ListAppVersions(req *restful.Request, resp *restful.Response) {
|
||||
|
||||
if statistics {
|
||||
for _, item := range result.Items {
|
||||
if version, ok := item.(*openpitrix.AppVersion); ok {
|
||||
if version, ok := item.(*types.AppVersion); ok {
|
||||
statisticsResult, err := openpitrix.ListApplications(¶ms.Conditions{Match: map[string]string{"app_id": version.AppId, "version_id": version.VersionId}}, 0, 0, "", false)
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
@@ -271,7 +272,7 @@ func ListApps(req *restful.Request, resp *restful.Response) {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := openpitrix.ListApps(conditions, orderBy, reverse, limit, offset)
|
||||
result, err := app.ListApps(conditions, orderBy, reverse, limit, offset)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -286,7 +287,7 @@ func ListApps(req *restful.Request, resp *restful.Response) {
|
||||
|
||||
if statistics {
|
||||
for _, item := range result.Items {
|
||||
if app, ok := item.(*openpitrix.App); ok {
|
||||
if app, ok := item.(*types.App); ok {
|
||||
status := "active|used|enabled|stopped|pending|creating|upgrading|updating|rollbacking|stopping|starting|recovering|resizing|scaling|deleting"
|
||||
statisticsResult, err := openpitrix.ListApplications(¶ms.Conditions{Match: map[string]string{"app_id": app.AppId, "status": status}}, 0, 0, "", false)
|
||||
if err != nil {
|
||||
@@ -304,7 +305,7 @@ func ListApps(req *restful.Request, resp *restful.Response) {
|
||||
|
||||
func ModifyApp(req *restful.Request, resp *restful.Response) {
|
||||
|
||||
var patchAppRequest openpitrix.ModifyAppRequest
|
||||
var patchAppRequest types.ModifyAppRequest
|
||||
err := req.ReadEntity(&patchAppRequest)
|
||||
appId := req.PathParameter("app")
|
||||
|
||||
@@ -313,7 +314,7 @@ func ModifyApp(req *restful.Request, resp *restful.Response) {
|
||||
return
|
||||
}
|
||||
|
||||
err = openpitrix.PatchApp(appId, &patchAppRequest)
|
||||
err = app.PatchApp(appId, &patchAppRequest)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -341,7 +342,7 @@ func ModifyApp(req *restful.Request, resp *restful.Response) {
|
||||
func DescribeApp(req *restful.Request, resp *restful.Response) {
|
||||
appId := req.PathParameter("app")
|
||||
|
||||
result, err := openpitrix.DescribeApp(appId)
|
||||
result, err := app.DescribeApp(appId)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -364,7 +365,7 @@ func DescribeApp(req *restful.Request, resp *restful.Response) {
|
||||
func DeleteApp(req *restful.Request, resp *restful.Response) {
|
||||
appId := req.PathParameter("app")
|
||||
|
||||
err := openpitrix.DeleteApp(appId)
|
||||
err := app.DeleteApp(appId)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -385,7 +386,7 @@ func DeleteApp(req *restful.Request, resp *restful.Response) {
|
||||
}
|
||||
|
||||
func CreateApp(req *restful.Request, resp *restful.Response) {
|
||||
createAppRequest := &openpitrix.CreateAppRequest{}
|
||||
createAppRequest := &types.CreateAppRequest{}
|
||||
err := req.ReadEntity(createAppRequest)
|
||||
if err != nil {
|
||||
resp.WriteHeaderAndEntity(http.StatusBadRequest, errors.Wrap(err))
|
||||
@@ -399,13 +400,13 @@ func CreateApp(req *restful.Request, resp *restful.Response) {
|
||||
var result interface{}
|
||||
|
||||
if validate {
|
||||
validatePackageRequest := &openpitrix.ValidatePackageRequest{
|
||||
validatePackageRequest := &types.ValidatePackageRequest{
|
||||
VersionPackage: createAppRequest.VersionPackage,
|
||||
VersionType: createAppRequest.VersionType,
|
||||
}
|
||||
result, err = openpitrix.ValidatePackage(validatePackageRequest)
|
||||
result, err = app.ValidatePackage(validatePackageRequest)
|
||||
} else {
|
||||
result, err = openpitrix.CreateApp(createAppRequest)
|
||||
result, err = app.CreateApp(createAppRequest)
|
||||
}
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
@@ -427,7 +428,7 @@ func CreateApp(req *restful.Request, resp *restful.Response) {
|
||||
}
|
||||
|
||||
func CreateAppVersion(req *restful.Request, resp *restful.Response) {
|
||||
var createAppVersionRequest openpitrix.CreateAppVersionRequest
|
||||
var createAppVersionRequest types.CreateAppVersionRequest
|
||||
err := req.ReadEntity(&createAppVersionRequest)
|
||||
if err != nil {
|
||||
resp.WriteHeaderAndEntity(http.StatusBadRequest, errors.Wrap(err))
|
||||
@@ -442,13 +443,13 @@ func CreateAppVersion(req *restful.Request, resp *restful.Response) {
|
||||
var result interface{}
|
||||
|
||||
if validate {
|
||||
validatePackageRequest := &openpitrix.ValidatePackageRequest{
|
||||
validatePackageRequest := &types.ValidatePackageRequest{
|
||||
VersionPackage: createAppVersionRequest.Package,
|
||||
VersionType: createAppVersionRequest.Type,
|
||||
}
|
||||
result, err = openpitrix.ValidatePackage(validatePackageRequest)
|
||||
result, err = app.ValidatePackage(validatePackageRequest)
|
||||
} else {
|
||||
result, err = openpitrix.CreateAppVersion(&createAppVersionRequest)
|
||||
result, err = app.CreateAppVersion(&createAppVersionRequest)
|
||||
}
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
@@ -471,7 +472,7 @@ func CreateAppVersion(req *restful.Request, resp *restful.Response) {
|
||||
|
||||
func ModifyAppVersion(req *restful.Request, resp *restful.Response) {
|
||||
|
||||
var patchAppVersionRequest openpitrix.ModifyAppVersionRequest
|
||||
var patchAppVersionRequest types.ModifyAppVersionRequest
|
||||
err := req.ReadEntity(&patchAppVersionRequest)
|
||||
versionId := req.PathParameter("version")
|
||||
|
||||
@@ -480,7 +481,7 @@ func ModifyAppVersion(req *restful.Request, resp *restful.Response) {
|
||||
return
|
||||
}
|
||||
|
||||
err = openpitrix.PatchAppVersion(versionId, &patchAppVersionRequest)
|
||||
err = app.PatchAppVersion(versionId, &patchAppVersionRequest)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -503,7 +504,7 @@ func ModifyAppVersion(req *restful.Request, resp *restful.Response) {
|
||||
func DeleteAppVersion(req *restful.Request, resp *restful.Response) {
|
||||
versionId := req.PathParameter("version")
|
||||
|
||||
err := openpitrix.DeleteAppVersion(versionId)
|
||||
err := app.DeleteAppVersion(versionId)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -526,7 +527,7 @@ func DeleteAppVersion(req *restful.Request, resp *restful.Response) {
|
||||
func DescribeAppVersion(req *restful.Request, resp *restful.Response) {
|
||||
versionId := req.PathParameter("version")
|
||||
|
||||
result, err := openpitrix.DescribeAppVersion(versionId)
|
||||
result, err := app.DescribeAppVersion(versionId)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
|
||||
@@ -19,19 +19,19 @@
|
||||
package openpitrix
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix"
|
||||
"kubesphere.io/kubesphere/pkg/server/errors"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"net/http"
|
||||
"github.com/emicklei/go-restful"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/attachment"
|
||||
"kubesphere.io/kubesphere/pkg/server/errors"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func DescribeAttachment(req *restful.Request, resp *restful.Response) {
|
||||
attachmentId := req.PathParameter("attachment")
|
||||
fileName := req.QueryParameter("filename")
|
||||
result, err := openpitrix.DescribeAttachment(attachmentId)
|
||||
result, err := attachment.DescribeAttachment(attachmentId)
|
||||
// file raw
|
||||
if fileName != "" {
|
||||
data := result.AttachmentContent[fileName]
|
||||
|
||||
@@ -23,7 +23,9 @@ import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/app"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/category"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"kubesphere.io/kubesphere/pkg/server/errors"
|
||||
"kubesphere.io/kubesphere/pkg/server/params"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client"
|
||||
@@ -32,14 +34,14 @@ import (
|
||||
)
|
||||
|
||||
func CreateCategory(req *restful.Request, resp *restful.Response) {
|
||||
createCategoryRequest := &openpitrix.CreateCategoryRequest{}
|
||||
createCategoryRequest := &types.CreateCategoryRequest{}
|
||||
err := req.ReadEntity(createCategoryRequest)
|
||||
if err != nil {
|
||||
resp.WriteHeaderAndEntity(http.StatusBadRequest, errors.Wrap(err))
|
||||
return
|
||||
}
|
||||
|
||||
result, err := openpitrix.CreateCategory(createCategoryRequest)
|
||||
result, err := category.CreateCategory(createCategoryRequest)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -59,7 +61,7 @@ func CreateCategory(req *restful.Request, resp *restful.Response) {
|
||||
func DeleteCategory(req *restful.Request, resp *restful.Response) {
|
||||
categoryId := req.PathParameter("category")
|
||||
|
||||
err := openpitrix.DeleteCategory(categoryId)
|
||||
err := category.DeleteCategory(categoryId)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -77,7 +79,7 @@ func DeleteCategory(req *restful.Request, resp *restful.Response) {
|
||||
resp.WriteEntity(errors.None)
|
||||
}
|
||||
func ModifyCategory(req *restful.Request, resp *restful.Response) {
|
||||
var modifyCategoryRequest openpitrix.ModifyCategoryRequest
|
||||
var modifyCategoryRequest types.ModifyCategoryRequest
|
||||
categoryId := req.PathParameter("category")
|
||||
err := req.ReadEntity(&modifyCategoryRequest)
|
||||
if err != nil {
|
||||
@@ -85,7 +87,7 @@ func ModifyCategory(req *restful.Request, resp *restful.Response) {
|
||||
return
|
||||
}
|
||||
|
||||
err = openpitrix.PatchCategory(categoryId, &modifyCategoryRequest)
|
||||
err = category.PatchCategory(categoryId, &modifyCategoryRequest)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -105,7 +107,7 @@ func ModifyCategory(req *restful.Request, resp *restful.Response) {
|
||||
func DescribeCategory(req *restful.Request, resp *restful.Response) {
|
||||
categoryId := req.PathParameter("category")
|
||||
|
||||
result, err := openpitrix.DescribeCategory(categoryId)
|
||||
result, err := category.DescribeCategory(categoryId)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -140,7 +142,7 @@ func ListCategories(req *restful.Request, resp *restful.Response) {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := openpitrix.ListCategories(conditions, orderBy, reverse, limit, offset)
|
||||
result, err := category.ListCategories(conditions, orderBy, reverse, limit, offset)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -155,8 +157,8 @@ func ListCategories(req *restful.Request, resp *restful.Response) {
|
||||
|
||||
if statistics {
|
||||
for _, item := range result.Items {
|
||||
if category, ok := item.(*openpitrix.Category); ok {
|
||||
statisticsResult, err := openpitrix.ListApps(¶ms.Conditions{Match: map[string]string{"category_id": category.CategoryID, "status": openpitrix.StatusActive, "repo": openpitrix.BuiltinRepoId}}, "", false, 0, 0)
|
||||
if category, ok := item.(*types.Category); ok {
|
||||
statisticsResult, err := app.ListApps(¶ms.Conditions{Match: map[string]string{"category_id": category.CategoryID, "status": app.StatusActive, "repo": app.BuiltinRepoId}}, "", false, 0, 0)
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
|
||||
|
||||
@@ -23,7 +23,8 @@ import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/repo"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"kubesphere.io/kubesphere/pkg/server/errors"
|
||||
"kubesphere.io/kubesphere/pkg/server/params"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client"
|
||||
@@ -32,7 +33,7 @@ import (
|
||||
)
|
||||
|
||||
func CreateRepo(req *restful.Request, resp *restful.Response) {
|
||||
createRepoRequest := &openpitrix.CreateRepoRequest{}
|
||||
createRepoRequest := &types.CreateRepoRequest{}
|
||||
err := req.ReadEntity(createRepoRequest)
|
||||
if err != nil {
|
||||
resp.WriteHeaderAndEntity(http.StatusBadRequest, errors.Wrap(err))
|
||||
@@ -43,14 +44,14 @@ func CreateRepo(req *restful.Request, resp *restful.Response) {
|
||||
var result interface{}
|
||||
|
||||
if validate {
|
||||
validateRepoRequest := &openpitrix.ValidateRepoRequest{
|
||||
validateRepoRequest := &types.ValidateRepoRequest{
|
||||
Type: createRepoRequest.Type,
|
||||
Url: createRepoRequest.URL,
|
||||
Credential: createRepoRequest.Credential,
|
||||
}
|
||||
result, err = openpitrix.ValidateRepo(validateRepoRequest)
|
||||
result, err = repo.ValidateRepo(validateRepoRequest)
|
||||
} else {
|
||||
result, err = openpitrix.CreateRepo(createRepoRequest)
|
||||
result, err = repo.CreateRepo(createRepoRequest)
|
||||
}
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
@@ -70,7 +71,7 @@ func CreateRepo(req *restful.Request, resp *restful.Response) {
|
||||
}
|
||||
|
||||
func DoRepoAction(req *restful.Request, resp *restful.Response) {
|
||||
repoActionRequest := &openpitrix.RepoActionRequest{}
|
||||
repoActionRequest := &types.RepoActionRequest{}
|
||||
repoId := req.PathParameter("repo")
|
||||
err := req.ReadEntity(repoActionRequest)
|
||||
if err != nil {
|
||||
@@ -78,7 +79,7 @@ func DoRepoAction(req *restful.Request, resp *restful.Response) {
|
||||
return
|
||||
}
|
||||
|
||||
err = openpitrix.DoRepoAction(repoId, repoActionRequest)
|
||||
err = repo.DoRepoAction(repoId, repoActionRequest)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -99,7 +100,7 @@ func DoRepoAction(req *restful.Request, resp *restful.Response) {
|
||||
func DeleteRepo(req *restful.Request, resp *restful.Response) {
|
||||
repoId := req.PathParameter("repo")
|
||||
|
||||
err := openpitrix.DeleteRepo(repoId)
|
||||
err := repo.DeleteRepo(repoId)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -118,7 +119,7 @@ func DeleteRepo(req *restful.Request, resp *restful.Response) {
|
||||
}
|
||||
|
||||
func ModifyRepo(req *restful.Request, resp *restful.Response) {
|
||||
var updateRepoRequest openpitrix.ModifyRepoRequest
|
||||
var updateRepoRequest types.ModifyRepoRequest
|
||||
repoId := req.PathParameter("repo")
|
||||
err := req.ReadEntity(&updateRepoRequest)
|
||||
if err != nil {
|
||||
@@ -126,7 +127,7 @@ func ModifyRepo(req *restful.Request, resp *restful.Response) {
|
||||
return
|
||||
}
|
||||
|
||||
err = openpitrix.PatchRepo(repoId, &updateRepoRequest)
|
||||
err = repo.PatchRepo(repoId, &updateRepoRequest)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -147,7 +148,7 @@ func ModifyRepo(req *restful.Request, resp *restful.Response) {
|
||||
func DescribeRepo(req *restful.Request, resp *restful.Response) {
|
||||
repoId := req.PathParameter("repo")
|
||||
|
||||
result, err := openpitrix.DescribeRepo(repoId)
|
||||
result, err := repo.DescribeRepo(repoId)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -179,7 +180,7 @@ func ListRepos(req *restful.Request, resp *restful.Response) {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := openpitrix.ListRepos(conditions, orderBy, reverse, limit, offset)
|
||||
result, err := repo.ListRepos(conditions, orderBy, reverse, limit, offset)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
@@ -205,7 +206,7 @@ func ListRepoEvents(req *restful.Request, resp *restful.Response) {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := openpitrix.ListRepoEvents(repoId, conditions, limit, offset)
|
||||
result, err := repo.ListRepoEvents(repoId, conditions, limit, offset)
|
||||
|
||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||
|
||||
@@ -1,50 +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 terminal
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful"
|
||||
"github.com/gorilla/websocket"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/models/terminal"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var upgrader = websocket.Upgrader{
|
||||
ReadBufferSize: 1024,
|
||||
WriteBufferSize: 1024,
|
||||
// Allow connections from any Origin
|
||||
CheckOrigin: func(r *http.Request) bool { return true },
|
||||
}
|
||||
|
||||
// Handles execute shell API call
|
||||
func HandleTerminalSession(request *restful.Request, resp *restful.Response) {
|
||||
|
||||
namespace := request.PathParameter("namespace")
|
||||
podName := request.PathParameter("pod")
|
||||
containerName := request.QueryParameter("container")
|
||||
shell := request.QueryParameter("shell")
|
||||
|
||||
conn, err := upgrader.Upgrade(resp.ResponseWriter, request.Request, nil)
|
||||
if err != nil {
|
||||
klog.Warning(err)
|
||||
return
|
||||
}
|
||||
|
||||
terminal.HandleSession(shell, namespace, podName, containerName, conn)
|
||||
}
|
||||
@@ -1,18 +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 workspaces
|
||||
1
pkg/kapis/devops/v1alpha2/handler.go
Normal file
1
pkg/kapis/devops/v1alpha2/handler.go
Normal file
@@ -0,0 +1 @@
|
||||
package v1alpha2
|
||||
1
pkg/kapis/iam/v1alpha2/handler.go
Normal file
1
pkg/kapis/iam/v1alpha2/handler.go
Normal file
@@ -0,0 +1 @@
|
||||
package v1alpha2
|
||||
1
pkg/kapis/logging/v1alpha2/handler.go
Normal file
1
pkg/kapis/logging/v1alpha2/handler.go
Normal file
@@ -0,0 +1 @@
|
||||
package v1alpha2
|
||||
@@ -1,14 +1,76 @@
|
||||
package v1
|
||||
|
||||
import "github.com/emicklei/go-restful"
|
||||
import (
|
||||
"github.com/emicklei/go-restful"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/api"
|
||||
"kubesphere.io/kubesphere/pkg/constants"
|
||||
"kubesphere.io/kubesphere/pkg/informers"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/application"
|
||||
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3/resource"
|
||||
"kubesphere.io/kubesphere/pkg/server/params"
|
||||
"openpitrix.io/openpitrix/pkg/pb"
|
||||
)
|
||||
|
||||
type openpitrixHandler struct {
|
||||
namespacesGetter *resource.NamespacedResourceGetter
|
||||
applicationOperator application.Interface
|
||||
}
|
||||
|
||||
func newOpenpitrixHandler() *openpitrixHandler {
|
||||
return &openpitrixHandler{}
|
||||
func newOpenpitrixHandler(factory informers.InformerFactory, client pb.ClusterManagerClient) *openpitrixHandler {
|
||||
return &openpitrixHandler{
|
||||
namespacesGetter: resource.New(factory),
|
||||
applicationOperator: application.NewApplicaitonOperator(factory.KubernetesSharedInformerFactory(), client),
|
||||
}
|
||||
}
|
||||
|
||||
func (h *openpitrixHandler) handleListApplications(request *restful.Request, response *restful.Response) {
|
||||
limit, offset := params.ParsePaging(request.QueryParameter(params.PagingParam))
|
||||
namespaceName := request.PathParameter("namespace")
|
||||
conditions, err := params.ParseConditions(request.QueryParameter(params.ConditionsParam))
|
||||
orderBy := request.QueryParameter(params.OrderByParam)
|
||||
reverse := params.ParseReverse(request)
|
||||
|
||||
if orderBy == "" {
|
||||
orderBy = "create_time"
|
||||
reverse = true
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
api.HandleBadRequest(response, err)
|
||||
return
|
||||
}
|
||||
|
||||
if namespaceName != "" {
|
||||
namespace, err := h.namespacesGetter.Get(api.ResourceKindNamespace, "", namespaceName)
|
||||
|
||||
if err != nil {
|
||||
api.HandleInternalError(response, err)
|
||||
return
|
||||
}
|
||||
var runtimeId string
|
||||
|
||||
if ns, ok := namespace.(*v1.Namespace); ok {
|
||||
runtimeId = ns.Annotations[constants.OpenPitrixRuntimeAnnotationKey]
|
||||
}
|
||||
|
||||
if runtimeId == "" {
|
||||
response.WriteAsJson(models.PageableResponse{Items: []interface{}{}, TotalCount: 0})
|
||||
return
|
||||
} else {
|
||||
conditions.Match["runtime_id"] = runtimeId
|
||||
}
|
||||
}
|
||||
|
||||
result, err := h.applicationOperator.List(conditions, limit, offset, orderBy, reverse)
|
||||
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
api.HandleInternalError(response, err)
|
||||
return
|
||||
}
|
||||
|
||||
resp.WriteAsJson(result)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@ import (
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
|
||||
"kubesphere.io/kubesphere/pkg/constants"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
opmodels "kubesphere.io/kubesphere/pkg/models/openpitrix"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/application"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"kubesphere.io/kubesphere/pkg/server/errors"
|
||||
"kubesphere.io/kubesphere/pkg/server/params"
|
||||
"net/http"
|
||||
@@ -78,7 +79,7 @@ func addWebService(c *restful.Container) error {
|
||||
|
||||
webservice.Route(webservice.GET("/namespaces/{namespace}/applications/{application}").
|
||||
To(openpitrix.DescribeApplication).
|
||||
Returns(http.StatusOK, ok, opmodels.Application{}).
|
||||
Returns(http.StatusOK, ok, application.Application{}).
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
|
||||
Doc("Describe the specified application of the namespace").
|
||||
Param(webservice.PathParameter("namespace", "the name of the project")).
|
||||
@@ -88,7 +89,7 @@ func addWebService(c *restful.Container) error {
|
||||
To(openpitrix.CreateApplication).
|
||||
Doc("Deploy a new application").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
|
||||
Reads(opmodels.CreateClusterRequest{}).
|
||||
Reads(types.CreateClusterRequest{}).
|
||||
Returns(http.StatusOK, ok, errors.Error{}).
|
||||
Param(webservice.PathParameter("namespace", "the name of the project")))
|
||||
|
||||
@@ -97,7 +98,7 @@ func addWebService(c *restful.Container) error {
|
||||
To(openpitrix.ModifyApplication).
|
||||
Doc("Modify application").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
|
||||
Reads(opmodels.ModifyClusterAttributesRequest{}).
|
||||
Reads(types.ModifyClusterAttributesRequest{}).
|
||||
Returns(http.StatusOK, ok, errors.Error{}).
|
||||
Param(webservice.PathParameter("namespace", "the name of the project")).
|
||||
Param(webservice.PathParameter("application", "the id of the application cluster")))
|
||||
@@ -114,9 +115,9 @@ func addWebService(c *restful.Container) error {
|
||||
To(openpitrix.CreateAppVersion).
|
||||
Doc("Create a new app template version").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
|
||||
Reads(opmodels.CreateAppVersionRequest{}).
|
||||
Reads(types.CreateAppVersionRequest{}).
|
||||
Param(webservice.QueryParameter("validate", "Validate format of package(pack by op tool)")).
|
||||
Returns(http.StatusOK, ok, opmodels.CreateAppVersionResponse{}).
|
||||
Returns(http.StatusOK, ok, types.CreateAppVersionResponse{}).
|
||||
Param(webservice.PathParameter("app", "app template id")))
|
||||
webservice.Route(webservice.DELETE("/apps/{app}/versions/{version}").
|
||||
To(openpitrix.DeleteAppVersion).
|
||||
@@ -130,7 +131,7 @@ func addWebService(c *restful.Container) error {
|
||||
To(openpitrix.ModifyAppVersion).
|
||||
Doc("Patch the specified app template version").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
|
||||
Reads(opmodels.ModifyAppVersionRequest{}).
|
||||
Reads(types.ModifyAppVersionRequest{}).
|
||||
Returns(http.StatusOK, ok, errors.Error{}).
|
||||
Param(webservice.PathParameter("version", "app template version id")).
|
||||
Param(webservice.PathParameter("app", "app template id")))
|
||||
@@ -138,7 +139,7 @@ func addWebService(c *restful.Container) error {
|
||||
To(openpitrix.DescribeAppVersion).
|
||||
Doc("Describe the specified app template version").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
|
||||
Returns(http.StatusOK, ok, opmodels.AppVersion{}).
|
||||
Returns(http.StatusOK, ok, types.AppVersion{}).
|
||||
Param(webservice.PathParameter("version", "app template version id")).
|
||||
Param(webservice.PathParameter("app", "app template id")))
|
||||
webservice.Route(webservice.GET("/apps/{app}/versions").
|
||||
@@ -158,13 +159,13 @@ func addWebService(c *restful.Container) error {
|
||||
webservice.Route(webservice.GET("/apps/{app}/versions/{version}/audits").
|
||||
To(openpitrix.ListAppVersionAudits).
|
||||
Doc("List audits information of version-specific app template").
|
||||
Returns(http.StatusOK, ok, opmodels.AppVersionAudit{}).
|
||||
Returns(http.StatusOK, ok, types.AppVersionAudit{}).
|
||||
Param(webservice.PathParameter("version", "app template version id")).
|
||||
Param(webservice.PathParameter("app", "app template id")))
|
||||
webservice.Route(webservice.GET("/apps/{app}/versions/{version}/package").
|
||||
To(openpitrix.GetAppVersionPackage).
|
||||
Doc("Get packages of version-specific app").
|
||||
Returns(http.StatusOK, ok, opmodels.GetAppVersionPackageResponse{}).
|
||||
Returns(http.StatusOK, ok, types.GetAppVersionPackageResponse{}).
|
||||
Param(webservice.PathParameter("version", "app template version id")).
|
||||
Param(webservice.PathParameter("app", "app template id")))
|
||||
webservice.Route(webservice.POST("/apps/{app}/versions/{version}/action").
|
||||
@@ -176,7 +177,7 @@ func addWebService(c *restful.Container) error {
|
||||
webservice.Route(webservice.GET("/apps/{app}/versions/{version}/files").
|
||||
To(openpitrix.GetAppVersionFiles).
|
||||
Doc("Get app template package files").
|
||||
Returns(http.StatusOK, ok, opmodels.GetAppVersionPackageFilesResponse{}).
|
||||
Returns(http.StatusOK, ok, types.GetAppVersionPackageFilesResponse{}).
|
||||
Param(webservice.PathParameter("version", "app template version id")).
|
||||
Param(webservice.PathParameter("app", "app template id")))
|
||||
webservice.Route(webservice.GET("/reviews").
|
||||
@@ -189,18 +190,18 @@ func addWebService(c *restful.Container) error {
|
||||
Required(false).
|
||||
DataFormat("limit=%d,page=%d").
|
||||
DefaultValue("limit=10,page=1")).
|
||||
Returns(http.StatusOK, ok, opmodels.AppVersionReview{}))
|
||||
Returns(http.StatusOK, ok, types.AppVersionReview{}))
|
||||
webservice.Route(webservice.GET("/apps/{app}/audits").
|
||||
To(openpitrix.ListAppVersionAudits).
|
||||
Doc("List audits information of the specific app template").
|
||||
Param(webservice.PathParameter("app", "app template id")).
|
||||
Returns(http.StatusOK, ok, opmodels.AppVersionAudit{}))
|
||||
Returns(http.StatusOK, ok, types.AppVersionAudit{}))
|
||||
webservice.Route(webservice.POST("/apps").
|
||||
To(openpitrix.CreateApp).
|
||||
Doc("Create a new app template").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
|
||||
Returns(http.StatusOK, ok, opmodels.CreateAppResponse{}).
|
||||
Reads(opmodels.CreateAppRequest{}).
|
||||
Returns(http.StatusOK, ok, types.CreateAppResponse{}).
|
||||
Reads(types.CreateAppRequest{}).
|
||||
Param(webservice.PathParameter("app", "app template id")))
|
||||
webservice.Route(webservice.DELETE("/apps/{app}").
|
||||
To(openpitrix.DeleteApp).
|
||||
@@ -213,14 +214,14 @@ func addWebService(c *restful.Container) error {
|
||||
To(openpitrix.ModifyApp).
|
||||
Doc("Patch the specified app template").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
|
||||
Reads(opmodels.ModifyAppVersionRequest{}).
|
||||
Reads(types.ModifyAppVersionRequest{}).
|
||||
Returns(http.StatusOK, ok, errors.Error{}).
|
||||
Param(webservice.PathParameter("app", "app template id")))
|
||||
webservice.Route(webservice.GET("/apps/{app}").
|
||||
To(openpitrix.DescribeApp).
|
||||
Doc("Describe the specified app template").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
|
||||
Returns(http.StatusOK, ok, opmodels.AppVersion{}).
|
||||
Returns(http.StatusOK, ok, types.AppVersion{}).
|
||||
Param(webservice.PathParameter("app", "app template id")))
|
||||
webservice.Route(webservice.POST("/apps/{app}/action").
|
||||
To(openpitrix.DoAppAction).
|
||||
@@ -245,8 +246,8 @@ func addWebService(c *restful.Container) error {
|
||||
To(openpitrix.CreateCategory).
|
||||
Doc("Create app template category").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
|
||||
Reads(opmodels.CreateCategoryRequest{}).
|
||||
Returns(http.StatusOK, ok, opmodels.CreateCategoryResponse{}).
|
||||
Reads(types.CreateCategoryRequest{}).
|
||||
Returns(http.StatusOK, ok, types.CreateCategoryResponse{}).
|
||||
Param(webservice.PathParameter("app", "app template id")))
|
||||
webservice.Route(webservice.DELETE("/categories/{category}").
|
||||
To(openpitrix.DeleteCategory).
|
||||
@@ -259,14 +260,14 @@ func addWebService(c *restful.Container) error {
|
||||
To(openpitrix.ModifyCategory).
|
||||
Doc("Patch the specified category").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
|
||||
Reads(opmodels.ModifyCategoryRequest{}).
|
||||
Reads(types.ModifyCategoryRequest{}).
|
||||
Returns(http.StatusOK, ok, errors.Error{}).
|
||||
Param(webservice.PathParameter("category", "category id")))
|
||||
webservice.Route(webservice.GET("/categories/{category}").
|
||||
To(openpitrix.DescribeCategory).
|
||||
Doc("Describe the specified category").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
|
||||
Returns(http.StatusOK, ok, opmodels.Category{}).
|
||||
Returns(http.StatusOK, ok, types.Category{}).
|
||||
Param(webservice.PathParameter("category", "category id")))
|
||||
webservice.Route(webservice.GET("/categories").
|
||||
To(openpitrix.ListCategories).
|
||||
@@ -286,15 +287,15 @@ func addWebService(c *restful.Container) error {
|
||||
To(openpitrix.DescribeAttachment).
|
||||
Doc("Get attachment by attachment id").
|
||||
Param(webservice.PathParameter("attachment", "attachment id")).
|
||||
Returns(http.StatusOK, ok, opmodels.Attachment{}))
|
||||
Returns(http.StatusOK, ok, types.Attachment{}))
|
||||
|
||||
webservice.Route(webservice.POST("/repos").
|
||||
To(openpitrix.CreateRepo).
|
||||
Doc("Create repository, repository used to store package of app").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
|
||||
Param(webservice.QueryParameter("validate", "Validate repository")).
|
||||
Returns(http.StatusOK, ok, opmodels.CreateRepoResponse{}).
|
||||
Reads(opmodels.CreateRepoRequest{}))
|
||||
Returns(http.StatusOK, ok, types.CreateRepoResponse{}).
|
||||
Reads(types.CreateRepoRequest{}))
|
||||
webservice.Route(webservice.DELETE("/repos/{repo}").
|
||||
To(openpitrix.DeleteRepo).
|
||||
Doc("Delete the specified repository").
|
||||
@@ -306,14 +307,14 @@ func addWebService(c *restful.Container) error {
|
||||
To(openpitrix.ModifyRepo).
|
||||
Doc("Patch the specified repository").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
|
||||
Reads(opmodels.ModifyRepoRequest{}).
|
||||
Reads(types.ModifyRepoRequest{}).
|
||||
Returns(http.StatusOK, ok, errors.Error{}).
|
||||
Param(webservice.PathParameter("repo", "repo id")))
|
||||
webservice.Route(webservice.GET("/repos/{repo}").
|
||||
To(openpitrix.DescribeRepo).
|
||||
Doc("Describe the specified repository").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
|
||||
Returns(http.StatusOK, ok, opmodels.Repo{}).
|
||||
Returns(http.StatusOK, ok, types.Repo{}).
|
||||
Param(webservice.PathParameter("repo", "repo id")))
|
||||
webservice.Route(webservice.GET("/repos").
|
||||
To(openpitrix.ListRepos).
|
||||
@@ -331,7 +332,7 @@ func addWebService(c *restful.Container) error {
|
||||
webservice.Route(webservice.POST("/repos/{repo}/action").
|
||||
To(openpitrix.DoRepoAction).
|
||||
Doc("Start index repository event").
|
||||
Reads(opmodels.RepoActionRequest{}).
|
||||
Reads(types.RepoActionRequest{}).
|
||||
Returns(http.StatusOK, ok, errors.Error{}).
|
||||
Param(webservice.PathParameter("repo", "repo id")))
|
||||
webservice.Route(webservice.GET("/repos/{repo}/events").
|
||||
|
||||
@@ -17,10 +17,10 @@ type Handler struct {
|
||||
}
|
||||
|
||||
func New(client k8s.Client) *Handler {
|
||||
factory := informers.NewInformerFactories(client.Kubernetes(), nil, nil, nil)
|
||||
factory := informers.NewInformerFactories(client.Kubernetes(), client.KubeSphere(), client.S2i(), client.Application())
|
||||
|
||||
return &Handler{
|
||||
namespacedResourceGetter: resource.New(factory.KubernetesSharedInformerFactory()),
|
||||
namespacedResourceGetter: resource.New(factory),
|
||||
componentsGetter: components.NewComponentsGetter(factory.KubernetesSharedInformerFactory()),
|
||||
}
|
||||
}
|
||||
|
||||
1
pkg/kapis/servicemesh/metrics/v1alpha2/handler.go
Normal file
1
pkg/kapis/servicemesh/metrics/v1alpha2/handler.go
Normal file
@@ -0,0 +1 @@
|
||||
package v1alpha2
|
||||
1
pkg/kapis/tenant/v1alpha2/handler.go
Normal file
1
pkg/kapis/tenant/v1alpha2/handler.go
Normal file
@@ -0,0 +1 @@
|
||||
package v1alpha2
|
||||
@@ -29,5 +29,5 @@ func init() {
|
||||
}
|
||||
|
||||
func Install(c *restful.Container) {
|
||||
urlruntime.Must(v1alpha2.AddToContainer(c))
|
||||
urlruntime.Must(v1alpha2.AddToContainer(c, nil, nil))
|
||||
}
|
||||
|
||||
43
pkg/kapis/terminal/v1alpha2/handler.go
Normal file
43
pkg/kapis/terminal/v1alpha2/handler.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package v1alpha2
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful"
|
||||
"github.com/gorilla/websocket"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/models/terminal"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var upgrader = websocket.Upgrader{
|
||||
ReadBufferSize: 1024,
|
||||
WriteBufferSize: 1024,
|
||||
// Allow connections from any Origin
|
||||
CheckOrigin: func(r *http.Request) bool { return true },
|
||||
}
|
||||
|
||||
type terminalHandler struct {
|
||||
terminaler terminal.Interface
|
||||
}
|
||||
|
||||
func newTerminalHandler(client kubernetes.Interface, config *rest.Config) *terminalHandler {
|
||||
return &terminalHandler{
|
||||
terminaler: terminal.NewTerminaler(client, config),
|
||||
}
|
||||
}
|
||||
|
||||
func (t *terminalHandler) handleTerminalSession(request *restful.Request, response *restful.Response) {
|
||||
namespace := request.PathParameter("namespace")
|
||||
podName := request.PathParameter("pod")
|
||||
containerName := request.QueryParameter("container")
|
||||
shell := request.QueryParameter("shell")
|
||||
|
||||
conn, err := upgrader.Upgrade(response.ResponseWriter, request.Request, nil)
|
||||
if err != nil {
|
||||
klog.Warning(err)
|
||||
return
|
||||
}
|
||||
|
||||
t.terminaler.HandleSession(shell, namespace, podName, containerName, conn)
|
||||
}
|
||||
@@ -21,30 +21,29 @@ import (
|
||||
"github.com/emicklei/go-restful"
|
||||
"github.com/emicklei/go-restful-openapi"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/terminal"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
)
|
||||
|
||||
const GroupName = "terminal.kubesphere.io"
|
||||
const (
|
||||
GroupName = "terminal.kubesphere.io"
|
||||
tag = "Terminal"
|
||||
)
|
||||
|
||||
var GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"}
|
||||
|
||||
var (
|
||||
WebServiceBuilder = runtime.NewContainerBuilder(addWebService)
|
||||
AddToContainer = WebServiceBuilder.AddToContainer
|
||||
)
|
||||
|
||||
func addWebService(c *restful.Container) error {
|
||||
func AddToContainer(c *restful.Container, client kubernetes.Interface, config *rest.Config) error {
|
||||
|
||||
webservice := runtime.NewWebService(GroupVersion)
|
||||
|
||||
tags := []string{"Terminal"}
|
||||
handler := newTerminalHandler(client, config)
|
||||
|
||||
webservice.Route(webservice.GET("/namespaces/{namespace}/pods/{pod}").
|
||||
To(terminal.HandleTerminalSession).
|
||||
To(handler.handleTerminalSession).
|
||||
Doc("create terminal session").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{tag}).
|
||||
Writes(models.PodInfo{}))
|
||||
|
||||
c.Add(webservice)
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/api/logging/v1alpha2"
|
||||
"kubesphere.io/kubesphere/pkg/apis/logging/v1alpha2"
|
||||
"kubesphere.io/kubesphere/pkg/informers"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -52,8 +52,8 @@ func createCRDClientSet() (*rest.RESTClient, *runtime.Scheme, error) {
|
||||
return fb.NewFluentbitCRDClient(config)
|
||||
}
|
||||
|
||||
func FluentbitOutputsQuery() *FluentbitOutputsResult {
|
||||
var result FluentbitOutputsResult
|
||||
func FluentbitOutputsQuery() *v1alpha2.FluentbitOutputsResult {
|
||||
var result v1alpha2.FluentbitOutputsResult
|
||||
|
||||
outputs, err := GetFluentbitOutputFromConfigMap()
|
||||
if err != nil {
|
||||
@@ -68,11 +68,11 @@ func FluentbitOutputsQuery() *FluentbitOutputsResult {
|
||||
return &result
|
||||
}
|
||||
|
||||
func FluentbitOutputInsert(output fb.OutputPlugin) *FluentbitOutputsResult {
|
||||
var result FluentbitOutputsResult
|
||||
func FluentbitOutputInsert(output v1alpha2.OutputPlugin) *v1alpha2.FluentbitOutputsResult {
|
||||
var result v1alpha2.FluentbitOutputsResult
|
||||
|
||||
// 1. Update ConfigMap
|
||||
var outputs []fb.OutputPlugin
|
||||
var outputs []v1alpha2.OutputPlugin
|
||||
outputs, err := GetFluentbitOutputFromConfigMap()
|
||||
if err != nil {
|
||||
// If the ConfigMap doesn't exist, a new one will be created later
|
||||
@@ -105,11 +105,11 @@ func FluentbitOutputInsert(output fb.OutputPlugin) *FluentbitOutputsResult {
|
||||
return &result
|
||||
}
|
||||
|
||||
func FluentbitOutputUpdate(output fb.OutputPlugin, id string) *FluentbitOutputsResult {
|
||||
var result FluentbitOutputsResult
|
||||
func FluentbitOutputUpdate(output v1alpha2.OutputPlugin, id string) *v1alpha2.FluentbitOutputsResult {
|
||||
var result v1alpha2.FluentbitOutputsResult
|
||||
|
||||
// 1. Update ConfigMap
|
||||
var outputs []fb.OutputPlugin
|
||||
var outputs []v1alpha2.OutputPlugin
|
||||
outputs, err := GetFluentbitOutputFromConfigMap()
|
||||
if err != nil {
|
||||
// If the ConfigMap doesn't exist, a new one will be created later
|
||||
@@ -152,8 +152,8 @@ func FluentbitOutputUpdate(output fb.OutputPlugin, id string) *FluentbitOutputsR
|
||||
return &result
|
||||
}
|
||||
|
||||
func FluentbitOutputDelete(id string) *FluentbitOutputsResult {
|
||||
var result FluentbitOutputsResult
|
||||
func FluentbitOutputDelete(id string) *v1alpha2.FluentbitOutputsResult {
|
||||
var result v1alpha2.FluentbitOutputsResult
|
||||
|
||||
// 1. Update ConfigMap
|
||||
// If the ConfigMap doesn't exist, a new one will be created
|
||||
@@ -194,7 +194,7 @@ func FluentbitOutputDelete(id string) *FluentbitOutputsResult {
|
||||
return &result
|
||||
}
|
||||
|
||||
func GetFluentbitOutputFromConfigMap() ([]fb.OutputPlugin, error) {
|
||||
func GetFluentbitOutputFromConfigMap() ([]v1alpha2.OutputPlugin, error) {
|
||||
configMap, err := informers.SharedInformerFactory().Core().V1().ConfigMaps().Lister().ConfigMaps(LoggingNamespace).Get(ConfigMapName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -265,22 +265,22 @@ func updateFluentbitOutputConfigMap(outputs []fb.OutputPlugin) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func syncFluentbitCRDOutputWithConfigMap(outputs []fb.OutputPlugin) error {
|
||||
func syncFluentbitCRDOutputWithConfigMap(outputs []v1alpha2.OutputPlugin) error {
|
||||
|
||||
var enabledOutputs []fb.Plugin
|
||||
var enabledOutputs []v1alpha2.Plugin
|
||||
for _, output := range outputs {
|
||||
if output.Enable {
|
||||
enabledOutputs = append(enabledOutputs, fb.Plugin{Type: output.Type, Name: output.Name, Parameters: output.Parameters})
|
||||
enabledOutputs = append(enabledOutputs, v1alpha2.Plugin{Type: output.Type, Name: output.Name, Parameters: output.Parameters})
|
||||
}
|
||||
}
|
||||
|
||||
// Empty output is not allowed, must specify a null-type output
|
||||
if len(enabledOutputs) == 0 {
|
||||
enabledOutputs = []fb.Plugin{
|
||||
enabledOutputs = []v1alpha2.Plugin{
|
||||
{
|
||||
Type: "fluentbit_output",
|
||||
Name: "fluentbit-output-null",
|
||||
Parameters: []fb.Parameter{
|
||||
Parameters: []v1alpha2.Parameter{
|
||||
{
|
||||
Name: "Name",
|
||||
Value: "null",
|
||||
@@ -301,7 +301,7 @@ func syncFluentbitCRDOutputWithConfigMap(outputs []fb.OutputPlugin) error {
|
||||
}
|
||||
|
||||
// Create a CRD client interface
|
||||
crdclient := fb.CrdClient(crdcs, scheme, LoggingNamespace)
|
||||
crdclient := v1alpha2.CrdClient(crdcs, scheme, LoggingNamespace)
|
||||
|
||||
fluentbit, err := crdclient.Get("fluent-bit")
|
||||
if err != nil {
|
||||
@@ -320,7 +320,7 @@ func syncFluentbitCRDOutputWithConfigMap(outputs []fb.OutputPlugin) error {
|
||||
}
|
||||
|
||||
// Parse es host, port and index
|
||||
func ParseEsOutputParams(params []fb.Parameter) *v1alpha2.Config {
|
||||
func ParseEsOutputParams(params []v1alpha2.Parameter) *v1alpha2.Config {
|
||||
|
||||
var (
|
||||
isEsFound bool
|
||||
|
||||
@@ -17,9 +17,3 @@
|
||||
*/
|
||||
|
||||
package log
|
||||
|
||||
type FluentbitOutputsResult struct {
|
||||
Status int `json:"status" description:"response status"`
|
||||
Error string `json:"error,omitempty" description:"debug information"`
|
||||
Outputs []fb.OutputPlugin `json:"outputs,omitempty" description:"array of fluent bit output plugins"`
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* /
|
||||
*/
|
||||
|
||||
package openpitrix
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/go-openapi/strfmt"
|
||||
@@ -25,6 +25,8 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/utils"
|
||||
"kubesphere.io/kubesphere/pkg/server/params"
|
||||
cs "kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||
@@ -83,13 +85,13 @@ func ListApps(conditions *params.Conditions, orderBy string, reverse bool, limit
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.AppSet {
|
||||
items = append(items, convertApp(item))
|
||||
items = append(items, utils.ConvertApp(item))
|
||||
}
|
||||
|
||||
return &models.PageableResponse{Items: items, TotalCount: int(resp.TotalCount)}, nil
|
||||
}
|
||||
|
||||
func DescribeApp(id string) (*App, error) {
|
||||
func DescribeApp(id string) (*types.App, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -104,10 +106,10 @@ func DescribeApp(id string) (*App, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var app *App
|
||||
var app *types.App
|
||||
|
||||
if len(resp.AppSet) > 0 {
|
||||
app = convertApp(resp.AppSet[0])
|
||||
app = utils.ConvertApp(resp.AppSet[0])
|
||||
return app, nil
|
||||
} else {
|
||||
err := status.New(codes.NotFound, "resource not found").Err()
|
||||
@@ -132,7 +134,7 @@ func DeleteApp(id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateApp(request *CreateAppRequest) (*CreateAppResponse, error) {
|
||||
func CreateApp(request *types.CreateAppRequest) (*types.CreateAppResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -157,13 +159,13 @@ func CreateApp(request *CreateAppRequest) (*CreateAppResponse, error) {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
return &CreateAppResponse{
|
||||
return &types.CreateAppResponse{
|
||||
AppID: resp.GetAppId().GetValue(),
|
||||
VersionID: resp.GetVersionId().GetValue(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func PatchApp(appId string, request *ModifyAppRequest) error {
|
||||
func PatchApp(appId string, request *types.ModifyAppRequest) error {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
@@ -237,7 +239,7 @@ func PatchApp(appId string, request *ModifyAppRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateAppVersion(request *CreateAppVersionRequest) (*CreateAppVersionResponse, error) {
|
||||
func CreateAppVersion(request *types.CreateAppVersionRequest) (*types.CreateAppVersionResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -259,12 +261,12 @@ func CreateAppVersion(request *CreateAppVersionRequest) (*CreateAppVersionRespon
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
return &CreateAppVersionResponse{
|
||||
return &types.CreateAppVersionResponse{
|
||||
VersionId: resp.GetVersionId().GetValue(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ValidatePackage(request *ValidatePackageRequest) (*ValidatePackageResponse, error) {
|
||||
func ValidatePackage(request *types.ValidatePackageRequest) (*types.ValidatePackageResponse, error) {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
@@ -288,7 +290,7 @@ func ValidatePackage(request *ValidatePackageRequest) (*ValidatePackageResponse,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := &ValidatePackageResponse{}
|
||||
result := &types.ValidatePackageResponse{}
|
||||
|
||||
if resp.Error != nil {
|
||||
result.Error = resp.Error.Value
|
||||
@@ -330,7 +332,7 @@ func DeleteAppVersion(id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func PatchAppVersion(id string, request *ModifyAppVersionRequest) error {
|
||||
func PatchAppVersion(id string, request *types.ModifyAppVersionRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -361,7 +363,7 @@ func PatchAppVersion(id string, request *ModifyAppVersionRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DescribeAppVersion(id string) (*AppVersion, error) {
|
||||
func DescribeAppVersion(id string) (*types.AppVersion, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -376,10 +378,10 @@ func DescribeAppVersion(id string) (*AppVersion, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var app *AppVersion
|
||||
var app *types.AppVersion
|
||||
|
||||
if len(resp.AppVersionSet) > 0 {
|
||||
app = convertAppVersion(resp.AppVersionSet[0])
|
||||
app = utils.ConvertAppVersion(resp.AppVersionSet[0])
|
||||
return app, nil
|
||||
} else {
|
||||
err := status.New(codes.NotFound, "resource not found").Err()
|
||||
@@ -388,7 +390,7 @@ func DescribeAppVersion(id string) (*AppVersion, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func GetAppVersionPackage(appId, versionId string) (*GetAppVersionPackageResponse, error) {
|
||||
func GetAppVersionPackage(appId, versionId string) (*types.GetAppVersionPackageResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -402,7 +404,7 @@ func GetAppVersionPackage(appId, versionId string) (*GetAppVersionPackageRespons
|
||||
return nil, err
|
||||
}
|
||||
|
||||
app := &GetAppVersionPackageResponse{
|
||||
app := &types.GetAppVersionPackageResponse{
|
||||
AppId: appId,
|
||||
VersionId: versionId,
|
||||
}
|
||||
@@ -414,7 +416,7 @@ func GetAppVersionPackage(appId, versionId string) (*GetAppVersionPackageRespons
|
||||
return app, nil
|
||||
}
|
||||
|
||||
func DoAppAction(appId string, request *ActionRequest) error {
|
||||
func DoAppAction(appId string, request *types.ActionRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
@@ -479,7 +481,7 @@ func DoAppAction(appId string, request *ActionRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DoAppVersionAction(versionId string, request *ActionRequest) error {
|
||||
func DoAppVersionAction(versionId string, request *types.ActionRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
@@ -529,7 +531,7 @@ func DoAppVersionAction(versionId string, request *ActionRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetAppVersionFiles(versionId string, request *GetAppVersionFilesRequest) (*GetAppVersionPackageFilesResponse, error) {
|
||||
func GetAppVersionFiles(versionId string, request *types.GetAppVersionFilesRequest) (*types.GetAppVersionPackageFilesResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -548,7 +550,7 @@ func GetAppVersionFiles(versionId string, request *GetAppVersionFilesRequest) (*
|
||||
return nil, err
|
||||
}
|
||||
|
||||
version := &GetAppVersionPackageFilesResponse{
|
||||
version := &types.GetAppVersionPackageFilesResponse{
|
||||
VersionId: versionId,
|
||||
}
|
||||
|
||||
@@ -600,7 +602,7 @@ func ListAppVersionAudits(conditions *params.Conditions, orderBy string, reverse
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.AppVersionAuditSet {
|
||||
appVersion := convertAppVersionAudit(item)
|
||||
appVersion := utils.ConvertAppVersionAudit(item)
|
||||
items = append(items, appVersion)
|
||||
}
|
||||
|
||||
@@ -640,7 +642,7 @@ func ListAppVersionReviews(conditions *params.Conditions, orderBy string, revers
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.AppVersionReviewSet {
|
||||
appVersion := convertAppVersionReview(item)
|
||||
appVersion := utils.ConvertAppVersionReview(item)
|
||||
items = append(items, appVersion)
|
||||
}
|
||||
|
||||
@@ -682,7 +684,7 @@ func ListAppVersions(conditions *params.Conditions, orderBy string, reverse bool
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.AppVersionSet {
|
||||
appVersion := convertAppVersion(item)
|
||||
appVersion := utils.ConvertAppVersion(item)
|
||||
items = append(items, appVersion)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
package openpitrix
|
||||
package application
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -32,6 +32,8 @@ import (
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/constants"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/utils"
|
||||
"kubesphere.io/kubesphere/pkg/server/params"
|
||||
cs "kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||
@@ -42,8 +44,8 @@ import (
|
||||
type Interface interface {
|
||||
List(conditions *params.Conditions, limit, offset int, orderBy string, reverse bool) (*models.PageableResponse, error)
|
||||
Get(namespace, clusterID string) (*Application, error)
|
||||
Create(namespace string, request CreateClusterRequest) error
|
||||
Patch(request ModifyClusterAttributesRequest) error
|
||||
Create(namespace string, request types.CreateClusterRequest) error
|
||||
Patch(request types.ModifyClusterAttributesRequest) error
|
||||
Delete(id string) error
|
||||
}
|
||||
|
||||
@@ -61,9 +63,9 @@ func NewApplicaitonOperator(informers informers.SharedInformerFactory, client pb
|
||||
|
||||
type Application struct {
|
||||
Name string `json:"name" description:"application name"`
|
||||
Cluster *Cluster `json:"cluster,omitempty" description:"application cluster info"`
|
||||
Version *AppVersion `json:"version,omitempty" description:"application template version info"`
|
||||
App *App `json:"app,omitempty" description:"application template info"`
|
||||
Cluster *types.Cluster `json:"cluster,omitempty" description:"application cluster info"`
|
||||
Version *types.AppVersion `json:"version,omitempty" description:"application template version info"`
|
||||
App *types.App `json:"app,omitempty" description:"application template info"`
|
||||
WorkLoads *workLoads `json:"workloads,omitempty" description:"application workloads"`
|
||||
Services []v1.Service `json:"services,omitempty" description:"application services"`
|
||||
Ingresses []v1beta1.Ingress `json:"ingresses,omitempty" description:"application ingresses"`
|
||||
@@ -130,14 +132,14 @@ func (c *applicationOperator) describeApplication(cluster *pb.Cluster) (*Applica
|
||||
}
|
||||
var app Application
|
||||
app.Name = cluster.Name.Value
|
||||
app.Cluster = convertCluster(cluster)
|
||||
app.Cluster = utils.ConvertCluster(cluster)
|
||||
versionInfo, err := op.App().DescribeAppVersions(openpitrix.SystemContext(), &pb.DescribeAppVersionsRequest{VersionId: []string{cluster.GetVersionId().GetValue()}})
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
if len(versionInfo.AppVersionSet) > 0 {
|
||||
app.Version = convertAppVersion(versionInfo.AppVersionSet[0])
|
||||
app.Version = utils.ConvertAppVersion(versionInfo.AppVersionSet[0])
|
||||
}
|
||||
appInfo, err := op.App().DescribeApps(openpitrix.SystemContext(), &pb.DescribeAppsRequest{AppId: []string{cluster.GetAppId().GetValue()}, Limit: 1})
|
||||
if err != nil {
|
||||
@@ -145,7 +147,7 @@ func (c *applicationOperator) describeApplication(cluster *pb.Cluster) (*Applica
|
||||
return nil, err
|
||||
}
|
||||
if len(appInfo.AppSet) > 0 {
|
||||
app.App = convertApp(appInfo.GetAppSet()[0])
|
||||
app.App = utils.ConvertApp(appInfo.GetAppSet()[0])
|
||||
}
|
||||
return &app, nil
|
||||
}
|
||||
@@ -350,7 +352,7 @@ func (c *applicationOperator) getIng(namespace string, services []v1.Service) []
|
||||
return ings
|
||||
}
|
||||
|
||||
func (c *applicationOperator) Create(namespace string, request CreateClusterRequest) error {
|
||||
func (c *applicationOperator) Create(namespace string, request types.CreateClusterRequest) error {
|
||||
ns, err := c.informers.Core().V1().Namespaces().Lister().Get(namespace)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -385,7 +387,7 @@ func (c *applicationOperator) Create(namespace string, request CreateClusterRequ
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *applicationOperator) Patch(request ModifyClusterAttributesRequest) error {
|
||||
func (c *applicationOperator) Patch(request types.ModifyClusterAttributesRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
@@ -16,18 +16,20 @@
|
||||
* /
|
||||
*/
|
||||
|
||||
package openpitrix
|
||||
package attachment
|
||||
|
||||
import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/utils"
|
||||
cs "kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||
"openpitrix.io/openpitrix/pkg/pb"
|
||||
)
|
||||
|
||||
func DescribeAttachment(id string) (*Attachment, error) {
|
||||
func DescribeAttachment(id string) (*types.Attachment, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -41,7 +43,7 @@ func DescribeAttachment(id string) (*Attachment, error) {
|
||||
return nil, err
|
||||
}
|
||||
if len(resp.Attachments) > 0 {
|
||||
return convertAttachment(resp.Attachments[id]), nil
|
||||
return utils.ConvertAttachment(resp.Attachments[id]), nil
|
||||
} else {
|
||||
err := status.New(codes.NotFound, "resource not found").Err()
|
||||
klog.Error(err)
|
||||
@@ -16,7 +16,7 @@
|
||||
* /
|
||||
*/
|
||||
|
||||
package openpitrix
|
||||
package category
|
||||
|
||||
import (
|
||||
"github.com/golang/protobuf/ptypes/wrappers"
|
||||
@@ -24,13 +24,15 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/utils"
|
||||
"kubesphere.io/kubesphere/pkg/server/params"
|
||||
cs "kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||
"openpitrix.io/openpitrix/pkg/pb"
|
||||
)
|
||||
|
||||
func CreateCategory(request *CreateCategoryRequest) (*CreateCategoryResponse, error) {
|
||||
func CreateCategory(request *types.CreateCategoryRequest) (*types.CreateCategoryResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -50,7 +52,7 @@ func CreateCategory(request *CreateCategoryRequest) (*CreateCategoryResponse, er
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
return &CreateCategoryResponse{
|
||||
return &types.CreateCategoryResponse{
|
||||
CategoryId: resp.GetCategoryId().GetValue(),
|
||||
}, nil
|
||||
}
|
||||
@@ -71,7 +73,7 @@ func DeleteCategory(id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func PatchCategory(id string, request *ModifyCategoryRequest) error {
|
||||
func PatchCategory(id string, request *types.ModifyCategoryRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -101,7 +103,7 @@ func PatchCategory(id string, request *ModifyCategoryRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DescribeCategory(id string) (*Category, error) {
|
||||
func DescribeCategory(id string) (*types.Category, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -116,10 +118,10 @@ func DescribeCategory(id string) (*Category, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var category *Category
|
||||
var category *types.Category
|
||||
|
||||
if len(resp.CategorySet) > 0 {
|
||||
category = convertCategory(resp.CategorySet[0])
|
||||
category = utils.ConvertCategory(resp.CategorySet[0])
|
||||
return category, nil
|
||||
} else {
|
||||
err := status.New(codes.NotFound, "resource not found").Err()
|
||||
@@ -156,7 +158,7 @@ func ListCategories(conditions *params.Conditions, orderBy string, reverse bool,
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.CategorySet {
|
||||
items = append(items, convertCategory(item))
|
||||
items = append(items, utils.ConvertCategory(item))
|
||||
}
|
||||
|
||||
return &models.PageableResponse{Items: items, TotalCount: int(resp.TotalCount)}, nil
|
||||
@@ -16,7 +16,7 @@
|
||||
* /
|
||||
*/
|
||||
|
||||
package openpitrix
|
||||
package repo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -25,6 +25,8 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/utils"
|
||||
"kubesphere.io/kubesphere/pkg/server/params"
|
||||
cs "kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||
@@ -32,7 +34,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func CreateRepo(request *CreateRepoRequest) (*CreateRepoResponse, error) {
|
||||
func CreateRepo(request *types.CreateRepoRequest) (*types.CreateRepoResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -61,7 +63,7 @@ func CreateRepo(request *CreateRepoRequest) (*CreateRepoResponse, error) {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
return &CreateRepoResponse{
|
||||
return &types.CreateRepoResponse{
|
||||
RepoID: resp.GetRepoId().GetValue(),
|
||||
}, nil
|
||||
}
|
||||
@@ -82,7 +84,7 @@ func DeleteRepo(id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func PatchRepo(id string, request *ModifyRepoRequest) error {
|
||||
func PatchRepo(id string, request *types.ModifyRepoRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -132,7 +134,7 @@ func PatchRepo(id string, request *ModifyRepoRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DescribeRepo(id string) (*Repo, error) {
|
||||
func DescribeRepo(id string) (*types.Repo, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -147,10 +149,10 @@ func DescribeRepo(id string) (*Repo, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var repo *Repo
|
||||
var repo *types.Repo
|
||||
|
||||
if len(resp.RepoSet) > 0 {
|
||||
repo = convertRepo(resp.RepoSet[0])
|
||||
repo = utils.ConvertRepo(resp.RepoSet[0])
|
||||
return repo, nil
|
||||
} else {
|
||||
err := status.New(codes.NotFound, "resource not found").Err()
|
||||
@@ -202,13 +204,13 @@ func ListRepos(conditions *params.Conditions, orderBy string, reverse bool, limi
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.RepoSet {
|
||||
items = append(items, convertRepo(item))
|
||||
items = append(items, utils.ConvertRepo(item))
|
||||
}
|
||||
|
||||
return &models.PageableResponse{Items: items, TotalCount: int(resp.TotalCount)}, nil
|
||||
}
|
||||
|
||||
func ValidateRepo(request *ValidateRepoRequest) (*ValidateRepoResponse, error) {
|
||||
func ValidateRepo(request *types.ValidateRepoRequest) (*types.ValidateRepoResponse, error) {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
@@ -227,13 +229,13 @@ func ValidateRepo(request *ValidateRepoRequest) (*ValidateRepoResponse, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ValidateRepoResponse{
|
||||
return &types.ValidateRepoResponse{
|
||||
ErrorCode: int64(resp.ErrorCode),
|
||||
Ok: resp.Ok.Value,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func DoRepoAction(repoId string, request *RepoActionRequest) error {
|
||||
func DoRepoAction(repoId string, request *types.RepoActionRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -289,7 +291,7 @@ func ListRepoEvents(repoId string, conditions *params.Conditions, limit, offset
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.RepoEventSet {
|
||||
items = append(items, convertRepoEvent(item))
|
||||
items = append(items, utils.ConvertRepoEvent(item))
|
||||
}
|
||||
|
||||
return &models.PageableResponse{Items: items, TotalCount: int(resp.TotalCount)}, nil
|
||||
@@ -1,4 +1,4 @@
|
||||
package openpitrix
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/go-openapi/strfmt"
|
||||
@@ -16,28 +16,29 @@
|
||||
* /
|
||||
*/
|
||||
|
||||
package openpitrix
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/go-openapi/strfmt"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"openpitrix.io/openpitrix/pkg/pb"
|
||||
"time"
|
||||
)
|
||||
|
||||
func convertApp(in *pb.App) *App {
|
||||
func ConvertApp(in *pb.App) *types.App {
|
||||
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
categorySet := make(AppCategorySet, 0)
|
||||
categorySet := make(types.AppCategorySet, 0)
|
||||
|
||||
for _, item := range in.CategorySet {
|
||||
category := convertResourceCategory(item)
|
||||
category := ConvertResourceCategory(item)
|
||||
categorySet = append(categorySet, category)
|
||||
}
|
||||
|
||||
out := App{
|
||||
out := types.App{
|
||||
CategorySet: categorySet,
|
||||
}
|
||||
|
||||
@@ -92,7 +93,7 @@ func convertApp(in *pb.App) *App {
|
||||
out.Keywords = in.Keywords.Value
|
||||
}
|
||||
if in.LatestAppVersion != nil {
|
||||
out.LatestAppVersion = convertAppVersion(in.LatestAppVersion)
|
||||
out.LatestAppVersion = ConvertAppVersion(in.LatestAppVersion)
|
||||
}
|
||||
if in.Name != nil {
|
||||
out.Name = in.Name.Value
|
||||
@@ -130,11 +131,11 @@ func convertApp(in *pb.App) *App {
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertAppVersion(in *pb.AppVersion) *AppVersion {
|
||||
func ConvertAppVersion(in *pb.AppVersion) *types.AppVersion {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := AppVersion{}
|
||||
out := types.AppVersion{}
|
||||
if in.AppId != nil {
|
||||
out.AppId = in.AppId.Value
|
||||
}
|
||||
@@ -209,11 +210,11 @@ func convertAppVersion(in *pb.AppVersion) *AppVersion {
|
||||
|
||||
}
|
||||
|
||||
func convertResourceCategory(in *pb.ResourceCategory) *ResourceCategory {
|
||||
func ConvertResourceCategory(in *pb.ResourceCategory) *types.ResourceCategory {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := ResourceCategory{}
|
||||
out := types.ResourceCategory{}
|
||||
|
||||
if in.CategoryId != nil {
|
||||
out.CategoryId = in.CategoryId.Value
|
||||
@@ -239,11 +240,11 @@ func convertResourceCategory(in *pb.ResourceCategory) *ResourceCategory {
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertCategory(in *pb.Category) *Category {
|
||||
func ConvertCategory(in *pb.Category) *types.Category {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := Category{}
|
||||
out := types.Category{}
|
||||
|
||||
if in.CategoryId != nil {
|
||||
out.CategoryID = in.CategoryId.Value
|
||||
@@ -275,11 +276,11 @@ func convertCategory(in *pb.Category) *Category {
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertAttachment(in *pb.Attachment) *Attachment {
|
||||
func ConvertAttachment(in *pb.Attachment) *types.Attachment {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := Attachment{}
|
||||
out := types.Attachment{}
|
||||
|
||||
out.AttachmentID = in.AttachmentId
|
||||
|
||||
@@ -297,11 +298,11 @@ func convertAttachment(in *pb.Attachment) *Attachment {
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertRepo(in *pb.Repo) *Repo {
|
||||
func ConvertRepo(in *pb.Repo) *types.Repo {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := Repo{}
|
||||
out := types.Repo{}
|
||||
|
||||
if in.RepoId != nil {
|
||||
out.RepoId = in.RepoId.Value
|
||||
@@ -316,10 +317,10 @@ func convertRepo(in *pb.Repo) *Repo {
|
||||
out.Credential = in.Credential.Value
|
||||
}
|
||||
|
||||
categorySet := make(RepoCategorySet, 0)
|
||||
categorySet := make(types.RepoCategorySet, 0)
|
||||
|
||||
for _, item := range in.CategorySet {
|
||||
category := convertResourceCategory(item)
|
||||
category := ConvertResourceCategory(item)
|
||||
categorySet = append(categorySet, category)
|
||||
}
|
||||
|
||||
@@ -338,10 +339,10 @@ func convertRepo(in *pb.Repo) *Repo {
|
||||
out.Description = in.Description.Value
|
||||
}
|
||||
|
||||
labelSet := make(RepoLabels, 0)
|
||||
labelSet := make(types.RepoLabels, 0)
|
||||
|
||||
for _, item := range in.Labels {
|
||||
label := convertRepoLabel(item)
|
||||
label := ConvertRepoLabel(item)
|
||||
labelSet = append(labelSet, label)
|
||||
}
|
||||
|
||||
@@ -357,10 +358,10 @@ func convertRepo(in *pb.Repo) *Repo {
|
||||
out.RepoId = in.RepoId.Value
|
||||
}
|
||||
|
||||
selectorSet := make(RepoSelectors, 0)
|
||||
selectorSet := make(types.RepoSelectors, 0)
|
||||
|
||||
for _, item := range in.Selectors {
|
||||
selector := convertRepoSelector(item)
|
||||
selector := ConvertRepoSelector(item)
|
||||
selectorSet = append(selectorSet, selector)
|
||||
}
|
||||
|
||||
@@ -384,11 +385,11 @@ func convertRepo(in *pb.Repo) *Repo {
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertRepoLabel(in *pb.RepoLabel) *RepoLabel {
|
||||
func ConvertRepoLabel(in *pb.RepoLabel) *types.RepoLabel {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := RepoLabel{}
|
||||
out := types.RepoLabel{}
|
||||
if in.CreateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CreateTime.Seconds, 0))
|
||||
out.CreateTime = &date
|
||||
@@ -402,11 +403,11 @@ func convertRepoLabel(in *pb.RepoLabel) *RepoLabel {
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertRepoSelector(in *pb.RepoSelector) *RepoSelector {
|
||||
func ConvertRepoSelector(in *pb.RepoSelector) *types.RepoSelector {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := RepoSelector{}
|
||||
out := types.RepoSelector{}
|
||||
if in.CreateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CreateTime.Seconds, 0))
|
||||
out.CreateTime = &date
|
||||
@@ -420,11 +421,11 @@ func convertRepoSelector(in *pb.RepoSelector) *RepoSelector {
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertAppVersionAudit(in *pb.AppVersionAudit) *AppVersionAudit {
|
||||
func ConvertAppVersionAudit(in *pb.AppVersionAudit) *types.AppVersionAudit {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := AppVersionAudit{}
|
||||
out := types.AppVersionAudit{}
|
||||
if in.AppId != nil {
|
||||
out.AppId = in.AppId.Value
|
||||
}
|
||||
@@ -462,11 +463,11 @@ func convertAppVersionAudit(in *pb.AppVersionAudit) *AppVersionAudit {
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertAppVersionReview(in *pb.AppVersionReview) *AppVersionReview {
|
||||
func ConvertAppVersionReview(in *pb.AppVersionReview) *types.AppVersionReview {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := AppVersionReview{}
|
||||
out := types.AppVersionReview{}
|
||||
if in.AppId != nil {
|
||||
out.AppId = in.AppId.Value
|
||||
}
|
||||
@@ -474,9 +475,9 @@ func convertAppVersionReview(in *pb.AppVersionReview) *AppVersionReview {
|
||||
out.AppName = in.AppName.Value
|
||||
}
|
||||
if in.Phase != nil {
|
||||
out.Phase = make(AppVersionReviewPhaseOAIGen)
|
||||
out.Phase = make(types.AppVersionReviewPhaseOAIGen)
|
||||
for k, v := range in.Phase {
|
||||
out.Phase[k] = *convertAppVersionReviewPhase(v)
|
||||
out.Phase[k] = *ConvertAppVersionReviewPhase(v)
|
||||
}
|
||||
}
|
||||
if in.ReviewId != nil {
|
||||
@@ -503,11 +504,11 @@ func convertAppVersionReview(in *pb.AppVersionReview) *AppVersionReview {
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertAppVersionReviewPhase(in *pb.AppVersionReviewPhase) *AppVersionReviewPhase {
|
||||
func ConvertAppVersionReviewPhase(in *pb.AppVersionReviewPhase) *types.AppVersionReviewPhase {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := AppVersionReviewPhase{}
|
||||
out := types.AppVersionReviewPhase{}
|
||||
if in.Message != nil {
|
||||
out.Message = in.Message.Value
|
||||
}
|
||||
@@ -531,11 +532,11 @@ func convertAppVersionReviewPhase(in *pb.AppVersionReviewPhase) *AppVersionRevie
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertRepoEvent(in *pb.RepoEvent) *RepoEvent {
|
||||
func ConvertRepoEvent(in *pb.RepoEvent) *types.RepoEvent {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := RepoEvent{}
|
||||
out := types.RepoEvent{}
|
||||
if in.CreateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CreateTime.Seconds, 0))
|
||||
out.CreateTime = &date
|
||||
@@ -563,11 +564,11 @@ func convertRepoEvent(in *pb.RepoEvent) *RepoEvent {
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertCluster(in *pb.Cluster) *Cluster {
|
||||
func ConvertCluster(in *pb.Cluster) *types.Cluster {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := Cluster{}
|
||||
out := types.Cluster{}
|
||||
if in.AdditionalInfo != nil {
|
||||
out.AdditionalInfo = in.AdditionalInfo.Value
|
||||
}
|
||||
@@ -132,9 +132,7 @@ func (s *appSearcher) Search(namespace string, conditions *params.Conditions, or
|
||||
}
|
||||
sort.Slice(result, func(i, j int) bool {
|
||||
if reverse {
|
||||
tmp := i
|
||||
i = j
|
||||
j = tmp
|
||||
i, j = j, i
|
||||
}
|
||||
return s.compare(result[i], result[j], orderBy)
|
||||
})
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/client-go/informers"
|
||||
"kubesphere.io/kubesphere/pkg/api"
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/query"
|
||||
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3"
|
||||
"strings"
|
||||
@@ -46,26 +48,26 @@ func New(sharedInformers informers.SharedInformerFactory) v1alpha3.Interface {
|
||||
return &deploymentsGetter{sharedInformers: sharedInformers}
|
||||
}
|
||||
|
||||
func (d *deploymentsGetter) Get(namespace, name string) (interface{}, error) {
|
||||
func (d *deploymentsGetter) Get(namespace, name string) (runtime.Object, error) {
|
||||
return d.sharedInformers.Apps().V1().Deployments().Lister().Deployments(namespace).Get(name)
|
||||
}
|
||||
|
||||
func (d *deploymentsGetter) List(namespace string) ([]interface{}, error) {
|
||||
func (d *deploymentsGetter) List(namespace string, query *query.Query) (*api.ListResult, error) {
|
||||
// first retrieves all deployments within given namespace
|
||||
all, err := d.sharedInformers.Apps().V1().Deployments().Lister().Deployments(namespace).List(labels.Everything())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result []interface{}
|
||||
var result []runtime.Object
|
||||
for _, deploy := range all {
|
||||
result = append(result, deploy)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
return v1alpha3.DefaultList(result, query, d.compare, d.filter), nil
|
||||
}
|
||||
|
||||
func (d *deploymentsGetter) Compare(left interface{}, right interface{}, field query.Field) bool {
|
||||
func (d *deploymentsGetter) compare(left runtime.Object, right runtime.Object, field query.Field) bool {
|
||||
|
||||
leftDeployment, ok := left.(*v1.Deployment)
|
||||
if !ok {
|
||||
@@ -89,7 +91,7 @@ func (d *deploymentsGetter) Compare(left interface{}, right interface{}, field q
|
||||
}
|
||||
}
|
||||
|
||||
func (d *deploymentsGetter) Filter(object interface{}, filter query.Filter) bool {
|
||||
func (d *deploymentsGetter) filter(object runtime.Object, filter query.Filter) bool {
|
||||
deployment, ok := object.(*v1.Deployment)
|
||||
if !ok {
|
||||
return false
|
||||
|
||||
@@ -125,7 +125,6 @@ func TestListDeployments(t *testing.T) {
|
||||
t.Run(test.description, func(t *testing.T) {
|
||||
objs := deploymentsToRuntimeObjects(test.deployments...)
|
||||
client := fake.NewSimpleClientset(objs...)
|
||||
//client := fake.NewSimpleClientset()
|
||||
|
||||
informer := informers.NewSharedInformerFactory(client, 0)
|
||||
|
||||
|
||||
@@ -1,19 +1,67 @@
|
||||
package v1alpha3
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"kubesphere.io/kubesphere/pkg/api"
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/query"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type Interface interface {
|
||||
// Get retrieves a single object by its namespace and name
|
||||
Get(namespace, name string) (interface{}, error)
|
||||
Get(namespace, name string) (runtime.Object, error)
|
||||
|
||||
// List retrieves a collection of objects matches given query
|
||||
List(namespace string) ([]interface{}, error)
|
||||
|
||||
//
|
||||
Filter(item interface{}, filter query.Filter) bool
|
||||
|
||||
//
|
||||
Compare(left interface{}, right interface{}, field query.Field) bool
|
||||
List(namespace string, query *query.Query) (*api.ListResult, error)
|
||||
}
|
||||
|
||||
type CompareFunc func(runtime.Object, runtime.Object, query.Field) bool
|
||||
|
||||
type FilterFunc func(runtime.Object, query.Filter) bool
|
||||
|
||||
func DefaultList(objects []runtime.Object, query *query.Query, compareFunc CompareFunc, filterFunc FilterFunc) *api.ListResult {
|
||||
// selected matched ones
|
||||
var filtered []runtime.Object
|
||||
for _, object := range objects {
|
||||
selected := true
|
||||
for _, filter := range query.Filters {
|
||||
if !filterFunc(object, filter) {
|
||||
selected = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if selected {
|
||||
filtered = append(filtered, object)
|
||||
}
|
||||
}
|
||||
|
||||
start, end := query.Pagination.GetPaginationSettings(len(filtered))
|
||||
if !query.Pagination.IsPageAvailable(len(filtered), start) {
|
||||
return &api.ListResult{
|
||||
Items: nil,
|
||||
TotalItems: 0,
|
||||
}
|
||||
}
|
||||
|
||||
// sort by sortBy field
|
||||
sort.Slice(filtered, func(i, j int) bool {
|
||||
if !query.Ascending {
|
||||
return !compareFunc(filtered[i], filtered[j], query.SortBy)
|
||||
}
|
||||
return compareFunc(filtered[i], filtered[j], query.SortBy)
|
||||
})
|
||||
|
||||
return &api.ListResult{
|
||||
Items: objectsToInterfaces(filtered[start:end]),
|
||||
TotalItems: len(filtered),
|
||||
}
|
||||
}
|
||||
|
||||
func objectsToInterfaces(objs []runtime.Object) []interface{} {
|
||||
var res []interface{}
|
||||
for _, obj := range objs {
|
||||
res = append(res, obj)
|
||||
}
|
||||
return res
|
||||
}
|
||||
75
pkg/models/resources/v1alpha3/namespace/namespaces.go
Normal file
75
pkg/models/resources/v1alpha3/namespace/namespaces.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package namespace
|
||||
|
||||
import (
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/client-go/informers"
|
||||
"kubesphere.io/kubesphere/pkg/api"
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/query"
|
||||
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type namespaceGetter struct {
|
||||
informers informers.SharedInformerFactory
|
||||
}
|
||||
|
||||
func NewNamespaceGetter(informers informers.SharedInformerFactory) v1alpha3.Interface {
|
||||
return &namespaceGetter{informers:informers}
|
||||
}
|
||||
|
||||
func (n namespaceGetter) Get(_, name string) (runtime.Object, error) {
|
||||
return n.informers.Core().V1().Namespaces().Lister().Get(name)
|
||||
}
|
||||
|
||||
func (n namespaceGetter) List(_ string, query *query.Query) (*api.ListResult, error) {
|
||||
ns, err := n.informers.Core().V1().Namespaces().Lister().List(labels.Everything())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result []runtime.Object
|
||||
for _, item := range ns {
|
||||
result = append(result, item)
|
||||
}
|
||||
|
||||
return v1alpha3.DefaultList(result, query, n.compare, n.filter), nil
|
||||
}
|
||||
|
||||
func (n namespaceGetter) filter(item runtime.Object, filter query.Filter) bool {
|
||||
namespace, ok := item.(*v1.Namespace)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
switch filter.Field {
|
||||
case query.FieldName:
|
||||
return query.ComparableString(namespace.Name).Contains(filter.Value)
|
||||
case query.FieldStatus:
|
||||
return query.ComparableString(namespace.Status.Phase).Compare(filter.Value) == 0
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (n namespaceGetter) compare(left runtime.Object, right runtime.Object, field query.Field) bool {
|
||||
leftNs, ok := left.(*v1.Namespace)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
rightNs, ok := right.(*v1.Namespace)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
|
||||
switch field {
|
||||
case query.FieldName:
|
||||
return strings.Compare(leftNs.Name, rightNs.Name) > 0
|
||||
case query.FieldCreationTimeStamp:
|
||||
return leftNs.CreationTimestamp.After(rightNs.CreationTimestamp.Time)
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package namespace
|
||||
@@ -3,12 +3,11 @@ package resource
|
||||
import (
|
||||
"errors"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/informers"
|
||||
"kubesphere.io/kubesphere/pkg/api"
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/query"
|
||||
"kubesphere.io/kubesphere/pkg/informers"
|
||||
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3"
|
||||
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3/deployment"
|
||||
"sort"
|
||||
)
|
||||
|
||||
var ErrResourceNotSupported = errors.New("resource is not supported")
|
||||
@@ -17,10 +16,10 @@ type NamespacedResourceGetter struct {
|
||||
getters map[schema.GroupVersionResource]v1alpha3.Interface
|
||||
}
|
||||
|
||||
func New(informers informers.SharedInformerFactory) *NamespacedResourceGetter {
|
||||
func New(factory informers.InformerFactory) *NamespacedResourceGetter {
|
||||
getters := make(map[schema.GroupVersionResource]v1alpha3.Interface)
|
||||
|
||||
getters[schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"}] = deployment.New(informers)
|
||||
getters[schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"}] = deployment.New(factory.KubernetesSharedInformerFactory())
|
||||
|
||||
return &NamespacedResourceGetter{
|
||||
getters: getters,
|
||||
@@ -54,45 +53,6 @@ func (r *NamespacedResourceGetter) List(resource, namespace string, query *query
|
||||
return nil, ErrResourceNotSupported
|
||||
}
|
||||
|
||||
all, err := getter.List(namespace)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return getter.List(namespace, query)
|
||||
|
||||
// selected matched ones
|
||||
var filtered []interface{}
|
||||
for _, deploy := range all {
|
||||
for _, filter := range query.Filters {
|
||||
if getter.Filter(deploy, filter) {
|
||||
filtered = append(filtered, deploy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sort
|
||||
sort.Slice(filtered, func(i, j int) bool {
|
||||
if !query.Ascending {
|
||||
return !getter.Compare(filtered[i], filtered[j], query.SortBy)
|
||||
}
|
||||
return getter.Compare(filtered[i], filtered[j], query.SortBy)
|
||||
})
|
||||
|
||||
start, end := query.Pagination.GetPaginationSettings(len(filtered))
|
||||
if query.Pagination.IsPageAvailable(len(filtered), start) {
|
||||
var result []interface{}
|
||||
|
||||
for i := start; i < end; i++ {
|
||||
result = append(result, filtered[i])
|
||||
}
|
||||
|
||||
return &api.ListResult{
|
||||
Items: result,
|
||||
TotalItems: len(filtered),
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &api.ListResult{
|
||||
Items: nil,
|
||||
TotalItems: len(filtered),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -24,10 +24,11 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
"io"
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/remotecommand"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -134,15 +135,23 @@ func (t TerminalSession) Close(status uint32, reason string) {
|
||||
t.conn.Close()
|
||||
}
|
||||
|
||||
type Interface interface {
|
||||
HandleSession(shell, namespace, podName, containerName string, conn *websocket.Conn)
|
||||
}
|
||||
|
||||
type terminaler struct {
|
||||
client kubernetes.Interface
|
||||
config *rest.Config
|
||||
}
|
||||
|
||||
func NewTerminaler(client kubernetes.Interface, config *rest.Config) Interface {
|
||||
return &terminaler{client:client, config:config}
|
||||
}
|
||||
|
||||
// startProcess is called by handleAttach
|
||||
// Executed cmd in the container specified in request and connects it up with the ptyHandler (a session)
|
||||
func startProcess(namespace, podName, containerName string, cmd []string, ptyHandler PtyHandler) error {
|
||||
|
||||
k8sClient := client.ClientSets().K8s().Kubernetes()
|
||||
|
||||
cfg := client.ClientSets().K8s().Config()
|
||||
|
||||
req := k8sClient.CoreV1().RESTClient().Post().
|
||||
func (t *terminaler)startProcess(namespace, podName, containerName string, cmd []string, ptyHandler PtyHandler) error {
|
||||
req := t.client.CoreV1().RESTClient().Post().
|
||||
Resource("pods").
|
||||
Name(podName).
|
||||
Namespace(namespace).
|
||||
@@ -156,7 +165,7 @@ func startProcess(namespace, podName, containerName string, cmd []string, ptyHan
|
||||
TTY: true,
|
||||
}, scheme.ParameterCodec)
|
||||
|
||||
exec, err := remotecommand.NewSPDYExecutor(cfg, "POST", req.URL())
|
||||
exec, err := remotecommand.NewSPDYExecutor(t.config, "POST", req.URL())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -185,8 +194,7 @@ func isValidShell(validShells []string, shell string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func HandleSession(shell, namespace, podName, containerName string, conn *websocket.Conn) {
|
||||
|
||||
func (t *terminaler)HandleSession(shell, namespace, podName, containerName string, conn *websocket.Conn) {
|
||||
var err error
|
||||
validShells := []string{"sh", "bash"}
|
||||
|
||||
@@ -194,13 +202,13 @@ func HandleSession(shell, namespace, podName, containerName string, conn *websoc
|
||||
|
||||
if isValidShell(validShells, shell) {
|
||||
cmd := []string{shell}
|
||||
err = startProcess(namespace, podName, containerName, cmd, session)
|
||||
err = t.startProcess(namespace, podName, containerName, cmd, session)
|
||||
} else {
|
||||
// No shell given or it was not valid: try some shells until one succeeds or all fail
|
||||
// FIXME: if the first shell fails then the first keyboard event is lost
|
||||
for _, testShell := range validShells {
|
||||
cmd := []string{testShell}
|
||||
if err = startProcess(namespace, podName, containerName, cmd, session); err == nil {
|
||||
if err = t.startProcess(namespace, podName, containerName, cmd, session); err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
39
pkg/simple/client/cache/cache.go
vendored
39
pkg/simple/client/cache/cache.go
vendored
@@ -20,41 +20,4 @@ type Interface interface {
|
||||
|
||||
// Expires updates object's expiration time, return err if key doesn't exist
|
||||
Expire(key string, duration time.Duration) error
|
||||
}
|
||||
|
||||
type simpleObject struct {
|
||||
value string
|
||||
expire time.Time
|
||||
}
|
||||
|
||||
type SimpleCache struct {
|
||||
store map[string]simpleObject
|
||||
}
|
||||
|
||||
func NewSimpleCache() Interface {
|
||||
return &SimpleCache{store: make(map[string]simpleObject)}
|
||||
}
|
||||
|
||||
func (s *SimpleCache) Keys(pattern string) ([]string, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (s *SimpleCache) Set(key string, value string, duration time.Duration) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (s *SimpleCache) Del(key string) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (s *SimpleCache) Get(key string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (s *SimpleCache) Exists(key string) (bool, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (s *SimpleCache) Expire(key string, duration time.Duration) error {
|
||||
panic("implement me")
|
||||
}
|
||||
}
|
||||
40
pkg/simple/client/cache/simple_cache.go
vendored
Normal file
40
pkg/simple/client/cache/simple_cache.go
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
package cache
|
||||
|
||||
import "time"
|
||||
|
||||
type simpleObject struct {
|
||||
value string
|
||||
expire time.Time
|
||||
}
|
||||
|
||||
type SimpleCache struct {
|
||||
store map[string]simpleObject
|
||||
}
|
||||
|
||||
func NewSimpleCache() Interface {
|
||||
return &SimpleCache{store: make(map[string]simpleObject)}
|
||||
}
|
||||
|
||||
func (s *SimpleCache) Keys(pattern string) ([]string, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (s *SimpleCache) Set(key string, value string, duration time.Duration) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (s *SimpleCache) Del(key string) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (s *SimpleCache) Get(key string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (s *SimpleCache) Exists(key string) (bool, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (s *SimpleCache) Expire(key string, duration time.Duration) error {
|
||||
panic("implement me")
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package devops
|
||||
|
||||
type Job struct {
|
||||
|
||||
}
|
||||
|
||||
type Interface interface {
|
||||
|
||||
39
pkg/simple/client/monitoring/interface.go
Normal file
39
pkg/simple/client/monitoring/interface.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package monitoring
|
||||
|
||||
|
||||
type ClusterQuery struct {
|
||||
|
||||
}
|
||||
|
||||
type ClusterMetrics struct {
|
||||
|
||||
}
|
||||
|
||||
type WorkspaceQuery struct {
|
||||
|
||||
}
|
||||
|
||||
type WorkspaceMetrics struct {
|
||||
|
||||
}
|
||||
|
||||
type NamespaceQuery struct {
|
||||
|
||||
}
|
||||
|
||||
type NamespaceMetrics struct {
|
||||
|
||||
}
|
||||
|
||||
// Interface defines all the abstract behaviors of monitoring
|
||||
type Interface interface {
|
||||
|
||||
// Get
|
||||
GetClusterMetrics(query ClusterQuery) ClusterMetrics
|
||||
|
||||
//
|
||||
GetWorkspaceMetrics(query WorkspaceQuery) WorkspaceMetrics
|
||||
|
||||
//
|
||||
GetNamespaceMetrics(query NamespaceQuery) NamespaceMetrics
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package monitoring
|
||||
|
||||
type Interface interface {
|
||||
}
|
||||
31
pkg/simple/client/monitoring/prometheus.go
Normal file
31
pkg/simple/client/monitoring/prometheus.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// prometheus implements monitoring interface backed by Prometheus
|
||||
type prometheus struct {
|
||||
options *Options
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
func NewPrometheus(options *Options) Interface {
|
||||
return &prometheus{
|
||||
options:options,
|
||||
client: &http.Client{ Timeout: 10 * time.Second },
|
||||
}
|
||||
}
|
||||
|
||||
func (p prometheus) GetClusterMetrics(query ClusterQuery) ClusterMetrics {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (p prometheus) GetWorkspaceMetrics(query WorkspaceQuery) WorkspaceMetrics {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (p prometheus) GetNamespaceMetrics(query NamespaceQuery) NamespaceMetrics {
|
||||
panic("implement me")
|
||||
}
|
||||
41
pkg/simple/client/monitoring/prometheus_options.go
Normal file
41
pkg/simple/client/monitoring/prometheus_options.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint"`
|
||||
SecondaryEndpoint string `json:"secondaryEndpoint,omitempty" yaml:"secondaryEndpoint"`
|
||||
}
|
||||
|
||||
func NewPrometheusOptions() *Options {
|
||||
return &Options{
|
||||
Endpoint: "",
|
||||
SecondaryEndpoint: "",
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Options) Validate() []error {
|
||||
var errs []error
|
||||
return errs
|
||||
}
|
||||
|
||||
func (s *Options) ApplyTo(options *Options) {
|
||||
if s.Endpoint != "" {
|
||||
options.Endpoint = s.Endpoint
|
||||
}
|
||||
|
||||
if s.SecondaryEndpoint != "" {
|
||||
options.SecondaryEndpoint = s.SecondaryEndpoint
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Options) AddFlags(fs *pflag.FlagSet, c *Options) {
|
||||
fs.StringVar(&s.Endpoint, "prometheus-endpoint", c.Endpoint, ""+
|
||||
"Prometheus service endpoint which stores KubeSphere monitoring data, if left "+
|
||||
"blank, will use builtin metrics-server as data source.")
|
||||
|
||||
fs.StringVar(&s.SecondaryEndpoint, "prometheus-secondary-endpoint", c.SecondaryEndpoint, ""+
|
||||
"Prometheus secondary service endpoint, if left empty and endpoint is set, will use endpoint instead.")
|
||||
}
|
||||
1
pkg/simple/client/monitoring/prometheus_test.go
Normal file
1
pkg/simple/client/monitoring/prometheus_test.go
Normal file
@@ -0,0 +1 @@
|
||||
package monitoring
|
||||
@@ -27,8 +27,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Interface interface {
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
client *http.Client
|
||||
|
||||
@@ -54,32 +54,6 @@ func NewS3Client(options *Options) (Interface, error) {
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
// NewS3ClientOrDie creates Client and panics if there is an error
|
||||
func NewS3ClientOrDie(options *Options) Interface {
|
||||
cred := credentials.NewStaticCredentials(options.AccessKeyID, options.SecretAccessKey, options.SessionToken)
|
||||
|
||||
config := aws.Config{
|
||||
Region: aws.String(options.Region),
|
||||
Endpoint: aws.String(options.Endpoint),
|
||||
DisableSSL: aws.Bool(options.DisableSSL),
|
||||
S3ForcePathStyle: aws.Bool(options.ForcePathStyle),
|
||||
Credentials: cred,
|
||||
}
|
||||
|
||||
s, err := session.NewSession(&config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := s3.New(s)
|
||||
|
||||
return &Client{
|
||||
s3Client: client,
|
||||
s3Session: s,
|
||||
bucket: options.Bucket,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Client) Client() *s3.S3 {
|
||||
|
||||
return s.s3Client
|
||||
|
||||
Reference in New Issue
Block a user