kube

package
v1.5.13 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package kube is a dependency-free Kubernetes REST client scoped to exactly what the bootnode plugin needs: server-side-apply of namespaced custom resources (bootno.de/v1 Network, NodeFleet, KMSSecret).

It deliberately avoids k8s.io/client-go and its transitive dependency tree. The bootnode plugin applies a handful of CR kinds; a full typed client is overkill. This client talks to the apiserver over net/http using the in-cluster service-account token + CA (the standard pod identity), falling back to KUBE_APISERVER + KUBE_TOKEN env for out-of-cluster development.

Apply uses Kubernetes server-side apply (PATCH with application/apply-patch+yaml). It is idempotent: applying the same object twice converges to the same state with bootnode as the field manager.

Index

Constants

This section is empty.

Variables

View Source
var (
	NetworkGVR   = GVR{Group: "bootno.de", Version: "v1", Plural: "networks", Kind: "Network"}
	NodeFleetGVR = GVR{Group: "bootno.de", Version: "v1", Plural: "nodefleets", Kind: "NodeFleet"}
	KMSSecretGVR = GVR{Group: "bootno.de", Version: "v1", Plural: "kmssecrets", Kind: "KMSSecret"}
)

bootno.de/v1 resources the bootnode plugin manages.

Functions

func SetTarget

func SetTarget(c *Client, apiServer, token string)

SetTarget overrides the apiserver and bearer token explicitly, marking the client available. Used for out-of-cluster wiring where the target is known programmatically (and by tests pointing at a stub apiserver).

Types

type Client

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

Client applies namespaced custom resources to a Kubernetes cluster.

func New

func New(defaultNamespace string) *Client

New constructs a Client. It resolves cluster access in this order:

  1. In-cluster service account (token + CA + namespace files).
  2. KUBE_APISERVER + KUBE_TOKEN environment variables (dev / out-of-cluster).

New never fails: when no cluster is reachable the Client is marked unavailable and Client.Available returns false. Callers decide whether a missing cluster is fatal for a given request (it is for network/node provisioning, surfaced as a 503).

func (*Client) Apply

func (c *Client) Apply(ctx context.Context, gvr GVR, name string, labels map[string]string, spec map[string]any) (string, error)

Apply performs a server-side apply of the given custom resource. It is idempotent. spec is the resource's .spec; labels are attached to metadata.

Returns the applied object's name on success.

func (*Client) Available

func (c *Client) Available() bool

Available reports whether a Kubernetes cluster was resolved at construction.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, gvr GVR, name string) error

Delete removes a named custom resource. A 404 is treated as success (idempotent delete).

func (*Client) Get

func (c *Client) Get(ctx context.Context, gvr GVR, name string, out any) (bool, error)

Get fetches a named custom resource and decodes it into out. Returns (false, nil) when the resource does not exist.

func (*Client) Namespace

func (c *Client) Namespace() string

Namespace returns the namespace the client applies resources into.

type CustomResource

type CustomResource struct {
	APIVersion string         `json:"apiVersion"`
	Kind       string         `json:"kind"`
	Metadata   Metadata       `json:"metadata"`
	Spec       map[string]any `json:"spec"`
}

CustomResource is the minimal shape of a namespaced custom resource. Apply fills in apiVersion/kind/namespace, so callers provide Name + Spec.

type GVR

type GVR struct {
	Group    string
	Version  string
	Plural   string
	Kind     string
	Singular string // used for apiVersion display only
}

GVR identifies a custom resource's group/version/plural for URL building.

type Metadata

type Metadata struct {
	Name      string            `json:"name"`
	Namespace string            `json:"namespace"`
	Labels    map[string]string `json:"labels,omitempty"`
}

Metadata is the object metadata Apply sets.

Jump to

Keyboard shortcuts

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