k8s

package
v0.2.1-experimental Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetKubeConfigPath added in v0.1.27

func GetKubeConfigPath() (string, bool)

GetKubeConfigPath returns the path to the kubeconfig file and a boolean indicating if the file exists

Types

type Client added in v0.1.27

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

func NewClient added in v0.1.27

func NewClient(disableClientThrottling bool) (*Client, error)

func (*Client) ApplyManifest added in v0.1.27

func (c *Client) ApplyManifest(obj *unstructured.Unstructured, source string, fallbackNamespace string) error

Helper function to apply a single manifest from an unstructured object

func (*Client) ApplyManifestFromFile added in v0.1.27

func (c *Client) ApplyManifestFromFile(path string, fallbackNamespace string) (int, error)

ApplyManifestFromFile applies a Kubernetes manifest from a file

func (*Client) ApplyManifestFromString added in v0.1.27

func (c *Client) ApplyManifestFromString(manifest string, fallbackNamespace string) (int, error)

func (*Client) CheckIfResourceExists added in v0.1.27

func (c *Client) CheckIfResourceExists(gvr schema.GroupVersionResource, namespace string, name string) (bool, error)

func (*Client) CreateNamespace added in v0.1.27

func (c *Client) CreateNamespace(namespace string) (bool, error)

create namespace. Returns true if the namespace was created, false if it already existed.

func (*Client) DeleteAllApplicationsOlderThan added in v0.1.27

func (c *Client) DeleteAllApplicationsOlderThan(namespace string, minutes int) error

DeleteAllApplicationsOlderThan deletes all ArgoCD applications older than a given number of minutes and matching the given label key

func (*Client) DeleteArgoCDApplication added in v0.1.27

func (c *Client) DeleteArgoCDApplication(namespace string, name string) error

DeleteArgoCDApplication deletes a single ArgoCD application by name

func (*Client) DeleteArgoCDApplications added in v0.1.27

func (c *Client) DeleteArgoCDApplications(namespace string) error

func (*Client) GetArgoCDApplication added in v0.1.27

func (c *Client) GetArgoCDApplication(namespace string, name string) (*v1alpha1.Application, error)

GetArgoCDApplication gets a single ArgoCD application by name

func (*Client) GetConfig added in v0.1.27

func (c *Client) GetConfig() *rest.Config

GetConfig returns the rest.Config used by the client

func (*Client) GetConfigMaps added in v0.1.27

func (c *Client) GetConfigMaps(namespace string, names ...string) (string, error)

func (*Client) GetListOfNamespacedScopedResources added in v0.1.27

func (c *Client) GetListOfNamespacedScopedResources() (map[schema.GroupKind]bool, error)

GetListOfNamespacedScopedResources returns metadata about all namespaced resource types Returns a map where the key is schema.GroupKind and the value is true (indicating the resource is namespaced) This format matches the interface expected by Argo CD's kubeutil.ResourceInfoProvider

func (*Client) GetSecretValue added in v0.1.27

func (c *Client) GetSecretValue(namespace string, name string, key string) (string, error)

get secret value from key. e.g. key: "password"

func (*Client) GetServiceNameByLabel added in v0.1.27

func (c *Client) GetServiceNameByLabel(namespace, labelSelector string) (string, error)

GetServiceNameByLabel finds a service in the namespace with the specified label selector Returns the name of the first matching service, or an error if no service is found

func (*Client) PortForwardToPod added in v0.1.27

func (c *Client) PortForwardToPod(namespace, podName string, localPort, remotePort int, readyChan chan struct{}, stopChan chan struct{}) error

PortForwardToPod sets up a port forward to a pod in the specified namespace Returns a channel that will be closed when the port forward is ready, a stop channel to terminate the forward, and an error if the setup fails

func (*Client) PortForwardToService added in v0.1.27

func (c *Client) PortForwardToService(namespace, serviceName string, localPort, remotePort int, readyChan chan struct{}, stopChan chan struct{}) error

PortForwardToService sets up a port forward to a service by finding a pod for that service Returns a channel that will be closed when the port forward is ready, a stop channel to terminate the forward, and an error if the setup fails

func (*Client) RemoveObstructiveFinalizers added in v0.1.27

func (c *Client) RemoveObstructiveFinalizers(namespace string) error

RemoveObstructiveFinalizers removes finalizers from applications that would prevent deletion

func (*Client) SetArgoCDAppRefreshAnnotation added in v0.1.27

func (c *Client) SetArgoCDAppRefreshAnnotation(namespace string, name string) error

SetArgoCDAppRefreshAnnotation sets the refresh annotation on an ArgoCD application to trigger a refresh

func (*Client) WaitForDeploymentReady added in v0.1.27

func (c *Client) WaitForDeploymentReady(namespace, labelSelector string, timeoutSeconds int) error

WaitForDeploymentReady waits for a deployment to be available Uses the provided label selector to find the deployment (e.g., "app.kubernetes.io/component=server")

func (*Client) WatchForContainerRestarts added in v0.1.27

func (c *Client) WatchForContainerRestarts(namespace, labelSelector string, pollInterval time.Duration) chan struct{}

WatchForContainerRestarts starts a background goroutine that monitors pods matching the given label selector for container restarts. It logs a warning whenever a container's restart count increases or when a container enters CrashLoopBackOff. Close the returned channel to stop watching.

type CrashEvent added in v0.1.27

type CrashEvent struct {
	PodName       string
	ContainerName string
	EventType     string // "restart" or "crash-loop"
	PrevRestarts  int32  // only set for "restart" events
	CurrRestarts  int32  // only set for "restart" events
}

CrashEvent represents a single crash event detected by the watcher.

type CrashWatcherState added in v0.1.27

type CrashWatcherState struct {
	// RestartCounts tracks "podName/containerName" -> last seen restart count
	RestartCounts map[string]int32
	// CrashLoopReported tracks whether we've already warned about CrashLoopBackOff for a given key
	CrashLoopReported map[string]bool
}

CrashWatcherState tracks restart counts and CrashLoopBackOff state across polls for the container crash watcher. Exported for testability.

func NewCrashWatcherState added in v0.1.27

func NewCrashWatcherState() *CrashWatcherState

NewCrashWatcherState creates a new CrashWatcherState with initialized maps.

func (*CrashWatcherState) DetectCrashEvents added in v0.1.27

func (s *CrashWatcherState) DetectCrashEvents(pods []corev1.Pod) []CrashEvent

DetectCrashEvents inspects container statuses from a list of pods and returns any new crash events (restarts or CrashLoopBackOff) since the last poll. It updates the state in-place so subsequent calls only report new events.

Jump to

Keyboard shortcuts

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