helm

package
v0.17.6 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: AGPL-3.0 Imports: 47 Imported by: 0

Documentation

Overview

Package helm wraps the Helm SDK and the Kubernetes client to manage workspace Helm releases and to inject workspace containers into existing workloads (Deployments, StatefulSets, DaemonSets). It also owns the label and annotation constants shared across the provisioner.

Index

Constants

View Source
const (
	// LabelInjected is stamped on a workload's pod template when a workspace is
	// injected, so that GetWorkspaces can discover injected pods cluster-wide.
	LabelInjected = "k8shell.io/injected"

	// AnnotationInjectionState holds a JSON-encoded InjectionState on the workload
	// object, recording everything needed to reverse the injection on eject.
	AnnotationInjectionState = "k8shell.io/injection"

	// LabelWorkloadKind and LabelWorkloadName are stamped onto the injected
	// workload's pod template so the owning workload can be identified directly
	// from any pod label selector, without traversing ReplicaSet owner refs.
	LabelWorkloadKind = "k8shell.io/workload-kind"
	LabelWorkloadName = "k8shell.io/workload-name"

	// Common pod/release labels used across workspace resources.
	LabelUsername     = "k8shell.io/username"
	LabelOrganization = "k8shell.io/organization"
	LabelBlueprint    = "k8shell.io/blueprint"
	LabelCanonicalId  = "k8shell.io/canonical-id"
	LabelJobId        = "k8shell.io/job-id"
	LabelAppVersion   = "k8shell.io/k8shelld-version"
	LabelStorageType  = "k8shell.io/storage-type"
	LabelStorageName  = "k8shell.io/storage-name"
	LabelSubdomain    = "k8shell.io/subdomain"

	// LabelBlueprintRevision holds the content revision of the blueprint
	// the workspace was provisioned from (blueprint.RawBlueprint.Revision).
	LabelBlueprintRevision = "k8shell.io/blueprint-revision"

	// LabelHostname holds the workspace's in-cluster DNS name in the form
	// "<hostname>.<subdomain>" (peers in the same namespace reach the workspace
	// at this name). It is only stamped when both hostname and subdomain are set.
	LabelHostname = "k8shell.io/hostname"

	LabelInjectTarget = "k8shell.io/inject-target"
	LabelManagedBy    = "k8shell.io/managed-by"

	// LabelNetworkPolicy records which predefined network policy class a
	// workspace pod belongs to. Other workspaces' NetworkPolicies select on it
	// (e.g. the "user" class allows ingress from pods labelled
	// k8shell.io/network-policy=system), so it is kept in sync with the
	// NetworkPolicy objects when a workspace's network class is changed.
	LabelNetworkPolicy = "k8shell.io/network-policy"

	// AnnotationUserStr holds the base64-encoded canonical user string on a workspace pod.
	AnnotationUserStr = "k8shell.io/userstr"

	// AnnotationEgressRules holds the JSON-encoded egress shortcuts
	// (allowEgressToCIDRs + allowEgressToPods) in force on a workspace pod, so
	// the workspace-list API can return them without reading the Helm release or
	// reverse-engineering the live NetworkPolicy. The chart writes it at
	// provisioning and UpdateWorkspaceResources rewrites it when it replaces a
	// workspace's egress rules. The payload shape is:
	//   {"allowEgressToCIDRs":["1.2.3.0/24"],"allowEgressToPods":[{"app":"db"}]}
	AnnotationEgressRules = "k8shell.io/egress-rules"

	// LabelWebProxy is stamped ("true") on a workspace pod that publishes a
	// TCP port through the web proxy, so the proxy can discover routable
	// workspaces by label selector.
	LabelWebProxy = "k8shell.io/web-proxy"

	// AnnotationWebProxyPort and AnnotationWebProxyRoles hold the web-proxy
	// route in force on a workspace pod, so the web proxy and the
	// workspace-list API can read it without the Helm release. The chart
	// writes them at provisioning and UpdateWorkspaceResources rewrites them
	// when it replaces the route. AnnotationWebProxyPort is the decimal port;
	// AnnotationWebProxyRoles is a JSON string array, e.g. ["developer","qa"].
	AnnotationWebProxyPort  = "k8shell.io/web-proxy-port"
	AnnotationWebProxyRoles = "k8shell.io/web-proxy-roles"

	// LabelWebProxyAlias holds the web-proxy alias applied to a workspace pod,
	// unique within its organization. The chart writes it at provisioning and
	// UpdateWorkspaceResources rewrites it. It is only stamped once the
	// workspace holds the alias's claim ConfigMap, which also carries this
	// label (next to LabelWebProxyAliasClaim) to name the alias it claims.
	LabelWebProxyAlias = "k8shell.io/web-proxy-alias"

	// LabelWebProxyAliasClaim is stamped ("true") on the ConfigMaps that
	// claim a web-proxy alias for a workspace. The claim is what makes an
	// alias unique per organization: its name is derived from the
	// (organization, alias) pair, so a second Create fails with AlreadyExists.
	LabelWebProxyAliasClaim = "k8shell.io/web-proxy-alias-claim"

	// AnnotationWebProxyAliasMessage explains why the blueprint's web-proxy
	// alias was not applied to a workspace pod, e.g. because another
	// workspace of the organization holds it.
	AnnotationWebProxyAliasMessage = "k8shell.io/web-proxy-alias-message"

	// LabelStopRequested is stamped on a workspace pod immediately before
	// Workspace.StopPod deletes it, so the pod still carries the label during
	// its graceful-termination window. AnalyzePod uses its presence to report
	// WorkspaceStatusStopping instead of WorkspaceStatusTerminating, since the
	// Helm release (and the rest of the workspace's resources) is left intact
	// rather than being torn down.
	LabelStopRequested = "k8shell.io/stop-requested"
)
View Source
const (
	WORKSPACE_CHART_NAME = "k8shell-workspace"
)

