k8sinterface

package
v1.0.121 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const ValueNotFound = -1

Variables

View Source
var ConnectedToCluster = true
View Source
var GroupsClusterScope = []string{}
View Source
var K8SConfig *restclient.Config

K8SConfig pointer to k8s config

View Source
var ResourceClusterScope = []string{"nodes", "namespaces", "clusterroles", "clusterrolebindings"}
View Source
var ResourceGroupMapping = map[string]string{
	"services":                        "/v1",
	"pods":                            "/v1",
	"replicationcontrollers":          "/v1",
	"podtemplates":                    "/v1",
	"namespaces":                      "/v1",
	"nodes":                           "/v1",
	"configmaps":                      "/v1",
	"secrets":                         "/v1",
	"serviceaccounts":                 "/v1",
	"persistentvolumeclaims":          "/v1",
	"limitranges":                     "/v1",
	"resourcequotas":                  "/v1",
	"daemonsets":                      "apps/v1",
	"deployments":                     "apps/v1",
	"replicasets":                     "apps/v1",
	"statefulsets":                    "apps/v1",
	"controllerrevisions":             "apps/v1",
	"jobs":                            "batch/v1",
	"cronjobs":                        "batch/v1beta1",
	"horizontalpodautoscalers":        "autoscaling/v1",
	"ingresses":                       "extensions/v1beta1",
	"networkpolicies":                 "networking.k8s.io/v1",
	"clusterroles":                    "rbac.authorization.k8s.io/v1",
	"clusterrolebindings":             "rbac.authorization.k8s.io/v1",
	"roles":                           "rbac.authorization.k8s.io/v1",
	"rolebindings":                    "rbac.authorization.k8s.io/v1",
	"mutatingwebhookconfigurations":   "admissionregistration.k8s.io/v1",
	"validatingwebhookconfigurations": "admissionregistration.k8s.io/v1",
}

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#-strong-api-groups-strong-

View Source
var RunningIncluster bool

RunningIncluster whether running in cluster

Functions

func CheckIsACRImage

func CheckIsACRImage(imageTag string) bool

func CheckIsECRImage

func CheckIsECRImage(imageTag string) bool

CheckIsECRImage check if this image is suspected as ECR hosted image

func CheckIsGCRImage

func CheckIsGCRImage(imageTag string) bool

func ConvertUnstructuredSliceToMap

func ConvertUnstructuredSliceToMap(unstructuredSlice []unstructured.Unstructured) []map[string]interface{}

func FilterOutOwneredResources

func FilterOutOwneredResources(result []unstructured.Unstructured) []unstructured.Unstructured

func GetCloudVendorRegistryCredentials

func GetCloudVendorRegistryCredentials(imageTag string) (map[string]types.AuthConfig, error)

func GetClusterName added in v1.0.44

func GetClusterName() string

func GetDefaultNamespace added in v1.0.44

func GetDefaultNamespace() string

func GetGroupVersionResource

func GetGroupVersionResource(resource string) (schema.GroupVersionResource, error)

func GetK8sConfig

func GetK8sConfig() *restclient.Config

GetK8sConfig get config. load if not loaded yet

func GetLoginDetailsForAzurCR

func GetLoginDetailsForAzurCR(imageTag string) (string, string, error)

GetLoginDetailsForAzurCR return user name + password to use

func GetLoginDetailsForECR

func GetLoginDetailsForECR(imageTag string) (string, string, error)

GetLoginDetailsForECR return user name + password using the default iam-role OR ~/.aws/config of the machine

func GetLoginDetailsForGCR

func GetLoginDetailsForGCR(imageTag string) (string, string, error)

GetLoginDetailsForGCR return user name + password to use

func GetResourceTriplets

func GetResourceTriplets(group, version, resource string) []string

func InspectWorkload

func InspectWorkload(workload interface{}, scopes ...string) (val interface{}, k bool)

InspectWorkload -

func IsAgentCompatibleAnnotation

func IsAgentCompatibleAnnotation(annotations map[string]string) *bool

func IsAgentCompatibleLabel

func IsAgentCompatibleLabel(labels map[string]string) *bool

func IsAttached

func IsAttached(labels map[string]string) *bool

func IsConnectedToCluster added in v1.0.44

func IsConnectedToCluster() bool

func IsLabel

func IsLabel(labels map[string]string, key string) *bool

func IsNamespaceScope

func IsNamespaceScope(apiGroup, resource string) bool

func IsStringInSlice

func IsStringInSlice(slice []string, val string) bool

