k8s

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2025 License: MIT Imports: 47 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContainerState

type ContainerState string
const (
	ContainerStateRunning    ContainerState = "Running"
	ContainerStateWaiting    ContainerState = "Waiting"
	ContainerStateTerminated ContainerState = "Terminated"
)

func (ContainerState) Schema

func (u ContainerState) Schema(r huma.Registry) *huma.Schema

type InstanceHealth

type InstanceHealth string
const (
	InstanceHealthPending  InstanceHealth = "pending"  // Waiting to be scheduled, or running but not ready yet
	InstanceHealthCrashing InstanceHealth = "crashing" // Has crashing instances
	InstanceHealthActive   InstanceHealth = "active"   // All instances running and healthy
)

func (InstanceHealth) Schema

func (u InstanceHealth) Schema(r huma.Registry) *huma.Schema

type InstanceStatus

type InstanceStatus struct {
	KubernetesName  string               `json:"kubernetes_name"`
	Ready           bool                 `json:"ready"`
	RestartCount    int32                `json:"restart_count"`
	State           ContainerState       `json:"state"`
	StateReason     string               `json:"state_reason,omitempty"`
	StateMessage    string               `json:"state_message,omitempty"`
	LastExitCode    int32                `json:"last_exit_code,omitempty"`
	LastTermination string               `json:"last_termination,omitempty"`
	IsCrashing      bool                 `json:"is_crashing"`
	CrashLoopReason string               `json:"crash_loop_reason,omitempty"`
	Events          []models.EventRecord `json:"events,omitempty" nullable:"false"`
}

type JobConditionType

type JobConditionType int

Get status of a kubernetes Job resource

const (
	JobSucceeded JobConditionType = iota
	JobFailed
	JobRunning
	JobPending
)

func (JobConditionType) String

func (js JobConditionType) String() string

type JobStatus

type JobStatus struct {
	ConditionType JobConditionType // JobPending, JobRunning, JobSucceeded, JobFailed
	FailureReason string           // Reason for failure if ConditionType is JobFailed
	StartTime     time.Time        // When the job started running
	CompletedTime time.Time        // When the job completed successfully
	FailedTime    time.Time        // When the job failed
}

JobStatus represents the status of a job with additional details

type KubeClient

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

func (*KubeClient) ApplyYAML

func (self *KubeClient) ApplyYAML(ctx context.Context, yaml []byte) error

ApplyYAML applies a YAML document to the cluster

func (*KubeClient) AvailableStorageBytes

func (self *KubeClient) AvailableStorageBytes(ctx context.Context) (*StorageMetadata, error)

AvailableStorageBytes inspects the default StorageClass and returns capacity / sizing metadata

• Longhorn – sums .status.diskStatus[*].storageAvailable live • Hetzner – 10 TiB max, 10 GiB min, 1 GiB step • AWS EBS – 64 TiB max, 1 GiB min, 1 GiB step • Azure Disk – 64 TiB max, 1 GiB min, 1 GiB step • GCP PD – 64 TiB max, 1 GiB min, 1 GiB step • DigitalOcean Volumes – 16 TiB max, 1 GiB min, 1 GiB step • Vultr Block Storage – 10 TiB max, 10 GiB min, 1 GiB step • Linode Block Storage – 16 TiB max, 10 GiB min, 1 GiB step • OpenStack Cinder – 12 TiB max, 10 GiB min, 1 GiB step

Anything else falls through with UnableToDetectAllocatable=true.

func (*KubeClient) CancelJobsByServiceID

func (self *KubeClient) CancelJobsByServiceID(ctx context.Context, serviceID string) error

For canceling jobs.

func (*KubeClient) CheckDeploymentsReady

func (k *KubeClient) CheckDeploymentsReady(ctx context.Context, version string) (bool, error)

CheckDeploymentsReady checks if all deployments with unbind images have at least one pod running with the specified version

func (*KubeClient) CopySecret

func (self *KubeClient) CopySecret(ctx context.Context, secretName string,
	sourceNamespace string, targetNamespace string,
	client *kubernetes.Clientset) (*corev1.Secret, error)

CopySecret copies a secret from one namespace to another

