k8s

package
v0.0.3-beta8 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: Apache-2.0 Imports: 43 Imported by: 54

Documentation

Index

Constants

View Source
const (
	DEFAULT_CLUSTER          = "default_cluster"
	DEVTRON_SERVICE_NAME     = "devtron-service"
	DefaultClusterUrl        = "https://kubernetes.default.svc"
	BearerToken              = "bearer_token"
	CertificateAuthorityData = "cert_auth_data"
	CertData                 = "cert_data"
	TlsKey                   = "tls_key"
	LiveZ                    = "/livez"
	Running                  = "Running"
	RestartingNotSupported   = "restarting not supported"
	DEVTRON_APP_LABEL_KEY    = "app"
	DEVTRON_APP_LABEL_VALUE1 = "devtron"
	DEVTRON_APP_LABEL_VALUE2 = "orchestrator"
)

Variables

This section is empty.

Functions

func CheckEvictionSupport

func CheckEvictionSupport(clientset kubernetes.Interface) (schema.GroupVersion, error)

CheckEvictionSupport uses Discovery API to find out if the server support eviction subresource If support, it will return its groupVersion; Otherwise, it will return an empty GroupVersion

func CheckIfValidLabel

func CheckIfValidLabel(labelKey string, labelValue string) error

func DeletePod

func DeletePod(pod v1.Pod, k8sClientSet *kubernetes.Clientset, deleteOptions metav1.DeleteOptions) error

DeletePod will delete the given pod, or return an error if it couldn't

func EvictPod

func EvictPod(pod v1.Pod, k8sClientSet *kubernetes.Clientset, evictionGroupVersion schema.GroupVersion, deleteOptions metav1.DeleteOptions) error

EvictPod will evict the given pod, or return an error if it couldn't

func IsDevtronApp

func IsDevtronApp(labels map[string]string) bool

func IsPod

func IsPod(gvk schema.GroupVersionKind) bool

func IsService

func IsService(gvk schema.GroupVersionKind) bool

func OverrideK8sHttpClientWithTracer

func OverrideK8sHttpClientWithTracer(restConfig *rest.Config) (*http.Client, error)

func ResolveResourceReferences

func ResolveResourceReferences(un *unstructured.Unstructured) ([]metav1.OwnerReference, func(ResourceKey) bool)

func ServerResourceForGroupVersionKind

func ServerResourceForGroupVersionKind(discoveryClient discovery.DiscoveryInterface, gvk schema.GroupVersionKind) (*metav1.APIResource, error)

func UpdateNodeUnschedulableProperty

func UpdateNodeUnschedulableProperty(desiredUnschedulable bool, node *v1.Node, k8sClientSet *kubernetes.Clientset) (*v1.Node, error)

Types

type ApplyResourcesRequest

type ApplyResourcesRequest struct {
	Manifest  string `json:"manifest"`
	ClusterId int    `json:"clusterId"`
}

type ApplyResourcesResponse

type ApplyResourcesResponse struct {
	Kind     string `json:"kind"`
	Name     string `json:"name"`
	Error    string `json:"error"`
	IsUpdate bool   `json:"isUpdate"`
}

type ClusterConfig

type ClusterConfig struct {
	ClusterName           string
	Host                  string
	BearerToken           string
	InsecureSkipTLSVerify bool
	KeyData               string
	CertData              string
	CAData                string
}

type ClusterResourceListMap

type ClusterResourceListMap struct {
	Headers       []string                 `json:"headers"`
	Data          []map[string]interface{} `json:"data"`
	ServerVersion string                   `json:"serverVersion"`
}

type EventsResponse

type EventsResponse struct {
	Events *v1.EventList `json:"events,omitempty"`
}

type GetAllApiResourcesResponse

type GetAllApiResourcesResponse struct {
	ApiResources []*K8sApiResource `json:"apiResources"`
	AllowedAll   bool              `json:"allowedAll"`
}

type JsonPatchType

type JsonPatchType struct {
	Op    string      `json:"op"`
	Path  string      `json:"path"`
	Value interface{} `json:"value"`
}

type K8sApiResource

type K8sApiResource struct {
	Gvk        schema.GroupVersionKind `json:"gvk"`
	Namespaced bool                    `json:"namespaced"`
}

type K8sRequestBean

type K8sRequestBean struct {
	ResourceIdentifier ResourceIdentifier `json:"resourceIdentifier"`
	Patch              string             `json:"patch,omitempty"`
	PodLogsRequest     PodLogsRequest     `json:"podLogsRequest,omitempty"`
	ForceDelete        bool               `json:"-"`
}

type K8sUtil

type K8sUtil struct {
	// contains filtered or unexported fields
}

func NewK8sUtil

