k8s

package
v0.0.0-...-e71a76f Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PodEventAdded is emitted when a pod is added
	PodEventAdded = "added"
	// PodEventDeleted is emitted when a pod is deleted
	PodEventDeleted = "deleted"
	// PodEventUpdated is emitted when a pod is updated
	PodEventUpdated = "updated"
)

Variables

This section is empty.

Functions

func CreateDeploymentManifest

func CreateDeploymentManifest(public *models.DeploymentPublic) *appsv1.Deployment

CreateDeploymentManifest creates a Kubernetes Deployment manifest from a models.DeploymentPublic.

func CreateHpaManifest

func CreateHpaManifest(public *models.HpaPublic) *autoscalingv2.HorizontalPodAutoscaler

CreateHpaManifest creates a Kubernetes HorizontalPodAutoscaler manifest from a models.HpaPublic.

func CreateIngressManifest

func CreateIngressManifest(public *models.IngressPublic) *networkingv1.Ingress

CreateIngressManifest creates a Kubernetes Ingress manifest from a models.IngressPublic.

func CreateJobManifest

func CreateJobManifest(public *models.JobPublic) *v1.Job

CreateJobManifest creates a Kubernetes Job manifest from a models.JobPublic.

func CreateNamespaceManifest

func CreateNamespaceManifest(public *models.NamespacePublic) *apiv1.Namespace

CreateNamespaceManifest creates a Kubernetes Namespace manifest from a models.NamespacePublic.

func CreateNetworkPolicyManifest

func CreateNetworkPolicyManifest(public *models.NetworkPolicyPublic) *networkingv1.NetworkPolicy

CreateNetworkPolicyManifest creates a Kubernetes NetworkPolicy manifest from a models.NetworkPolicyPublic.

func CreatePvManifest

func CreatePvManifest(public *models.PvPublic) *apiv1.PersistentVolume

CreatePvManifest creates a Kubernetes PersistentVolume manifest from a models.PvPublic.

func CreatePvcManifest

func CreatePvcManifest(public *models.PvcPublic) *apiv1.PersistentVolumeClaim

CreatePvcManifest creates a Kubernetes PersistentVolumeClaim manifest from a models.PvcPublic.

func CreateSecretManifest

func CreateSecretManifest(public *models.SecretPublic) *apiv1.Secret

CreateSecretManifest creates a Kubernetes Secret manifest from a models.SecretPublic.

func CreateServiceManifest

func CreateServiceManifest(public *models.ServicePublic) *apiv1.Service

CreateServiceManifest creates a Kubernetes Service manifest from a models.ServicePublic.

func CreateVmManifest

func CreateVmManifest(public *models.VmPublic, resourceVersion ...string) *kubevirtv1.VirtualMachine

CreateVmManifest creates a Kubernetes VirtualMachine manifest from a models.VmPublic.

func CreateVmSnapshotManifest

func CreateVmSnapshotManifest(public *models.VmSnapshotPublic) *snapshotalpha1.VirtualMachineSnapshot

CreateVmSnapshotManifest creates a Kubernetes VirtualMachineSnapshot manifest from a models.VmSnapshotPublic.

func GetLabel

func GetLabel(labels map[string]string, key string) string

GetLabel returns the value of a label from a map. If the label does not exist, an empty string is returned.

func IsHasBeenModifiedErr

func IsHasBeenModifiedErr(err error) bool

IsHasBeenModifiedErr returns true if the error is a Kubernetes HasBeenModified error.

func IsImmutabilityErr

func IsImmutabilityErr(err error) bool

IsImmutabilityErr returns true if the error is a Kubernetes Immutability error.

func IsNotFoundErr

func IsNotFoundErr(err error) bool

IsNotFoundErr returns true if the error is a Kubernetes NotFound error.

Types

type Client

type Client struct {
	K8sClient         *kubernetes.Clientset
	KubeVirtK8sClient *kubevirt.Clientset
	Namespace         string
}

Client is a wrapper around the Kubernetes client.

func New

func New(conf *ClientConf) (*Client, error)

New creates a new Kubernetes wrapper client.

func (*Client) CountPods

func (client *Client) CountPods() (int, error)

CountPods returns a list of pods in the cluster.

func (*Client) CreateDeployment

func (client *Client) CreateDeployment(public *models.DeploymentPublic) (*models.DeploymentPublic, error)

CreateDeployment creates a deployment in Kubernetes.

func (*Client) CreateHPA

func (client *Client) CreateHPA(public *models.HpaPublic) (*models.HpaPublic, error)

CreateHPA creates a HorizontalPodAutoscaler in Kubernetes.

func (*Client) CreateIngress

func (client *Client) CreateIngress(public *models.IngressPublic) (*models.IngressPublic, error)

CreateIngress creates a Ingress in Kubernetes.

func (*Client) CreateJob

func (client *Client) CreateJob(public *models.JobPublic) (*models.JobPublic, error)

CreateJob creates a Job in Kubernetes.

func (*Client) CreateNamespace

