kubeclient

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

pkg/kubeclient/context.go

pkg/kubeclient/dynamic.go

pkg/kubeclient/genericclient.go

pkg/kubeclient/kubeclient.go

pkg/kubeclient/patch_status.go

pkg/kubeclient/provider.go

Index

Constants

View Source
const ContextKey contextKey = "orkestra-kubeclient"

ContextKey is the key used to store and retrieve a *Kubeclient from a context. Used by OrkestraRegistry hook implementations to access the kube client without changing the domain.ReconcileHooks function signatures.

Usage — inject before calling hooks:

ctx = kubeclient.WithKubeclient(ctx, kube)

Usage — retrieve in generated hooks:

kube, ok := ctx.Value(kubeclient.ContextKey).(*kubeclient.Kubeclient)
if !ok || kube == nil {
    return fmt.Errorf("kubeclient not found in context")
}

Variables

This section is empty.

Functions

func NewFakeClientset

func NewFakeClientset() kubernetes.Interface

New fake client

func WithKubeclient

func WithKubeclient(ctx context.Context, kube *Kubeclient) context.Context

WithKubeclient returns a new context with the Kubeclient stored under ContextKey. Example usage: This is called in GenericReconciler.Reconcile before invoking hook functions. To allow hooks retrieve the kubeclient

Types

type CRDInfo

type CRDInfo struct {
	Kind                 string                  // Required by Registry
	Group                string                  // Required if GroupVersion is not specified
	Version              string                  // Required if GroupVersion is not specified
	GroupVersion         *schema.GroupVersion    // Optional (can be used if Group and Version are not specified)
	GroupVersionKind     schema.GroupVersionKind //	Useful for some manipulations
	GroupVersionResource schema.GroupResource
	Plural               string
	Namespaced           bool // Required for cluster-scoped resources
	APIPath              string
	Namespace            string
}

CRDInfo defines what a CRD is

type Client

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

Client definition

func (*Client) List

func (c *Client) List(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error)

A generic client should know how to List and Watch just as the dynamic client List returns runtime.Object - exactly what GenericClient needs!

func (*Client) Watch

func (c *Client) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)

Watch returns the watch interface

type ClientFactory

type ClientFactory func(*Kubeclient) (informer.GenericClient, error)

ClientFactory accepts kubeclient and returns a generic client The generic client is the hallmark of the whole design konstructOrkestra() performs per CRD registration and hands over to ghe informer factory

type ClientProvider

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

ClientProvider definition for registering new clients

func (*ClientProvider) For

For returns a generic client for a registered object

func (*ClientProvider) Register

func (p *ClientProvider) Register(obj runtime.Object, factory ClientFactory)

Register adds a new object to clients

type DynamicListerWatcher

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

DynamicListerWatcher implements cache.ListerWatcher using the dynamic client. Safe to construct before kube.Start() — k.dynamic is resolved at call time.

func (*DynamicListerWatcher) List

List implements cache.ListerWatcher. *unstructured.UnstructuredList satisfies runtime.Object — explicit cast needed because dynamic.ResourceInterface.List returns the concrete type, not the interface.

func (*DynamicListerWatcher) Watch

Watch implements cache.ListerWatcher.

type Kubeclient

type Kubeclient struct {
	Info *CRDInfo

	// Testing
	FakeClientset kubernetes.Interface
	// contains filtered or unexported fields
}

Kubeclient defines what a kube client is

func FromContext

func FromContext(ctx context.Context) (*Kubeclient, bool)

FromContext retrieves the Kubeclient from a context. Returns (nil, false) if not present.

func NewKubeclient

func NewKubeclient(kfg *konfig.Konfig, scheme *runtime.Scheme) *Kubeclient

----------------------------------------------------------------------------- Entry point ----------------------------------------------------------------------------- NewKubeclient returns a new Kubeclient with the correct scheme

func (*Kubeclient) ApiextensionsClient

func (k *Kubeclient) ApiextensionsClient() apiextclientset.Interface

ApiextensionsClient returns the apiextensions clientset for CRD operations.

func (*Kubeclient) Clientset

func (k *Kubeclient) Clientset() kubernetes.Interface

Clientset returns the kubernetes interface

func (*Kubeclient) DynamicClient

func (k *Kubeclient) DynamicClient() dynamic.Interface

Dynamic returns yhe dynamic interface. Useful in 'dynamic' reconciler mode

func (*Kubeclient) DynamicClientFor

func (k *Kubeclient) DynamicClientFor(apiPath, group, version string) (dynamic.Interface, error)

