kube

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package kube provides the cluster operations ate-setup needs, replacing the kubectl invocations the install shell scripts made. Manifests are applied with server-side apply through the dynamic client, so no kubectl binary has to be on PATH.

Index

Constants

View Source
const (
	KindDeployment  = "deployment"
	KindDaemonSet   = "daemonset"
	KindStatefulSet = "statefulset"
)

Workload kinds accepted by RolloutStatus.

View Source
const FieldManager = "ate-setup"

FieldManager identifies ate-setup's writes in managedFields.

Variables

This section is empty.

Functions

func DecodeManifest

func DecodeManifest(r io.Reader) ([]*unstructured.Unstructured, error)

DecodeManifest splits a multi-document YAML stream into objects, preserving document order. Empty documents are skipped the way kubectl skips them.

func DecodeManifestBytes

func DecodeManifestBytes(data []byte) ([]*unstructured.Unstructured, error)

DecodeManifestBytes decodes a multi-document YAML stream held in memory.

func Describe

func Describe(obj *unstructured.Unstructured) string

Describe renders an object reference for log output, in kubectl's kind/name form.

func LoadPath

func LoadPath(path string) ([]*unstructured.Unstructured, error)

LoadPath reads a manifest file, or every manifest directly inside a directory.

Directory handling deliberately mirrors `kubectl apply -f <dir>`: it is non-recursive and processes files in lexical order. deploy_ate_system and delete_ate_system in the shell installer depend on that ordering, and the comments there call out specific filename-ordering hazards, so recursing or reordering here would change install behavior.

func ReadPath

func ReadPath(path string) ([]byte, error)

ReadPath concatenates the same files LoadPath would read into a single multi-document stream, leaving them unparsed.

This is the input the pre-built image resolver takes, and sharing manifestFiles keeps it reading exactly what an apply applies. ko is handed the path and enumerates it itself, accepting only .yaml and .json where this also accepts .yml; nothing in the tree uses that extension, and a manifest that did would reach an apply with its ko:// references unresolved.

Types

type Client

type Client struct {
	Config  *rest.Config
	Typed   kubernetes.Interface
	Dynamic dynamic.Interface
	// contains filtered or unexported fields
}

Client bundles the typed, dynamic, and discovery clients along with the RESTMapper used to route unstructured objects to their resource.

func New

func New(kubeconfig, kubeContext string) (*Client, error)

New builds a Client for the given kubeconfig and context. An empty context selects the kubeconfig's current context, matching the KUBECTL_CONTEXT convention in the shell scripts.

func (*Client) Apply

func (c *Client) Apply(ctx context.Context, objs []*unstructured.Unstructured) error

Apply server-side applies every object in order.

The shell scripts piped manifests to `kubectl apply -f -`, which is a client-side apply by default. Server-side apply is used instead because it is the supported path for repeated reconciliation of the same objects and avoids the last-applied-configuration annotation growing unboundedly on the large generated CRDs.

func (*Client) ApplyBytes

func (c *Client) ApplyBytes(ctx context.Context, data []byte) error

ApplyBytes applies a multi-document manifest held in memory, such as the output of ko resolve or a kustomize build.

func (*Client) ApplyConfigMap

func (c *Client) ApplyConfigMap(ctx context.Context, namespace, name string, data map[string]string) error

ApplyConfigMap applies a ConfigMap from string data.

func (*Client) ApplyOne

func (c *Client) ApplyOne(ctx context.Context, obj *unstructured.Unstructured) error

ApplyOne server-side applies a single object.

func (*Client) ApplyPath

func (c *Client) ApplyPath(ctx context.Context, path string) error

ApplyPath applies a manifest file or directory.

func (*Client) ApplySecret

func (c *Client) ApplySecret(ctx context.Context, namespace, name string, data map[string]string) error

ApplySecret applies an opaque Secret from string data.

func (*Client) ApplyTolerant

func (c *Client) ApplyTolerant(ctx context.Context, objs []*unstructured.Unstructured, onSkip func(obj *unstructured.Unstructured, err error)) error

ApplyTolerant applies objects but skips any whose kind the cluster does not recognize, reporting the skips through onSkip.

The upstream CSI hostpath bundle ships a VolumeSnapshotClass whose CRD is not installed on a stock Kind cluster. The shell installer dealt with that by ignoring kubectl's exit code entirely, which also hid real failures; skipping only the unmappable kinds keeps everything else strict.

func (*Client) CAPoolRootPEM

func (c *Client) CAPoolRootPEM(ctx context.Context, namespace, name string) ([]byte, error)

CAPoolRootPEM extracts a CA pool Secret's root certificates and returns them PEM-encoded.

This replaces ca_pool_root_pem in the shell installer, which piped the Secret through jsonpath, base64, grep, sed, and openssl. Decoding the pool with the same library that wrote it removes the whole toolchain dependency and, more importantly, turns a malformed or empty pool into an error instead of an empty string that silently became a trust bundle with no roots.

func (*Client) ConfigMapExists

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