func JoinResourceTriplets

func JoinResourceTriplets(group, version, resource string) string

func LoadK8sConfig

func LoadK8sConfig() error

LoadK8sConfig load config from local file or from cluster

func PodMetadata

func PodMetadata(kind string) []string

func PodSpec

func PodSpec(kind string) []string

func ResourceGroupToString

func ResourceGroupToString(group, version, resource string) []string

func SelectorToString

func SelectorToString(ls labels.Set) string

String returns all labels listed as a human readable string. Conveniently, exactly the format that ParseSelector takes.

func SetAgentCompatibleAnnotation

func SetAgentCompatibleAnnotation(annotations map[string]string, val bool)

func SetAgentCompatibleLabel

func SetAgentCompatibleLabel(labels map[string]string, val bool)

func SetLabel

func SetLabel(labels map[string]string, key string, val bool)

func StringInSlice

func StringInSlice(strSlice []string, str string) int

func StringToResourceGroup

func StringToResourceGroup(str string) (string, string, string)

func V1AllClusterWithCompromisedRegistriesMock

func V1AllClusterWithCompromisedRegistriesMock() *unstructured.UnstructuredList

func V1KubeSystemNamespaceMock

func V1KubeSystemNamespaceMock() *unstructured.UnstructuredList

Types

type IBasicWorkload

type IBasicWorkload interface {

	// Set
	SetKind(string)
	SetWorkload(map[string]interface{})
	SetLabel(key, value string)
	SetAnnotation(key, value string)
	SetNamespace(string)
	SetName(string)

	// Get
	GetNamespace() string
	GetName() string
	GetGenerateName() string
	GetApiVersion() string
	GetKind() string
	GetInnerAnnotation(string) (string, bool)
	GetPodAnnotation(string) (string, bool)
	GetAnnotation(string) (string, bool)
	GetLabel(string) (string, bool)
	GetAnnotations() map[string]string
	GetInnerAnnotations() map[string]string
	GetPodAnnotations() map[string]string
	GetLabels() map[string]string
	GetInnerLabels() map[string]string
	GetPodLabels() map[string]string
	GetVolumes() ([]corev1.Volume, error)
	GetReplicas() int
	GetContainers() ([]corev1.Container, error)
	GetInitContainers() ([]corev1.Container, error)
	GetOwnerReferences() ([]metav1.OwnerReference, error)
	GetImagePullSecret() ([]corev1.LocalObjectReference, error)
	GetServiceAccountName() string
	GetSelector() (*metav1.LabelSelector, error)
	GetResourceVersion() string
	GetUID() string
	GetPodSpec() (*corev1.PodSpec, error)

	GetWorkload() map[string]interface{}

	// REMOVE
	RemoveLabel(string)
	RemoveAnnotation(string)
	RemovePodStatus()
	RemoveResourceVersion()
}

type IWorkload

type IWorkload interface {
	IBasicWorkload

	// Convert
	ToUnstructured() (*unstructured.Unstructured, error)
	ToString() string
	Json() string // DEPRECATED

	// GET
	GetWlid() string
	GetJobID() *apis.JobTracking
	GetVersion() string
	GetGroup() string

	// SET
	SetWlid(string)
	SetInject()
	SetIgnore()
	SetUpdateTime()
	SetJobID(apis.JobTracking)
	SetCompatible()
	SetIncompatible()
	SetReplaceheaders()

	// EXIST
	IsIgnore() bool
	IsInject() bool
	IsAttached() bool
	IsCompatible() bool
	IsIncompatible() bool

	// REMOVE
	RemoveWlid()
	RemoveSecretData()
	RemoveInject()
	RemoveIgnore()
	RemoveUpdateTime()
	RemoveJobID()
	RemoveCompatible()
	RemoveArmoMetadata()
	RemoveArmoLabels()
	RemoveArmoAnnotations()
}

type KubernetesApi

type KubernetesApi struct {
	KubernetesClient kubernetes.Interface
	DynamicClient    dynamic.Interface
	Context          context.Context
}

KubernetesApi -

func NewKubernetesApi

func NewKubernetesApi() *KubernetesApi

NewKubernetesApi -

func (*KubernetesApi) CalculateWorkloadParentRecursive

func (k8sAPI *KubernetesApi) CalculateWorkloadParentRecursive(workload *Workload) (string, string, error)

func (*KubernetesApi) CreateWorkload

func (k8sAPI *KubernetesApi) CreateWorkload(workload *Workload) (*Workload, error)