Variables

This section is empty.

Functions

func GetChartFS

func GetChartFS() fs.FS

GetChartFS returns the embedded filesystem containing Helm charts

func InjectedCanonicalId

func InjectedCanonicalId(annotations map[string]string) string

InjectedCanonicalId returns the canonical workspace ID recorded in the injection annotation, or "" if the workload is not injected.

func LoadChartFromMemory

func LoadChartFromMemory(chartName string) (*chart.Chart, error)

LoadChartFromMemory loads a Helm chart from embedded filesystem

func ManifestDocuments added in v0.17.0

func ManifestDocuments(manifest string) (map[string]map[string]any, error)

ManifestDocuments decodes a rendered chart manifest into plain objects keyed "Kind/name". Secrets are left out and ConfigMaps lose their data and binaryData, so the result can be handed to the policy engine.

func PodManifestFromRelease added in v0.16.0

func PodManifestFromRelease(rel *release.Release) (*corev1.Pod, error)

PodManifestFromRelease extracts the Pod object from an already-fetched Helm release's stored manifest (e.g. from List/ListWithSelector), without an extra round-trip to Helm's release storage. Used to recover a workspace's labels, annotations and spec after its live pod has been deleted (StopPod) while the Helm release itself is left installed.

func SupportedWorkloadKinds

func SupportedWorkloadKinds() []string

SupportedWorkloadKinds returns the list of workload kinds the adapter factory supports.

Types

type Client

type Client struct {
	Registry        config.DefaultRegistry
	PrivateRegistry config.PrivateRegistry
	AppVersion      string
	Commit          string
	// contains filtered or unexported fields
}

Client is the provisioner's Helm and Kubernetes client. It holds the in-memory Helm charts, Kubernetes typed and dynamic clients, and registry configuration needed to install, upgrade, and uninstall workspace releases.

func NewClient