func (*KubeClient) CountActiveDeploymentJobs

func (self *KubeClient) CountActiveDeploymentJobs(ctx context.Context) (int, error)

func (*KubeClient) CreateClientWithToken

func (self *KubeClient) CreateClientWithToken(token string) (*kubernetes.Clientset, error)

func (*KubeClient) CreateDeployment

func (self *KubeClient) CreateDeployment(ctx context.Context, deploymentID string, env map[string]string) (jobName string, err error)

func (*KubeClient) CreateMultiRegistryCredentials

func (self *KubeClient) CreateMultiRegistryCredentials(ctx context.Context, name, namespace string,
	credentials []RegistryCredential, client *kubernetes.Clientset) (*corev1.Secret, error)

CreateMultiRegistryCredentials creates or updates a kubernetes.io/dockerconfigjson secret for multiple container registries

func (*KubeClient) CreateNamespace

func (k *KubeClient) CreateNamespace(ctx context.Context, namespaceName string, client *kubernetes.Clientset) (*v1.Namespace, error)

CreateNamespace creates a new namespace in the Kubernetes cluster

func (*KubeClient) CreatePersistentVolumeClaim

func (self *KubeClient) CreatePersistentVolumeClaim(
	ctx context.Context,
	namespace string,
	pvcName string,
	displayName string,
	labels map[string]string,
	storageRequest string,
	accessModes []corev1.PersistentVolumeAccessMode,
	storageClassName *string,
	client *kubernetes.Clientset,
) (*models.PVCInfo, error)

CreatePersistentVolumeClaim creates a new PersistentVolumeClaim in the specified namespace.

func (*KubeClient) CreateVerificationIngress

func (self *KubeClient) CreateVerificationIngress(
	ctx context.Context,
	domain string,
	client *kubernetes.Clientset,
) (*networkingv1.Ingress, string, error)

CreateVerificationIngress creates an ingress with a configuration snippet to help verify that a domain is pointing to the Kubernetes cluster

func (*KubeClient) DeleteOldVerificationIngresses

func (self *KubeClient) DeleteOldVerificationIngresses(
	ctx context.Context,
	client *kubernetes.Clientset,
) error

DeleteOldVerificationIngresses deletes verification ingresses created more than 10 minutes ago

func (*KubeClient) DeletePersistentVolumeClaim

func (self *KubeClient) DeletePersistentVolumeClaim(ctx context.Context, namespace string, pvcName string, client *kubernetes.Clientset) error

DeletePersistentVolumeClaim deletes a specific PersistentVolumeClaim by its name and namespace.

func (*KubeClient) DeleteSecret

func (self *KubeClient) DeleteSecret(ctx context.Context, name, namespace string, client *kubernetes.Clientset) error

DeleteSecret deletes a secret by name in the given namespace

func (*KubeClient) DeleteStatefulSetsWithOrphanCascade

func (self *KubeClient) DeleteStatefulSetsWithOrphanCascade(ctx context.Context, namespace string, labels map[string]string, client *kubernetes.Clientset) error

DeleteStatefulSetsWithOrphanCascade deletes StatefulSets matching the label selector with orphan cascade

func (*KubeClient) DeleteUnbindService

func (k *KubeClient) DeleteUnbindService(ctx context.Context, namespace, name string) error

Delete a custom unbind service CRD

func (*KubeClient) DeleteVerificationIngress

func (self *KubeClient) DeleteVerificationIngress(
	ctx context.Context,
	ingressName string,
	client *kubernetes.Clientset,
) error

DeleteVerificationIngress deletes the verification ingress for a domain

func (*KubeClient) DeployUnbindService

func (self *KubeClient) DeployUnbindService(ctx context.Context, service *v1.Service) (*unstructured.Unstructured, *v1.Service, error)

DeployImage creates (or replaces) the service resource in the target namespace for deployment after a successful build job.

func (*KubeClient) DiscoverEndpointsByLabels

func (self *KubeClient) DiscoverEndpointsByLabels(ctx context.Context, namespace string, labels map[string]string, checkDNS bool, client *kubernetes.Clientset) (*models.EndpointDiscovery, error)

DiscoverEndpointsByLabels returns both internal (services) and external (ingresses) endpoints matching the provided labels in a namespace

func (*KubeClient) GetAllSecrets

func (self *KubeClient) GetAllSecrets(
	ctx context.Context,
	teamID uuid.UUID,
	teamSecret string,
	projectID uuid.UUID,
	projectSecret string,
	environmentID uuid.UUID,
	environmentSecret string,
	serviceSecrets map[uuid.UUID]string,
	client *kubernetes.Clientset,
	namespace string,
) ([]models.SecretData, error)

GetAllSecrets retrieves all secrets for the team hierarchy concurrently and returns them with just their keys

func (*KubeClient) GetExpectedInstances

func (k *KubeClient) GetExpectedInstances(ctx context.Context, namespace string, podName string, client *kubernetes.Clientset) (int, error)

func (*KubeClient) GetIngressNginxIP

func (self *KubeClient) GetIngressNginxIP(ctx context.Context) (*LoadBalancerAddresses, error)

GetIngressNginxIP is a convenience function to get the IP of the ingress-nginx controller

func (*KubeClient) GetInternalClient

func (self *KubeClient) GetInternalClient() *kubernetes.Clientset

This function is used to manage unbind-system resources

func (*KubeClient) GetJobStatus

func (self *KubeClient) GetJobStatus(ctx context.Context, jobName string) (JobStatus, error)

func (*KubeClient) GetLoadBalancerIPs

func (self *KubeClient) GetLoadBalancerIPs(ctx context.Context, labelSelector string) ([]LoadBalancerAddresses, error)

GetLoadBalancerIPs returns the external IP addresses for load balancer services If labelSelector is provided, it will filter services based on the selector (e.g. "app.kubernetes.io/name=ingress-nginx")

func (*KubeClient) GetNamespaces

func (k *KubeClient) GetNamespaces(ctx context.Context, namespaceNames []string, bearerToken string) ([]*v1.Namespace, error)

Gets specified namespaces

func (*KubeClient) GetOrCreateSecret

func (self *KubeClient) GetOrCreateSecret(ctx context.Context, name, namespace string, client *kubernetes.Clientset) (*corev1.Secret, bool, error)

GetOrCreateSecret retrieves an existing secret or creates a new one if it doesn't exist Returns the secret and a boolean indicating if it was created (true) or retrieved (false)

func (*KubeClient) GetPersistentVolumeClaim

func (self *KubeClient) GetPersistentVolumeClaim(ctx context.Context, namespace string, pvcName string, client *kubernetes.Clientset) (*models.PVCInfo, error)

GetPersistentVolumeClaim retrieves a specific PersistentVolumeClaim by its name and namespace.

func (*KubeClient) GetPodContainerStatusByLabels

func (self *KubeClient) GetPodContainerStatusByLabels(ctx context.Context, namespace string, labels map[string]string, client *kubernetes.Clientset) ([]PodContainerStatus, error)

GetPodContainerStatusByLabels efficiently fetches pod status with inferred events from container state

func (*KubeClient) GetPodContainerStatusByLabelsWithOptions

func (self *KubeClient) GetPodContainerStatusByLabelsWithOptions(ctx context.Context, namespace string, labels map[string]string, client *kubernetes.Clientset, options PodStatusOptions) ([]PodContainerStatus, error)

GetPodContainerStatusByLabelsWithOptions efficiently fetches pod status with configurable options Container state events are always inferred (lightweight and reliable)

func (*KubeClient) GetPodsByLabels

func (k *KubeClient) GetPodsByLabels(ctx context.Context, namespace string, labels map[string]string, client *kubernetes.Clientset) (*corev1.PodList, error)

GetPodsByLabels returns pods matching the provided labels in a namespace

func (*KubeClient) GetPodsUsingPVC

func (self *KubeClient) GetPodsUsingPVC(ctx context.Context, namespace string, pvcName string, client *kubernetes.Clientset) ([]corev1.Pod, error)

GetPodsUsingPVC finds all pods in a given namespace that are mounting the specified PVC.

func (*KubeClient) GetSecret

func (self *KubeClient) GetSecret(ctx context.Context, name, namespace string, client *kubernetes.Clientset) (*corev1.Secret, error)