func NewK8sUtil(logger *zap.SugaredLogger, runTimeConfig *client.RuntimeConfig) *K8sUtil

func (K8sUtil) BuildK8sObjectListTableData

func (impl K8sUtil) BuildK8sObjectListTableData(manifest *unstructured.UnstructuredList, namespaced bool, gvk schema.GroupVersionKind, validateResourceAccess func(namespace string, group string, kind string, resourceName string) bool) (*ClusterResourceListMap, error)

func (K8sUtil) CheckIfNsExists added in v0.0.5

func (impl K8sUtil) CheckIfNsExists(namespace string, client *v12.CoreV1Client) (exists bool, err error)

func (K8sUtil) CreateConfigMap

func (impl K8sUtil) CreateConfigMap(namespace string, cm *v1.ConfigMap, client *v12.CoreV1Client) (*v1.ConfigMap, error)

func (K8sUtil) CreateJob

func (impl K8sUtil) CreateJob(namespace string, name string, clusterConfig *ClusterConfig, job *batchV1.Job) error

func (K8sUtil) CreateK8sClientSet

func (impl K8sUtil) CreateK8sClientSet(restConfig *rest.Config) (*kubernetes.Clientset, error)

func (K8sUtil) CreateNsIfNotExists

func (impl K8sUtil) CreateNsIfNotExists(namespace string, clusterConfig *ClusterConfig) (err error)

func (*K8sUtil) CreateResources

func (impl *K8sUtil) CreateResources(ctx context.Context, restConfig *rest.Config, manifest string, gvk schema.GroupVersionKind, namespace string) (*ManifestResponse, error)

func (K8sUtil) CreateSecret

func (impl K8sUtil) CreateSecret(namespace string, data map[string][]byte, secretName string, secretType v1.SecretType, client *v12.CoreV1Client, labels map[string]string, stringData map[string]string) (*v1.Secret, error)

func (K8sUtil) CreateSecretData

func (impl K8sUtil) CreateSecretData(namespace string, secret *v1.Secret, v1Client *v12.CoreV1Client) (*v1.Secret, error)

func (*K8sUtil) DecodeGroupKindversion

func (impl *K8sUtil) DecodeGroupKindversion(data string) (*schema.GroupVersionKind, error)

func (K8sUtil) DeleteAndCreateJob

func (impl K8sUtil) DeleteAndCreateJob(content []byte, namespace string, clusterConfig *ClusterConfig) error

DeleteAndCreateJob Deletes and recreates if job exists else creates the job

func (K8sUtil) DeleteJob

func (impl K8sUtil) DeleteJob(namespace string, name string, clusterConfig *ClusterConfig) error

func (K8sUtil) DeletePodByLabel

func (impl K8sUtil) DeletePodByLabel(namespace string, labels string, clusterConfig *ClusterConfig) error

func (*K8sUtil) DeleteResource

func (impl *K8sUtil) DeleteResource(ctx context.Context, restConfig *rest.Config, gvk schema.GroupVersionKind, namespace string, name string, forceDelete bool) (*ManifestResponse, error)

func (K8sUtil) DeleteSecret

func (impl K8sUtil) DeleteSecret(namespace string, name string, client *v12.CoreV1Client) error

func (K8sUtil) DiscoveryClientGetLiveZCall

func (impl K8sUtil) DiscoveryClientGetLiveZCall(cluster *ClusterConfig) ([]byte, error)

func (K8sUtil) ExtractK8sServerMajorAndMinorVersion

func (impl K8sUtil) ExtractK8sServerMajorAndMinorVersion(k8sServerVersion *version.Info) (int, int, error)

func (K8sUtil) FetchConnectionStatusForCluster

func (impl K8sUtil) FetchConnectionStatusForCluster(k8sClientSet *kubernetes.Clientset) error

func (K8sUtil) GetApiResources

func (impl K8sUtil) GetApiResources(restConfig *rest.Config, includeOnlyVerb string) ([]*K8sApiResource, error)

if verb is supplied empty, that means - return all

func (K8sUtil) GetClientByToken

func (impl K8sUtil) GetClientByToken(serverUrl string, token map[string]string) (*v12.CoreV1Client, error)

func (K8sUtil) GetClientForInCluster

func (impl K8sUtil) GetClientForInCluster() (*v12.CoreV1Client, error)

func (K8sUtil) GetConfigMap

func (impl K8sUtil) GetConfigMap(namespace string, name string, client *v12.CoreV1Client) (*v1.ConfigMap, error)

func (K8sUtil) GetCoreV1Client

func (impl K8sUtil) GetCoreV1Client(clusterConfig *ClusterConfig) (*v12.CoreV1Client, error)

func (K8sUtil) GetCoreV1ClientByRestConfig