func NewClient(targetNamespace string, registry config.DefaultRegistry, privateRegistry config.PrivateRegistry,
	kubeClientQPS float32, kubeClientBurst int) (*Client, error)

NewClient constructs a Client using in-cluster Kubernetes credentials, loads the embedded workspace Helm chart into memory, and returns a ready-to-use client. kubeClientQPS and kubeClientBurst override client-go's default rate limit (5 QPS / 10 burst), which otherwise throttles this process client-side under concurrent request load; a value <= 0 leaves client-go's default in place.

func NewClientWithKube added in v0.17.4

func NewClientWithKube(kubeClient kubernetes.Interface, targetNamespace string) *Client

NewClientWithKube returns a Client backed only by the given Kubernetes client, for tests that exercise pod-level operations against a fake clientset. Any Helm operation on it fails.

func (*Client) ApplyNamespacedResources

func (c *Client) ApplyNamespacedResources(ctx context.Context, namespace string, resources map[string]string, labels map[string]string) error

ApplyNamespacedResources creates or updates each resource document in the given namespace. resources is the map returned by WorkspaceResourcesFromTemplate.

func (*Client) CanUpgrade

func (c *Client) CanUpgrade(ctx context.Context, opts InstallOptions) error

CanUpgrade performs a client-side dry-run upgrade to check whether the given release can be upgraded. It fails if the release does not exist or is in a pending state. Use this before an actual Upgrade to surface config errors early.

func (*Client) CanUpgradeDryRunServer

func (c *Client) CanUpgradeDryRunServer(ctx context.Context, opts InstallOptions) error

CanUpgradeDryRunServer performs a server-side dry-run upgrade, which lets the Kubernetes API server validate admission webhooks and resource constraints without applying any changes.

func (*Client) DeleteNamespacedWorkspaceResources

func (c *Client) DeleteNamespacedWorkspaceResources(ctx context.Context, namespace, canonicalId string) error

DeleteNamespacedWorkspaceResources deletes all resources in namespace that carry the k8shell.io/canonical-id label matching canonicalId.

func (*Client) DynamicClient added in v0.16.0

func (c *Client) DynamicClient() dynamic.Interface

DynamicClient returns the underlying dynamic Kubernetes client, used for custom resources such as CiliumNetworkPolicy that have no typed client.

func (*Client) EjectFromWorkload

func (c *Client) EjectFromWorkload(ctx context.Context, adapter WorkloadAdapter,
	workspaceCanonicalId string) (string, error)

EjectFromWorkload reverses a previous InjectIntoWorkload call. It reads the injection tracking annotations, removes the named containers/initContainers/volumes from the pod template, clears the annotations, and returns the canonical ID so the caller can delete the associated namespaced resources.

func (*Client) EnsureBase

func (c *Client) EnsureBase(ctx context.Context) error

EnsureBase ensures the base namespace resources are present and up to date. Resources are applied directly via the Kubernetes API rather than through Helm

func (*Client) GetRelease

func (c *Client) GetRelease(releaseName string) (*release.Release, error)

GetRelease gets information about a specific release in a namespace

func (*Client) GetWorkloadAdapter

func (c *Client) GetWorkloadAdapter(ctx context.Context, namespace, kind, name string) (WorkloadAdapter, error)

GetWorkloadAdapter fetches the named workload of the given kind from the cluster and returns the appropriate adapter. Kind matching is case-insensitive; name is lowercased before the lookup (Kubernetes names are always lowercase).

func (*Client) InjectIntoWorkload

func (c *Client) InjectIntoWorkload(ctx context.Context, adapter WorkloadAdapter,
	workspaceCanonicalId string, spec *InjectionSpec) error

InjectIntoWorkload injects the workspace into the workload identified by adapter, appending containers, init containers, and volumes from spec, and recording the injection in the workload's annotations so it can be reversed by EjectFromWorkload. It fails if the workload is already injected with any workspace.

func (*Client) InjectionSpecFromTemplate