ConfigMapExists reports whether a ConfigMap is present.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, objs []*unstructured.Unstructured) error

Delete removes every object, ignoring those that are already gone. This is the `kubectl delete --ignore-not-found -f` equivalent.

func (*Client) DeleteBytes

func (c *Client) DeleteBytes(ctx context.Context, data []byte) error

DeleteBytes deletes the objects described by an in-memory manifest.

func (*Client) DeleteOne

func (c *Client) DeleteOne(ctx context.Context, obj *unstructured.Unstructured) error

DeleteOne removes a single object, ignoring NotFound.

A kind that no longer resolves is also treated as already deleted: tearing down after the CRDs have been removed must not fail, which is how `kubectl delete --ignore-not-found` behaved for these manifests.

func (*Client) DeletePath

func (c *Client) DeletePath(ctx context.Context, path string) error

DeletePath deletes the objects described by a manifest file or directory.

A path that does not exist is not an error. Teardown runs over a fixed list covering every install shape, so a manifest the running configuration never referenced is simply absent -- the same reason the shell scripts passed --ignore-not-found. Erroring here would abort the loop and strand every resource named after the missing file.

func (*Client) DeploymentExists

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

DeploymentExists reports whether a Deployment is present. delete_demo_actors used this to decide whether the control plane is still up before trying to talk to it.

func (*Client) EnsureNamespace

func (c *Client) EnsureNamespace(ctx context.Context, name string) error

EnsureNamespace applies a namespace, replacing the `kubectl create namespace <ns> --dry-run=client -o yaml | kubectl apply -f -` idiom the shell scripts used to make creation idempotent.

func (*Client) Exists

func (c *Client) Exists(ctx context.Context, gvk schema.GroupVersionKind, namespace, name string) (bool, error)

Exists reports whether a named object is present.

func (*Client) GetSecret

func (c *Client) GetSecret(ctx context.Context, namespace, name string) (*corev1.Secret, error)

GetSecret returns a Secret, or nil when it does not exist.

func (*Client) InvalidateDiscovery

func (c *Client) InvalidateDiscovery()

InvalidateDiscovery drops the cached discovery data so newly installed CRDs become mappable.

Each kubectl invocation in the shell scripts started with an empty cache, so `kubectl apply -f generated` followed by applying a SandboxConfig just worked. Inside one long-lived process the RESTMapper would keep serving the pre-CRD discovery document and report "no matches for kind", so every code path that installs CRDs has to call this afterwards.

func (*Client) OIDCIssuer

func (c *Client) OIDCIssuer(ctx context.Context) string

OIDCIssuer reads the cluster's OpenID configuration and returns its issuer. An empty string means the endpoint is unavailable or has no issuer, which callers treat as "fall back to the in-cluster default".

func (*Client) RolloutRestart

func (c *Client) RolloutRestart(ctx context.Context, namespace, name string, now time.Time) error

RolloutRestart triggers a restart of a DaemonSet by stamping the pod template, the same annotation `kubectl rollout restart` writes. A missing DaemonSet is not an error: the CSI setup restarts atelet only if present.

func (*Client) RolloutRestartDeployment

func (c *Client) RolloutRestartDeployment(ctx context.Context, namespace, name string, now time.Time) error

RolloutRestartDeployment triggers a restart of a Deployment by stamping the pod template with the restartedAt annotation.

func (*Client) RolloutStatus

func (c *Client) RolloutStatus(ctx context.Context, kind, namespace, name string, timeout time.Duration) error

RolloutStatus blocks until a workload has finished rolling out, replacing `kubectl rollout status <kind>/<name> -n <ns> --timeout=<t>`. The readiness conditions match kubectl's own status viewers.

func (*Client) SecretExists

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

SecretExists reports whether a Secret is present.

func (*Client) ServerVersion

func (c *Client) ServerVersion(_ context.Context) (string, error)

ServerVersion returns the API server version, doubling as a connectivity check with a clear error message.

func (*Client) WaitClusterTrustBundles

func (c *Client) WaitClusterTrustBundles(ctx context.Context, names []string, timeout time.Duration) error

WaitClusterTrustBundles blocks until the podcertificate controller has published the identity bundles the rest of the install depends on.

func (*Client) WaitCondition

func (c *Client) WaitCondition(ctx context.Context, gvk schema.GroupVersionKind, namespace, name, condition string, timeout time.Duration) error

WaitCondition blocks until a custom resource reports the named status condition as True, replacing `kubectl wait --for=condition=<type>`.

func (*Client) WaitDeleted

func (c *Client) WaitDeleted(ctx context.Context, gvk schema.GroupVersionKind, namespace, name string, timeout time.Duration) error

WaitDeleted blocks until the named object is no longer present.

func (*Client) WaitNamespaceActive

func (c *Client) WaitNamespaceActive(ctx context.Context, name string, timeout time.Duration) error

WaitNamespaceActive replaces `kubectl wait --for=jsonpath='{.status.phase}'=Active namespace/<name>`.

Jump to

Keyboard shortcuts

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