locator

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsLocateError added in v0.0.2

func IsLocateError(err error) bool

IsLocateError checks if an error is a LocateError

func NewAPITransientError added in v0.0.2

func NewAPITransientError(msg string, err error) error

NewAPITransientError creates an error for transient API issues

func NewConfigInvalidError added in v0.0.2

func NewConfigInvalidError(msg string, err error) error

NewConfigInvalidError creates an error for invalid configuration

func NewNetworkTransientError added in v0.0.2

func NewNetworkTransientError(msg string, err error) error

NewNetworkTransientError creates an error for transient network issues

func NewPermissionDeniedError added in v0.0.2

func NewPermissionDeniedError(operation, resource string, err error) error

NewPermissionDeniedError creates an error for permission issues

func NewPodFailedError added in v0.0.2

func NewPodFailedError(podName string, err error) error

NewPodFailedError creates an error for failed pods

func NewPodNotRunningError added in v0.0.2

func NewPodNotRunningError(podName, phase string, err error) error

NewPodNotRunningError creates an error for non-running pods

func NewResourceNotFoundError added in v0.0.2

func NewResourceNotFoundError(resourceType, name string, err error) error

NewResourceNotFoundError creates an error for missing resources

Types

type ErrorType added in v0.0.2

type ErrorType int

ErrorType categorizes locator errors for intelligent error handling

const (
	ErrorTypeUnknown ErrorType = iota

	// Transient errors - retry with backoff
	ErrorTypeNetworkTransient // Network timeout, connection reset
	ErrorTypeAPITransient     // API timeout, server error (5xx)

	// Permanent errors - fail fast or give up after few retries
	ErrorTypeResourceNotFound // Pod, Service, Deployment doesn't exist
	ErrorTypePodNotRunning    // Pod exists but not in Running state
	ErrorTypePodFailed        // Pod in Failed state
	ErrorTypeConfigInvalid    // Invalid configuration (port, selector, etc)
	ErrorTypePermissionDenied // No permission to access resource
	ErrorTypeNoPodAvailable   // No running pods available for resource (might retry longer)
)

func GetErrorType added in v0.0.2

func GetErrorType(err error) ErrorType

GetErrorType extracts the error type from a LocateError

type LocateError added in v0.0.2

type LocateError struct {
	Type    ErrorType
	Message string
	Err     error
}

LocateError wraps location errors with type information for intelligent retry handling

func (*LocateError) Error added in v0.0.2

func (e *LocateError) Error() string

Error implements the error interface

func (*LocateError) Unwrap added in v0.0.2

func (e *LocateError) Unwrap() error

Unwrap implements error unwrapping for error chains

type Locator

type Locator interface {
	// Locate returns the pod name and ports for port forwarding.
	Locate(ctx context.Context) (string, []string, error)
}

Locator is the interface for discovering pods or services in Kubernetes.

func BuildLocator

func BuildLocator(resource string, namespace string, ports []string, client kubernetes.Interface) (Locator, error)

BuildLocator creates the appropriate locator based on the resource string. Supported formats: - "pod-name" - direct pod reference - "svc/service-name" or "service/service-name" - service reference - "dep/deployment-name" or "deployment/deployment-name" - deployment reference - "sts/statefulset-name" or "statefulset/statefulset-name" - statefulset reference - "ds/daemonset-name" or "daemonset/daemonset-name" - daemonset reference

type PodLocator

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

PodLocator locates a specific pod by name and returns its port mappings.

func NewPodLocator

func NewPodLocator(podName string, namespace string, ports []string, client kubernetes.Interface) (*PodLocator, error)

NewPodLocator creates a new pod locator for the specified pod name.

func (*PodLocator) Locate

func (l *PodLocator) Locate(ctx context.Context) (string, []string, error)

Locate finds the pod and verifies it's running, then returns its name and ports.

type SelectorBasedLocator added in v0.0.2

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

SelectorBasedLocator locates a pod backing a Kubernetes resource with a selector (Deployment, StatefulSet, DaemonSet, etc) and returns the first running pod.

func NewSelectorBasedLocator added in v0.0.2

func NewSelectorBasedLocator(resourceType string, resourceName string, namespace string, ports []string, client kubernetes.Interface) (*SelectorBasedLocator, error)

NewSelectorBasedLocator creates a locator for any resource type with a selector.

func (*SelectorBasedLocator) Locate added in v0.0.2

func (l *SelectorBasedLocator) Locate(ctx context.Context) (string, []string, error)

Locate finds a running pod backing the resource and returns its name and ports.

type ServiceLocator

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

ServiceLocator locates a pod backing a service and maps service ports to pod ports.

func NewServiceLocator

func NewServiceLocator(svcName string, namespace string, ports []string, client kubernetes.Interface) (*ServiceLocator, error)

NewServiceLocator creates a new service locator for the specified service name.

func (*ServiceLocator) Locate

func (l *ServiceLocator) Locate(ctx context.Context) (string, []string, error)

Locate finds a running pod backing the service and returns its name and mapped ports.

Jump to

Keyboard shortcuts

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