GetSecret retrieves a secret by name in the given namespace

func (*KubeClient) GetSecretMap

func (self *KubeClient) GetSecretMap(ctx context.Context, name, namespace string, client *kubernetes.Clientset) (map[string][]byte, error)

GetSecretMap retrieves all key-value pairs from a secret as a map

func (*KubeClient) GetSecretValue

func (self *KubeClient) GetSecretValue(ctx context.Context, name, namespace, key string, client *kubernetes.Clientset) ([]byte, error)

GetSecretValue retrieves a specific key from a secret

func (*KubeClient) GetSimpleHealthStatus

func (self *KubeClient) GetSimpleHealthStatus(ctx context.Context, namespace string, labels map[string]string, client *kubernetes.Clientset) (*SimpleHealthStatus, error)

func (*KubeClient) GetUnusedNodePort

func (self *KubeClient) GetUnusedNodePort(ctx context.Context) (int32, error)

GetUnusedNodePort returns an unused NodePort, determined by letting kubernetes allocate one then deleting the temp service

func (*KubeClient) ListPersistentVolumeClaims

func (self *KubeClient) ListPersistentVolumeClaims(ctx context.Context, namespace string, labels map[string]string, client *kubernetes.Clientset) ([]*models.PVCInfo, error)

ListPersistentVolumeClaims lists all PersistentVolumeClaims in a given namespace, optionally filtered by a label selector,

func (*KubeClient) OverwriteSecretValues

func (self *KubeClient) OverwriteSecretValues(ctx context.Context, name, namespace string, values map[string][]byte, client *kubernetes.Clientset) (*corev1.Secret, error)

OverwriteSecretValues overwrites all values in a secret with new values

func (*KubeClient) ParseRegistryCredentials

func (self *KubeClient) ParseRegistryCredentials(secret *v1.Secret) (string, string, error)

After you've retrieved the credentials Secret

func (*KubeClient) RollingRestartPodsByLabel

func (k *KubeClient) RollingRestartPodsByLabel(
	ctx context.Context,
	namespace string,
	labelKey string,
	labelValue string,
	client *kubernetes.Clientset,
) error

RollingRestartPodsByLabel performs a rolling restart of all pods with a specific label regardless of whether they're part of Deployments, StatefulSets, or standalone pods.

func (*KubeClient) StreamPodLogs

func (self *KubeClient) StreamPodLogs(
	ctx context.Context,
	namespace string,
	opts loki.LokiLogStreamOptions,
	meta loki.LogMetadata,
	client *kubernetes.Clientset,
	eventChan chan<- loki.LogEvents,
) error

StreamPodLogs streams logs from a pod to the provided writer with filtering

func (*KubeClient) SyncDatabaseSecretForService

func (self *KubeClient) SyncDatabaseSecretForService(ctx context.Context, service *ent.Service) error

SyncDatabaseSecretForService syncs the database secret for a specific service

func (*KubeClient) SyncDatabaseSecretForServiceID

func (self *KubeClient) SyncDatabaseSecretForServiceID(ctx context.Context, serviceID uuid.UUID) error

SyncDatabaseSecretForServiceID syncs the database secret for a specific service ID

func (*KubeClient) SyncDatabaseSecrets

func (self *KubeClient) SyncDatabaseSecrets(ctx context.Context) error

SyncDatabaseSecrets syncs all database secrets with the operator logic

func (*KubeClient) UpdateDeploymentImages

func (k *KubeClient) UpdateDeploymentImages(ctx context.Context, newVersion string) error

UpdateDeploymentImages updates container images in deployments based on the new version

func (*KubeClient) UpdatePersistentVolumeClaim

func (self *KubeClient) UpdatePersistentVolumeClaim(
	ctx context.Context,
	namespace string,
	pvcName string,
	newSize *string,
	client *kubernetes.Clientset,
) (*models.PVCInfo, error)

UpdatePersistentVolumeClaim updates an existing PersistentVolumeClaim with new parameters (size, name)

func (*KubeClient) UpdateSecret

