k8sinterface

package
v0.0.176 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: Apache-2.0 Imports: 30 Imported by: 44

Documentation

Index

Constants

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

Variables

View Source
var ConfigClusterServerName = ""
View Source
var K8SConfig *restclient.Config

K8SConfig pointer to k8s config

View Source
var K8SGitServerVersion = ""
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 GetCluster added in v0.0.141

func GetCluster() *clientcmdapi.Cluster

GetCluster returns a pointer to the clientcmdapi Cluster object of the current context

func GetConfig added in v0.0.93

func GetConfig() *clientcmdapi.Config

get config from ~/.kube/config

func GetContext added in v0.0.141

func GetContext() *clientcmdapi.Context

func GetContextName

func GetContextName() string

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 GetK8SServerGitVersion added in v0.0.131

func GetK8SServerGitVersion() (string, error)

func GetK8sConfig

func GetK8sConfig() *restclient.Config

GetK8sConfig get config. load if not loaded yet

func GetK8sConfigClusterServerName added in v0.0.131

func GetK8sConfigClusterServerName() string

GetK8sConfigClusterServerName get the server name of desired cluster context

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 SetClientConfigAPI added in v0.0.141

func SetClientConfigAPI(conf *clientcmdapi.Config)

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 SetConfigClusterServerName added in v0.0.131

func SetConfigClusterServerName(contextName string)

func SetConnectedToCluster added in v0.0.141

func SetConnectedToCluster(isConnected bool)

func SetK8SGitServerVersion added in v0.0.131

func SetK8SGitServerVersion(K8SGitServerVersionInput string)

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

func WorkloadHasParent added in v0.0.134

func WorkloadHasParent(workload IWorkload) bool

Types

type IWorkload

type IWorkload workloadinterface.IWorkload

type KubernetesApi

type KubernetesApi struct {
	ApiExtensionsClient clientset.Interface
	KubernetesClient    kubernetes.Interface
	DynamicClient       dynamic.Interface
	DiscoveryClient     discovery.DiscoveryInterface
	Context             context.Context
	K8SConfig           *restclient.Config
}

KubernetesApi -

func NewKubernetesApi

func NewKubernetesApi() *KubernetesApi

NewKubernetesApi -

func NewKubernetesApiMock added in v0.0.164

func NewKubernetesApiMock() *KubernetesApi

func (*KubernetesApi) CalculateWorkloadParentRecursive

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

CalculateWorkloadParentRecursive returns the parent of the workload kind and name

func (*KubernetesApi) CreateWorkload

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

func (*KubernetesApi) DeleteWorkloadByWlid

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

func (*KubernetesApi) GetDiscoveryClient added in v0.0.164

func (k8sAPI *KubernetesApi) GetDiscoveryClient() discovery.DiscoveryInterface

func (*KubernetesApi) GetDynamicClient added in v0.0.164

func (k8sAPI *KubernetesApi) GetDynamicClient() dynamic.Interface

func (*KubernetesApi) GetKubernetesClient added in v0.0.164

func (k8sAPI *KubernetesApi) GetKubernetesClient() kubernetes.Interface

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, fieldSelector 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