fix: application api

Signed-off-by: hongming <talonwan@yunify.com>
This commit is contained in:
hongming
2019-05-14 16:03:10 +08:00
committed by zryfish
parent 4c111533b1
commit 4ae7d3256e
11 changed files with 267 additions and 209 deletions

View File

@@ -18,6 +18,7 @@
package applications
import (
"fmt"
"github.com/golang/glog"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/api/core/v1"
@@ -25,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/models"
"kubesphere.io/kubesphere/pkg/models/resources"
@@ -283,3 +285,22 @@ func getIng(namespace string, services []v1.Service) []v1beta1.Ingress {
return ings
}
func DeployApplication(namespace string, app openpitrix.CreateClusterRequest) error {
ns, err := informers.SharedInformerFactory().Core().V1().Namespaces().Lister().Get(namespace)
if err != nil {
glog.Errorf("deploy application failed: %+v", err)
return err
}
if runtimeId := ns.Annotations[constants.OpenPitrixRuntimeAnnotationKey]; runtimeId != "" {
app.RuntimeId = runtimeId
} else {
return fmt.Errorf("runtime not init: namespace %s", namespace)
}
return openpitrix.CreateCluster(app)
}
func DeleteApplication(clusterId string) error {
return openpitrix.DeleteCluster(openpitrix.DeleteClusterRequest{ClusterId: []string{clusterId}})
}