func (client *Client) CreateNamespace(public *models.NamespacePublic) (*models.NamespacePublic, error)

CreateNamespace creates a Namespace in Kubernetes.

func (*Client) CreateNetworkPolicy

func (client *Client) CreateNetworkPolicy(public *models.NetworkPolicyPublic) (*models.NetworkPolicyPublic, error)

func (*Client) CreateOneShotJob

func (client *Client) CreateOneShotJob(public *models.JobPublic) error

CreateOneShotJob creates a Job in Kubernetes that runs once and then deletes itself.

This is useful for running tasks, such as creating NFS PVs, that should only be run once.

This function is blocking.

func (*Client) CreatePV

func (client *Client) CreatePV(public *models.PvPublic) (*models.PvPublic, error)

CreatePV creates a PersistentVolume in Kubernetes.

func (*Client) CreatePVC

func (client *Client) CreatePVC(public *models.PvcPublic) (*models.PvcPublic, error)

CreatePVC creates a PersistentVolumeClaim in Kubernetes.

func (*Client) CreateSecret

func (client *Client) CreateSecret(public *models.SecretPublic) (*models.SecretPublic, error)

CreateSecret creates a Secret in Kubernetes.

func (*Client) CreateService

func (client *Client) CreateService(public *models.ServicePublic) (*models.ServicePublic, error)

CreateService creates a Service in Kubernetes.

func (*Client) CreateVM

func (client *Client) CreateVM(public *models.VmPublic) (*models.VmPublic, error)

func (*Client) CreateVmSnapshot

func (client *Client) CreateVmSnapshot(public *models.VmSnapshotPublic) (*models.VmSnapshotPublic, error)

func (*Client) DeleteDeployment

func (client *Client) DeleteDeployment(name string) error

DeleteDeployment deletes a deployment in Kubernetes.

func (*Client) DeleteHPA

func (client *Client) DeleteHPA(name string) error

DeleteHPA deletes a HorizontalPodAutoscaler in Kubernetes.

func (*Client) DeleteIngress

func (client *Client) DeleteIngress(name string) error

DeleteIngress deletes a Ingress in Kubernetes.

func (*Client) DeleteJob

func (client *Client) DeleteJob(name string) error

DeleteJob deletes a Job in Kubernetes.

func (*Client) DeleteNamespace

func (client *Client) DeleteNamespace(name string) error

DeleteNamespace deletes a Namespace in Kubernetes.

func (*Client) DeleteNamespaceIfEmpty

func (client *Client) DeleteNamespaceIfEmpty(name string) error

DeleteNamespaceIfEmpty deletes a Namespace in Kubernetes if it is empty.

func (*Client) DeleteNetworkPolicy

func (client *Client) DeleteNetworkPolicy(name string) error

func (*Client) DeletePV

func (client *Client) DeletePV(name string) error

DeletePV deletes a PersistentVolume in Kubernetes.

func (*Client) DeletePVC

func (client *Client) DeletePVC(name string) error

DeletePVC deletes a PersistentVolumeClaim in Kubernetes.

func (*Client) DeleteSecret

func (client *Client) DeleteSecret(name string) error

DeleteSecret deletes a Secret in Kubernetes.

func (*Client) DeleteService

func (client *Client) DeleteService(name string) error

DeleteService deletes a Service in Kubernetes.

func (*Client) DeleteVM

func (client *Client) DeleteVM(id string) error

func (*Client) DeleteVMIs

func (client *Client) DeleteVMIs(vmID string) error

DeleteVMIs deletes all VMIs for a VM.

It assumes that the VirtualMachine parent has the same name as the VMIs.

func (*Client) DeleteVmSnapshot

func (client *Client) DeleteVmSnapshot(id string) error

func (*Client) ListDeploymentStatus

func (client *Client) ListDeploymentStatus() ([]*models.DeploymentStatus, error)

ListDeploymentStatus returns a list of deployment statuses in Kubernetes.

func (*Client) ListNodes

func (client *Client) ListNodes() ([]models.NodePublic, error)

func (*Client) ListPods

func (client *Client) ListPods() ([]models.PodPublic, error)

ListPods returns a list of pods in the cluster.

func (*Client) ListVmStatus

func (client *Client) ListVmStatus() ([]*models.VmStatus, error)

ListVmStatus returns the statuses of all VMs.

func (*Client) ListVmiStatus

func (client *Client) ListVmiStatus() ([]*models.VmiStatus, error)

ListVmiStatus returns the statuses of all VMIs.

func (*Client) PodExists

func (client *Client) PodExists(podName string) (bool, error)

PodExists checks if a pod exists in the cluster.

func (*Client) ReadAllNamespaces

func (client *Client) ReadAllNamespaces(prefix *string) ([]models.NamespacePublic, error)

ReadAllNamespaces reads all namespaces from Kubernetes. If prefix is supplied, only namespaces with that prefix will be returned.

func (*Client) ReadDeployment

func (client *Client) ReadDeployment(name string) (*models.DeploymentPublic, error)

