format code
This commit is contained in:
@@ -294,4 +294,4 @@ func GetComponents() (result []Components, err error) {
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,16 +18,17 @@ package models
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/golang/glog"
|
||||
"text/template"
|
||||
"encoding/base64"
|
||||
"text/template"
|
||||
|
||||
"github.com/golang/glog"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/client"
|
||||
"kubesphere.io/kubesphere/pkg/options"
|
||||
)
|
||||
|
||||
var kubeconfigTemp =
|
||||
"apiVersion: v1\n" +
|
||||
var kubeconfigTemp = "apiVersion: v1\n" +
|
||||
"clusters:\n" +
|
||||
"- cluster:\n" +
|
||||
" certificate-authority-data: {{.Certificate}}\n" +
|
||||
@@ -51,9 +52,9 @@ const DefaultServiceAccount = "default"
|
||||
|
||||
type Config struct {
|
||||
Certificate string
|
||||
Server string
|
||||
User string
|
||||
Token string
|
||||
Server string
|
||||
User string
|
||||
Token string
|
||||
}
|
||||
|
||||
func GetKubeConfig(namespace string) (string, error) {
|
||||
@@ -77,24 +78,24 @@ func GetKubeConfig(namespace string) (string, error) {
|
||||
func getKubeConfig(namespace, apiserverHost string) (*Config, error) {
|
||||
k8sClient := client.NewK8sClient()
|
||||
saInfo, err := k8sClient.CoreV1().ServiceAccounts(namespace).Get(DefaultServiceAccount, meta_v1.GetOptions{})
|
||||
if err != nil{
|
||||
if err != nil {
|
||||
glog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
secretName := saInfo.Secrets[0].Name
|
||||
|
||||
secretInfo, err := k8sClient.CoreV1().Secrets(namespace).Get(secretName, meta_v1.GetOptions{})
|
||||
if err != nil{
|
||||
if err != nil {
|
||||
glog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
secretData := secretInfo.Data
|
||||
certificate := string(secretData["ca.crt"])
|
||||
certificate= base64.StdEncoding.EncodeToString([]byte(certificate))
|
||||
certificate = base64.StdEncoding.EncodeToString([]byte(certificate))
|
||||
server := apiserverHost
|
||||
token := string(secretData["token"])
|
||||
user := string(secretData["namespace"])
|
||||
|
||||
return &Config{Certificate:certificate, Server:server, Token:token, User:user}, nil
|
||||
return &Config{Certificate: certificate, Server: server, Token: token, User: user}, nil
|
||||
}
|
||||
|
||||
@@ -19,13 +19,14 @@ package models
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"kubesphere.io/kubesphere/pkg/client"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/api/core/v1"
|
||||
)
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/client"
|
||||
)
|
||||
|
||||
const (
|
||||
deploymentName = "kubectl"
|
||||
@@ -33,7 +34,7 @@ const (
|
||||
|
||||
type kubectlPodInfo struct {
|
||||
Namespace string `json: "namespace"`
|
||||
Pod string `json: "podname"`
|
||||
Pod string `json: "podname"`
|
||||
Container string `json: "container"`
|
||||
}
|
||||
|
||||
@@ -47,36 +48,35 @@ func GetKubectlPod(namespace string) (kubectlPodInfo, error) {
|
||||
|
||||
selectors := deploy.Spec.Selector.MatchLabels
|
||||
labelSelector := labels.Set(selectors).AsSelector().String()
|
||||
podList, err := k8sClient.CoreV1().Pods(namespace).List(meta_v1.ListOptions{LabelSelector:labelSelector})
|
||||
podList, err := k8sClient.CoreV1().Pods(namespace).List(meta_v1.ListOptions{LabelSelector: labelSelector})
|
||||
if err != nil {
|
||||
glog.Errorln(err)
|
||||
return kubectlPodInfo{}, err
|
||||
}
|
||||
|
||||
pod, err := selectCorrectPod(namespace, podList.Items)
|
||||
if err != nil{
|
||||
if err != nil {
|
||||
glog.Errorln(err)
|
||||
return kubectlPodInfo{}, err
|
||||
}
|
||||
|
||||
info := kubectlPodInfo{Namespace:pod.Namespace, Pod:pod.Name, Container:pod.Status.ContainerStatuses[0].Name}
|
||||
info := kubectlPodInfo{Namespace: pod.Namespace, Pod: pod.Name, Container: pod.Status.ContainerStatuses[0].Name}
|
||||
|
||||
return info, nil
|
||||
|
||||
}
|
||||
|
||||
|
||||
func selectCorrectPod(namespace string, pods []v1.Pod) (kubectlPod v1.Pod, err error) {
|
||||
|
||||
var kubectPodList []v1.Pod
|
||||
for _, pod := range pods{
|
||||
for _, condition := range pod.Status.Conditions{
|
||||
if condition.Type == "Ready" && condition.Status == "True"{
|
||||
for _, pod := range pods {
|
||||
for _, condition := range pod.Status.Conditions {
|
||||
if condition.Type == "Ready" && condition.Status == "True" {
|
||||
kubectPodList = append(kubectPodList, pod)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(kubectPodList) < 1{
|
||||
if len(kubectPodList) < 1 {
|
||||
err = fmt.Errorf("cannot find valid kubectl pod in namespace:%s", namespace)
|
||||
return v1.Pod{}, err
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/client"
|
||||
ksutil "kubesphere.io/kubesphere/pkg/util"
|
||||
|
||||
|
||||
@@ -14,9 +14,11 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"kubesphere.io/kubesphere/pkg/constants"
|
||||
"math"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/constants"
|
||||
)
|
||||
|
||||
type ResultPod struct {
|
||||
|
||||
@@ -237,4 +237,4 @@ func QueryRegistries(project string) (regList []Registries, err error) {
|
||||
|
||||
return regList, nil
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@ package models
|
||||
|
||||
import (
|
||||
"k8s.io/api/rbac/v1"
|
||||
"kubesphere.io/kubesphere/pkg/client"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/client"
|
||||
)
|
||||
|
||||
const ClusterRoleKind = "ClusterRole"
|
||||
|
||||
@@ -17,15 +17,15 @@ limitations under the License.
|
||||
package models
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/glog"
|
||||
coreV1 "k8s.io/api/core/v1"
|
||||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
extensionsV1beta1 "k8s.io/api/extensions/v1beta1"
|
||||
"k8s.io/api/rbac/v1beta1"
|
||||
"github.com/golang/glog"
|
||||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/client"
|
||||
)
|
||||
@@ -37,7 +37,7 @@ type Router struct {
|
||||
Annotations string `json:"annotations"`
|
||||
}
|
||||
|
||||
func GetAllRouters() ([] *coreV1.Service, error) {
|
||||
func GetAllRouters() ([]*coreV1.Service, error) {
|
||||
|
||||
k8sClient := client.NewK8sClient()
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
v12 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/client"
|
||||
)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package models
|
||||
import (
|
||||
v12 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/client"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user