devlopment branch (#1736)
This commit is contained in:
1
pkg/api/resource/resource.go
Normal file
1
pkg/api/resource/resource.go
Normal file
@@ -0,0 +1 @@
|
||||
package resource
|
||||
29
pkg/api/resource/v1alpha2/types.go
Normal file
29
pkg/api/resource/v1alpha2/types.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package v1alpha2
|
||||
|
||||
import "time"
|
||||
|
||||
// ComponentStatus represents system component status.
|
||||
type ComponentStatus struct {
|
||||
Name string `json:"name" description:"component name"`
|
||||
Namespace string `json:"namespace" description:"the name of the namespace"`
|
||||
SelfLink string `json:"selfLink" description:"self link"`
|
||||
Label interface{} `json:"label" description:"labels"`
|
||||
StartedAt time.Time `json:"startedAt" description:"started time"`
|
||||
TotalBackends int `json:"totalBackends" description:"the total replicas of each backend system component"`
|
||||
HealthyBackends int `json:"healthyBackends" description:"the number of healthy backend components"`
|
||||
}
|
||||
|
||||
// NodeStatus assembles cluster nodes status, simply wrap unhealthy and total nodes.
|
||||
type NodeStatus struct {
|
||||
// total nodes of cluster, including master nodes
|
||||
TotalNodes int `json:"totalNodes" description:"total number of nodes"`
|
||||
|
||||
// healthy nodes means nodes whose state is NodeReady
|
||||
HealthyNodes int `json:"healthyNodes" description:"the number of healthy nodes"`
|
||||
}
|
||||
|
||||
//
|
||||
type HealthStatus struct {
|
||||
KubeSphereComponents []ComponentStatus `json:"kubesphereStatus" description:"kubesphere components status"`
|
||||
NodeStatus NodeStatus `json:"nodeStatus" description:"nodes status"`
|
||||
}
|
||||
170
pkg/api/types.go
Normal file
170
pkg/api/types.go
Normal file
@@ -0,0 +1,170 @@
|
||||
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 {
|
||||
Items []interface{} `json:"items,omitempty"`
|
||||
TotalItems int `json:"totalItems,omitempty"`
|
||||
}
|
||||
|
||||
type ResourceQuota struct {
|
||||
Namespace string `json:"namespace" description:"namespace"`
|
||||
Data corev1.ResourceQuotaStatus `json:"data" description:"resource quota status"`
|
||||
}
|
||||
|
||||
type NamespacedResourceQuota struct {
|
||||
Namespace string `json:"namespace,omitempty"`
|
||||
|
||||
Data struct {
|
||||
corev1.ResourceQuotaStatus
|
||||
|
||||
// quota left status, do the math on the side, cause it's
|
||||
// a lot easier with go-client library
|
||||
Left corev1.ResourceList `json:"left,omitempty"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type Router struct {
|
||||
RouterType string `json:"type"`
|
||||
Annotations map[string]string `json:"annotations"`
|
||||
}
|
||||
|
||||
type GitCredential struct {
|
||||
RemoteUrl string `json:"remoteUrl" description:"git server url"`
|
||||
SecretRef *corev1.SecretReference `json:"secretRef,omitempty" description:"auth secret reference"`
|
||||
}
|
||||
|
||||
type RegistryCredential struct {
|
||||
Username string `json:"username" description:"username"`
|
||||
Password string `json:"password" description:"password"`
|
||||
ServerHost string `json:"serverhost" description:"registry server host"`
|
||||
}
|
||||
|
||||
type Workloads struct {
|
||||
Namespace string `json:"namespace" description:"the name of the namespace"`
|
||||
Count map[string]int `json:"data" description:"the number of unhealthy workloads"`
|
||||
Items map[string]interface{} `json:"items,omitempty" description:"unhealthy workloads"`
|
||||
}
|
||||
|
||||
type ClientType string
|
||||
|
||||
const (
|
||||
ClientKubernetes ClientType = "Kubernetes"
|
||||
ClientKubeSphere ClientType = "Kubesphere"
|
||||
ClientIstio ClientType = "Istio"
|
||||
ClientS2i ClientType = "S2i"
|
||||
ClientApplication ClientType = "Application"
|
||||
|
||||
StatusOK = "ok"
|
||||
)
|
||||
|
||||
var SupportedGroupVersionResources = map[ClientType][]schema.GroupVersionResource{
|
||||
// all supported kubernetes api objects
|
||||
ClientKubernetes: {
|
||||
{Group: "", Version: "v1", Resource: "namespaces"},
|
||||
{Group: "", Version: "v1", Resource: "nodes"},
|
||||
{Group: "", Version: "v1", Resource: "resourcequotas"},
|
||||
{Group: "", Version: "v1", Resource: "pods"},
|
||||
{Group: "", Version: "v1", Resource: "services"},
|
||||
{Group: "", Version: "v1", Resource: "persistentvolumeclaims"},
|
||||
{Group: "", Version: "v1", Resource: "secrets"},
|
||||
{Group: "", Version: "v1", Resource: "configmaps"},
|
||||
|
||||
{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "roles"},
|
||||
{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "rolebindings"},
|
||||
{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "clusterroles"},
|
||||
{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "clusterrolebindings"},
|
||||
|
||||
{Group: "apps", Version: "v1", Resource: "deployments"},
|
||||
{Group: "apps", Version: "v1", Resource: "daemonsets"},
|
||||
{Group: "apps", Version: "v1", Resource: "replicasets"},
|
||||
{Group: "apps", Version: "v1", Resource: "statefulsets"},
|
||||
{Group: "apps", Version: "v1", Resource: "controllerrevisions"},
|
||||
|
||||
{Group: "storage.k8s.io", Version: "v1", Resource: "storageclasses"},
|
||||
|
||||
{Group: "batch", Version: "v1", Resource: "jobs"},
|
||||
{Group: "batch", Version: "v1beta1", Resource: "cronjobs"},
|
||||
|
||||
{Group: "extensions", Version: "v1beta1", Resource: "ingresses"},
|
||||
|
||||
{Group: "autoscaling", Version: "v2beta2", Resource: "horizontalpodautoscalers"},
|
||||
},
|
||||
|
||||
// all supported kubesphere api objects
|
||||
ClientKubeSphere: {
|
||||
{Group: "tenant.kubesphere.io", Version: "v1alpha1", Resource: "workspaces"},
|
||||
{Group: "devops.kubesphere.io", Version: "v1alpha1", Resource: "s2ibinaries"},
|
||||
|
||||
{Group: "servicemesh.kubesphere.io", Version: "v1alpha2", Resource: "strategies"},
|
||||
{Group: "servicemesh.kubesphere.io", Version: "v1alpha2", Resource: "servicepolicies"},
|
||||
},
|
||||
|
||||
// all supported istio api objects
|
||||
ClientIstio: {},
|
||||
|
||||
// all supported s2i api objects
|
||||
// TODO: move s2i clientset into kubesphere
|
||||
ClientS2i: {
|
||||
{Group: "devops.kubesphere.io", Version: "v1alpha1", Resource: "s2ibuildertemplates"},
|
||||
{Group: "devops.kubesphere.io", Version: "v1alpha1", Resource: "s2iruns"},
|
||||
{Group: "devops.kubesphere.io", Version: "v1alpha1", Resource: "s2ibuilders"},
|
||||
},
|
||||
|
||||
// kubernetes-sigs application api objects
|
||||
ClientApplication: {
|
||||
{Group: "app.k8s.io", Version: "v1beta1", Resource: "applications"},
|
||||
},
|
||||
}
|
||||
|
||||
// List of all resource kinds supported by the UI.
|
||||
const (
|
||||
ResourceKindConfigMap = "configmaps"
|
||||
ResourceKindDaemonSet = "daemonsets"
|
||||
ResourceKindDeployment = "deployments"
|
||||
ResourceKindEvent = "events"
|
||||
ResourceKindHorizontalPodAutoscaler = "horizontalpodautoscalers"
|
||||
ResourceKindIngress = "ingresses"
|
||||
ResourceKindJob = "jobs"
|
||||
ResourceKindCronJob = "cronjobs"
|
||||
ResourceKindLimitRange = "limitranges"
|
||||
ResourceKindNamespace = "namespaces"
|
||||
ResourceKindNode = "nodes"
|
||||
ResourceKindPersistentVolumeClaim = "persistentvolumeclaims"
|
||||
ResourceKindPersistentVolume = "persistentvolumes"
|
||||
ResourceKindCustomResourceDefinition = "customresourcedefinitions"
|
||||
ResourceKindPod = "pods"
|
||||
ResourceKindReplicaSet = "replicasets"
|
||||
ResourceKindResourceQuota = "resourcequota"
|
||||
ResourceKindSecret = "secrets"
|
||||
ResourceKindService = "services"
|
||||
ResourceKindStatefulSet = "statefulsets"
|
||||
ResourceKindStorageClass = "storageclasses"
|
||||
ResourceKindClusterRole = "clusterroles"
|
||||
ResourceKindClusterRoleBinding = "clusterrolebindings"
|
||||
ResourceKindRole = "roles"
|
||||
ResourceKindRoleBinding = "rolebindings"
|
||||
ResourceKindWorkspace = "workspaces"
|
||||
ResourceKindS2iBinary = "s2ibinaries"
|
||||
ResourceKindStrategy = "strategy"
|
||||
ResourceKindServicePolicy = "servicepolicies"
|
||||
ResourceKindS2iBuilderTemplate = "s2ibuildertemplates"
|
||||
ResourceKindeS2iRun = "s2iruns"
|
||||
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) {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user