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: 13 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

ManifestConfig.ApplyOrDeleteManifest(context.Context)
ApplyOrDeleteManifest(context.Context) error

ApplyOrDeleteManifest applies or deletes a Kubernetes manifest based on the ManifestConfig settings.

Parameters:

ctx: Context for the operation.

Returns:

error: Error if any issue occurs while applying or deleting the manifest.


ManifestConfig.HandleRawManifest(context.Context, dynamic.Interface)
HandleRawManifest(context.Context, dynamic.Interface) error

HandleRawManifest applies or deletes raw Kubernetes manifests based on the operation specified in ManifestConfig.

Parameters:

ctx: The context for the operation. dynClient: The dynamic client to perform Kubernetes operations.

Returns:

error: Error if any issue occurs while handling the raw manifest.


ManifestOperation.String()
String() string

String returns the string representation of the ManifestType.

Returns:

string: The string representation of the ManifestType.


NewManifestConfig()
NewManifestConfig() *ManifestConfig

NewManifestConfig creates a new ManifestConfig with default settings.

Returns:

*ManifestConfig: A new ManifestConfig instance with ReadFile set to os.ReadFile.


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

This section is empty.

Types

type ManifestConfig

type ManifestConfig struct {
	KubeConfigPath string
	ManifestPath   string
	Namespace      string
	Type           ManifestType
	Operation      ManifestOperation
	Metadata       *MetadataConfig
	Client         dynamic.Interface
	ReadFile       func(string) ([]byte, error)
}

ManifestConfig represents the configuration needed to manage Kubernetes manifests.

**Attributes:**

KubeConfigPath: Path to the kubeconfig file. ManifestPath: Path to the Kubernetes manifest file. Namespace: Kubernetes namespace in which the operations will be performed. Type: The type of manifest (raw, Helm, or Kustomize). Operation: The operation to perform (apply or delete). Metadata: Metadata related to the manifest. Client: The dynamic Kubernetes client interface. ReadFile: Function to read the manifest file from the filesystem.

func NewManifestConfig

func NewManifestConfig() *ManifestConfig

NewManifestConfig creates a new ManifestConfig with default settings.

**Returns:**

*ManifestConfig: A new ManifestConfig instance with ReadFile set to os.ReadFile.

func (*ManifestConfig) ApplyOrDeleteManifest

func (mc *ManifestConfig) ApplyOrDeleteManifest(ctx context.Context) error

ApplyOrDeleteManifest applies or deletes a Kubernetes manifest based on the ManifestConfig settings.

**Parameters:**

ctx: Context for the operation.

**Returns:**

error: Error if any issue occurs while applying or deleting the manifest.

func (*ManifestConfig) HandleRawManifest

func (mc *ManifestConfig) HandleRawManifest(ctx context.Context, dynClient dynamic.Interface) error

HandleRawManifest applies or deletes raw Kubernetes manifests based on the operation specified in ManifestConfig.

**Parameters:**

ctx: The context for the operation. dynClient: The dynamic client to perform Kubernetes operations.

**Returns:**

error: Error if any issue occurs while handling the raw manifest.

type ManifestOperation

type ManifestOperation int

ManifestOperation specifies the type of operation to perform on the manifest.

**Values:**

OperationApply: Apply the manifest. OperationDelete: Delete the manifest.

const (
	OperationApply ManifestOperation = iota
	OperationDelete
)

func (ManifestOperation) String

func (mo ManifestOperation) String() string

String returns the string representation of the ManifestType.

**Returns:**

string: The string representation of the ManifestType.

type ManifestType

type ManifestType int

ManifestType defines the type of Kubernetes manifest.

**Values:**

ManifestRaw: Raw Kubernetes manifest. ManifestHelm: Helm chart. ManifestKustomize: Kustomize configuration.

const (
	ManifestRaw ManifestType = iota
	ManifestHelm
	ManifestKustomize
	ManifestJob
)

type MetadataConfig

type MetadataConfig struct {
	Name string // and any other fields you expect
}

MetadataConfig holds metadata configuration for Kubernetes resources.

**Attributes:**

Name: The name of the resource.

Jump to

Keyboard shortcuts

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