kubectl

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateNamespace

func CreateNamespace(name string) error

CreateNamespace creates a namespace

func DeleteNamespace

func DeleteNamespace(name string, timeout string) error

DeleteNamespace deletes a namespace with retry and force delete fallback Handles CRD resources with finalizers to prevent stuck namespaces

func GetNamespace

func GetNamespace(name string) (*corev1.Namespace, error)

GetNamespace retrieves namespace information

func ValidateJSONPath

func ValidateJSONPath(jsonPath string) error

ValidateJSONPath validates JSONPath expressions used with kubectl. This is a basic validation to prevent obvious injection attempts.

func ValidateLabelSelector

func ValidateLabelSelector(selector string) error

ValidateLabelSelector validates Kubernetes label selectors. Label selectors have specific syntax requirements for keys and values.

func ValidateNamespace

func ValidateNamespace(namespace string) error

ValidateNamespace validates namespace against RFC 1123 DNS Label requirements. A valid namespace must: - Be 1-63 characters long - Contain only lowercase alphanumeric characters or '-' - Start with an alphanumeric character - End with an alphanumeric character Empty namespace is allowed for cluster-scoped resources

func ValidateResourceName

func ValidateResourceName(name string) error

ValidateResourceName validates Kubernetes resource names against RFC 1123 DNS Subdomain requirements. A valid resource name must: - Be 1-253 characters long - Contain only lowercase alphanumeric characters, '-', or '.' - Start with an alphanumeric character - End with an alphanumeric character

func ValidateResourceType

func ValidateResourceType(resourceType string) error

ValidateResourceType validates Kubernetes resource type names. These are typically lowercase and may contain '.' for API groups.

func ValidateTimeout

func ValidateTimeout(timeout string) error

ValidateTimeout validates timeout strings used with kubectl commands. Valid formats: "30s", "5m", "1h", "2m0s", "1h30m", "1h30m45s" Accepts both simple format (5m) and Go duration format (5m0s)

Types

type Client

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

Client provides convenient kubectl operations

func NewClient

func NewClient(namespace string) *Client

NewClient creates a new kubectl client for the given namespace

func (*Client) Apply

func (c *Client) Apply(yamlContent string) error

Apply applies YAML content to the cluster with explicit namespace override This ensures resources are created in the correct test namespace

func (*Client) ApplyWithoutNamespaceOverride

func (c *Client) ApplyWithoutNamespaceOverride(yamlContent string) error

ApplyWithoutNamespaceOverride applies YAML content without forcing namespace Use this when the YAML already contains the correct namespace field

func (*Client) Delete

func (c *Client) Delete(resourceType, name string) error

Delete deletes a resource

func (*Client) DeleteClusterScoped

func (c *Client) DeleteClusterScoped(resourceType, name string) error

DeleteClusterScoped deletes a cluster-scoped resource (no namespace)

func (*Client) DeleteFromYAML

func (c *Client) DeleteFromYAML(yamlContent string) error

DeleteFromYAML deletes resources from YAML content

func (*Client) Get

func (c *Client) Get(resourceType, name string) ([]byte, error)

Get retrieves a resource by name and type

func (*Client) GetAll

func (c *Client) GetAll(resourceType string, labelSelector string) (string, error)

GetAll retrieves all resources of a type with optional label selector

func (*Client) GetPodLogs

func (c *Client) GetPodLogs(podName string) (string, error)

GetPodLogs retrieves logs from a pod

func (*Client) GetPodLogsSince

func (c *Client) GetPodLogsSince(podName string, since string) (string, error)

GetPodLogsSince retrieves logs from a pod since a specific time

func (*Client) GetPodLogsSinceTime

func (c *Client) GetPodLogsSinceTime(podName string, since time.Time, tailLines int) (string, error)

GetPodLogsSinceTime retrieves logs from a pod since a specific time with line limit Uses --since-time for temporal filtering and --tail as a safety limit

func (*Client) GetPodLogsTail

func (c *Client) GetPodLogsTail(podName string, lines int) (string, error)

GetPodLogsTail retrieves the last N lines of logs from a pod

func (*Client) GetPodsByLabel

func (c *Client) GetPodsByLabel(labelSelector string) ([]string, error)

GetPodsByLabel retrieves pod names matching a label selector

func (*Client) GetWithJsonPath

func (c *Client) GetWithJsonPath(resourceType, name, jsonPath string) (string, error)

GetWithJsonPath retrieves a specific field from a resource If name is empty, retrieves from all resources of the given type

func (*Client) Wait

func (c *Client) Wait(resourceType, name, condition string, timeout string) error

Wait waits for a resource condition

func (*Client) WaitForDeploymentReady

func (c *Client) WaitForDeploymentReady(name string)

WaitForDeploymentReady waits for a deployment to be created and ready

func (*Client) WaitForPipelineInvalid

func (c *Client) WaitForPipelineInvalid(name string)

WaitForPipelineInvalid waits for a VectorPipeline to become invalid (for negative tests)

func (*Client) WaitForPipelineValid

func (c *Client) WaitForPipelineValid(name string)

WaitForPipelineValid waits for a VectorPipeline to become valid

func (*Client) WaitForPodReady

func (c *Client) WaitForPodReady(podName string, timeout string) error

WaitForPodReady waits for a pod to become ready

func (*Client) WaitForServiceCount

func (c *Client) WaitForServiceCount(labelSelector string, expectedCount int, timeout time.Duration)

WaitForServiceCount waits for a specific number of services matching filter

func (*Client) WaitForServiceExists

func (c *Client) WaitForServiceExists(name string)

WaitForServiceExists waits for a service to be created

Jump to

Keyboard shortcuts

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