On-demand dynamic client

func (*Kubeclient) Name

func (k *Kubeclient) Name() string

Name returns the name of the kubeclient

func (*Kubeclient) NewClient

func (k *Kubeclient) NewClient(objList runtime.Object, info CRDInfo) (*Client, error)

NewClient returns a new client using ths shared client factory

func (*Kubeclient) NewClientProvider

func (k *Kubeclient) NewClientProvider() *ClientProvider

NewClientProvider creates a new provider with the passed in kubeclient At this stage, it only accepts the kubeclient and created the clients map This is because kube is not live yet

func (*Kubeclient) NewDynamicListerWatcher

func (k *Kubeclient) NewDynamicListerWatcher(info CRDInfo, opts ListOptions) cache.ListerWatcher

NewDynamicListerWatcher builds a cache.ListerWatcher for an unstructured CRD. Safe to call before kube.Start() — dynamic client is resolved lazily.

func (*Kubeclient) PatchAnnotations

func (k *Kubeclient) PatchAnnotations(
	ctx context.Context,
	obj runtime.Object,
	gvr schema.GroupVersionResource,
	annotations map[string]string,
) error

func (*Kubeclient) PatchFinalizers

func (k *Kubeclient) PatchFinalizers(
	ctx context.Context,
	obj runtime.Object,
	gvr schema.GroupVersionResource,
	finalizers []string,
) error

Patch Finalizers

func (*Kubeclient) PatchLabels

func (k *Kubeclient) PatchLabels(
	ctx context.Context,
	obj runtime.Object,
	gvr schema.GroupVersionResource,
	labels map[string]string,
) error

Patch Labels

func (*Kubeclient) PatchSpec

func (k *Kubeclient) PatchSpec(
	ctx context.Context,
	obj domain.Object,
	gvr schema.GroupVersionResource,
	specFields map[string]interface{},
) error

pkg/kubeclient/patch_spec.go

func (*Kubeclient) PatchStatus

func (k *Kubeclient) PatchStatus(
	ctx context.Context,
	obj domain.Object,
	gvr schema.GroupVersionResource,
	statusFields map[string]interface{},
) error

PatchStatus applies a merge patch to the /status subresource of a CR.

statusFields is the map of status fields to set — it is merged into the existing status, not replaced entirely. Fields not present in statusFields are left untouched.

The patch is applied to the /status subresource, which requires the CRD to declare:

spec:
  versions:
    - name: v1
      subresources:
        status: {}   # ← this enables the status subresource

If the CRD does not declare a status subresource, the API server returns a 404 "the server could not find the requested resource". Callers should treat this as a non-fatal condition — the CRD simply does not support status updates.

PatchStatus uses merge patch (application/merge-patch+json) rather than strategic merge patch. Merge patch is simpler and sufficient for status updates — we are setting top-level status fields, not merging lists.

Example statusFields:

{
  "conditions": [{"type": "Ready", "status": "True", ...}],
  "observedGeneration": 3,
  "phase": "Running",
  "endpoint": "my-site.default.svc.cluster.local"
}

The API server wraps this in {"status": <statusFields>} before applying. Callers pass only the status contents — not the "status" wrapper key.

func (*Kubeclient) RestClientFor

func (k *Kubeclient) RestClientFor(apiPath, group, version string) (*rest.RESTClient, error)

On-demand rest client

func (*Kubeclient) RestConfig

func (k *Kubeclient) RestConfig() *rest.Config

RestConfig returns the rest confif for the kube client

func (*Kubeclient) RuntimeParameterCodec

func (k *Kubeclient) RuntimeParameterCodec() runtime.ParameterCodec

func (*Kubeclient) Scheme

func (k *Kubeclient) Scheme() *runtime.Scheme

Scheme returns the runtime scheme for yhe kubeclient

func (*Kubeclient) SharedClientFactory

func (k *Kubeclient) SharedClientFactory(apiPath, group, version string) (*rest.RESTClient, error)

SharedClientFactory provides a simple way to build clients from config

func (*Kubeclient) Shutdown

func (k *Kubeclient) Shutdown(ctx context.Context)

Shutdown is called by orkestra fir graceful shutdown

func (*Kubeclient) Start

func (k *Kubeclient) Start(ctx context.Context) error

Start is called by orkestra.Start() to start kube client

func (*Kubeclient) Started

func (k *Kubeclient) Started() bool

Started is called by orkestra for healthcheck

type ListOptions

type ListOptions struct {
	LabelSelector string
	FieldSelector string
}

Jump to

Keyboard shortcuts

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