k8s

package
v2.2.6 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 8 Imported by: 0

README

goutils/v2/k8s

The k8s package is a collection of utility functions designed to simplify common k8s tasks.


Table of contents


Functions

DeploymentLogger.FetchAndLog(context.Context)
FetchAndLog(context.Context) error

FetchAndLog fetches the deployment details and logs related pod events.

Parameters:

ctx: Context to control the request lifetime.

Returns:

error: An error if any occurs during fetching and logging.


FetchAndLogPods(context.Context, kubernetes.Interface, string)
FetchAndLogPods(context.Context, kubernetes.Interface, string) error

FetchAndLogPods fetches and logs pods based on the specified label selector.

Parameters:

ctx: Context to control the request lifetime. clientset: Kubernetes clientset to interact with Kubernetes API. namespace: Namespace from which to list the pods. labelSelector: String defining the label selector for filtering pods.

Returns:

error: An error if any occurs during fetching and logging of pods.


NewDeploymentLogger(*k8s.KubernetesClient, string)
NewDeploymentLogger(*k8s.KubernetesClient, string) *DeploymentLogger

NewDeploymentLogger creates a new instance of DeploymentLogger.

Parameters:

kc: Pointer to KubernetesClient. namespace: Namespace where the deployment is located. deploymentName: Name of the deployment.

Returns:

*DeploymentLogger: A new instance of DeploymentLogger.


NewServiceLogger(*k8s.KubernetesClient, string)
NewServiceLogger(*k8s.KubernetesClient, string) *ServiceLogger

NewServiceLogger creates a new instance of ServiceLogger.

Parameters:

kc: Pointer to KubernetesClient. namespace: Namespace where the service is located. serviceName: Name of the service.

Returns:

*ServiceLogger: A new instance of ServiceLogger.


ServiceLogger.FetchAndLog(context.Context)
FetchAndLog(context.Context) error

FetchAndLog fetches the service details and logs related pod events.

Parameters:

ctx: Context to control the request lifetime.

Returns:

error: An error if any occurs during fetching and logging.


StreamLogs(kubernetes.Interface, string)
StreamLogs(kubernetes.Interface, string) error

StreamLogs streams logs for a specific resource within a namespace.

Parameters:

clientset: Kubernetes clientset to interact with Kubernetes API. namespace: Namespace where the resource is located. resourceType: Type of resource ('pod', 'job', or 'deployment'). resourceName: Name of the resource to stream logs from.

Returns:

error: An error if any occurs during the log streaming process.


Installation

To use the goutils/v2/k8s package, you first need to install it. Follow the steps below to install via go get.

go get github.com/l50/goutils/v2/k8s

Usage

After installation, you can import the package in your Go project using the following import statement:

import "github.com/l50/goutils/v2/k8s"

Tests

To ensure the package is working correctly, run the following command to execute the tests for goutils/v2/k8s:

go test -v

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.


License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchAndLogPods

func FetchAndLogPods(ctx context.Context, clientset kubernetes.Interface, namespace, labelSelector string) error

FetchAndLogPods fetches and logs pods based on the specified label selector.

**Parameters:**

ctx: Context to control the request lifetime. clientset: Kubernetes clientset to interact with Kubernetes API. namespace: Namespace from which to list the pods. labelSelector: String defining the label selector for filtering pods.

**Returns:**

error: An error if any occurs during fetching and logging of pods.

func StreamLogs

func StreamLogs(clientset kubernetes.Interface, namespace, resourceType, resourceName string) error

StreamLogs streams logs for a specific resource within a namespace.

**Parameters:**

clientset: Kubernetes clientset to interact with Kubernetes API. namespace: Namespace where the resource is located. resourceType: Type of resource ('pod', 'job', or 'deployment'). resourceName: Name of the resource to stream logs from.

**Returns:**

error: An error if any occurs during the log streaming process.

Types

type DeploymentLogger

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

DeploymentLogger represents a logger specifically designed for logging Kubernetes deployments.

**Attributes:**

kc: Pointer to KubernetesClient used for API requests. namespace: Namespace where the deployment is located. deploymentName: Name of the deployment to log.

func NewDeploymentLogger

func NewDeploymentLogger(kc *k8s.KubernetesClient, namespace, deploymentName string) *DeploymentLogger

NewDeploymentLogger creates a new instance of DeploymentLogger.

**Parameters:**

kc: Pointer to KubernetesClient. namespace: Namespace where the deployment is located. deploymentName: Name of the deployment.

**Returns:**

*DeploymentLogger: A new instance of DeploymentLogger.

func (*DeploymentLogger) FetchAndLog

func (d *DeploymentLogger) FetchAndLog(ctx context.Context) error

FetchAndLog fetches the deployment details and logs related pod events.

**Parameters:**

ctx: Context to control the request lifetime.

**Returns:**

error: An error if any occurs during fetching and logging.

type ServiceLogger

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

ServiceLogger represents a logger specifically designed for logging Kubernetes services.

**Attributes:**

kc: Pointer to KubernetesClient used for API requests. namespace: Namespace where the service is located. serviceName: Name of the service to log.

func NewServiceLogger

func NewServiceLogger(kc *k8s.KubernetesClient, namespace, serviceName string) *ServiceLogger

NewServiceLogger creates a new instance of ServiceLogger.

**Parameters:**

kc: Pointer to KubernetesClient. namespace: Namespace where the service is located. serviceName: Name of the service.

**Returns:**

*ServiceLogger: A new instance of ServiceLogger.

func (*ServiceLogger) FetchAndLog

func (s *ServiceLogger) FetchAndLog(ctx context.Context) error

FetchAndLog fetches the service details and logs related pod events.

**Parameters:**

ctx: Context to control the request lifetime.

**Returns:**

error: An error if any occurs during fetching and logging.

Jump to

Keyboard shortcuts

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