client

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultQPS is the default queries per second for CLI client.
	// This is significantly higher than kubectl's default (5) to support
	// parallel operations like backup with multiple concurrent workers.
	DefaultQPS = 50

	// DefaultBurst is the default burst capacity for CLI client.
	// This is significantly higher than kubectl's default (10) to handle
	// initial spikes when all workers start simultaneously.
	DefaultBurst = 100
)

Variables

This section is empty.

Functions

func ConfigureThrottling added in v0.0.12

func ConfigureThrottling(config *rest.Config, qps float32, burst int)

ConfigureThrottling configures QPS and Burst on a REST config. These settings control client-side rate limiting for Kubernetes API requests.

QPS (Queries Per Second): Sustained rate of API requests allowed. Burst: Maximum number of requests that can be issued in a short burst.

For CLI tools with parallel operations (like backup), higher values are recommended to avoid unnecessary throttling delays.

func DiscoverGVRs added in v0.0.17

func DiscoverGVRs(ctx context.Context, c Client, opts ...DiscoverGVRsOption) ([]schema.GroupVersionResource, error)

DiscoverGVRs discovers custom resources and returns their GVRs. Requires full Client access because it uses the APIExtensions client.

func GetApplicationsNamespace added in v0.0.17

func GetApplicationsNamespace(ctx context.Context, r Reader) (string, error)

GetApplicationsNamespace retrieves the applications namespace from DSCInitialization. Returns the namespace string and nil error if found. Returns empty string and NotFound error if DSCI doesn't exist or if applicationsNamespace is not set or empty. Returns empty string and wrapped error for other failures.

func GetDSCInitialization added in v0.0.17

func GetDSCInitialization(ctx context.Context, r Reader) (*unstructured.Unstructured, error)

GetDSCInitialization retrieves the cluster's DSCInitialization singleton resource.

func GetDataScienceCluster added in v0.0.17

func GetDataScienceCluster(ctx context.Context, r Reader) (*unstructured.Unstructured, error)

GetDataScienceCluster retrieves the cluster's DataScienceCluster singleton resource.

func GetSingleton added in v0.0.17

func GetSingleton(ctx context.Context, r Reader, resourceType resources.ResourceType) (*unstructured.Unstructured, error)

GetSingleton expects exactly one instance of the resource type to exist. Returns error if zero or multiple instances found.

func IsPermissionError added in v0.0.13

func IsPermissionError(err error) bool

IsPermissionError checks if an error is due to insufficient permissions. Returns true for Forbidden (403) and Unauthorized (401) errors.

func IsResourceTypeNotFound added in v0.0.12

func IsResourceTypeNotFound(err error) bool