func (*KubernetesApi) DeleteWorkloadByWlid

func (k8sAPI *KubernetesApi) DeleteWorkloadByWlid(wlid string) error

func (*KubernetesApi) GetNamespace

func (k8sAPI *KubernetesApi) GetNamespace(ns string) (*Workload, error)

func (*KubernetesApi) GetWorkload

func (k8sAPI *KubernetesApi) GetWorkload(namespace, kind, name string) (*Workload, error)

func (*KubernetesApi) GetWorkloadByWlid

func (k8sAPI *KubernetesApi) GetWorkloadByWlid(wlid string) (*Workload, error)

func (*KubernetesApi) ListAttachedPods

func (k8sAPI *KubernetesApi) ListAttachedPods(namespace string) ([]corev1.Pod, error)

func (*KubernetesApi) ListPods

func (k8sAPI *KubernetesApi) ListPods(namespace string, podLabels map[string]string) ([]corev1.Pod, error)

func (*KubernetesApi) ListWorkloads

func (k8sAPI *KubernetesApi) ListWorkloads(groupVersionResource *schema.GroupVersionResource, namespace string, podLabels, fieldSelector map[string]string) ([]Workload, error)

func (*KubernetesApi) ResourceInterface

func (k8sAPI *KubernetesApi) ResourceInterface(resource *schema.GroupVersionResource, namespace string) dynamic.ResourceInterface

func (*KubernetesApi) UpdateWorkload

func (k8sAPI *KubernetesApi) UpdateWorkload(workload *Workload) (*Workload, error)

type Workload

type Workload struct {
	// contains filtered or unexported fields
}

func NewWorkload

func NewWorkload(bWorkload []byte) (*Workload, error)

func NewWorkloadObj

func NewWorkloadObj(workload map[string]interface{}) *Workload

func (*Workload) DeepCopy

func (workload *Workload) DeepCopy(w map[string]interface{})

func (*Workload) GetAnnotation

func (w *Workload) GetAnnotation(annotation string) (string, bool)

func (*Workload) GetAnnotations

func (w *Workload) GetAnnotations() map[string]string

func (*Workload) GetApiVersion

func (w *Workload) GetApiVersion() string

func (*Workload) GetContainers

func (w *Workload) GetContainers() ([]corev1.Container, error)

GetContainers -

func (*Workload) GetGenerateName

func (w *Workload) GetGenerateName() string

func (*Workload) GetGroup

func (w *Workload) GetGroup() string

func (*Workload) GetImagePullSecret

func (w *Workload) GetImagePullSecret() ([]corev1.LocalObjectReference, error)

func (*Workload) GetInitContainers

func (w *Workload) GetInitContainers() ([]corev1.Container, error)

GetInitContainers -

func (*Workload) GetInnerAnnotation

func (w *Workload) GetInnerAnnotation(annotation string) (string, bool)

GetInnerAnnotation DEPRECATED

func (*Workload) GetInnerAnnotations

func (w *Workload) GetInnerAnnotations() map[string]string

GetInnerAnnotations - DEPRECATED

func (*Workload) GetInnerLabels

func (w *Workload) GetInnerLabels() map[string]string

GetInnerLabels - DEPRECATED

func (*Workload) GetJobID

func (w *Workload) GetJobID() *apis.JobTracking

func (*Workload) GetKind

func (w *Workload) GetKind() string

func (*Workload) GetLabel

func (w *Workload) GetLabel(label string) (string, bool)

func (*Workload) GetLabels

func (w *Workload) GetLabels() map[string]string

func (*Workload) GetName

func (w *Workload) GetName() string

func (*Workload) GetNamespace

func (w *Workload) GetNamespace() string

func (*Workload) GetOwnerReferences

func (w *Workload) GetOwnerReferences() ([]metav1.OwnerReference, error)

GetOwnerReferences -

func (*Workload) GetPodAnnotation

func (w *Workload) GetPodAnnotation(annotation string) (string, bool)

func (*Workload) GetPodAnnotations

func (w *Workload) GetPodAnnotations() map[string]string

GetPodAnnotations

func (*Workload) GetPodLabel

func (w *Workload) GetPodLabel(label string) (string, bool)

func (*Workload) GetPodLabels

func (w *Workload) GetPodLabels() map[string]string

func (*Workload) GetPodSpec

func (w *Workload) GetPodSpec() (*corev1.PodSpec, error)

func (*Workload) GetReplicas

func (w *Workload) GetReplicas() int

func (*Workload) GetResourceVersion

func (w *Workload) GetResourceVersion() string

func (*Workload) GetSelector

func (w *Workload) GetSelector() (*metav1.LabelSelector, error)

func (*Workload) GetServiceAccountName

func (w *Workload) GetServiceAccountName() string

func (*Workload) GetUID

func (w *Workload) GetUID() string

func (*Workload) GetVersion

func (w *Workload) GetVersion() string

func (*Workload) GetVolumes

func (w *Workload) GetVolumes() ([]corev1.Volume, error)

GetVolumes -

func (*Workload) GetWlid

func (w *Workload) GetWlid() string

func (*Workload) GetWorkload

func (w *Workload) GetWorkload() map[string]interface{}

========================================= GET =========================================

func (*Workload) IsAttached

func (w *Workload) IsAttached() bool

func (*Workload) IsCompatible

func (w *Workload) IsCompatible() bool

func (*Workload) IsIgnore

func (w *Workload) IsIgnore() bool

func (*Workload) IsIncompatible

func (w *Workload) IsIncompatible() bool

func (*Workload) IsInject

func (w *Workload) IsInject() bool

func (*Workload) IsReplaceheaders

func (w *Workload) IsReplaceheaders() bool

func (*Workload) Json

func (w *Workload) Json() string

func (*Workload) RemoveAnnotation

func (w *Workload) RemoveAnnotation(key string)

func (*Workload) RemoveArmoAnnotations

func (w *Workload) RemoveArmoAnnotations()

func (*Workload) RemoveArmoLabels

func (w *Workload) RemoveArmoLabels()

func (*Workload) RemoveArmoMetadata

func (w *Workload) RemoveArmoMetadata()

func (*Workload) RemoveCompatible

func (w *Workload) RemoveCompatible()

func (*Workload) RemoveIgnore

func (w *Workload) RemoveIgnore()

func (*Workload) RemoveInject

func (w *Workload) RemoveInject()

func (*Workload) RemoveJobID

func (w *Workload) RemoveJobID()

func (*Workload) RemoveLabel

func (w *Workload) RemoveLabel(key string)

func (*Workload) RemoveMetadata

func (w *Workload) RemoveMetadata(scope []string, metadata, key string)

func (*Workload) RemovePodAnnotation

func (w *Workload) RemovePodAnnotation(key string)

func (*Workload) RemovePodLabel

func (w *Workload) RemovePodLabel(key string)

func (*Workload) RemovePodStatus

func (w *Workload) RemovePodStatus()

func (*Workload) RemoveResourceVersion

func (w *Workload) RemoveResourceVersion()

func (*Workload) RemoveSecretData

func (w *Workload) RemoveSecretData()

func (*Workload) RemoveUpdateTime

func (w *Workload) RemoveUpdateTime()

func (*Workload) RemoveWlid

func (w *Workload) RemoveWlid()

func (*Workload) SetAnnotation

func (w *Workload) SetAnnotation(key, value string)

func (*Workload) SetCompatible

func (w *Workload) SetCompatible()

func (*Workload) SetIgnore

func (w *Workload) SetIgnore()

func (*Workload) SetIncompatible

func (w *Workload) SetIncompatible()

func (*Workload) SetInject

func (w *Workload) SetInject()

func (*Workload) SetJobID

func (w *Workload) SetJobID(jobTracking apis.JobTracking)

func (*Workload) SetKind

func (w *Workload) SetKind(kind string)

func (*Workload) SetLabel

func (w *Workload) SetLabel(key, value string)

func (*Workload) SetMetadata

func (w *Workload) SetMetadata(scope []string, key string, val interface{})

func (*Workload) SetName

func (w *Workload) SetName(name string)

func (*Workload) SetNamespace

func (w *Workload) SetNamespace(namespace string)

func (*Workload) SetPodAnnotation

func (w *Workload) SetPodAnnotation(key, value string)

func (*Workload) SetPodLabel

func (w *Workload) SetPodLabel(key, value string)

func (*Workload) SetReplaceheaders

func (w *Workload) SetReplaceheaders()

func (*Workload) SetUpdateTime

func (w *Workload) SetUpdateTime()

func (*Workload) SetWlid

func (w *Workload) SetWlid(wlid string)

func (*Workload) SetWorkload

func (w *Workload) SetWorkload(workload map[string]interface{})

func (*Workload) ToString

func (w *Workload) ToString() string

func (*Workload) ToUnstructured

func (w *Workload) ToUnstructured() (*unstructured.Unstructured, error)

Jump to

Keyboard shortcuts

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