k8sinterface

package
v0.0.129 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: Apache-2.0 Imports: 24 Imported by: 44

Documentation

Index

Constants

View Source
const (
	ValueNotFound       = -1
	ResourceNotFoundErr = "resource not found"
)

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 GetConfig added in v0.0.93

func GetConfig() *clientcmdapi.Config

get config from ~/.kube/config

func GetContextName

func GetContextName() string

func GetCurrentContext

func GetCurrentContext() *clientcmdapi.Context

DEPRECATED

func GetDefaultNamespace

func GetDefaultNamespace() string

GetDefaultNamespace returns the default namespace for the current context

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

func GetResourceGroupMapping() map[string]string

GetResourceGroupMapping returns copy of ResourceGroupMapping map object

func GetResourceListMock

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

func GetResourceNamesapcedScope

func GetResourceNamesapcedScope() []string

func GetSingleResourceFromGroupMapping

func GetSingleResourceFromGroupMapping(resource string) (string, bool)

func GroupVersionResourceToString

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

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

func InitializeMapResourcesMock()

func IsConnectedToCluster

func IsConnectedToCluster() bool

func IsKindKubernetes

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

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

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

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 SetClusterContextName

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

func SplitApiVersion(apiVersion string) (string, string)

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

func SplitResourceTriplets

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) ListPods

func (k8sAPI *KubernetesApi) ListPods(namespace string, podLabels map[string]string) (*corev1.PodList, 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