Documentation
¶
Overview ¶
Package k8s provides Kubernetes client helpers for Deployah resources.
It wraps label selectors, pod queries, and component discovery for projects deployed through Deployah.
Index ¶
- Constants
- func BuildComponentSelector(project, component string) (string, error)
- func BuildLabelSelector(project, environment string) (labels.Selector, error)
- func BuildProjectSelector(project string) (string, error)
- func BuildSelector(project, component, environment string) (string, error)
- func CheckAPIRequirements(client kubernetes.Interface, reqs []APIRequirement) error
- func EnsureSelfSignedCert(ctx context.Context, client kubernetes.Interface, namespace, fqdn string) (certPEM, keyPEM []byte, err error)
- func GenerateSelfSignedCert(fqdn string) (certPEM, keyPEM []byte, err error)
- func HasSelfSignedComponents(resolved *spec.ResolvedSpec) bool
- func MaterializeSelfSignedTLS(ctx context.Context, client kubernetes.Interface, namespace string, ...) error
- func WatchDeployEvents(ctx context.Context, client kubernetes.Interface, ...) (<-chan DeployEvent, error)
- type APIRequirement
- type Client
- func (c *Client) GetAvailableComponents(ctx context.Context, projectName string) ([]string, error)
- func (c *Client) GetAvailableEnvironments(ctx context.Context, projectName, componentName string) ([]string, error)
- func (c *Client) GetKubernetesClient() kubernetes.Interface
- func (c *Client) GetNamespace() string
- func (c *Client) GetPodInfo(ctx context.Context, podName string) (*PodInfo, error)
- func (c *Client) GetPodStatus(ctx context.Context, releaseName string) (int, int, string, error)
- func (c *Client) GetRunningPods(ctx context.Context, project, component, environment string) ([]PodInfo, error)
- func (c *Client) ValidateComponentExists(ctx context.Context, projectName, componentName string) error
- func (c *Client) ValidatePodExists(ctx context.Context, podName string) error
- type DeployEvent
- type PodInfo
- type SelectorBuilder
Constants ¶
const ( ProjectLabel = "deployah.dev/project" ComponentLabel = "deployah.dev/component" EnvironmentLabel = "deployah.dev/environment" )
Label constants for Deployah resources.
Variables ¶
This section is empty.
Functions ¶
func BuildComponentSelector ¶
BuildComponentSelector builds a selector for a specific project and component
func BuildLabelSelector ¶
BuildLabelSelector returns a labels.Selector for project and/or environment filters.
func BuildProjectSelector ¶
BuildProjectSelector builds a selector for a specific project
func BuildSelector ¶
BuildSelector builds a label selector from project, component, and environment.
func CheckAPIRequirements ¶ added in v0.3.0
func CheckAPIRequirements(client kubernetes.Interface, reqs []APIRequirement) error
CheckAPIRequirements probes the cluster's available API groups and returns an error listing every requirement that is not satisfied. Returns nil when all requirements are met.
The check calls ServerGroups once and builds an in-memory set of available group/version strings, so it incurs a single network round-trip regardless of how many requirements are checked.
NOTE: client-go's ServerGroups does not accept a context (it uses context.TODO internally). Cancellation is not propagated to the underlying HTTP call. See https://github.com/kubernetes/kubernetes/issues/110810.
func EnsureSelfSignedCert ¶ added in v0.4.0
func EnsureSelfSignedCert(ctx context.Context, client kubernetes.Interface, namespace, fqdn string) (certPEM, keyPEM []byte, err error)
EnsureSelfSignedCert returns a PEM cert/key pair for fqdn, reusing the existing `kubernetes.io/tls` Secret named `<fqdn>-tls` in namespace when present and not close to expiry. Otherwise it generates a new self-signed pair. Reuse (rather than regenerating on every call) is what keeps the rendered manifest identical across plan/apply/re-deploy: a fresh keypair every render would defeat both the apply-time verification and skip-on-no-change.
func GenerateSelfSignedCert ¶ added in v0.4.0
GenerateSelfSignedCert generates a fresh self-signed PEM cert/key pair for fqdn without any cluster access. Used for the plan --offline render, where there is no cluster to fetch a reusable secret from.
func HasSelfSignedComponents ¶ added in v0.4.0
func HasSelfSignedComponents(resolved *spec.ResolvedSpec) bool
HasSelfSignedComponents reports whether resolved has at least one exposed component whose TLSMode is selfSigned, meaning a caller must have a working Kubernetes clientset (or explicitly accept offline generation) before rendering.
func MaterializeSelfSignedTLS ¶ added in v0.4.0
func MaterializeSelfSignedTLS(ctx context.Context, client kubernetes.Interface, namespace string, resolved *spec.ResolvedSpec) error
MaterializeSelfSignedTLS fills TLSCertPEM/TLSKeyPEM on every resolved component whose TLSMode is selfSigned. Call it once per CLI invocation, before any chart render, so the plan render, apply-time verification render, and real apply all see identical certificate bytes. Pass a nil client to force offline generation (no cluster access), as plan --offline does.
func WatchDeployEvents ¶ added in v0.3.0
func WatchDeployEvents( ctx context.Context, client kubernetes.Interface, namespace, releasePrefix string, ) (<-chan DeployEvent, error)
WatchDeployEvents watches Kubernetes events in namespace and returns a channel of DeployEvent values filtered to resources whose name starts with releasePrefix. The channel is closed when ctx is canceled.
It lists existing events to obtain the initial resourceVersion, then uses a RetryWatcher for automatic reconnection on transient API failures. The background goroutine stops when ctx is canceled; the returned channel is closed once the goroutine exits.
Types ¶
type APIRequirement ¶ added in v0.3.0
type APIRequirement struct {
// GroupVersions holds the acceptable group/version strings (e.g.
// ["autoscaling/v2", "autoscaling/v2beta2"]). Any single match satisfies
// the requirement.
GroupVersions []string
// Reason is a human-readable explanation shown when the requirement is
// not met, e.g. `required by component "web" (autoscaling enabled)`.
Reason string
}
APIRequirement describes a cluster API group/version that a spec feature needs. At least one of the GroupVersions must be present on the cluster.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps Kubernetes operations for Deployah resources.
func NewClient ¶
func NewClient(k8sClient kubernetes.Interface, namespace string) *Client
NewClient creates a new Kubernetes client for Deployah operations.
func (*Client) GetAvailableComponents ¶
GetAvailableComponents lists component names from running pods for a project.
func (*Client) GetAvailableEnvironments ¶
func (c *Client) GetAvailableEnvironments(ctx context.Context, projectName, componentName string) ([]string, error)
GetAvailableEnvironments lists environment names from running pods for a project and component.
func (*Client) GetKubernetesClient ¶
func (c *Client) GetKubernetesClient() kubernetes.Interface
GetKubernetesClient returns the underlying Kubernetes client.
func (*Client) GetNamespace ¶
GetNamespace returns the namespace this client operates in.
func (*Client) GetPodInfo ¶
GetPodInfo retrieves detailed information about a specific pod
func (*Client) GetPodStatus ¶
GetPodStatus retrieves pod status information for a release.
func (*Client) GetRunningPods ¶
func (c *Client) GetRunningPods(ctx context.Context, project, component, environment string) ([]PodInfo, error)
GetRunningPods lists running pods for a project, component, and environment.
type DeployEvent ¶ added in v0.3.0
type DeployEvent struct {
// UID is the Kubernetes object UID of the source event.
UID types.UID
// Type is the event severity, either "Normal" or "Warning".
Type string
// Reason is the short CamelCase reason string
// (Scheduled, Pulled, BackOff, etc.).
Reason string
// Message is the human-readable event description.
Message string
// Object is the formatted involvedObject reference,
// for example "pod/api-7d9abc" or "replicaset/api-5f123".
Object string
// Count is the number of times this event has occurred.
Count int32
// Timestamp is the last time the event was observed.
Timestamp time.Time
}
DeployEvent carries a single Kubernetes event relevant to a deploy. It is a thin translation of a Kubernetes Event object with only the fields the deploy watcher needs for rendering and deduplication.
type PodInfo ¶
type PodInfo struct {
// Name is the pod name in the cluster.
Name string
// Namespace is the pod namespace.
Namespace string
// Containers lists container names in the pod.
Containers []string
// Status is the pod phase or ready summary string.
Status string
}
PodInfo summarizes a pod returned by Client.GetRunningPods and related queries.
type SelectorBuilder ¶
type SelectorBuilder struct {
// contains filtered or unexported fields
}
SelectorBuilder helps build Kubernetes label selectors for Deployah resources
func NewSelectorBuilder ¶
func NewSelectorBuilder() *SelectorBuilder
NewSelectorBuilder constructs an empty SelectorBuilder.
func (*SelectorBuilder) Build ¶
func (sb *SelectorBuilder) Build() string
Build returns the final label selector string.
func (*SelectorBuilder) WithComponent ¶
func (sb *SelectorBuilder) WithComponent(component string) (*SelectorBuilder, error)
WithComponent adds a component label requirement to the selector
func (*SelectorBuilder) WithEnvironment ¶
func (sb *SelectorBuilder) WithEnvironment(environment string) (*SelectorBuilder, error)
WithEnvironment adds an environment label requirement to the selector. The name is normalized to its label-safe form so wildcard environments (review/pr-42) match what deploy wrote.
func (*SelectorBuilder) WithProject ¶
func (sb *SelectorBuilder) WithProject(project string) (*SelectorBuilder, error)
WithProject adds a project label requirement to the selector