k8s

package
v0.4.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrResourceNotFound is returned when a resource is not found in the cluster.
	ErrResourceNotFound = errors.New("resource not found")
)

Functions

func GetKubectl

func GetKubectl() string

GetKubectl returns the kubectl command to use.

func IsResourceNotFound

func IsResourceNotFound(err error) bool

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

type KubectlResult struct {
	Stdout string
	Stderr string
}

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

Jump to

Keyboard shortcuts

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