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:
@@ -31,7 +31,7 @@ import (
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/models/resources"
|
||||
"kubesphere.io/kubesphere/pkg/params"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -63,7 +63,11 @@ type workLoads struct {
|
||||
}
|
||||
|
||||
func ListApplication(runtimeId string, conditions *params.Conditions, limit, offset int) (*models.PageableResponse, error) {
|
||||
clusterList, err := openpitrix.ListClusters(runtimeId, conditions.Match["keyword"], conditions.Match["status"], limit, offset)
|
||||
openPitrixClient, err := client.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
clusterList, err := openPitrixClient.ListClusters(runtimeId, conditions.Match["keyword"], conditions.Match["status"], limit, offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -76,13 +80,13 @@ func ListApplication(runtimeId string, conditions *params.Conditions, limit, off
|
||||
app.ClusterID = item.ClusterID
|
||||
app.UpdateTime = item.UpdateTime
|
||||
app.Status = item.Status
|
||||
versionInfo, _ := openpitrix.GetVersion(item.VersionID)
|
||||
versionInfo, _ := openPitrixClient.GetVersion(item.VersionID)
|
||||
app.Version = versionInfo
|
||||
app.VersionId = item.VersionID
|
||||
runtimeInfo, _ := openpitrix.GetRuntime(item.RunTimeId)
|
||||
runtimeInfo, _ := openPitrixClient.GetRuntime(item.RunTimeId)
|
||||
app.Runtime = runtimeInfo
|
||||
app.RuntimeId = item.RunTimeId
|
||||
appInfo, _, appId, _ := openpitrix.GetAppInfo(item.AppID)
|
||||
appInfo, _, appId, _ := openPitrixClient.GetAppInfo(item.AppID)
|
||||
app.App = appInfo
|
||||
app.AppId = appId
|
||||
app.Description = item.Description
|
||||
@@ -94,8 +98,11 @@ func ListApplication(runtimeId string, conditions *params.Conditions, limit, off
|
||||
}
|
||||
|
||||
func GetApp(clusterId string) (*Application, error) {
|
||||
|
||||
item, err := openpitrix.GetCluster(clusterId)
|
||||
openPitrixClient, err := client.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
item, err := openPitrixClient.GetCluster(clusterId)
|
||||
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
@@ -109,19 +116,19 @@ func GetApp(clusterId string) (*Application, error) {
|
||||
app.UpdateTime = item.UpdateTime
|
||||
app.CreateTime = item.CreateTime
|
||||
app.Status = item.Status
|
||||
versionInfo, _ := openpitrix.GetVersion(item.VersionID)
|
||||
versionInfo, _ := openPitrixClient.GetVersion(item.VersionID)
|
||||
app.Version = versionInfo
|
||||
app.VersionId = item.VersionID
|
||||
|
||||
runtimeInfo, _ := openpitrix.GetRuntime(item.RunTimeId)
|
||||
runtimeInfo, _ := openPitrixClient.GetRuntime(item.RunTimeId)
|
||||
app.Runtime = runtimeInfo
|
||||
app.RuntimeId = item.RunTimeId
|
||||
appInfo, repoId, appId, _ := openpitrix.GetAppInfo(item.AppID)
|
||||
appInfo, repoId, appId, _ := openPitrixClient.GetAppInfo(item.AppID)
|
||||
app.App = appInfo
|
||||
app.AppId = appId
|
||||
app.Description = item.Description
|
||||
|
||||
app.RepoName, _ = openpitrix.GetRepo(repoId)
|
||||
app.RepoName, _ = openPitrixClient.GetRepo(repoId)
|
||||
|
||||
workloads, err := getWorkLoads(app.Runtime, item.ClusterRoleSets)
|
||||
if err != nil {
|
||||
@@ -195,7 +202,7 @@ func getWorkLoads(namespace string, clusterRoles []openpitrix.ClusterRole) (*wor
|
||||
}
|
||||
|
||||
func getLabels(namespace string, workloads *workLoads) *[]map[string]string {
|
||||
k8sClient := k8s.Client()
|
||||
k8sClient := client.ClientSets().K8s().Kubernetes()
|
||||
|
||||
var workloadLables []map[string]string
|
||||
if workloads == nil {
|
||||
@@ -242,7 +249,7 @@ func getSvcs(namespace string, workLoadLabels *[]map[string]string) []v1.Service
|
||||
if len(*workLoadLabels) == 0 {
|
||||
return nil
|
||||
}
|
||||
k8sClient := k8s.Client()
|
||||
k8sClient := client.ClientSets().K8s().Kubernetes()
|
||||
var services []v1.Service
|
||||
for _, label := range *workLoadLabels {
|
||||
labelSelector := labels.Set(label).AsSelector().String()
|
||||
@@ -302,6 +309,11 @@ func getIng(namespace string, services []v1.Service) []v1beta1.Ingress {
|
||||
}
|
||||
|
||||
func DeployApplication(namespace string, app openpitrix.CreateClusterRequest) error {
|
||||
openPitrixClient, err := client.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ns, err := informers.SharedInformerFactory().Core().V1().Namespaces().Lister().Get(namespace)
|
||||
if err != nil {
|
||||
glog.Errorf("deploy application failed: %+v", err)
|
||||
@@ -313,9 +325,14 @@ func DeployApplication(namespace string, app openpitrix.CreateClusterRequest) er
|
||||
} else {
|
||||
return fmt.Errorf("runtime not init: namespace %s", namespace)
|
||||
}
|
||||
return openpitrix.CreateCluster(app)
|
||||
return openPitrixClient.CreateCluster(app)
|
||||
}
|
||||
|
||||
func DeleteApplication(clusterId string) error {
|
||||
return openpitrix.DeleteCluster(openpitrix.DeleteClusterRequest{ClusterId: []string{clusterId}})
|
||||
openPitrixClient, err := client.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return openPitrixClient.DeleteCluster(openpitrix.DeleteClusterRequest{ClusterId: []string{clusterId}})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user