func (impl K8sUtil) GetCoreV1ClientByRestConfig(restConfig *rest.Config) (*v12.CoreV1Client, error)

func (K8sUtil) GetCoreV1ClientInCluster

func (impl K8sUtil) GetCoreV1ClientInCluster() (*v12.CoreV1Client, error)

func (K8sUtil) GetK8sConfigAndClients

func (impl K8sUtil) GetK8sConfigAndClients(clusterConfig *ClusterConfig) (*rest.Config, *http.Client, *kubernetes.Clientset, error)

func (K8sUtil) GetK8sConfigAndClientsByRestConfig

func (impl K8sUtil) GetK8sConfigAndClientsByRestConfig(restConfig *rest.Config) (*http.Client, *kubernetes.Clientset, error)

func (K8sUtil) GetK8sDiscoveryClient

func (impl K8sUtil) GetK8sDiscoveryClient(clusterConfig *ClusterConfig) (*discovery.DiscoveryClient, error)

func (K8sUtil) GetK8sDiscoveryClientInCluster

func (impl K8sUtil) GetK8sDiscoveryClientInCluster() (*discovery.DiscoveryClient, error)

func (K8sUtil) GetK8sInClusterConfigAndClients

func (impl K8sUtil) GetK8sInClusterConfigAndClients() (*rest.Config, *http.Client, *kubernetes.Clientset, error)

func (K8sUtil) GetK8sInClusterConfigAndDynamicClients

func (impl K8sUtil) GetK8sInClusterConfigAndDynamicClients() (*rest.Config, *http.Client, dynamic.Interface, error)

func (K8sUtil) GetK8sInClusterRestConfig

func (impl K8sUtil) GetK8sInClusterRestConfig() (*rest.Config, error)

func (K8sUtil) GetK8sServerVersion

func (impl K8sUtil) GetK8sServerVersion(clientSet *kubernetes.Clientset) (*version.Info, error)

func (K8sUtil) GetKubeVersion

func (impl K8sUtil) GetKubeVersion() (*version.Info, error)

func (K8sUtil) GetLiveZCall

func (impl K8sUtil) GetLiveZCall(path string, k8sClientSet *kubernetes.Clientset) ([]byte, error)

func (K8sUtil) GetLogsForAPod

func (impl K8sUtil) GetLogsForAPod(kubeClient *kubernetes.Clientset, namespace string, podName string, container string, follow bool) *restclient.Request

func (K8sUtil) GetMetricsClientSet

func (impl K8sUtil) GetMetricsClientSet(restConfig *rest.Config, k8sHttpClient *http.Client) (*metrics.Clientset, error)

func (K8sUtil) GetNmByName

func (impl K8sUtil) GetNmByName(ctx context.Context, metricsClientSet *metrics.Clientset, name string) (*v1beta1.NodeMetrics, error)

func (K8sUtil) GetNmList

func (impl K8sUtil) GetNmList(ctx context.Context, metricsClientSet *metrics.Clientset) (*v1beta1.NodeMetricsList, error)

func (K8sUtil) GetNodeByName

func (impl K8sUtil) GetNodeByName(ctx context.Context, k8sClientSet *kubernetes.Clientset, name string) (*v1.Node, error)

func (K8sUtil) GetNodesList

func (impl K8sUtil) GetNodesList(ctx context.Context, k8sClientSet *kubernetes.Clientset) (*v1.NodeList, error)

func (K8sUtil) GetPodByName

func (impl K8sUtil) GetPodByName(namespace string, name string, client *v12.CoreV1Client) (*v1.Pod, error)

func (K8sUtil) GetPodListByLabel

func (impl K8sUtil) GetPodListByLabel(namespace, label string, clientSet *kubernetes.Clientset) ([]v1.Pod, error)

func (K8sUtil) GetPodLogs

func (impl K8sUtil) GetPodLogs(ctx context.Context, restConfig *rest.Config, name string, namespace string, sinceTime *metav1.Time, tailLines int, follow bool, containerName string, isPrevContainerLogsEnabled bool) (io.ReadCloser, error)

func (K8sUtil) GetPodsListForNamespace

func (impl K8sUtil) GetPodsListForNamespace(ctx context.Context, k8sClientSet *kubernetes.Clientset, namespace string) (*v1.PodList, error)

func (*K8sUtil) GetResource

func (impl *K8sUtil) GetResource(ctx context.Context, namespace string, name string, gvk schema.GroupVersionKind, restConfig *rest.Config) (*ManifestResponse, error)

func (K8sUtil) GetResourceIf

func (impl K8sUtil) GetResourceIf(restConfig *rest.Config, groupVersionKind schema.GroupVersionKind) (resourceIf dynamic.NamespaceableResourceInterface, namespaced bool, err error)

