This is a huge commit, it does following things:
1. refactor kubesphere dependency service client creation, we can disable dependency by config 2. dependencies can be configured by configuration file 3. refactor cmd package using cobra.Command, so we can use hypersphere to invoke command sepearately. Later we only need to build one image to contains all kubesphere core components. One command to rule them all! 4. live reloading configuration currently not implemented
This commit is contained in:
@@ -25,7 +25,6 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -35,86 +34,9 @@ const (
|
||||
StateSuffix = "-StatefulSet"
|
||||
)
|
||||
|
||||
type Cluster struct {
|
||||
ClusterID string `json:"cluster_id"`
|
||||
Name string `json:"name"`
|
||||
AppID string `json:"app_id"`
|
||||
VersionID string `json:"version_id"`
|
||||
Status string `json:"status"`
|
||||
UpdateTime time.Time `json:"status_time"`
|
||||
CreateTime time.Time `json:"create_time"`
|
||||
RunTimeId string `json:"runtime_id"`
|
||||
Description string `json:"description"`
|
||||
ClusterRoleSets []ClusterRole `json:"cluster_role_set"`
|
||||
}
|
||||
|
||||
type ClusterRole struct {
|
||||
ClusterID string `json:"cluster_id"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
|
||||
type ClusterList struct {
|
||||
Total int `json:"total_count"`
|
||||
Clusters []Cluster `json:"cluster_set"`
|
||||
}
|
||||
|
||||
type VersionList struct {
|
||||
Total int `json:"total_count"`
|
||||
Versions []version `json:"app_version_set"`
|
||||
}
|
||||
|
||||
type version struct {
|
||||
Name string `json:"name"`
|
||||
VersionID string `json:"version_id"`
|
||||
}
|
||||
|
||||
type runtime struct {
|
||||
RuntimeID string `json:"runtime_id"`
|
||||
Zone string `json:"zone"`
|
||||
}
|
||||
|
||||
type runtimeList struct {
|
||||
Total int `json:"total_count"`
|
||||
Runtimes []runtime `json:"runtime_set"`
|
||||
}
|
||||
|
||||
type app struct {
|
||||
AppId string `json:"app_id"`
|
||||
Name string `json:"name"`
|
||||
ChartName string `json:"chart_name"`
|
||||
RepoId string `json:"repo_id"`
|
||||
}
|
||||
|
||||
type repo struct {
|
||||
RepoId string `json:"repo_id"`
|
||||
Name string `json:"name"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type appList struct {
|
||||
Total int `json:"total_count"`
|
||||
Apps []app `json:"app_set"`
|
||||
}
|
||||
|
||||
type repoList struct {
|
||||
Total int `json:"total_count"`
|
||||
Repos []repo `json:"repo_set"`
|
||||
}
|
||||
|
||||
type CreateClusterRequest struct {
|
||||
AppId string `json:"app_id" description:"ID of app to run in cluster, e.g. app-AA3A3y3zEgEM"`
|
||||
VersionId string `json:"version_id" description:"app version, e.g. appv-154gXYx5RKRp"`
|
||||
RuntimeId string `json:"runtime_id" description:"ID of runtime, e.g. runtime-wWwXL0LzWqEr"`
|
||||
Conf string `json:"conf" description:"conf a json string, include cpu, memory info of cluster"`
|
||||
}
|
||||
|
||||
type DeleteClusterRequest struct {
|
||||
ClusterId []string `json:"cluster_id" description:"cluster ID"`
|
||||
}
|
||||
|
||||
func GetAppInfo(appId string) (string, string, string, error) {
|
||||
url := fmt.Sprintf("%s/v1/apps?app_id=%s", openpitrixAPIServer, appId)
|
||||
resp, err := makeHttpRequest("GET", url, "")
|
||||
func (c *OpenPitrixClient) GetAppInfo(appId string) (string, string, string, error) {
|
||||
url := fmt.Sprintf("%s/v1/apps?app_id=%s", c.apiServer, appId)
|
||||
resp, err := c.makeHttpRequest("GET", url, "")
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
return Unknown, Unknown, Unknown, err
|
||||
@@ -134,14 +56,10 @@ func GetAppInfo(appId string) (string, string, string, error) {
|
||||
return apps.Apps[0].ChartName, apps.Apps[0].RepoId, apps.Apps[0].AppId, nil
|
||||
}
|
||||
|
||||
func GetCluster(clusterId string) (*Cluster, error) {
|
||||
if strings.HasSuffix(openpitrixAPIServer, "/") {
|
||||
openpitrixAPIServer = strings.TrimSuffix(openpitrixAPIServer, "/")
|
||||
}
|
||||
func (c *OpenPitrixClient) GetCluster(clusterId string) (*Cluster, error) {
|
||||
url := fmt.Sprintf("%s/v1/clusters?cluster_id=%s", c.apiServer, clusterId)
|
||||
|
||||
url := fmt.Sprintf("%s/v1/clusters?cluster_id=%s", openpitrixAPIServer, clusterId)
|
||||
|
||||
resp, err := makeHttpRequest("GET", url, "")
|
||||
resp, err := c.makeHttpRequest("GET", url, "")
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
return nil, err
|
||||
@@ -162,14 +80,11 @@ func GetCluster(clusterId string) (*Cluster, error) {
|
||||
return &clusterList.Clusters[0], nil
|
||||
}
|
||||
|
||||
func ListClusters(runtimeId, searchWord, status string, limit, offset int) (*ClusterList, error) {
|
||||
if strings.HasSuffix(openpitrixAPIServer, "/") {
|
||||
openpitrixAPIServer = strings.TrimSuffix(openpitrixAPIServer, "/")
|
||||
}
|
||||
func (c *OpenPitrixClient) ListClusters(runtimeId, searchWord, status string, limit, offset int) (*ClusterList, error) {
|
||||
|
||||
defaultStatus := "status=active&status=stopped&status=pending&status=ceased"
|
||||
|
||||
url := fmt.Sprintf("%s/v1/clusters?limit=%s&offset=%s", openpitrixAPIServer, strconv.Itoa(limit), strconv.Itoa(offset))
|
||||
url := fmt.Sprintf("%s/v1/clusters?limit=%s&offset=%s", c.apiServer, strconv.Itoa(limit), strconv.Itoa(offset))
|
||||
|
||||
if searchWord != "" {
|
||||
url = fmt.Sprintf("%s&search_word=%s", url, searchWord)
|
||||
@@ -185,7 +100,7 @@ func ListClusters(runtimeId, searchWord, status string, limit, offset int) (*Clu
|
||||
url = fmt.Sprintf("%s&runtime_id=%s", url, runtimeId)
|
||||
}
|
||||
|
||||
resp, err := makeHttpRequest("GET", url, "")
|
||||
resp, err := c.makeHttpRequest("GET", url, "")
|
||||
if err != nil {
|
||||
glog.Errorf("request %s failed, reason: %s", url, err)
|
||||
return nil, err
|
||||
@@ -201,9 +116,9 @@ func ListClusters(runtimeId, searchWord, status string, limit, offset int) (*Clu
|
||||
return &clusterList, nil
|
||||
}
|
||||
|
||||
func GetRepo(repoId string) (string, error) {
|
||||
url := fmt.Sprintf("%s/v1/repos?repo_id=%s", openpitrixAPIServer, repoId)
|
||||
resp, err := makeHttpRequest("GET", url, "")
|
||||
func (c *OpenPitrixClient) GetRepo(repoId string) (string, error) {
|
||||
url := fmt.Sprintf("%s/v1/repos?repo_id=%s", c.apiServer, repoId)
|
||||
resp, err := c.makeHttpRequest("GET", url, "")
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
return Unknown, err
|
||||
@@ -223,9 +138,9 @@ func GetRepo(repoId string) (string, error) {
|
||||
return repos.Repos[0].Name, nil
|
||||
}
|
||||
|
||||
func GetVersion(versionId string) (string, error) {
|
||||
versionUrl := fmt.Sprintf("%s/v1/app_versions?version_id=%s", openpitrixAPIServer, versionId)
|
||||
resp, err := makeHttpRequest("GET", versionUrl, "")
|
||||
func (c *OpenPitrixClient) GetVersion(versionId string) (string, error) {
|
||||
versionUrl := fmt.Sprintf("%s/v1/app_versions?version_id=%s", c.apiServer, versionId)
|
||||
resp, err := c.makeHttpRequest("GET", versionUrl, "")
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
return Unknown, err
|
||||
@@ -244,10 +159,10 @@ func GetVersion(versionId string) (string, error) {
|
||||
return versions.Versions[0].Name, nil
|
||||
}
|
||||
|
||||
func GetRuntime(runtimeId string) (string, error) {
|
||||
func (c *OpenPitrixClient) GetRuntime(runtimeId string) (string, error) {
|
||||
|
||||
versionUrl := fmt.Sprintf("%s/v1/runtimes?runtime_id=%s", openpitrixAPIServer, runtimeId)
|
||||
resp, err := makeHttpRequest("GET", versionUrl, "")
|
||||
versionUrl := fmt.Sprintf("%s/v1/runtimes?runtime_id=%s", c.apiServer, runtimeId)
|
||||
resp, err := c.makeHttpRequest("GET", versionUrl, "")
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
return Unknown, err
|
||||
@@ -267,9 +182,9 @@ func GetRuntime(runtimeId string) (string, error) {
|
||||
return runtimes.Runtimes[0].Zone, nil
|
||||
}
|
||||
|
||||
func CreateCluster(request CreateClusterRequest) error {
|
||||
func (c *OpenPitrixClient) CreateCluster(request CreateClusterRequest) error {
|
||||
|
||||
versionUrl := fmt.Sprintf("%s/v1/clusters/create", openpitrixAPIServer)
|
||||
versionUrl := fmt.Sprintf("%s/v1/clusters/create", c.apiServer)
|
||||
|
||||
data, err := json.Marshal(request)
|
||||
|
||||
@@ -278,7 +193,7 @@ func CreateCluster(request CreateClusterRequest) error {
|
||||
return err
|
||||
}
|
||||
|
||||
data, err = makeHttpRequest("POST", versionUrl, string(data))
|
||||
data, err = c.makeHttpRequest("POST", versionUrl, string(data))
|
||||
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
@@ -288,9 +203,9 @@ func CreateCluster(request CreateClusterRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteCluster(request DeleteClusterRequest) error {
|
||||
func (c *OpenPitrixClient) DeleteCluster(request DeleteClusterRequest) error {
|
||||
|
||||
versionUrl := fmt.Sprintf("%s/v1/clusters/delete", openpitrixAPIServer)
|
||||
versionUrl := fmt.Sprintf("%s/v1/clusters/delete", c.apiServer)
|
||||
|
||||
data, err := json.Marshal(request)
|
||||
|
||||
@@ -299,7 +214,7 @@ func DeleteCluster(request DeleteClusterRequest) error {
|
||||
return err
|
||||
}
|
||||
|
||||
data, err = makeHttpRequest("POST", versionUrl, string(data))
|
||||
data, err = c.makeHttpRequest("POST", versionUrl, string(data))
|
||||
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
@@ -309,7 +224,7 @@ func DeleteCluster(request DeleteClusterRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func makeHttpRequest(method, url, data string) ([]byte, error) {
|
||||
func (c *OpenPitrixClient) makeHttpRequest(method, url, data string) ([]byte, error) {
|
||||
var req *http.Request
|
||||
|
||||
var err error
|
||||
@@ -319,7 +234,7 @@ func makeHttpRequest(method, url, data string) ([]byte, error) {
|
||||
req, err = http.NewRequest(method, url, strings.NewReader(data))
|
||||
}
|
||||
|
||||
req.Header.Add("Authorization", openpitrixProxyToken)
|
||||
req.Header.Add("Authorization", c.token)
|
||||
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
@@ -329,7 +244,7 @@ func makeHttpRequest(method, url, data string) ([]byte, error) {
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Request to %s failed, method: %s,token: %s, reason: %s ", url, method, openpitrixProxyToken, err)
|
||||
err := fmt.Errorf("Request to %s failed, method: %s,token: %s, reason: %s ", url, method, c.apiServer, err)
|
||||
glog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -20,105 +20,64 @@ package openpitrix
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/golang/glog"
|
||||
"io/ioutil"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
openpitrixAPIServer string
|
||||
openpitrixProxyToken string
|
||||
once sync.Once
|
||||
c client
|
||||
)
|
||||
|
||||
type RunTime struct {
|
||||
RuntimeId string `json:"runtime_id"`
|
||||
RuntimeUrl string `json:"runtime_url"`
|
||||
Name string `json:"name"`
|
||||
Provider string `json:"provider"`
|
||||
Zone string `json:"zone"`
|
||||
RuntimeCredential string `json:"runtime_credential"`
|
||||
func NewOpenPitrixClient(options *OpenPitrixOptions) (*OpenPitrixClient, error) {
|
||||
return &OpenPitrixClient{
|
||||
client: &http.Client{
|
||||
Timeout: time.Duration(3) * time.Second,
|
||||
},
|
||||
apiServer: options.APIServer,
|
||||
token: options.Token,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type Interface interface {
|
||||
CreateRuntime(runtime *RunTime) error
|
||||
DeleteRuntime(runtimeId string) error
|
||||
}
|
||||
type cluster struct {
|
||||
Status string `json:"status"`
|
||||
ClusterId string `json:"cluster_id"`
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
status int
|
||||
message string
|
||||
}
|
||||
|
||||
func (e Error) Error() string {
|
||||
return fmt.Sprintf("status: %d,message: %s", e.status, e.message)
|
||||
}
|
||||
|
||||
type client struct {
|
||||
client http.Client
|
||||
}
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&openpitrixAPIServer, "openpitrix-api-server", "http://openpitrix-api-gateway.openpitrix-system.svc:9100", "openpitrix api server")
|
||||
flag.StringVar(&openpitrixProxyToken, "openpitrix-proxy-token", "", "openpitrix proxy token")
|
||||
}
|
||||
|
||||
func Client() Interface {
|
||||
once.Do(func() {
|
||||
c = client{client: http.Client{}}
|
||||
})
|
||||
return c
|
||||
}
|
||||
|
||||
func (c client) CreateRuntime(runtime *RunTime) error {
|
||||
func (c *OpenPitrixClient) CreateRuntime(runtime *RunTime) error {
|
||||
|
||||
data, err := json.Marshal(runtime)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/v1/runtimes", openpitrixAPIServer), bytes.NewReader(data))
|
||||
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/v1/runtimes", c.apiServer), bytes.NewReader(data))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
req.Header.Add("Authorization", openpitrixProxyToken)
|
||||
req.Header.Add("Authorization", c.token)
|
||||
|
||||
resp, err := c.client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
data, err = ioutil.ReadAll(resp.Body)
|
||||
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode > http.StatusOK {
|
||||
err = Error{resp.StatusCode, string(data)}
|
||||
glog.Error(err)
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c client) deleteClusters(clusters []cluster) error {
|
||||
func (c *OpenPitrixClient) deleteClusters(clusters []cluster) error {
|
||||
clusterId := make([]string, 0)
|
||||
|
||||
for _, cluster := range clusters {
|
||||
@@ -137,16 +96,16 @@ func (c client) deleteClusters(clusters []cluster) error {
|
||||
ClusterId: clusterId,
|
||||
}
|
||||
data, _ := json.Marshal(deleteRequest)
|
||||
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/v1/clusters/delete", openpitrixAPIServer), bytes.NewReader(data))
|
||||
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/v1/clusters/delete", c.apiServer), bytes.NewReader(data))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Add("Authorization", openpitrixProxyToken)
|
||||
req.Header.Add("Authorization", c.token)
|
||||
|
||||
resp, err := c.client.Do(req)
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -154,44 +113,44 @@ func (c client) deleteClusters(clusters []cluster) error {
|
||||
data, err = ioutil.ReadAll(resp.Body)
|
||||
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode > http.StatusOK {
|
||||
err = Error{resp.StatusCode, string(data)}
|
||||
glog.Error(err)
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c client) listClusters(runtimeId string) ([]cluster, error) {
|
||||
func (c *OpenPitrixClient) listClusters(runtimeId string) ([]cluster, error) {
|
||||
limit := 200
|
||||
offset := 0
|
||||
clusters := make([]cluster, 0)
|
||||
for {
|
||||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/v1/clusters?runtime_id=%s&limit=%d&offset=%d", openpitrixAPIServer, runtimeId, limit, offset), nil)
|
||||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/v1/clusters?runtime_id=%s&limit=%d&offset=%d", c.apiServer, runtimeId, limit, offset), nil)
|
||||
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Header.Add("Authorization", openpitrixProxyToken)
|
||||
req.Header.Add("Authorization", c.token)
|
||||
|
||||
resp, err := c.client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -199,7 +158,7 @@ func (c client) listClusters(runtimeId string) ([]cluster, error) {
|
||||
|
||||
if resp.StatusCode > http.StatusOK {
|
||||
err = Error{resp.StatusCode, string(data)}
|
||||
glog.Error(err)
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
listClusterResponse := struct {
|
||||
@@ -209,7 +168,7 @@ func (c client) listClusters(runtimeId string) ([]cluster, error) {
|
||||
err = json.Unmarshal(data, &listClusterResponse)
|
||||
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -225,18 +184,18 @@ func (c client) listClusters(runtimeId string) ([]cluster, error) {
|
||||
return clusters, nil
|
||||
}
|
||||
|
||||
func (c client) DeleteRuntime(runtimeId string) error {
|
||||
func (c *OpenPitrixClient) DeleteRuntime(runtimeId string) error {
|
||||
clusters, err := c.listClusters(runtimeId)
|
||||
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.deleteClusters(clusters)
|
||||
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
43
pkg/simple/client/openpitrix/options.go
Normal file
43
pkg/simple/client/openpitrix/options.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package openpitrix
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/pflag"
|
||||
"kubesphere.io/kubesphere/pkg/utils/reflectutils"
|
||||
)
|
||||
|
||||
type OpenPitrixOptions struct {
|
||||
APIServer string `json:"apiServer,omitempty" yaml:"apiServer,omitempty"`
|
||||
Token string `json:"token,omitempty" yaml:"token,omitempty"`
|
||||
}
|
||||
|
||||
func NewOpenPitrixOptions() *OpenPitrixOptions {
|
||||
return &OpenPitrixOptions{
|
||||
APIServer: "",
|
||||
Token: "",
|
||||
}
|
||||
}
|
||||
|
||||
func (s *OpenPitrixOptions) ApplyTo(options *OpenPitrixOptions) {
|
||||
reflectutils.Override(s, options)
|
||||
}
|
||||
|
||||
func (s *OpenPitrixOptions) Validate() []error {
|
||||
errs := []error{}
|
||||
|
||||
if s.APIServer != "" {
|
||||
if s.Token == "" {
|
||||
errs = append(errs, fmt.Errorf("OpenPitrix access token cannot be empty"))
|
||||
}
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
func (s *OpenPitrixOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&s.APIServer, "openpitrix-apiserver", s.APIServer, ""+
|
||||
"OpenPitrix api gateway endpoint, if left blank, following options will be ignored.")
|
||||
|
||||
fs.StringVar(&s.Token, "openpitrix-token", s.Token, ""+
|
||||
"OpenPitrix api access token.")
|
||||
}
|
||||
117
pkg/simple/client/openpitrix/types.go
Normal file
117
pkg/simple/client/openpitrix/types.go
Normal file
@@ -0,0 +1,117 @@
|
||||
package openpitrix
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Cluster struct {
|
||||
ClusterID string `json:"cluster_id"`
|
||||
Name string `json:"name"`
|
||||
AppID string `json:"app_id"`
|
||||
VersionID string `json:"version_id"`
|
||||
Status string `json:"status"`
|
||||
UpdateTime time.Time `json:"status_time"`
|
||||
CreateTime time.Time `json:"create_time"`
|
||||
RunTimeId string `json:"runtime_id"`
|
||||
Description string `json:"description"`
|
||||
ClusterRoleSets []ClusterRole `json:"cluster_role_set"`
|
||||
}
|
||||
|
||||
type ClusterRole struct {
|
||||
ClusterID string `json:"cluster_id"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
|
||||
type ClusterList struct {
|
||||
Total int `json:"total_count"`
|
||||
Clusters []Cluster `json:"cluster_set"`
|
||||
}
|
||||
|
||||
type VersionList struct {
|
||||
Total int `json:"total_count"`
|
||||
Versions []version `json:"app_version_set"`
|
||||
}
|
||||
|
||||
type version struct {
|
||||
Name string `json:"name"`
|
||||
VersionID string `json:"version_id"`
|
||||
}
|
||||
|
||||
type runtime struct {
|
||||
RuntimeID string `json:"runtime_id"`
|
||||
Zone string `json:"zone"`
|
||||
}
|
||||
|
||||
type runtimeList struct {
|
||||
Total int `json:"total_count"`
|
||||
Runtimes []runtime `json:"runtime_set"`
|
||||
}
|
||||
|
||||
type app struct {
|
||||
AppId string `json:"app_id"`
|
||||
Name string `json:"name"`
|
||||
ChartName string `json:"chart_name"`
|
||||
RepoId string `json:"repo_id"`
|
||||
}
|
||||
|
||||
type repo struct {
|
||||
RepoId string `json:"repo_id"`
|
||||
Name string `json:"name"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type appList struct {
|
||||
Total int `json:"total_count"`
|
||||
Apps []app `json:"app_set"`
|
||||
}
|
||||
|
||||
type repoList struct {
|
||||
Total int `json:"total_count"`
|
||||
Repos []repo `json:"repo_set"`
|
||||
}
|
||||
|
||||
type CreateClusterRequest struct {
|
||||
AppId string `json:"app_id" description:"ID of app to run in cluster, e.g. app-AA3A3y3zEgEM"`
|
||||
VersionId string `json:"version_id" description:"app version, e.g. appv-154gXYx5RKRp"`
|
||||
RuntimeId string `json:"runtime_id" description:"ID of runtime, e.g. runtime-wWwXL0LzWqEr"`
|
||||
Conf string `json:"conf" description:"conf a json string, include cpu, memory info of cluster"`
|
||||
}
|
||||
|
||||
type DeleteClusterRequest struct {
|
||||
ClusterId []string `json:"cluster_id" description:"cluster ID"`
|
||||
}
|
||||
|
||||
type RunTime struct {
|
||||
RuntimeId string `json:"runtime_id"`
|
||||
RuntimeUrl string `json:"runtime_url"`
|
||||
Name string `json:"name"`
|
||||
Provider string `json:"provider"`
|
||||
Zone string `json:"zone"`
|
||||
RuntimeCredential string `json:"runtime_credential"`
|
||||
}
|
||||
|
||||
type Interface interface {
|
||||
CreateRuntime(runtime *RunTime) error
|
||||
DeleteRuntime(runtimeId string) error
|
||||
}
|
||||
type cluster struct {
|
||||
Status string `json:"status"`
|
||||
ClusterId string `json:"cluster_id"`
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
status int
|
||||
message string
|
||||
}
|
||||
|
||||
func (e Error) Error() string {
|
||||
return fmt.Sprintf("status: %d,message: %s", e.status, e.message)
|
||||
}
|
||||
|
||||
type OpenPitrixClient struct {
|
||||
client *http.Client
|
||||
apiServer string
|
||||
token string
|
||||
}
|
||||
Reference in New Issue
Block a user