ReadDeployment reads a deployment from Kubernetes.

func (*Client) ReadHPA

func (client *Client) ReadHPA(name string) (*models.HpaPublic, error)

ReadHPA reads a HorizontalPodAutoscaler from Kubernetes.

func (*Client) ReadIngress

func (client *Client) ReadIngress(name string) (*models.IngressPublic, error)

ReadIngress reads a Ingress from Kubernetes.

func (*Client) ReadJob

func (client *Client) ReadJob(name string) (*models.JobPublic, error)

ReadJob reads a Job from Kubernetes.

func (*Client) ReadNamespace

func (client *Client) ReadNamespace(name string) (*models.NamespacePublic, error)

ReadNamespace reads a Namespace from Kubernetes.

func (*Client) ReadNetworkPolicy

func (client *Client) ReadNetworkPolicy(name string) (*models.NetworkPolicyPublic, error)

func (*Client) ReadNode

func (client *Client) ReadNode(name string) (*models.NodePublic, error)

ReadNode returns the node with the given name

func (*Client) ReadPV

func (client *Client) ReadPV(name string) (*models.PvPublic, error)

ReadPV reads a PersistentVolume from Kubernetes.

func (*Client) ReadPVC

func (client *Client) ReadPVC(name string) (*models.PvcPublic, error)

ReadPVC reads a PersistentVolumeClaim from Kubernetes.

func (*Client) ReadSecret

func (client *Client) ReadSecret(name string) (*models.SecretPublic, error)

ReadSecret reads a Secret from Kubernetes.

func (*Client) ReadService

func (client *Client) ReadService(name string) (*models.ServicePublic, error)

ReadService reads a Service from Kubernetes.

func (*Client) ReadVM

func (client *Client) ReadVM(id string) (*models.VmPublic, error)

func (*Client) ReadVmSnapshot

func (client *Client) ReadVmSnapshot(id string) (*models.VmSnapshotPublic, error)

func (*Client) ReadVmSnapshots

func (client *Client) ReadVmSnapshots(vmID string) ([]*models.VmSnapshotPublic, error)

func (*Client) RestartDeployment

func (client *Client) RestartDeployment(name string) error

RestartDeployment restarts a deployment in Kubernetes. This is done by updating the deployment's annotation `kubectl.kubernetes.io/restartedAt` to the current time.

func (*Client) SetPermittedHostDevices

func (client *Client) SetPermittedHostDevices(devices models.PermittedHostDevices) error

func (*Client) SetupPodLogStream

func (client *Client) SetupPodLogStream(ctx context.Context, podName string, from time.Time, onLog func(deploymentName string, lines []models.LogLine)) error

SetupPodLogStream reads logs from a pod and sends them to the callback function

func (*Client) SetupPodWatcher

func (client *Client) SetupPodWatcher(ctx context.Context, callback func(podName, event string)) error

SetupPodWatcher is a function that sets up a pod watcher with a callback. It triggers the callback when a pod event occurs.

func (*Client) SetupStatusWatcher

func (client *Client) SetupStatusWatcher(ctx context.Context, resourceType string, handler func(string, interface{}), opts ...opts.WatcherOpts) error

SetupStatusWatcher sets up a status watcher for a given resource type in a namespace

This should only be called once per cluster

func (*Client) UpdateDeployment

func (client *Client) UpdateDeployment(public *models.DeploymentPublic) (*models.DeploymentPublic, error)

UpdateDeployment updates a deployment in Kubernetes.

func (*Client) UpdateHPA

func (client *Client) UpdateHPA(public *models.HpaPublic) (*models.HpaPublic, error)

UpdateHPA updates a HorizontalPodAutoscaler in Kubernetes.

func (*Client) UpdateIngress

func (client *Client) UpdateIngress(public *models.IngressPublic) (*models.IngressPublic, error)

UpdateIngress updates a Ingress in Kubernetes.

func (*Client) UpdateNamespace

func (client *Client) UpdateNamespace(public *models.NamespacePublic) (*models.NamespacePublic, error)

UpdateNamespace updates a Namespace in Kubernetes.

func (*Client) UpdateNetworkPolicy

func (client *Client) UpdateNetworkPolicy(public *models.NetworkPolicyPublic) (*models.NetworkPolicyPublic, error)

func (*Client) UpdateSecret

func (client *Client) UpdateSecret(public *models.SecretPublic) (*models.SecretPublic, error)

UpdateSecret updates a Secret in Kubernetes.

func (*Client) UpdateService

func (client *Client) UpdateService(public *models.ServicePublic) (*models.ServicePublic, error)

UpdateService updates a Service in Kubernetes.

func (*Client) UpdateVM

func (client *Client) UpdateVM(public *models.VmPublic) (*models.VmPublic, error)

type ClientConf

type ClientConf struct {
	K8sClient         *kubernetes.Clientset
	KubeVirtK8sClient *kubevirt.Clientset
	Namespace         string
}

ClientConf is the configuration for the Kubernetes wrapper client.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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