IsResourceTypeNotFound checks if an error indicates the resource type/CRD doesn't exist. Catches both:

  • meta.NoResourceMatchError from the REST mapper when the GVK/GVR is unknown
  • 404 NotFound from the dynamic/metadata clients, which bypass the REST mapper and hit the API server directly (returns 404 when the resource endpoint doesn't exist)

func IsUnrecoverableError

func IsUnrecoverableError(err error) bool

IsUnrecoverableError checks if an error is unrecoverable and should not be retried. Returns true for errors like Forbidden, Unauthorized, Invalid, MethodNotSupported, and NotAcceptable.

func List added in v0.0.18

func List[T namespacedNamer](
	ctx context.Context,
	r Reader,
	resourceType resources.ResourceType,
	filter func(T) (bool, error),
) ([]T, error)

List lists resources of the given type, applies an optional filter, and returns matching items. CRD-not-found errors are treated as an empty list. Pass nil filter to return all. T must be *unstructured.Unstructured (dispatches to Reader.List) or *metav1.PartialObjectMetadata (dispatches to Reader.ListMetadata).

func NewDiscoveryClient

func NewDiscoveryClient(configFlags *genericclioptions.ConfigFlags) (discovery.DiscoveryInterface, error)

NewDiscoveryClient creates a new discovery client from ConfigFlags.

func NewDynamicClient

func NewDynamicClient(configFlags *genericclioptions.ConfigFlags) (dynamic.Interface, error)

NewDynamicClient creates a new dynamic client from ConfigFlags.

func NewRESTConfig added in v0.0.12

func NewRESTConfig(
	configFlags *genericclioptions.ConfigFlags,
	qps float32,
	burst int,
) (*rest.Config, error)

NewRESTConfig creates a REST config with appropriate throttling for CLI usage. The QPS and Burst parameters allow callers to customize throttling settings. Use DefaultQPS and DefaultBurst for standard parallel operations.

Types

type CSVReader added in v0.0.17

CSVReader provides read-only access to OLM ClusterServiceVersion resources.

type Client

type Client interface {
	Reader
	Writer

	// Dynamic returns the dynamic Kubernetes client.
	Dynamic() dynamic.Interface

	// Discovery returns the Kubernetes discovery client.
	Discovery() discovery.DiscoveryInterface

	// APIExtensions returns the API extensions client for CRD operations.
	APIExtensions() apiextensionsclientset.Interface

	// Metadata returns the metadata-only client for efficient resource listing.
	Metadata() metadata.Interface

	// RESTMapper returns the REST mapper for GVK/GVR resolution.
	RESTMapper() meta.RESTMapper

	// OLMClient returns the full OLM clientset for write operations (subscriptions, CSVs).
	// Use OLM() from Reader for read-only access.
	OLMClient() olmclientset.Interface
}

Client provides full access to Kubernetes resources. Embeds Reader and Writer, and exposes the underlying clientsets for callers that need low-level or write access.

func NewClient

func NewClient(configFlags *genericclioptions.ConfigFlags) (Client, error)

NewClient creates a unified client with default throttling settings. The client is configured with appropriate throttling for parallel CLI operations.

func NewClientWithConfig added in v0.0.12

func NewClientWithConfig(restConfig *rest.Config) (Client, error)

NewClientWithConfig creates a client from a pre-configured REST config. This allows callers to customize throttling settings before client creation.

func NewForTesting added in v0.0.17

func NewForTesting(cfg TestClientConfig) Client

NewForTesting creates a Client for use in tests. Only the sub-clients that are needed for the test need to be populated.

type DiscoverGVRsConfig

type DiscoverGVRsConfig struct {
	LabelSelector string
}

DiscoverGVRsConfig configures CRD discovery.

type DiscoverGVRsOption

type DiscoverGVRsOption = util.Option[DiscoverGVRsConfig]

DiscoverGVRsOption is an option for configuring DiscoverGVRs.

func WithCRDLabelSelector

func WithCRDLabelSelector(selector string) DiscoverGVRsOption

WithCRDLabelSelector filters CRDs by label selector.

type GetConfig

type GetConfig struct {
	Namespace string
}

GetConfig holds options for customizing Get operations (e.g., namespace scope).

type GetOption

type GetOption = util.Option[GetConfig]

GetOption is a functional option for configuring Get operations.

func InNamespace

func InNamespace(ns string) GetOption

InNamespace specifies the namespace for the resource (optional for cluster-scoped).

type ListResourcesConfig

type ListResourcesConfig struct {
	Namespace     string
	LabelSelector string
	FieldSelector string
}

ListResourcesConfig configures resource listing.

type ListResourcesOption

type ListResourcesOption = util.Option[ListResourcesConfig]

ListResourcesOption is an option for configuring ListResources.

func WithFieldSelector

func WithFieldSelector(selector string) ListResourcesOption

WithFieldSelector filters resources by field selector.

func WithLabelSelector

func WithLabelSelector(selector string) ListResourcesOption

WithLabelSelector filters resources by label selector.

func WithNamespace

func WithNamespace(ns string) ListResourcesOption

WithNamespace filters resources to a specific namespace.

type OLMReader added in v0.0.17

type OLMReader interface {
	// Available returns true if OLM is available in the cluster.
	Available() bool

	// Subscriptions returns a read-only accessor for OLM subscriptions in the given namespace.
	// Use empty string for all namespaces.
	Subscriptions(namespace string) SubscriptionReader

	// ClusterServiceVersions returns a read-only accessor for CSVs in the given namespace.
	// Use empty string for all namespaces.
	ClusterServiceVersions(namespace string) CSVReader
}

OLMReader provides read-only access to OLM resources.

type Reader added in v0.0.17

type Reader interface {
	// List lists all instances of a resource type handling pagination automatically.
	List(
		ctx context.Context,
		resourceType resources.ResourceType,
		opts ...ListResourcesOption,
	) ([]*unstructured.Unstructured, error)

	// ListMetadata lists all instances of a resource type returning only metadata.
	ListMetadata(
		ctx context.Context,
		resourceType resources.ResourceType,
		opts ...ListResourcesOption,
	) ([]*metav1.PartialObjectMetadata, error)

	// ListResources lists all instances of a resource by GVR handling pagination automatically.
	ListResources(
		ctx context.Context,
		gvr schema.GroupVersionResource,
		opts ...ListResourcesOption,
	) ([]*unstructured.Unstructured, error)

	// Get retrieves a single resource by GVR and name.
	Get(
		ctx context.Context,
		gvr schema.GroupVersionResource,
		name string,
		opts ...GetOption,
	) (*unstructured.Unstructured, error)

	// GetResource retrieves a single resource by ResourceType and name.
	GetResource(
		ctx context.Context,
		resourceType resources.ResourceType,
		name string,
		opts ...GetOption,
	) (*unstructured.Unstructured, error)

	// GetResourceMetadata retrieves only the metadata of a single resource.
	// Use this when you only need name, namespace, labels, or annotations.
	GetResourceMetadata(
		ctx context.Context,
		resourceType resources.ResourceType,
		name string,
		opts ...GetOption,
	) (*metav1.PartialObjectMetadata, error)

	// OLM returns a read-only accessor for OLM resources (subscriptions, CSVs).
	OLM() OLMReader
}

Reader provides read-only access to Kubernetes resources. Used by lint checks to enforce that no write operations can occur.

type SubscriptionReader added in v0.0.17

type SubscriptionReader interface {
	List(ctx context.Context, opts metav1.ListOptions) (*operatorsv1alpha1.SubscriptionList, error)
	Get(ctx context.Context, name string, opts metav1.GetOptions) (*operatorsv1alpha1.Subscription, error)
}

SubscriptionReader provides read-only access to OLM Subscription resources.

type TestClientConfig added in v0.0.17

type TestClientConfig struct {
	Dynamic       dynamic.Interface
	Discovery     discovery.DiscoveryInterface
	APIExtensions apiextensionsclientset.Interface
	OLM           olmclientset.Interface
	Metadata      metadata.Interface
	RESTMapper    meta.RESTMapper
}

TestClientConfig holds all sub-clients for constructing a test client.

type Writer added in v0.0.17

type Writer any

Writer provides write access to Kubernetes resources. Currently empty -- write operations will be added as needed.

Jump to

Keyboard shortcuts

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