func (c *Client) InjectionSpecFromTemplate(ctx context.Context,
	values map[string]interface{}, workspaceCanonicalId string, jobId string,
	sharedPvcPrefix string) (*InjectionSpec, error)

InjectionSpecFromTemplate renders the workspace Helm chart, extracts the Pod document, and returns its containers/initContainers/volumes renamed with the given prefix to avoid conflicts with the target workload's own containers.

func (*Client) Install

func (c *Client) Install(ctx context.Context, chartName string, opts InstallOptions) error

Install installs a Helm chart in the specified namespace

func (*Client) KubeClient

func (c *Client) KubeClient() kubernetes.Interface

KubeClient returns the underlying Kubernetes typed client.

func (*Client) List

func (c *Client) List(namespace string) ([]*release.Release, error)

List lists Helm releases in a specific namespace

func (*Client) ListAllNamespaces

func (c *Client) ListAllNamespaces() ([]*release.Release, error)

ListAllNamespaces lists Helm releases across all namespaces

func (*Client) ListDeployedReleasePodsCached added in v0.17.3

func (c *Client) ListDeployedReleasePodsCached(ctx context.Context, namespace string) ([]*ReleasePod, error)

ListDeployedReleasePodsCached returns a ReleasePod for every deployed Helm release in namespace. For the target namespace it is served from the release-secret informer once synced (see StartWorkspaceInformers); otherwise from a short-lived cache shared across concurrent callers (see ttlCache). Callers needing a subset filter the result themselves, e.g. with k8s.io/apimachinery/pkg/labels.Selector.Matches against each ReleasePod's Labels. The returned ReleasePods are shared and must not be mutated.

Only for read-only lookups: the result can lag the cluster (by up to listCacheTTL on the fallback path), so callers that must observe a just-completed mutation (stop, delete, eject) must use List or ListReleasesBySelector instead.

func (*Client) ListPodsCached added in v0.16.6

func (c *Client) ListPodsCached(ctx context.Context, namespace, selector string) ([]corev1.Pod, error)

ListPodsCached lists pods in namespace matching selector. When an informer covers the lookup (see StartWorkspaceInformers) and has synced, it is served from there; otherwise from a short-lived cache shared across concurrent callers with an identical (namespace, selector) pair (see ttlCache). The returned pods share maps and slices with the cache and must not be mutated.

Only for read-only lookups: the result can lag the cluster (by up to listCacheTTL on the fallback path), so callers that must observe a just-completed mutation (stop, delete, eject) must list pods directly via KubeClient() instead.

func (*Client) ListReleasesBySelector added in v0.16.8

func (c *Client) ListReleasesBySelector(ctx context.Context, namespace, selector string) ([]*release.Release, error)

ListReleasesBySelector lists Helm releases in namespace whose Secret matches selector (a standard Kubernetes label selector, e.g. as built by the workspace package's getSelector), narrowed server-side by the Kubernetes API — unlike ListWithSelector, which fetches and decodes every release in the namespace regardless of selector. This works because Helm writes a release's own Labels onto its storage Secret's metadata.labels alongside its "owner"/"status"/"name" system labels (see helm.sh/helm/v3/pkg/storage/driver/secrets.go's newSecretsObject), so the same labels callers already filter pods on are equally queryable on the release secret itself. Only "deployed" (i.e. current) releases are returned, matching ListWithSelector's ListDeployed state mask.

This also sidesteps createActionConfig/action.NewList, which rebuilds a full Kubernetes client (including a discovery client) on every call — itself a bigger cost than decoding a handful of releases. This reuses c.kubeClient, already built once in NewClient.

func (*Client) ListWithSelector

func (c *Client) ListWithSelector(namespace, selector string) ([]*release.Release, error)

ListWithSelector lists Helm releases in namespace, applying selector. Despite taking a selector, this is not server-side filtered: Helm's List action decodes every release secret in the namespace regardless of selector, then filters in memory (see helm.sh/helm/v3/pkg/storage/driver Secrets.List). Prefer ListReleasesBySelector, which does filter server-side, or ListDeployedReleasePodsCached when the caller can tolerate a cache and apply its own filtering in memory.