func (self *KubeClient) UpdateSecret(ctx context.Context, name, namespace string, data map[string][]byte, client *kubernetes.Clientset) (*corev1.Secret, error)

UpdateSecret updates an existing secret with new data

func (*KubeClient) UpsertSecretValues

func (self *KubeClient) UpsertSecretValues(ctx context.Context, name, namespace string, values map[string][]byte, client *kubernetes.Clientset) (*corev1.Secret, error)

UpsertSecretValues adds or updates specific keys in a secret without affecting other keys

type LoadBalancerAddresses

type LoadBalancerAddresses struct {
	Name      string
	Namespace string
	IPv4      string
	IPv6      string
	Hostname  string
}

LoadBalancerAddresses contains the addresses for a load balancer service

type PodContainerStatus

type PodContainerStatus struct {
	KubernetesName       string           `json:"kubernetes_name"`
	Namespace            string           `json:"namespace"`
	Phase                PodPhase         `json:"phase"`
	PodIP                string           `json:"pod_ip,omitempty"`
	StartTime            string           `json:"start_time,omitempty"`
	HasCrashingInstances bool             `json:"has_crashing_instances"`
	Instances            []InstanceStatus `json:"instances" nullable:"false"`
	InstanceDependencies []InstanceStatus `json:"instance_dependencies" nullable:"false"`
	TeamID               uuid.UUID        `json:"team_id"`
	ProjectID            uuid.UUID        `json:"project_id"`
	EnvironmentID        uuid.UUID        `json:"environment_id"`
	ServiceID            uuid.UUID        `json:"service_id"`
}

type PodPhase

type PodPhase string
const (
	PodPending   PodPhase = "Pending"
	PodRunning   PodPhase = "Running"
	PodSucceeded PodPhase = "Succeeded"
	PodFailed    PodPhase = "Failed"
	PodUnknown   PodPhase = "Unknown"
)

func (PodPhase) Schema

func (u PodPhase) Schema(r huma.Registry) *huma.Schema

type PodStatusOptions

type PodStatusOptions struct {
	IncludeKubernetesEvents bool // Whether to fetch additional events from Kubernetes Events API (more expensive)
}

PodStatusOptions controls what data to fetch for pod status

type RBACManager

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

RBACManager integrates unbind groups with Kubernetes RBAC.

func NewRBACManager

func NewRBACManager(repository repositories.RepositoriesInterface, kubeClient *KubeClient) *RBACManager

func (*RBACManager) DeleteK8sRBAC

func (self *RBACManager) DeleteK8sRBAC(ctx context.Context, group *ent.Group) error

DeleteK8sRBAC removes Kubernetes RBAC resources for a group

func (*RBACManager) SyncAllGroups

func (self *RBACManager) SyncAllGroups(ctx context.Context) error

SyncAllGroups synchronizes all groups with Kubernetes RBAC

func (*RBACManager) SyncGroupToK8s

func (self *RBACManager) SyncGroupToK8s(ctx context.Context, group *ent.Group) error

SyncGroupToK8s creates or updates Kubernetes RBAC resources for a group, must have permissions edge populated

type RegistryCredential

type RegistryCredential struct {
	RegistryURL string
	Username    string
	Password    string
}

RegistryCredential represents credentials for a single registry

type SimpleHealthStatus

type SimpleHealthStatus struct {
	Health            InstanceHealth         `json:"health"`
	ExpectedInstances int                    `json:"expected_instances"`
	Instances         []SimpleInstanceStatus `json:"instances"`
}

type SimpleInstanceStatus

type SimpleInstanceStatus struct {
	KubernetesName string               `json:"kubernetes_name"`
	Status         ContainerState       `json:"status"`
	Events         []models.EventRecord `json:"events,omitempty" nullable:"false"`
}

type StorageMetadata

type StorageMetadata struct {
	StorageClassName          string  `json:"storage_class_name"`
	MinimumStorageGB          float64 `json:"minimum_storage_gb"`
	MaximumStorageGB          float64 `json:"maximum_storage_gb"`
	StorageStepGB             float64 `json:"storage_step_gb"`
	UnableToDetectAllocatable bool    `json:"unable_to_detect_allocatable"`
}

Jump to

Keyboard shortcuts

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