Documentation
¶
Index ¶
- Variables
- func GetKubectl() string
- func IsResourceNotFound(err error) bool
- func ResourceNotOwnedByName(obj *unstructured.Unstructured, ownerName string) bool
- func RetrieveClusterResourceLabel(ctx context.Context, log *logger.Logger, ...) (string, error)
- func RetrieveResourceFromCluster(ctx context.Context, log *logger.Logger, ...) (*unstructured.Unstructured, error)
- type KubectlOptions
- type KubectlResult
Constants ¶
This section is empty.
Variables ¶
var ( // ErrResourceNotFound is returned when a resource is not found in the cluster. ErrResourceNotFound = errors.New("resource not found") )
Functions ¶
func IsResourceNotFound ¶
IsResourceNotFound checks if an error is a resource not found error.
func ResourceNotOwnedByName ¶
func ResourceNotOwnedByName(obj *unstructured.Unstructured, ownerName string) bool
ResourceNotOwnedByName checks if the given unstructured object does not have an owner reference with the specified owner name. The negative version of this function is better suited for our needs, because there can be multiple owner references and we are only interested in checking if a given resource is NOT owned by a specific owner.
func RetrieveClusterResourceLabel ¶
func RetrieveClusterResourceLabel(ctx context.Context, log *logger.Logger, namespace, resourceType, resourceName, label string) (string, error)
RetrieveClusterResourceLabel retrieves the specified label from a Kubernetes resource from the cluster.
Parameters: Same as for RetrieveResourceFromCluster, plus
- label: The label to retrieve.
Returns:
- string: the label value -- if the label is not found, an empty string is returned without error.
- error: nil if successful, error otherwise (including ErrResourceNotFound for not found resources)
func RetrieveResourceFromCluster ¶
func RetrieveResourceFromCluster(ctx context.Context, log *logger.Logger, namespace, resourceType, resourceName string) (*unstructured.Unstructured, error)
RetrieveResourceFromCluster retrieves a Kubernetes resource from the cluster and returns it as an unstructured.Unstructured.
Parameters:
- ctx: The context for the kubectl command
- log: Logger for diagnostic output (can be nil for silent operation)
- namespace: The namespace where the resource is located (use "" for cluster-scoped resources)
- resourceType: The resource type (e.g., "pod", "secret", "pvc")
- resourceName: The name of the resource
Returns:
- *unstructured.Unstructured: The resource as an unstructured object containing all metadata
- error: nil if successful, error otherwise (including ErrResourceNotFound for not found resources)
Types ¶
type KubectlOptions ¶
type KubectlOptions struct {
Args []string // Command arguments (e.g., ["get", "pod", "my-pod"])
Stdin io.Reader // Optional stdin for commands like "apply -f -"
MaxAttempts int // Maximum number of retry attempts (default: 3)
RetryDelay int // Base retry delay in seconds (default: 2)
IgnoreErrors bool // If true, return nil on errors (useful for cleanup operations)
}
KubectlOptions contains options for running kubectl commands
type KubectlResult ¶
KubectlResult contains the result of a kubectl command execution
func RunKubectl ¶
func RunKubectl(ctx context.Context, log *logger.Logger, opts KubectlOptions) (KubectlResult, error)
RunKubectl executes a kubectl command with automatic retries on transient errors