Documentation
¶
Index ¶
- func IsCRDReady(obj *unstructured.Unstructured, err error) (bool, error)
- func IsDeleted(obj *unstructured.Unstructured, err error) (bool, error)
- func IsDeploymentReady(obj *unstructured.Unstructured, err error) (bool, error)
- func IsJobComplete(obj *unstructured.Unstructured, err error) (bool, error)
- func IsNodeReady(obj *unstructured.Unstructured, err error) (bool, error)
- func IsPVCBound(obj *unstructured.Unstructured, err error) (bool, error)
- func IsPhase(desired Phase) func(obj *unstructured.Unstructured, err error) (bool, error)
- func IsPodReady(obj *unstructured.Unstructured, err error) (bool, error)
- func IsPresent(obj *unstructured.Unstructured, err error) (bool, error)
- func RegisterKind(kind ResourceKind, gvr schema.GroupVersionResource)
- func ToGroupVersionResource(kind ResourceKind) (schema.GroupVersionResource, error)
- func WithKubeClient(ctx context.Context, kc *Client) context.Context
- type CheckFunc
- type Client
- func (c *Client) AnnotateResource(ctx context.Context, kind ResourceKind, namespace, name string, ...) error
- func (c *Client) ApplyManifest(ctx context.Context, manifestPath string) error
- func (c *Client) CRDExists(ctx context.Context, crdName string) (bool, error)
- func (c *Client) DeleteManifest(ctx context.Context, manifestPath string) error
- func (c *Client) DeletePV(ctx context.Context, name string) error
- func (c *Client) DeletePVC(ctx context.Context, namespace, name string) error
- func (c *Client) List(ctx context.Context, kind ResourceKind, namespace string, opts WaitOptions) (*unstructured.UnstructuredList, error)
- func (c *Client) ScaleDeployment(ctx context.Context, namespace, name string, replicas int32) error
- func (c *Client) ScaleStatefulSet(ctx context.Context, namespace, name string, replicas int32) error
- func (c *Client) WaitForContainer(ctx context.Context, namespace string, checkFn CheckFunc, ...) error
- func (c *Client) WaitForResource(ctx context.Context, kind ResourceKind, namespace, name string, ...) error
- func (c *Client) WaitForResources(ctx context.Context, kind ResourceKind, namespace string, checkFn CheckFunc, ...) error
- func (c *Client) WaitForResourcesDeletion(ctx context.Context, kind ResourceKind, namespace string, ...) error
- type ClientProvider
- type ClientProviderFromContext
- type KubeConfigManager
- type Phase
- type ResourceKind
- type WaitOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsCRDReady ¶
func IsCRDReady(obj *unstructured.Unstructured, err error) (bool, error)
IsCRDReady checks if a CustomResourceDefinition is established
func IsDeleted ¶
func IsDeleted(obj *unstructured.Unstructured, err error) (bool, error)
IsDeleted checks if a resource has been deleted (returns true if obj is nil or error is NotFound)
func IsDeploymentReady ¶
func IsDeploymentReady(obj *unstructured.Unstructured, err error) (bool, error)
IsDeploymentReady checks if a Deployment has all desired replicas ready
func IsJobComplete ¶
func IsJobComplete(obj *unstructured.Unstructured, err error) (bool, error)
IsJobComplete checks if a Job has completed successfully
func IsNodeReady ¶
func IsNodeReady(obj *unstructured.Unstructured, err error) (bool, error)
IsNodeReady checks if a Node has Ready condition == True
func IsPVCBound ¶
func IsPVCBound(obj *unstructured.Unstructured, err error) (bool, error)
IsPVCBound checks if a PersistentVolumeClaim is in Bound phase
func IsPhase ¶
func IsPhase(desired Phase) func(obj *unstructured.Unstructured, err error) (bool, error)
IsPhase returns a check function that verifies if the resource is in the desired phase
func IsPodReady ¶
func IsPodReady(obj *unstructured.Unstructured, err error) (bool, error)
IsPodReady checks if a Pod is in Ready condition
func IsPresent ¶
func IsPresent(obj *unstructured.Unstructured, err error) (bool, error)
IsPresent checks if the item exists
func RegisterKind ¶
func RegisterKind(kind ResourceKind, gvr schema.GroupVersionResource)
func ToGroupVersionResource ¶
func ToGroupVersionResource(kind ResourceKind) (schema.GroupVersionResource, error)
Types ¶
type CheckFunc ¶
type CheckFunc func(obj *unstructured.Unstructured, err error) (bool, error)
CheckFunc defines a function type for checking resource conditions Notes: when err != nil, obj may be nil. CheckFunc should handle API errors like IsNotFound, IsForbidden.
func IsContainerReady ¶
IsContainerReady returns a CheckFunc that succeeds when the named container reports Ready==true. This is meant to be used for WaitForContainer function.
func IsContainerTerminated ¶
IsContainerTerminated returns a CheckFunc that succeeds when the named container terminated with the specified exit code. If terminated with a different exit code it returns an error. This is meant to be used for WaitForContainer function.
type Client ¶
type Client struct {
Dyn dynamic.Interface
Mapper *restmapper.DeferredDiscoveryRESTMapper
}
Client wraps Kubernetes dynamic client and REST mapper It is intended to be a replacement of invoking kubectl commands directly
func NewClient ¶
NewClient creates a Kubernetes client that automatically detects whether it is running inside a cluster or using a kubeconfig file. It returns a fully prepared dynamic client + discovery mapper.
func (*Client) AnnotateResource ¶ added in v0.8.0
func (c *Client) AnnotateResource(ctx context.Context, kind ResourceKind, namespace, name string, annotations map[string]string) error
AnnotateResource adds or updates annotations on a resource. The annotations map is merged with existing annotations.
func (*Client) ApplyManifest ¶
ApplyManifest applies resources defined in the given manifest file
func (*Client) CRDExists ¶ added in v0.7.0
CRDExists checks if a CustomResourceDefinition exists in the cluster. The crdName should be in the format "resource.group.domain" (e.g., "servicemonitors.monitoring.coreos.com").
func (*Client) DeleteManifest ¶
DeleteManifest deletes resources defined in the given manifest file
func (*Client) DeletePV ¶ added in v0.7.0
DeletePV deletes a PersistentVolume by name. Returns nil if the PV doesn't exist.
func (*Client) DeletePVC ¶ added in v0.7.0
DeletePVC deletes a PersistentVolumeClaim by name and namespace. Returns nil if the PVC doesn't exist.
func (*Client) List ¶
func (c *Client) List(ctx context.Context, kind ResourceKind, namespace string, opts WaitOptions) (*unstructured.UnstructuredList, error)
List lists resources of the given kind in the specified namespace with optional filtering. If opts.NamePrefix is set, client-side filtering is applied to return only resources whose names start with the specified prefix.
func (*Client) ScaleDeployment ¶ added in v0.8.0
ScaleDeployment scales a Deployment to the specified number of replicas. It uses a JSON Merge Patch (RFC 7386) on spec.replicas for atomic scaling with minimal RBAC requirements and reduced conflict potential.
func (*Client) ScaleStatefulSet ¶ added in v0.8.0
func (c *Client) ScaleStatefulSet(ctx context.Context, namespace, name string, replicas int32) error
ScaleStatefulSet scales a StatefulSet to the specified number of replicas. It uses a JSON Merge Patch (RFC 7386) on spec.replicas for atomic scaling with minimal RBAC requirements and reduced conflict potential.
func (*Client) WaitForContainer ¶
func (c *Client) WaitForContainer(ctx context.Context, namespace string, checkFn CheckFunc, timeout time.Duration, opts WaitOptions) error
WaitForContainer waits until the specified container in the given Pod is ready or has terminated successfully within the timeout. It returns an error when the container terminates with a non-zero exit code or on other failures.
func (*Client) WaitForResource ¶
func (c *Client) WaitForResource( ctx context.Context, kind ResourceKind, namespace, name string, checkFn CheckFunc, timeout time.Duration, ) error
WaitForResource waits until the specified resource of the given kind in the specified namespace satisfies the condition defined by checkFn within the timeout. It returns an error if the timeout is reached or if any fatal API errors occur.
func (*Client) WaitForResources ¶
func (c *Client) WaitForResources( ctx context.Context, kind ResourceKind, namespace string, checkFn CheckFunc, timeout time.Duration, opts WaitOptions, ) error
WaitForResources waits until all resources of the given kind in the specified namespace satisfy the condition defined by checkFn within the timeout. It returns an error if the timeout is reached or if any fatal API errors occur.
func (*Client) WaitForResourcesDeletion ¶ added in v0.8.0
func (c *Client) WaitForResourcesDeletion( ctx context.Context, kind ResourceKind, namespace string, timeout time.Duration, opts WaitOptions, ) error
WaitForResourcesDeletion waits until all resources of the given kind matching the options are deleted from the specified namespace within the timeout. It returns nil when no matching resources exist, or an error if the timeout is reached.
type ClientProvider ¶
ClientProvider is a function that provides a kube client NewClient can be used for this provider type
type ClientProviderFromContext ¶
ClientProviderFromContext is a function that provides a kube client instance from context. ClientFromContext can be used for this provider type
type KubeConfigManager ¶
type KubeConfigManager struct {
// contains filtered or unexported fields
}
KubeConfigManager manages kubeconfig file operations with injected dependencies.
func NewKubeConfigManager ¶
func NewKubeConfigManager() (*KubeConfigManager, error)
NewKubeConfigManager creates a new KubeConfigManager with the default dependencies.
func (*KubeConfigManager) Configure ¶
func (m *KubeConfigManager) Configure() error
Configure copies the kubeconfig file to the user's home directory, to /root/.kube, and to the current user's directory. This allows kubectl to be used without requiring root privileges and ensures the config is available for all relevant users.
func (*KubeConfigManager) SetKubeDir ¶
func (m *KubeConfigManager) SetKubeDir(dir string)
SetKubeDir sets a custom kubeconfig directory path. If not set, the default ~/.kube will be used.
type Phase ¶
type Phase string
func RegisterPhase ¶
RegisterPhase allows registering a new Phase value
type ResourceKind ¶
type ResourceKind string
const ( KindNode ResourceKind = "Node" KindService ResourceKind = "Service" KindNamespace ResourceKind = "Namespace" KindConfigMap ResourceKind = "ConfigMap" KindPod ResourceKind = "Pod" KindDeployment ResourceKind = "Deployment" KindStatefulSet ResourceKind = "StatefulSet" KindJob ResourceKind = "Job" KindPVC ResourceKind = "PersistentVolumeClaim" KindCRD ResourceKind = "CustomResourceDefinition" )
func ToResourceKind ¶
func ToResourceKind(gvr schema.GroupVersionResource) ResourceKind
func (ResourceKind) String ¶
func (k ResourceKind) String() string
type WaitOptions ¶
type WaitOptions struct {
// NamePrefix restricts the list of returned objects to those whose names start with the given prefix.
// +optional
NamePrefix string `json:"namePrefix,omitempty"`
// A selector to restrict the list of returned objects by their labels.
// Defaults to everything.
// +optional
LabelSelector string `json:"labelSelector,omitempty"`
// A selector to restrict the list of returned objects by their fields.
// Defaults to everything.
// +optional
FieldSelector string `json:"fieldSelector,omitempty"`
}
func (WaitOptions) AsListOptions ¶
func (w WaitOptions) AsListOptions() metav1.ListOptions
func (WaitOptions) String ¶
func (w WaitOptions) String() string