func (*Client) PodFromRelease

func (c *Client) PodFromRelease(releaseName string) (*corev1.Pod, error)

PodFromRelease extracts the Pod object from the stored Helm release manifest. This allows re-creating only the pod without a full Helm upgrade cycle.

func (*Client) RegistryValues

func (c *Client) RegistryValues() map[string]interface{}

RegistryValues returns the merged registry values for Helm chart templates. host comes from DefaultRegistry and is used to prefix image names.

func (*Client) StartWorkspaceInformers added in v0.17.3

func (c *Client) StartWorkspaceInformers(ctx context.Context, injectNamespaces []string)

StartWorkspaceInformers starts the informers backing ListPodsCached and ListDeployedReleasePodsCached for the target namespace and, if any, the injection namespaces ("*" for cluster-wide). It returns immediately: until each informer finishes its initial list, the lookups it would serve keep using the TTL cache. The informers stop when ctx is cancelled.

func (*Client) StuckReleaseExists added in v0.17.5

func (c *Client) StuckReleaseExists(ctx context.Context, namespace, name string) (bool, error)

StuckReleaseExists reports whether namespace holds a release named name whose latest revision is not "deployed" but still present in storage, i.e. one an interrupted uninstall (status "uninstalling") or a failed install/upgrade left behind. ListReleasesBySelector never returns these, so callers use this to let deletion finish them.

func (*Client) TargetNamespace

func (c *Client) TargetNamespace() string

TargetNamespace returns the target namespace for Helm operations

func (*Client) Template

func (c *Client) Template(ctx context.Context, chartName string, opts InstallOptions) (string, error)

Template renders the named Helm chart with opts.Values in dry-run / client-only mode and returns the resulting YAML manifest string without contacting the cluster.

func (*Client) Uninstall

func (c *Client) Uninstall(releaseName string, timeout int, wait bool) error

Uninstall removes a Helm release from a specific namespace

func (*Client) UpdatePATSecret added in v0.16.0

func (c *Client) UpdatePATSecret(ctx context.Context, releaseName, token string) error

UpdatePATSecret refreshes the token key of a workspace's PAT secret (named "<releaseName>-pat", rendered by the workspace chart) in place, preserving its existing labels so it stays tracked by the owning Helm release. This lets a rotated PAT be picked up by a pod that is recreated directly from a stored release manifest (see Workspace.doStart), without going through a full Helm install/upgrade.

func (*Client) UpdateReleaseLabels

func (c *Client) UpdateReleaseLabels(releaseName, namespace string, labels map[string]string) error

UpdateReleaseLabels updates the labels of a Helm release in a specific namespace

func (*Client) Upgrade

func (c *Client) Upgrade(ctx context.Context, opts InstallOptions) error

Upgrade upgrades a Helm release in the specified namespace

func (*Client) WorkspaceResourcesFromTemplate

func (c *Client) WorkspaceResourcesFromTemplate(ctx context.Context, values map[string]interface{},
	workspaceCanonicalId string) (map[string]string, error)

WorkspaceResourcesFromTemplate renders the workspace Helm chart and extracts all non-Pod YAML documents (ConfigMaps, PVCs, NetworkPolicies, Certs, etc.) as raw YAML strings, keyed by "kind/name".

type DaemonSetAdapter

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

DaemonSetAdapter implements WorkloadAdapter for apps/v1 DaemonSets.

func (*DaemonSetAdapter) DeleteAnnotation

func (a *DaemonSetAdapter) DeleteAnnotation(key string)

func (*DaemonSetAdapter) GetAnnotations

func (a *DaemonSetAdapter) GetAnnotations() map[string]string

func (*DaemonSetAdapter) GetPodTemplate

func (a *DaemonSetAdapter) GetPodTemplate() *corev1.PodTemplateSpec

