mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
【修改】k8s 配置
This commit is contained in:
@@ -241,7 +241,7 @@ func (s *toolsGenTableColumn) GenTableInit(tableName string) entity.DevGenTable
|
||||
}
|
||||
} else if s.IsTimeObject(dataType) {
|
||||
//字段为时间类型
|
||||
column.GoType = "time.Time"
|
||||
column.GoType = "Time"
|
||||
column.HtmlType = "datetime"
|
||||
} else if s.IsNumberObject(dataType) {
|
||||
//字段为数字类型
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
package Init
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"k8s.io/client-go/dynamic"
|
||||
"os"
|
||||
"pandax/base/global"
|
||||
"path/filepath"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
@@ -12,30 +18,67 @@ import (
|
||||
)
|
||||
|
||||
// GetK8sClient 获取k8s Client
|
||||
func GetK8sClient(k8sConf string) (*kubernetes.Clientset, error) {
|
||||
|
||||
config, err := clientcmd.RESTConfigFromKubeConfig([]byte(k8sConf))
|
||||
// skips the validity check for the server's certificate. This will make your HTTPS connections insecure.
|
||||
// config.TLSClientConfig.Insecure = true
|
||||
if err != nil {
|
||||
global.Log.Error("KubeConfig内容错误", zap.Any("err", err))
|
||||
return nil, errors.New("KubeConfig内容错误")
|
||||
func GetK8sClient(ctx context.Context, kubeConfig string) (*kubernetes.Clientset, error) {
|
||||
var config *rest.Config
|
||||
var err error
|
||||
if kubeConfig != "" {
|
||||
clientConfig := GetClientConfig(kubeConfig, nil)
|
||||
config, err = clientConfig.ClientConfig()
|
||||
if err != nil {
|
||||
return nil, errors.New("KubeConfig内容错误")
|
||||
}
|
||||
} else {
|
||||
config, err = rest.InClusterConfig()
|
||||
if err != nil {
|
||||
return nil, errors.New("KubeConfig内容错误")
|
||||
}
|
||||
}
|
||||
|
||||
//config, err := clientcmd.RESTConfigFromKubeConfig([]byte(k8sConf))
|
||||
// skips the validity check for the server's certificate. This will make your HTTPS connections insecure.
|
||||
// config.TLSClientConfig.Insecure = true
|
||||
clientSet, err := kubernetes.NewForConfig(config)
|
||||
if err != nil {
|
||||
global.Log.Error("创建Client失败", zap.Any("err", err))
|
||||
return nil, errors.New("创建Client失败!")
|
||||
}
|
||||
_, err = dynamic.NewForConfig(config)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("kubernetes dynamic client create error:%s", err.Error())
|
||||
}
|
||||
return clientSet, nil
|
||||
}
|
||||
|
||||
// GetRestConf 获取k8s RESTConfig
|
||||
func GetRestConf(k8sConf string) (restConf *rest.Config, err error) {
|
||||
|
||||
if restConf, err = clientcmd.RESTConfigFromKubeConfig([]byte(k8sConf)); err != nil {
|
||||
fmt.Println("err: ", err)
|
||||
return nil, err
|
||||
}
|
||||
return restConf, nil
|
||||
func GetClientConfig(kubeConfig string, reader io.Reader) clientcmd.ClientConfig {
|
||||
loadingRules := GetLoadingRules(kubeConfig)
|
||||
overrides := &clientcmd.ConfigOverrides{ClusterDefaults: clientcmd.ClusterDefaults}
|
||||
return clientcmd.NewInteractiveDeferredLoadingClientConfig(loadingRules, overrides, reader)
|
||||
}
|
||||
|
||||
func GetLoadingRules(kubeConfig string) *clientcmd.ClientConfigLoadingRules {
|
||||
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||
loadingRules.DefaultClientConfig = &clientcmd.DefaultClientConfig
|
||||
if kubeConfig != "" {
|
||||
loadingRules.ExplicitPath = kubeConfig
|
||||
}
|
||||
|
||||
var otherFiles []string
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err == nil {
|
||||
otherFiles = append(otherFiles, filepath.Join(homeDir, ".kube", "k3s.yaml"))
|
||||
}
|
||||
otherFiles = append(otherFiles, "/etc/rancher/k3s/k3s.yaml")
|
||||
loadingRules.Precedence = append(loadingRules.Precedence, canRead(otherFiles)...)
|
||||
|
||||
return loadingRules
|
||||
}
|
||||
|
||||
func canRead(files []string) (result []string) {
|
||||
for _, f := range files {
|
||||
_, err := ioutil.ReadFile(f)
|
||||
if err == nil {
|
||||
result = append(result, f)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package cronjob
|
||||
|
||||
import (
|
||||
"context"
|
||||
"pandax/base/global"
|
||||
|
||||
"go.uber.org/zap"
|
||||
batch "k8s.io/api/batch/v1"
|
||||
@@ -10,7 +11,7 @@ import (
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"pandax/apps/devops/entity/k8s"
|
||||
k8scommon "pandax/apps/devops/services/k8s/common"
|
||||
"pandax/apps/devops/services/pkg/k8s/job"
|
||||
"pandax/apps/devops/services/k8s/job"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package daemonset
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"pandax/base/global"
|
||||
|
||||
"go.uber.org/zap"
|
||||
apps "k8s.io/api/apps/v1"
|
||||
|
||||
@@ -3,12 +3,13 @@ package daemonset
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"pandax/base/global"
|
||||
|
||||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
k8scommon "pandax/apps/devops/services/k8s/common"
|
||||
"pandax/apps/devops/services/pkg/k8s/service"
|
||||
"pandax/apps/devops/services/k8s/service"
|
||||
)
|
||||
|
||||
// DaemonSetDetail represents detailed information about a Daemon Set.
|
||||
|
||||
@@ -2,6 +2,7 @@ package daemonset
|
||||
|
||||
import (
|
||||
"context"
|
||||
"pandax/base/global"
|
||||
|
||||
"go.uber.org/zap"
|
||||
apps "k8s.io/api/apps/v1"
|
||||
|
||||
@@ -3,12 +3,13 @@ package ingress
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"pandax/base/global"
|
||||
|
||||
"pandax/apps/devops/entity/k8s"
|
||||
k8scommon "pandax/apps/devops/services/k8s/common"
|
||||
"pandax/apps/devops/services/k8s/dataselect"
|
||||
//v1 "k8s.io/api/extensions/v1beta1"
|
||||
v1 "k8s.io/api/networking/v1"
|
||||
v1 "k8s.io/api/networking/v1beta1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
client "k8s.io/client-go/kubernetes"
|
||||
)
|
||||
@@ -36,7 +37,7 @@ type IngressList struct {
|
||||
// GetIngressList returns all ingresses in the given namespace.
|
||||
func GetIngressList(client *client.Clientset, namespace *k8scommon.NamespaceQuery, dsQuery *dataselect.DataSelectQuery) (*IngressList, error) {
|
||||
//ingressList, err := client.ExtensionsV1beta1().Ingresses(namespace.ToRequestParam()).List(context.TODO(), k8s.ListEverything)
|
||||
ingressList, err := client.NetworkingV1().Ingresses(namespace.ToRequestParam()).List(context.TODO(), k8s.ListEverything)
|
||||
ingressList, err := client.NetworkingV1beta1().Ingresses(namespace.ToRequestParam()).List(context.TODO(), k8s.ListEverything)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -3,7 +3,7 @@ package ingress
|
||||
import (
|
||||
"pandax/apps/devops/services/k8s/dataselect"
|
||||
//v1 "k8s.io/api/extensions/v1beta1"
|
||||
v1 "k8s.io/api/networking/v1"
|
||||
v1 "k8s.io/api/networking/v1beta1"
|
||||
)
|
||||
|
||||
// The code below allows to perform complex data section on []extensions.Ingress
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"pandax/base/global"
|
||||
|
||||
//v1 "k8s.io/api/extensions/v1beta1"
|
||||
v1 "k8s.io/api/networking/v1"
|
||||
v1 "k8s.io/api/networking/v1beta1"
|
||||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
client "k8s.io/client-go/kubernetes"
|
||||
)
|
||||
@@ -29,7 +29,7 @@ func GetIngressDetail(client *client.Clientset, namespace, name string) (*Ingres
|
||||
global.Log.Info(fmt.Sprintf("Getting details of %s ingress in %s namespace", name, namespace))
|
||||
|
||||
//rawIngress, err := client.ExtensionsV1beta1().Ingresses(namespace).Get(context.TODO(), name, metaV1.GetOptions{})
|
||||
rawIngress, err := client.NetworkingV1().Ingresses(namespace).Get(context.TODO(), name, metaV1.GetOptions{})
|
||||
rawIngress, err := client.NetworkingV1beta1().Ingresses(namespace).Get(context.TODO(), name, metaV1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package job
|
||||
|
||||
import (
|
||||
"context"
|
||||
"pandax/base/global"
|
||||
|
||||
"go.uber.org/zap"
|
||||
batch "k8s.io/api/batch/v1"
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"pandax/apps/devops/services/k8s/event"
|
||||
"pandax/base/global"
|
||||
|
||||
"pandax/apps/devops/entity/k8s"
|
||||
k8scommon "pandax/apps/devops/services/k8s/common"
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"pandax/apps/devops/services/pkg/k8s/logs"
|
||||
"pandax/apps/devops/services/k8s/logs"
|
||||
)
|
||||
|
||||
// maximum number of lines loaded from the apiserver
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"pandax/base/global"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
res "k8s.io/apimachinery/pkg/api/resource"
|
||||
@@ -16,7 +17,7 @@ import (
|
||||
k8scommon "pandax/apps/devops/services/k8s/common"
|
||||
"pandax/apps/devops/services/k8s/controller"
|
||||
"pandax/apps/devops/services/k8s/dataselect"
|
||||
"pandax/apps/devops/services/pkg/k8s/pvc"
|
||||
"pandax/apps/devops/services/k8s/pvc"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package pods
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"pandax/base/global"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
@@ -3,6 +3,7 @@ package pv
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"pandax/base/global"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
@@ -3,6 +3,7 @@ package pv
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"pandax/base/global"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
@@ -3,6 +3,7 @@ package pvc
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"pandax/base/global"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
@@ -3,6 +3,7 @@ package pvc
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"pandax/base/global"
|
||||
|
||||
api "k8s.io/api/core/v1"
|
||||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
@@ -3,6 +3,7 @@ package secret
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"pandax/base/global"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
@@ -3,6 +3,7 @@ package statefulset
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"pandax/base/global"
|
||||
|
||||
"go.uber.org/zap"
|
||||
apps "k8s.io/api/apps/v1"
|
||||
@@ -226,10 +227,10 @@ func ScaleStatefulSet(client *kubernetes.Clientset, ns string, name string, scal
|
||||
// GetStatusInfo is used to get the status information from the *apps.StatefulSetStatus
|
||||
func GetStatusInfo(statefulSetStatus *apps.StatefulSetStatus) StatusInfo {
|
||||
return StatusInfo{
|
||||
Replicas: statefulSetStatus.Replicas,
|
||||
Updated: statefulSetStatus.UpdatedReplicas,
|
||||
AvailableReplicas: statefulSetStatus.AvailableReplicas,
|
||||
ReadyReplicas: statefulSetStatus.ReadyReplicas,
|
||||
CurrentReplicas: statefulSetStatus.CurrentReplicas,
|
||||
Replicas: statefulSetStatus.Replicas,
|
||||
Updated: statefulSetStatus.UpdatedReplicas,
|
||||
//AvailableReplicas: statefulSetStatus.AvailableReplicas,
|
||||
ReadyReplicas: statefulSetStatus.ReadyReplicas,
|
||||
CurrentReplicas: statefulSetStatus.CurrentReplicas,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package statefulset
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"pandax/base/global"
|
||||
|
||||
apps "k8s.io/api/apps/v1"
|
||||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -10,7 +11,7 @@ import (
|
||||
k8scommon "pandax/apps/devops/services/k8s/common"
|
||||
"pandax/apps/devops/services/k8s/dataselect"
|
||||
"pandax/apps/devops/services/k8s/event"
|
||||
"pandax/apps/devops/services/pkg/k8s/service"
|
||||
"pandax/apps/devops/services/k8s/service"
|
||||
)
|
||||
|
||||
// StatefulSetDetail is a presentation layer view of Kubernetes Stateful Set resource. This means it is Stateful
|
||||
|
||||
@@ -2,6 +2,7 @@ package statefulset
|
||||
|
||||
import (
|
||||
"context"
|
||||
"pandax/base/global"
|
||||
|
||||
"go.uber.org/zap"
|
||||
apps "k8s.io/api/apps/v1"
|
||||
|
||||
@@ -3,6 +3,7 @@ package storageclass
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"pandax/base/global"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
storage "k8s.io/api/storage/v1"
|
||||
|
||||
@@ -3,12 +3,13 @@ package storageclass
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"pandax/base/global"
|
||||
|
||||
storage "k8s.io/api/storage/v1"
|
||||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"pandax/apps/devops/services/k8s/dataselect"
|
||||
"pandax/apps/devops/services/pkg/k8s/pv"
|
||||
"pandax/apps/devops/services/k8s/pv"
|
||||
)
|
||||
|
||||
// StorageClassDetail provides the presentation layer view of Storage Class resource.
|
||||
|
||||
Reference in New Issue
Block a user