Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertUnstructuredSliceToMap(unstructuredSlice []unstructured.Unstructured) []map[string]interface{}
- func FilterOutOwneredResources(result []unstructured.Unstructured) []unstructured.Unstructured
- func GetAllResourceGroupMappings() map[string][]string
- func GetCluster() *clientcmdapi.Cluster
- func GetConfig() *clientcmdapi.Config
- func GetContext() *clientcmdapi.Context
- func GetContextName() string
- func GetDefaultNamespace() string
- func GetGroupVersionResource(resource string) (schema.GroupVersionResource, error)
- func GetK8SServerGitVersion() (string, error)
- func GetK8sConfig() *restclient.Config
- func GetK8sConfigClusterServerName() string
- func GetResourceFromGroupMapping(resource string) ([]string, bool)
- 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 SetClientConfigAPI(conf *clientcmdapi.Config)
- func SetClusterContextName(contextName string)
- func SetConfigClusterServerName(contextName string)
- func SetConnectedToCluster(isConnected bool)
- func SetK8SGitServerVersion(K8SGitServerVersionInput 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
- func WorkloadHasParent(workload IWorkload) bool
- 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) GetDiscoveryClient() discovery.DiscoveryInterface
- func (k8sAPI *KubernetesApi) GetDynamicClient() dynamic.Interface
- func (k8sAPI *KubernetesApi) GetKubernetesClient() kubernetes.Interface
- 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, fieldSelector 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" ResourceForbiddenErr = "is forbidden" )
Variables ¶
var ConfigClusterServerName = ""
var K8SConfig *restclient.Config
K8SConfig pointer to k8s config
var K8SGitServerVersion = ""
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 GetAllResourceGroupMappings ¶ added in v0.0.209
GetAllResourceGroupMappings returns a copy of the full resource→[]group/version map.
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 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 GetResourceFromGroupMapping ¶ added in v0.0.209
GetResourceFromGroupMapping returns every known group/version for the given resource name. Returns (nil, false) when the resource is unknown.
func GetResourceGroupMapping ¶
GetResourceGroupMapping returns a copy of the resource→group/version map, with one group per resource (the first one discovered). Kept for backward compatibility. Use GetAllResourceGroupMappings if you need every group serving each resource.
func GetResourceListMock ¶
func GetResourceListMock() ([]*metav1.APIResourceList, error)
func GetResourceNamesapcedScope ¶
func GetResourceNamesapcedScope() []string
func GetSingleResourceFromGroupMapping ¶
GetSingleResourceFromGroupMapping returns the first known group/version for the resource. Kept for backward compatibility. Callers that need every group serving a resource should use GetResourceFromGroupMapping.
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 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.
If contextName differs from the currently set context, the cached client config (K8SConfig, clientConfigAPI) is invalidated so the next GetK8sConfig/GetConfig call reloads it for the new context instead of silently continuing to serve the previous context's config. Without this, GetContextName() reports the new context while GetK8sConfig() keeps returning the old one, since both LoadK8sConfig and GetConfig only (re)load when their respective cache is nil (see #158). connectedToCluster is reset to true so a load failure on the previous context does not suppress a retry for the new one; IsConnectedToCluster re-derives it from the new load attempt.
Repeated calls with the same contextName are a no-op here, same as before, so the common single-cluster-per-process case keeps its caching benefit unchanged.
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 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
func WorkloadHasParent ¶ added in v0.0.134
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 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) 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)