k8s

package
v0.0.0-...-1b7dea3 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Clientset     kubernetes.Interface
	DynamicClient dynamic.Interface
}

Client wraps the Kubernetes clientset and dynamic client.

func NewClient

func NewClient(kubeconfig, context string) (*Client, error)

NewClient creates a Kubernetes client from the given kubeconfig and context. If kubeconfig is empty, it uses the default loading rules. If context is empty, it uses the current context.

func (*Client) ApplyAppOfApps

func (c *Client) ApplyAppOfApps(ctx context.Context, repoURL, targetRevision, env, appPath string, dryRun bool) (string, bool, error)

ApplyAppOfApps creates or updates the App of Apps root Application CR. Returns a boolean indicating if it was created (true) or updated (false) when not in dry-run mode. NOTE: This function's signature was changed to return an additional boolean value, which is a breaking API change. External callers must be updated to handle the extra return value.

func (*Client) CreateGitCryptKeySecret

func (c *Client) CreateGitCryptKeySecret(ctx context.Context, keyData []byte) (bool, error)

CreateGitCryptKeySecret creates or updates the git-crypt-key secret in the argocd namespace. The key data is the raw symmetric key used by git-crypt. Returns a boolean indicating if it was created (true) or updated (false).

func (*Client) CreateRepoSSHSecret

func (c *Client) CreateRepoSSHSecret(ctx context.Context, repoURL, sshPrivateKey string, dryRun bool) (*corev1.Secret, bool, error)

CreateRepoSSHSecret creates or updates the repo-ssh-key secret in the argocd namespace. This matches the exact labels/annotations from the original install.sh. Returns the secret and a boolean indicating if it was created (true) or updated (false).

func (*Client) EnsureNamespace

func (c *Client) EnsureNamespace(ctx context.Context, name string) (bool, error)

EnsureNamespace creates a namespace if it does not already exist.

type ClientInterface

type ClientInterface interface {
	EnsureNamespace(ctx context.Context, name string) (bool, error)
	CreateRepoSSHSecret(ctx context.Context, repoURL, sshPrivateKey string, dryRun bool) (*corev1.Secret, bool, error)
	CreateGitCryptKeySecret(ctx context.Context, keyData []byte) (bool, error)
	ApplyAppOfApps(ctx context.Context, repoURL, targetRevision, env, appPath string, dryRun bool) (string, bool, error)
}

ClientInterface defines the interface that both Client and MockClient implement. This is useful for testing code that uses a K8s client.

type MockClient

type MockClient struct {
	// Namespaces created in this mock.
	Namespaces map[string]bool
	// Secrets created in this mock.
	Secrets map[string]map[string]*corev1.Secret
	// Applications created in this mock.
	Applications map[string]*unstructured.Unstructured
	// Simulate errors for specific operations.
	EnsureNamespaceErr       error
	CreateRepoSSHSecretErr   error
	CreateGitCryptKeyErr     error
	ApplyAppOfAppsErr        error
	EnsureNamespaceForbidden bool
	CreateSecretForbidden    bool
}

MockClient is a mock Kubernetes client for testing. It allows simulating errors and state.

func NewMockClient

func NewMockClient() *MockClient

NewMockClient creates a new mock client for testing.

func (*MockClient) ApplyAppOfApps

func (m *MockClient) ApplyAppOfApps(ctx context.Context, repoURL, targetRevision, env, appPath string, dryRun bool) (string, bool, error)

ApplyAppOfApps simulates Application CR creation.

func (*MockClient) CreateGitCryptKeySecret

func (m *MockClient) CreateGitCryptKeySecret(ctx context.Context, keyData []byte) (bool, error)

CreateGitCryptKeySecret simulates git-crypt key secret creation.

func (*MockClient) CreateRepoSSHSecret

func (m *MockClient) CreateRepoSSHSecret(ctx context.Context, repoURL, sshPrivateKey string, dryRun bool) (*corev1.Secret, bool, error)

CreateRepoSSHSecret simulates secret creation with mock state.

func (*MockClient) EnsureNamespace

func (m *MockClient) EnsureNamespace(ctx context.Context, name string) (bool, error)

EnsureNamespace simulates namespace creation with mock state.

func (*MockClient) GetApplication

func (m *MockClient) GetApplication(name string) *unstructured.Unstructured

GetApplication retrieves a stored application from the mock (for testing verification).

func (*MockClient) GetSecret

func (m *MockClient) GetSecret(namespace, name string) *corev1.Secret

GetSecret retrieves a stored secret from the mock (for testing verification).

Jump to

Keyboard shortcuts

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