k8s

package
v0.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Client = sync.OnceValue(func() *kubernetes.Clientset {
	config := ShowKubeConfig()

	clientset, errKubernetes := kubernetes.NewForConfig(config)
	if errKubernetes != nil {
		logrus.Fatal(errKubernetes)
	}

	return clientset
})

Client 获取k8s client

View Source
var PodCache = sync.OnceValue(func() *podCache {
	c := &podCache{
		livetime: time.Second * time.Duration(comm.ShowKubeteaConfig().PodCacheLivetime),
		dataRead: make(chan bool),
	}
	return c
})
View Source
var ShowApiConfig = sync.OnceValue(func() *api.Config {
	configAccess := clientcmd.NewDefaultPathOptions()
	configAccess.GetLoadingPrecedence()
	config, err := configAccess.GetStartingConfig()
	if err != nil {
		logrus.Fatalf("show api config error: %v", err)
	}
	return config
})

ShowApiConfig 获取kube的配置

View Source
var ShowKubeConfig = sync.OnceValue(func() *restclient.Config {

	configOverrides := &clientcmd.ConfigOverrides{
		CurrentContext: ShowContext(),
	}
	config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
		&clientcmd.ClientConfigLoadingRules{ExplicitPath: ShowKubeConfigPath()},
		configOverrides,
	).ClientConfig()
	if err != nil {
		logrus.Fatalf("Error loading kubeconfig: %v\n", err)
	}

	return config
})

ShowKubeConfig 获取kube的配置

View Source
var ShowKubeConfigPath = sync.OnceValue(func() string {

	kubeconfig := comm.Context.String("kubeconfig")
	if kubeconfig == "" {
		home, err := os.UserHomeDir()
		if err != nil {
			logrus.Fatal(err)
		}
		kubeconfig = filepath.Join(home, ".kube", "config")
	}
	return kubeconfig
})

ShowKubeConfigPath 获取kubeconfig的路径

Functions

func ContainerLog

func ContainerLog(podName string, containerName string) *rest.Request

ContainerLog 获取一个容器的日志

func ContainerShell

func ContainerShell(podName string, containerName string) *exec.Cmd

ContainerShell 生成一个容器Shell命令

func KubeCmd

func KubeCmd() *exec.Cmd

KubeCmd 生成kubectl基础命令,带有配置文件等通用参数

func KubeCmdArgs added in v0.0.13

func KubeCmdArgs(args ...string) *exec.Cmd

KubeCmdArgs 生成带指定参数的kubectl命令

func PodGet

func PodGet(name string) (*v12.Pod, error)

PodGet 获取一个POD的配置

func ShowContext

func ShowContext() string

ShowContext 获取指定的context

func ShowNamespace

func ShowNamespace() string

ShowNamespace 获取指定的的namespace

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL