k8sinterface

package
v0.0.79 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const ValueNotFound = -1

Variables

View Source
var K8SConfig *restclient.Config

K8SConfig pointer to k8s config

View Source
var ResourceClusterScope = []string{}

DEPRECATED - use the 'ResourceNamesapcedScope' instead

View Source
var RunningIncluster bool

RunningIncluster whether running in cluster

Functions

func ConvertUnstructuredSliceToMap

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

func FilterOutOwneredResources

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

func GetContextName added in v0.0.69

func GetContextName() string

func GetCurrentContext

func GetCurrentContext() *api.Context

DEPRECATED

func GetDefaultNamespace

func GetDefaultNamespace() string

func GetGroupVersionResource

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

GetGroupVersionResource get the group and version from the resource name. Returns error if not found

func GetK8sConfig

func GetK8sConfig() *restclient.Config

GetK8sConfig get config. load if not loaded yet

func GetResourceGroupMapping added in v0.0.49

func GetResourceGroupMapping() map[string]string

GetResourceGroupMapping returns copy of ResourceGroupMapping map object

func GetResourceListMock added in v0.0.28

func GetResourceListMock() ([]*metav1.APIResourceList, error)

func GetResourceNamesapcedScope added in v0.0.49

func GetResourceNamesapcedScope() []string

func GetSingleResourceFromGroupMapping added in v0.0.49

func GetSingleResourceFromGroupMapping(resource string) (string, bool)

func GroupVersionResourceToString added in v0.0.24

func GroupVersionResourceToString(resource *schema.GroupVersionResource) string

JoinResourceTriplets converts the schema.GroupVersionResource object to string by returning the group, version and kind with the '/' separator

func InitializeMapResources added in v0.0.24

func InitializeMapResources(discoveryClient discovery.DiscoveryInterface)

InitializeMapResources get supported api-resource (similar to 'kubectl api-resources') and map to 'ResourceGroupMapping' and 'ResourceNamesapcedScope'. If this function is not called, many functions may not work

func InitializeMapResourcesMock added in v0.0.24

func InitializeMapResourcesMock()

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

func IsConnectedToCluster() bool

func IsKindKubernetes added in v0.0.42

func IsKindKubernetes(kind string) bool

IsKindKubernetes check if the kind is known to be a kubernetes kind. In this check we do not test the apiVersion

func IsLabel

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

func IsNamespaceScope

func IsNamespaceScope(resource *schema.GroupVersionResource) bool

IsNamespaceScope returns true if the schema.GroupVersionResource is a kubernetes namespaced resource

func IsResourceInNamespaceScope added in v0.0.44

func IsResourceInNamespaceScope(resource string) bool

IsResourceInNamespaceScope returns true if the resource is a kubernetes namespaced resource

func IsStringInSlice

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

func IsTypeWorkload added in v0.0.46

func IsTypeWorkload(object map[string]interface{}) bool

TODO - consider using a k8s manifest validator Return if this object is a valide k8s workload

func JoinGroupVersion added in v0.0.24

func JoinGroupVersion(group, version string) string

JoinGroupVersion returns the group and version with the '/' separator

func JoinResourceTriplets

func JoinResourceTriplets(group, version, resource string) string

JoinResourceTriplets returns the group, version and kind with the '/' separator

func LoadK8sConfig

func LoadK8sConfig() error

LoadK8sConfig load config from local file or from cluster

func ResourceGroupToSlice

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

ResourceGroupToSlice receives a partly defined schema.GroupVersionResource and returns a list of all resources (kinds) in the representation of group/version/resource that support what was missing. Will ignore if kind is not Kubernetes

Examples:

GetResourceTriplets("*","*","pods") -> []string{"/v1/pods"} GetResourceTriplets("apps","v1","*") -> []string{"apps/v1/deployments", "apps/v1/replicasets", ... }

func ResourceGroupToString

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

DEPRECATED

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 SetClusterContextName added in v0.0.54

func SetClusterContextName(contextName string)

SetClusterContextName set the name of desired cluster context. The package will use this name when loading the context

func SetLabel

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

func SplitApiVersion added in v0.0.46

func SplitApiVersion(apiVersion string) (string, string)

SplitApiVersion receives apiVersion ("group/version") returns the group and version splitted

func SplitResourceTriplets added in v0.0.49

func SplitResourceTriplets(resourceTriplets string) (string, string, string)

SplitResourceTriplets receives group, version and kind with the '/' separator and returns them separated

func StringInSlice

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

StringInSlice utility for finding a string in a slice. Returns ValueNotFound (-1) if the string is not found in the slice

func StringToResourceGroup

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

StringToResourceGroup convert a representation to the original triplet

Examples:

StringToResourceGroup("apps/v1/deployments") -> "apps", "v1", "deployments" StringToResourceGroup("/v1/pods") -> "", "v1", "pods"

func V1AllClusterWithCompromisedRegistriesMock

func V1AllClusterWithCompromisedRegistriesMock() *unstructured.UnstructuredList

func V1KubeSystemNamespaceMock

func V1KubeSystemNamespaceMock() *unstructured.UnstructuredList

Types

type IWorkload

type IWorkload workloadinterface.IWorkload

type KubernetesApi

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

KubernetesApi -

func NewKubernetesApi

func NewKubernetesApi() *KubernetesApi

NewKubernetesApi -

func (*KubernetesApi) CalculateWorkloadParentRecursive

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

func (*KubernetesApi) CreateWorkload

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

func (*KubernetesApi) DeleteWorkloadByWlid

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

func (*KubernetesApi) GetNamespace

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

func (*KubernetesApi) GetWorkload

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

func (*KubernetesApi) GetWorkloadByWlid

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

func (*KubernetesApi) ListAllWorkload

func (k8sAPI *KubernetesApi) ListAllWorkload() ([]IWorkload, 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) ([]IWorkload, error)

func (*KubernetesApi) ListWorkloads2

func (k8sAPI *KubernetesApi) ListWorkloads2(namespace, kind string) ([]IWorkload, error)

func (*KubernetesApi) ResourceInterface

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

func (*KubernetesApi) UpdateWorkload

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

Jump to

Keyboard shortcuts

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