k8sinterface

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const ValueNotFound = -1

Variables

View Source
var ConnectedToCluster = true
View Source
var GroupsClusterScope = []string{}
View Source
var K8SConfig *restclient.Config

K8SConfig pointer to k8s config

View Source
var ResourceClusterScope = []string{"nodes", "namespaces", "podsecuritypolicies", "clusterroles", "clusterrolebindings", "validatingwebhookconfigurations", "mutatingwebhookconfigurations"}
View Source
var ResourceGroupMapping = map[string]string{
	"services":                        "/v1",
	"pods":                            "/v1",
	"replicationcontrollers":          "/v1",
	"podtemplates":                    "/v1",
	"namespaces":                      "/v1",
	"nodes":                           "/v1",
	"configmaps":                      "/v1",
	"secrets":                         "/v1",
	"serviceaccounts":                 "/v1",
	"persistentvolumeclaims":          "/v1",
	"limitranges":                     "/v1",
	"resourcequotas":                  "/v1",
	"daemonsets":                      "apps/v1",
	"deployments":                     "apps/v1",
	"replicasets":                     "apps/v1",
	"statefulsets":                    "apps/v1",
	"controllerrevisions":             "apps/v1",
	"jobs":                            "batch/v1",
	"cronjobs":                        "batch/v1",
	"horizontalpodautoscalers":        "autoscaling/v1",
	"ingresses":                       "extensions/v1beta1",
	"podsecuritypolicies":             "policy/v1beta1",
	"poddisruptionbudgets":            "policy/v1",
	"networkpolicies":                 "networking.k8s.io/v1",
	"clusterroles":                    "rbac.authorization.k8s.io/v1",
	"clusterrolebindings":             "rbac.authorization.k8s.io/v1",
	"roles":                           "rbac.authorization.k8s.io/v1",
	"rolebindings":                    "rbac.authorization.k8s.io/v1",
	"mutatingwebhookconfigurations":   "admissionregistration.k8s.io/v1",
	"validatingwebhookconfigurations": "admissionregistration.k8s.io/v1",
}

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#-strong-api-groups-strong-

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 GetClusterName

func GetClusterName() string

func GetCurrentContext

func GetCurrentContext() *api.Context

func GetDefaultNamespace

func GetDefaultNamespace() string

func GetGroupVersionResource

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

func GetK8sConfig

func GetK8sConfig() *restclient.Config

GetK8sConfig get config. load if not loaded yet

func GetResourceTriplets

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

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 IsLabel

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

func IsNamespaceScope

func IsNamespaceScope(apiGroup, resource string) bool

func IsStringInSlice

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

func JoinResourceTriplets

func JoinResourceTriplets(group, version, resource string) string

func LoadK8sConfig

func LoadK8sConfig() error

LoadK8sConfig load config from local file or from cluster

func ResourceGroupToSlice

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

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 SetLabel

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

func StringInSlice

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

func StringToResourceGroup

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

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