func (*DaemonSetAdapter) GetSelector

func (a *DaemonSetAdapter) GetSelector() *metav1.LabelSelector

func (*DaemonSetAdapter) Kind

func (a *DaemonSetAdapter) Kind() string

func (*DaemonSetAdapter) Name

func (a *DaemonSetAdapter) Name() string

func (*DaemonSetAdapter) Namespace

func (a *DaemonSetAdapter) Namespace() string

func (*DaemonSetAdapter) NewInformer

func (*DaemonSetAdapter) SetAnnotation

func (a *DaemonSetAdapter) SetAnnotation(key, value string)

func (*DaemonSetAdapter) SetPodTemplate

func (a *DaemonSetAdapter) SetPodTemplate(tpl *corev1.PodTemplateSpec)

func (*DaemonSetAdapter) Update

func (a *DaemonSetAdapter) Update(ctx context.Context, client kubernetes.Interface) error

type DeploymentAdapter

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

DeploymentAdapter implements WorkloadAdapter for apps/v1 Deployments.

func (*DeploymentAdapter) DeleteAnnotation

func (a *DeploymentAdapter) DeleteAnnotation(key string)

func (*DeploymentAdapter) GetAnnotations

func (a *DeploymentAdapter) GetAnnotations() map[string]string

func (*DeploymentAdapter) GetPodTemplate

func (a *DeploymentAdapter) GetPodTemplate() *corev1.PodTemplateSpec

func (*DeploymentAdapter) GetSelector

func (a *DeploymentAdapter) GetSelector() *metav1.LabelSelector

func (*DeploymentAdapter) Kind

func (a *DeploymentAdapter) Kind() string

func (*DeploymentAdapter) Name

func (a *DeploymentAdapter) Name() string

func (*DeploymentAdapter) Namespace

func (a *DeploymentAdapter) Namespace() string

func (*DeploymentAdapter) NewInformer

func (*DeploymentAdapter) SetAnnotation

func (a *DeploymentAdapter) SetAnnotation(key, value string)

func (*DeploymentAdapter) SetPodTemplate

func (a *DeploymentAdapter) SetPodTemplate(tpl *corev1.PodTemplateSpec)

func (*DeploymentAdapter) Update

func (a *DeploymentAdapter) Update(ctx context.Context, client kubernetes.Interface) error

type InjectionSpec

type InjectionSpec struct {
	Containers     []corev1.Container
	InitContainers []corev1.Container
	Volumes        []corev1.Volume
	PodLabels      map[string]string
	// PodAnnotations carries key annotations (e.g. k8shell.io/userstr) from the
	// rendered workspace pod so they can be added to the Deployment's pod template,
	// enabling FindWorkspace/GetWorkspaces to discover injected workspaces by label.
	PodAnnotations map[string]string
}

InjectionSpec holds the containers, init containers, volumes, and pod-template labels/annotations extracted from a rendered workspace chart, ready for injection.

type InjectionState

type InjectionState struct {
	CanonicalId    string   `json:"canonicalId"`
	Containers     []string `json:"containers,omitempty"`
	InitContainers []string `json:"initContainers,omitempty"`
	Volumes        []string `json:"volumes,omitempty"`
	SharePID       bool     `json:"sharePID"`
}

InjectionState is the structured payload stored in AnnotationInjectionState. It records all information needed to cleanly reverse an injection.

func ParseInjectionState

func ParseInjectionState(annotations map[string]string) (*InjectionState, bool)

ParseInjectionState decodes the injection annotation from an annotation map. Returns nil, false if the annotation is absent or malformed.

type InstallOptions

type InstallOptions struct {
	ReleaseName     string
	CreateNamespace bool
	ChartName       string
	Values          map[string]interface{}
	Wait            bool
	Labels          map[string]string
	Timeout         int
	AppVersion      string
}

InstallOptions carries parameters shared by Install, Upgrade, and Template operations so callers do not need to configure the action objects directly.

