automatically create kubeconfig

Signed-off-by: hongming <talonwan@yunify.com>
This commit is contained in:
hongming
2019-04-25 10:29:57 +08:00
committed by zryfish
parent da0ca36d1a
commit ece9049836
23 changed files with 123 additions and 95 deletions

View File

@@ -19,6 +19,7 @@ package resources
import (
"github.com/emicklei/go-restful"
"github.com/golang/glog"
"k8s.io/api/core/v1"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/errors"
@@ -42,6 +43,7 @@ func ApplicationHandler(req *restful.Request, resp *restful.Response) {
if len(clusterId) > 0 {
app, err := applications.GetApp(clusterId)
if err != nil {
glog.Errorln("get application error", err)
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
return
}
@@ -66,14 +68,13 @@ func NamespacedApplicationHandler(req *restful.Request, resp *restful.Response)
clusterId := req.QueryParameter("cluster_id")
conditions, err := params.ParseConditions(req.QueryParameter(params.ConditionsParam))
if err != nil {
if err != nil {
resp.WriteHeaderAndEntity(http.StatusBadRequest, errors.Wrap(err))
return
}
resp.WriteHeaderAndEntity(http.StatusBadRequest, errors.Wrap(err))
return
}
if len(clusterId) > 0 {
app, err := applications.GetApp(clusterId)
if err != nil {
glog.Errorln("get app failed", err)
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
return
}
@@ -84,6 +85,7 @@ func NamespacedApplicationHandler(req *restful.Request, resp *restful.Response)
namespace, err := resources.GetResource("", resources.Namespaces, namespaceName)
if err != nil {
glog.Errorln("get namespace failed", err)
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
return
}
@@ -95,6 +97,7 @@ func NamespacedApplicationHandler(req *restful.Request, resp *restful.Response)
}
if runtimeId == "" {
glog.Errorln("runtime id not found")
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.New("openpitrix runtime not init"))
return
}
@@ -102,6 +105,7 @@ func NamespacedApplicationHandler(req *restful.Request, resp *restful.Response)
result, err := applications.ListApplication(runtimeId, conditions, limit, offset)
if err != nil {
glog.Errorln("list applications failed", err)
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
return
}

View File

@@ -19,6 +19,7 @@ package resources
import (
"github.com/emicklei/go-restful"
k8serr "k8s.io/apimachinery/pkg/api/errors"
"net/http"
"kubesphere.io/kubesphere/pkg/errors"
@@ -47,7 +48,14 @@ func GetKubeconfig(req *restful.Request, resp *restful.Response) {
kubectlConfig, err := kubeconfig.GetKubeConfig(user)
if err != nil {
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
if k8serr.IsNotFound(err) {
// recreate
kubeconfig.CreateKubeConfig(user)
resp.WriteHeaderAndEntity(http.StatusNotFound, errors.Wrap(err))
} else {
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
}
return
}