Documentation ΒΆ
Overview ΒΆ
Package ok8s help you manger kubernetes resource
A High encapsulation Kubernetes Golang-api base client-go ΒΆ
As quick start
nsName := "test" client := ok8s.NewTestClientSet()
Create deployment
namespaceInstance := ok8s.NewNameSpace(client) namespaceInstance.Create(nsName)
Get deployment
_, deployment := deploymentInstance.Get(nsName, resourceName) FormatPrint("Deployment", deployment.Deployment.Name)
Delete deployment
deploymentInstance.Delete(nsName, resourceName) if deploymentInstance.IsExits(nsName, resourceName) { fmt.Println("Not delete") } else { fmt.Println("Delete Success") }
Index ΒΆ
- func AllToMi(value string) string
- func BuildConfig(kubeConfigPath ...string) (*rest.Config, error)
- func ClientSet(file string) *kubernetes.Clientset
- func DefaultTimeOut() context.Context
- func MetricsClientSet(file string) *versioned.Clientset
- func MetricsToInt(metric, sep string) int
- func NewInformer(sets *kubernetes.Clientset)
- func TimeOut(time time.Duration) context.Context
- type ClientSets
- type ConfigMapType
- func (c *ConfigMapType) Create(namespace string, resource interface{}) (bool, error)
- func (c *ConfigMapType) Delete(namespace, name string) (bool, error)
- func (c *ConfigMapType) Get(namespace, name string) (bool, KResource)
- func (c *ConfigMapType) IsExits(namespace, name string) bool
- func (c *ConfigMapType) List(namespace string) (KResource, error)
- func (c *ConfigMapType) Update(namespace string, resource interface{}) bool
- func (d *ConfigMapType) Watch(namespace string, eventFuncs cache.ResourceEventHandlerFuncs)
- type DeploymentType
- func (d *DeploymentType) Create(namespace string, resource interface{}) (bool, error)
- func (d *DeploymentType) Delete(namespace, name string) (bool, error)
- func (d *DeploymentType) Get(namespace, name string) (bool, KResource)
- func (d *DeploymentType) IsExits(namespace, name string) bool
- func (d *DeploymentType) Labels(deployment, namespace string) map[string]map[string]string
- func (d *DeploymentType) List(namespace string) (KResource, error)
- func (d *DeploymentType) Prefix(namespace string) interface{}
- func (d *DeploymentType) Update(namespace string, resource interface{}) bool
- func (d *DeploymentType) Watch(namespace string, eventFuncs cache.ResourceEventHandlerFuncs)
- type IngressType
- func (i *IngressType) Create(namespace string, resource interface{}) (bool, error)
- func (i *IngressType) Delete(namespace, name string) (bool, error)
- func (i *IngressType) Get(namespace, name string) (bool, KResource)
- func (i *IngressType) IsExits(namespace, name string) bool
- func (i *IngressType) List(namespace string) (KResource, error)
- func (i *IngressType) Prefix(namespace string) interface{}
- func (i *IngressType) Update(namespace string, resource interface{}) bool
- func (i *IngressType) Watch(namespace string, eventFuncs cache.ResourceEventHandlerFuncs)
- type K8sApi
- type KResource
- type MetricsClientSets
- type MetricsType
- func (m *MetricsType) GetContainerCpu(namespace, name string) (map[string]int64, error)
- func (m *MetricsType) GetLimitResource(namespace, name string) map[string]int64
- func (m *MetricsType) GetPodMetrics(namespace, name string) map[string]int64
- func (m *MetricsType) GetRequestResource(namespace, name string) map[string]int64
- func (m *MetricsType) GetSinglePodCpuUsage(namespace, name string) (cpu int64)
- func (m *MetricsType) GetSinglePodMemUsage(namespace, name string) int64
- type NameSpace
- func (ns *NameSpace) Create(namespace string) (bool, error)
- func (ns *NameSpace) Delete(name string) (bool, error)
- func (ns *NameSpace) IsExits(name string) bool
- func (ns *NameSpace) Label(name string, labels map[string]string) (bool, error)
- func (ns *NameSpace) List() (v1.NamespaceList, error)
- func (ns *NameSpace) Prefix() v12.NamespaceInterface
- func (ns *NameSpace) ShowLabels(name string) map[string]string
- type PodType
- func (p *PodType) Create(namespace string, resource interface{}) (bool, error)
- func (p *PodType) Delete(namespace, name string) (bool, error)
- func (p *PodType) Get(namespace, name string) (bool, KResource)
- func (p *PodType) GetByLabel(namespace string, label string) (*corev1.PodList, error)
- func (p *PodType) IsExits(namespace, name string) bool
- func (p *PodType) List(namespace string) (KResource, error)
- func (p *PodType) Prefix(namespace string) interface{}
- func (p *PodType) Update(namespace string, resource interface{}) bool
- func (p *PodType) Watch(namespace string, eventFuncs cache.ResourceEventHandlerFuncs)
- type SecretType
- func (s *SecretType) Create(namespace string, resource interface{}) (bool, error)
- func (s *SecretType) Delete(namespace, name string) (bool, error)
- func (s *SecretType) Get(namespace, name string) (bool, KResource)
- func (s *SecretType) IsExits(namespace, name string) bool
- func (s *SecretType) List(namespace string) (KResource, error)
- func (s *SecretType) Prefix(namespace string) interface{}
- func (s *SecretType) Update(namespace string, resource interface{}) bool
- func (s *SecretType) Watch(namespace string, eventFuncs cache.ResourceEventHandlerFuncs)
- type ServiceType
- func (s *ServiceType) Create(namespace string, resource interface{}) (bool, error)
- func (s *ServiceType) Delete(namespace, name string) (bool, error)
- func (s *ServiceType) Get(namespace, name string) (bool, KResource)
- func (s *ServiceType) IsExits(namespace, name string) bool
- func (s *ServiceType) List(namespace string) (KResource, error)
- func (s *ServiceType) Prefix(namespace string) interface{}
- func (s *ServiceType) Update(namespace string, resource interface{}) bool
- func (s *ServiceType) Watch(namespace string, eventFuncs cache.ResourceEventHandlerFuncs)
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func BuildConfig ΒΆ added in v0.1.8
func ClientSet ΒΆ
func ClientSet(file string) *kubernetes.Clientset
func DefaultTimeOut ΒΆ
func MetricsClientSet ΒΆ
MetricsClientSet use get pod cpu mem and other monitor metrics
func MetricsToInt ΒΆ
func NewInformer ΒΆ
func NewInformer(sets *kubernetes.Clientset)
Types ΒΆ
type ClientSets ΒΆ
type ClientSets struct {
ClientSet *kubernetes.Clientset
}
ClientSet kubernetes.Clientset
func NewClientSet ΒΆ
func NewClientSet(clientset *kubernetes.Clientset) *ClientSets
func NewTestClientSet ΒΆ
func NewTestClientSet() ClientSets
func (*ClientSets) Prefix ΒΆ
func (c *ClientSets) Prefix(namespace string) interface{}
type ConfigMapType ΒΆ
type ConfigMapType struct { ClientSets KResource }
func (*ConfigMapType) Create ΒΆ
func (c *ConfigMapType) Create(namespace string, resource interface{}) (bool, error)
The resource struct is apicorev1.ConfigMapType
func (*ConfigMapType) Delete ΒΆ
func (c *ConfigMapType) Delete(namespace, name string) (bool, error)
func (*ConfigMapType) Get ΒΆ
func (c *ConfigMapType) Get(namespace, name string) (bool, KResource)
Get return apicorev1.ConfigMapType
func (*ConfigMapType) IsExits ΒΆ
func (c *ConfigMapType) IsExits(namespace, name string) bool
func (*ConfigMapType) List ΒΆ
func (c *ConfigMapType) List(namespace string) (KResource, error)
List return multiple apicorev1.ConfigMapType
func (*ConfigMapType) Update ΒΆ
func (c *ConfigMapType) Update(namespace string, resource interface{}) bool
The resource struct is apicorev1.ConfigMapType
func (*ConfigMapType) Watch ΒΆ
func (d *ConfigMapType) Watch(namespace string, eventFuncs cache.ResourceEventHandlerFuncs)
type DeploymentType ΒΆ
type DeploymentType struct { ClientSets KResource }
func (*DeploymentType) Create ΒΆ
func (d *DeploymentType) Create(namespace string, resource interface{}) (bool, error)
func (*DeploymentType) Delete ΒΆ
func (d *DeploymentType) Delete(namespace, name string) (bool, error)
func (*DeploymentType) Get ΒΆ
func (d *DeploymentType) Get(namespace, name string) (bool, KResource)
func (*DeploymentType) IsExits ΒΆ
func (d *DeploymentType) IsExits(namespace, name string) bool
func (*DeploymentType) Labels ΒΆ
func (d *DeploymentType) Labels(deployment, namespace string) map[string]map[string]string
func (*DeploymentType) Prefix ΒΆ
func (d *DeploymentType) Prefix(namespace string) interface{}
func (*DeploymentType) Update ΒΆ
func (d *DeploymentType) Update(namespace string, resource interface{}) bool
func (*DeploymentType) Watch ΒΆ
func (d *DeploymentType) Watch(namespace string, eventFuncs cache.ResourceEventHandlerFuncs)
type IngressType ΒΆ
type IngressType struct { ClientSets KResource }
func (*IngressType) Create ΒΆ
func (i *IngressType) Create(namespace string, resource interface{}) (bool, error)
func (*IngressType) IsExits ΒΆ
func (i *IngressType) IsExits(namespace, name string) bool
func (*IngressType) Prefix ΒΆ
func (i *IngressType) Prefix(namespace string) interface{}
func (*IngressType) Update ΒΆ
func (i *IngressType) Update(namespace string, resource interface{}) bool
func (*IngressType) Watch ΒΆ
func (i *IngressType) Watch(namespace string, eventFuncs cache.ResourceEventHandlerFuncs)
type K8sApi ΒΆ
type K8sApi interface { // The resource api interface Prefix(namespace string) interface{} // Create resource from namespace and resource struct /* For DeploymentType k8s.io/api/apps/v1 v1.deployment * For Configmap k8s.io/api/core/v1 v1.configmap */ Create(namespace string, resource interface{}) (bool, error) // Get a resource from namespace and resource name Get(namespace, name string) (bool, KResource) // IsExits judge resource exits IsExits(namespace, name string) bool // Delete a resource from namespace and resource name Delete(namespace, name string) (bool, error) // List multiple resource from one namespace List(namespace string) (KResource, error) // Update a resource Update(namespace string, resource interface{}) bool //Labels(DeploymentType, namespace string) map[string]map[string]string // Watch a resource /* Example: * eventFuncs := new(cache.ResourceEventHandlerFuncs) * eventFuncs.DeleteFunc= func(obj interface{}) { * DeploymentType := obj.(*appsv1.DeploymentType) * log.Printf("delete DeploymentType %s",DeploymentType.Name) * fmt.Println(Deployment.Labels,DeploymentType.Spec.Template.Labels) * } * eventFuncs.AddFunc= func(obj interface{}) { * DeploymentType := obj.(*appsv1.DeploymentType) * log.Printf("add DeploymentType %s",DeploymentType.Name) * fmt.Println(DeploymentType.Labels,DeploymentType.Spec.Template.Labels) * } * Watch("default",eventFuncs) */ Watch(namespace string, eventFuncs cache.ResourceEventHandlerFuncs) }
K8sApi define resource operate method
func NewConfigMap ΒΆ
func NewConfigMap(cs ClientSets) K8sApi
func NewDeployment ΒΆ
func NewDeployment(cs ClientSets) K8sApi
func NewIngress ΒΆ
func NewIngress(cs ClientSets) K8sApi
func NewSecret ΒΆ
func NewSecret(cs ClientSets) K8sApi
func NewService ΒΆ
func NewService(cs ClientSets) K8sApi
type KResource ΒΆ
type KResource struct { Deployment appsv1.Deployment DeploymentList appsv1.DeploymentList Configmap apicorev1.ConfigMap ConfigmapList apicorev1.ConfigMapList Service apicorev1.Service ServiceList apicorev1.ServiceList Secret apicorev1.Secret SecretList apicorev1.SecretList Ingress v1beta1.Ingress IngressList v1beta1.IngressList Pod apicorev1.Pod PodList apicorev1.PodList }
Kubernetes Resource struct
Unified all resource
type MetricsClientSets ΒΆ
type MetricsType ΒΆ added in v0.1.6
type MetricsType struct { MetricsClientSets PodType }
func NewMetrics ΒΆ added in v0.1.6
func NewMetrics(kubeConfig string) *MetricsType
func (*MetricsType) GetContainerCpu ΒΆ added in v0.1.6
func (m *MetricsType) GetContainerCpu(namespace, name string) (map[string]int64, error)
GetContainerCpu return a pod all containers cpu(map[string]int)
func (*MetricsType) GetLimitResource ΒΆ added in v0.1.6
func (m *MetricsType) GetLimitResource(namespace, name string) map[string]int64
func (*MetricsType) GetPodMetrics ΒΆ added in v0.1.7
func (m *MetricsType) GetPodMetrics(namespace, name string) map[string]int64
GetPodMetrics return a map. This contain cpu(m)γmem(Mi) and storage
func (*MetricsType) GetRequestResource ΒΆ added in v0.1.6
func (m *MetricsType) GetRequestResource(namespace, name string) map[string]int64
default unit cpu is,m mem is Mi
func (*MetricsType) GetSinglePodCpuUsage ΒΆ added in v0.1.7
func (m *MetricsType) GetSinglePodCpuUsage(namespace, name string) (cpu int64)
GetSinglePodCpuUsage return pod cpu(int)
func (*MetricsType) GetSinglePodMemUsage ΒΆ added in v0.1.7
func (m *MetricsType) GetSinglePodMemUsage(namespace, name string) int64
GetSinglePodMemUsage return mem(int)
type NameSpace ΒΆ
type NameSpace struct {
ClientSets
}
func NewNameSpace ΒΆ
func NewNameSpace(cs ClientSets) *NameSpace
func (*NameSpace) Prefix ΒΆ
func (ns *NameSpace) Prefix() v12.NamespaceInterface
type PodType ΒΆ
type PodType struct { ClientSets KResource }
func NewPodFunc ΒΆ added in v0.1.6
func (*PodType) GetByLabel ΒΆ
type SecretType ΒΆ
type SecretType struct { ClientSets KResource }
func (*SecretType) Create ΒΆ
func (s *SecretType) Create(namespace string, resource interface{}) (bool, error)
func (*SecretType) IsExits ΒΆ
func (s *SecretType) IsExits(namespace, name string) bool
func (*SecretType) Prefix ΒΆ
func (s *SecretType) Prefix(namespace string) interface{}
func (*SecretType) Update ΒΆ
func (s *SecretType) Update(namespace string, resource interface{}) bool
func (*SecretType) Watch ΒΆ
func (s *SecretType) Watch(namespace string, eventFuncs cache.ResourceEventHandlerFuncs)
type ServiceType ΒΆ
type ServiceType struct { ClientSets KResource }
func (*ServiceType) Create ΒΆ
func (s *ServiceType) Create(namespace string, resource interface{}) (bool, error)
func (*ServiceType) IsExits ΒΆ
func (s *ServiceType) IsExits(namespace, name string) bool
func (*ServiceType) Prefix ΒΆ
func (s *ServiceType) Prefix(namespace string) interface{}
func (*ServiceType) Update ΒΆ
func (s *ServiceType) Update(namespace string, resource interface{}) bool
func (*ServiceType) Watch ΒΆ
func (s *ServiceType) Watch(namespace string, eventFuncs cache.ResourceEventHandlerFuncs)