Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertUnstructuredSliceToMap(unstructuredSlice []unstructured.Unstructured) []map[string]interface{}
- func FilterOutOwneredResources(result []unstructured.Unstructured) []unstructured.Unstructured
- func GetConfig() *clientcmdapi.Config
- func GetContextName() string
- func GetCurrentContext() *clientcmdapi.Context
- func GetDefaultNamespace() string
- func GetGroupVersionResource(resource string) (schema.GroupVersionResource, error)
- func GetK8sConfig() *restclient.Config
- func GetResourceGroupMapping() map[string]string
- func GetResourceListMock() ([]*metav1.APIResourceList, error)
- func GetResourceNamesapcedScope() []string
- func GetSingleResourceFromGroupMapping(resource string) (string, bool)
- func GroupVersionResourceToString(resource *schema.GroupVersionResource) string
- func InitializeMapResources(discoveryClient discovery.DiscoveryInterface)
- func InitializeMapResourcesMock()
- func IsConnectedToCluster() bool
- func IsKindKubernetes(kind string) bool
- func IsLabel(labels map[string]string, key string) *bool
- func IsNamespaceScope(resource *schema.GroupVersionResource) bool
- func IsResourceInNamespaceScope(resource string) bool
- func IsStringInSlice(slice []string, val string) bool
- func IsTypeWorkload(object map[string]interface{}) bool
- func JoinGroupVersion(group, version string) string
- func JoinResourceTriplets(group, version, resource string) string
- func LoadK8sConfig() error
- func ResourceGroupToSlice(group, version, resource string) []string
- func ResourceGroupToString(group, version, resource string) []string
- func SelectorToString(ls labels.Set) string
- func SetClusterContextName(contextName string)
- func SetLabel(labels map[string]string, key string, val bool)
- func SplitApiVersion(apiVersion string) (string, string)
- func SplitResourceTriplets(resourceTriplets string) (string, string, string)
- func StringInSlice(strSlice []string, str string) int
- func StringToResourceGroup(str string) (string, string, string)
- func V1AllClusterWithCompromisedRegistriesMock() *unstructured.UnstructuredList
- func V1KubeSystemNamespaceMock() *unstructured.UnstructuredList
- type IWorkload
- type KubernetesApi
- func (k8sAPI *KubernetesApi) CalculateWorkloadParentRecursive(workload IWorkload) (string, string, error)
- func (k8sAPI *KubernetesApi) CreateWorkload(workload IWorkload) (IWorkload, error)
- func (k8sAPI *KubernetesApi) DeleteWorkloadByWlid(wlid string) error
- func (k8sAPI *KubernetesApi) GetNamespace(ns string) (IWorkload, error)
- func (k8sAPI *KubernetesApi) GetWorkload(namespace, kind, name string) (IWorkload, error)
- func (k8sAPI *KubernetesApi) GetWorkloadByWlid(wlid string) (IWorkload, error)
- func (k8sAPI *KubernetesApi) ListAllWorkload() ([]IWorkload, error)
- func (k8sAPI *KubernetesApi) ListPods(namespace string, podLabels map[string]string) (*corev1.PodList, error)
- func (k8sAPI *KubernetesApi) ListWorkloads(groupVersionResource *schema.GroupVersionResource, namespace string, ...) ([]IWorkload, error)
- func (k8sAPI *KubernetesApi) ListWorkloads2(namespace, kind string) ([]IWorkload, error)
- func (k8sAPI *KubernetesApi) ResourceInterface(resource *schema.GroupVersionResource, namespace string) dynamic.ResourceInterface
- func (k8sAPI *KubernetesApi) UpdateWorkload(workload IWorkload) (IWorkload, error)
Constants ¶
const ( ValueNotFound = -1 ResourceNotFoundErr = "resource not found" )
Variables ¶
var K8SConfig *restclient.Config
K8SConfig pointer to k8s config
var ResourceClusterScope = []string{}
DEPRECATED - use the 'ResourceNamesapcedScope' instead
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 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 ¶
GetResourceGroupMapping returns copy of ResourceGroupMapping map object
func GetResourceListMock ¶
func GetResourceListMock() ([]*metav1.APIResourceList, error)
func GetResourceNamesapcedScope ¶
func GetResourceNamesapcedScope() []string
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 ¶
IsKindKubernetes check if the kind is known to be a kubernetes kind. In this check we do not test the apiVersion
func IsNamespaceScope ¶
func IsNamespaceScope(resource *schema.GroupVersionResource) bool
IsNamespaceScope returns true if the schema.GroupVersionResource is a kubernetes namespaced resource
func IsResourceInNamespaceScope ¶
IsResourceInNamespaceScope returns true if the resource is a kubernetes namespaced resource
func IsStringInSlice ¶
func IsTypeWorkload ¶
TODO - consider using a k8s manifest validator Return if this object is a valide k8s workload
func JoinGroupVersion ¶
JoinGroupVersion returns the group and version with the '/' separator
func JoinResourceTriplets ¶
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 ¶
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 ¶
DEPRECATED
func SelectorToString ¶
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 SplitApiVersion ¶
SplitApiVersion receives apiVersion ("group/version") returns the group and version splitted
func SplitResourceTriplets ¶
SplitResourceTriplets receives group, version and kind with the '/' separator and returns them separated
func StringInSlice ¶
StringInSlice utility for finding a string in a slice. Returns ValueNotFound (-1) if the string is not found in the slice
func StringToResourceGroup ¶
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 (*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) 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)