type ReleasePod added in v0.17.3

type ReleasePod struct {
	metav1.TypeMeta
	metav1.ObjectMeta

	Pod           *corev1.Pod
	FirstDeployed time.Time
	LastDeployed  time.Time
}

ReleasePod is the part of a deployed Helm release that the read-only workspace lookups need: the release Secret's metadata (whose labels carry the workspace's username/organization/blueprint) plus the Pod decoded from the release's stored manifest. Pod is nil when the release has no Pod in its manifest (i.e. it isn't a workspace release) or failed to decode.

It is what ListDeployedReleasePodsCached returns, and also the object the release-secret informer stores in place of the Secret itself: a release Secret carries the whole chart (templates included) and decodes to ~65 KB of JSON, so decoding it once per change and keeping only this is what makes listing hundreds of workspaces cheap.

func (*ReleasePod) DeepCopyObject added in v0.17.3

func (r *ReleasePod) DeepCopyObject() runtime.Object

DeepCopyObject implements runtime.Object so ReleasePod can live in an informer store.

type StatefulSetAdapter

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

StatefulSetAdapter implements WorkloadAdapter for apps/v1 StatefulSets.

func (*StatefulSetAdapter) DeleteAnnotation

func (a *StatefulSetAdapter) DeleteAnnotation(key string)

func (*StatefulSetAdapter) GetAnnotations

func (a *StatefulSetAdapter) GetAnnotations() map[string]string

func (*StatefulSetAdapter) GetPodTemplate

func (a *StatefulSetAdapter) GetPodTemplate() *corev1.PodTemplateSpec

func (*StatefulSetAdapter) GetSelector

func (a *StatefulSetAdapter) GetSelector() *metav1.LabelSelector

func (*StatefulSetAdapter) Kind

func (a *StatefulSetAdapter) Kind() string

func (*StatefulSetAdapter) Name

func (a *StatefulSetAdapter) Name() string

func (*StatefulSetAdapter) Namespace

func (a *StatefulSetAdapter) Namespace() string

func (*StatefulSetAdapter) NewInformer

func (*StatefulSetAdapter) SetAnnotation

func (a *StatefulSetAdapter) SetAnnotation(key, value string)

func (*StatefulSetAdapter) SetPodTemplate

func (a *StatefulSetAdapter) SetPodTemplate(tpl *corev1.PodTemplateSpec)

func (*StatefulSetAdapter) Update

type WorkloadAdapter

type WorkloadAdapter interface {
	// Identity
	Kind() string
	Name() string
	Namespace() string

	// Annotations on the workload object (used for injection tracking).
	GetAnnotations() map[string]string
	SetAnnotation(key, value string)
	DeleteAnnotation(key string)

	// Pod template — containers, volumes, labels, annotations.
	GetPodTemplate() *corev1.PodTemplateSpec
	SetPodTemplate(tpl *corev1.PodTemplateSpec)

	// Selector is needed to ensure labels required by the selector are not removed.
	GetSelector() *metav1.LabelSelector

	// Update persists the in-memory changes back to the cluster.
	Update(ctx context.Context, client kubernetes.Interface) error

	// NewInformer returns a SharedIndexInformer scoped to this kind.
	// The watcher calls this for each registered adapter to build its informer set.
	NewInformer(factory informers.SharedInformerFactory) cache.SharedIndexInformer
}

WorkloadAdapter abstracts over Deployment, StatefulSet, and DaemonSet so that inject/eject logic and the watcher can work with any supported kind uniformly. New kinds (including CRDs via custom adapters) implement this interface.

func ProtoAdapter

func ProtoAdapter(kind string, _ kubernetes.Interface) (WorkloadAdapter, error)

ProtoAdapter returns a zero-value adapter for kind that can be used to call NewInformer without needing a real cluster object. kubeClient is not used here but is kept in the signature for symmetry with GetWorkloadAdapter.

Jump to

Keyboard shortcuts

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