func (K8sUtil) GetResourceIfWithAcceptHeader

func (impl K8sUtil) GetResourceIfWithAcceptHeader(restConfig *rest.Config, groupVersionKind schema.GroupVersionKind) (resourceIf dynamic.NamespaceableResourceInterface, namespaced bool, err error)

func (K8sUtil) GetResourceInfoByLabelSelector

func (impl K8sUtil) GetResourceInfoByLabelSelector(ctx context.Context, namespace string, labelSelector string) (*v1.Pod, error)

func (K8sUtil) GetResourceList

func (impl K8sUtil) GetResourceList(ctx context.Context, restConfig *rest.Config, gvk schema.GroupVersionKind, namespace string) (*ResourceListResponse, bool, error)

func (K8sUtil) GetRestConfigByCluster

func (impl K8sUtil) GetRestConfigByCluster(clusterConfig *ClusterConfig) (*restclient.Config, error)

func (K8sUtil) GetSecret

func (impl K8sUtil) GetSecret(namespace string, name string, client *v12.CoreV1Client) (*v1.Secret, error)

func (K8sUtil) GetServerVersionFromDiscoveryClient

func (impl K8sUtil) GetServerVersionFromDiscoveryClient(k8sClientSet *kubernetes.Clientset) (*version.Info, error)

func (K8sUtil) ListEvents

func (impl K8sUtil) ListEvents(restConfig *rest.Config, namespace string, groupVersionKind schema.GroupVersionKind, ctx context.Context, name string) (*v1.EventList, error)

func (K8sUtil) ListNamespaces

func (impl K8sUtil) ListNamespaces(client *v12.CoreV1Client) (*v1.NamespaceList, error)

func (K8sUtil) PatchConfigMap

func (impl K8sUtil) PatchConfigMap(namespace string, clusterConfig *ClusterConfig, name string, data map[string]interface{}) (*v1.ConfigMap, error)

func (K8sUtil) PatchConfigMapJsonType

func (impl K8sUtil) PatchConfigMapJsonType(namespace string, clusterConfig *ClusterConfig, name string, data interface{}, path string) (*v1.ConfigMap, error)

func (K8sUtil) PatchResourceRequest

func (impl K8sUtil) PatchResourceRequest(ctx context.Context, restConfig *rest.Config, pt types.PatchType, manifest string, name string, namespace string, gvk schema.GroupVersionKind) (*ManifestResponse, error)

func (K8sUtil) UpdateConfigMap

func (impl K8sUtil) UpdateConfigMap(namespace string, cm *v1.ConfigMap, client *v12.CoreV1Client) (*v1.ConfigMap, error)

func (*K8sUtil) UpdateResource

func (impl *K8sUtil) UpdateResource(ctx context.Context, restConfig *rest.Config, gvk schema.GroupVersionKind, namespace string, k8sRequestPatch string) (*ManifestResponse, error)

func (K8sUtil) UpdateSecret

func (impl K8sUtil) UpdateSecret(namespace string, secret *v1.Secret, client *v12.CoreV1Client) (*v1.Secret, error)

func (K8sUtil) ValidateResource

func (impl K8sUtil) ValidateResource(resourceObj map[string]interface{}, gvk schema.GroupVersionKind, validateCallback func(namespace string, group string, kind string, resourceName string) bool) bool

type ManifestResponse

type ManifestResponse struct {
	Manifest unstructured.Unstructured `json:"manifest,omitempty"`
}

type PodLogsRequest

type PodLogsRequest struct {
	SinceTime                  *v12.Time `json:"sinceTime,omitempty"`
	TailLines                  int       `json:"tailLines"`
	Follow                     bool      `json:"follow"`
	ContainerName              string    `json:"containerName"`
	IsPrevContainerLogsEnabled bool      `json:"previous"`
}

type ResourceIdentifier

type ResourceIdentifier struct {
	Name             string                  `json:"name"` //pod name for logs request
	Namespace        string                  `json:"namespace"`
	GroupVersionKind schema.GroupVersionKind `json:"groupVersionKind"`
}

type ResourceKey

type ResourceKey struct {
	Group     string
	Kind      string
	Namespace string
	Name      string
}

func GetResourceKey

func GetResourceKey(obj *unstructured.Unstructured) ResourceKey

func NewResourceKey

func NewResourceKey(group string, kind string, namespace string, name string) ResourceKey

func (ResourceKey) GroupKind

func (k ResourceKey) GroupKind() schema.GroupKind

func (*ResourceKey) String

func (k *ResourceKey) String() string

type ResourceListResponse

type ResourceListResponse struct {
	Resources unstructured.UnstructuredList `json:"resources,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL