Documentation
¶
Overview ¶
Package secrets provides utilities for working with Kubernetes Secrets.
This package offers a Client that wraps the controller-runtime client and provides convenience methods for common Secret operations like Get, GetValue, and Upsert with optional owner references.
Example usage:
client := secrets.NewClient(ctrlClient, scheme) // Get a secret value value, err := client.GetSecretValue(ctx, "namespace", secretKeySelector) // Upsert a secret with owner reference result, err := client.UpsertWithOwnerReference(ctx, secret, ownerObject)
Index ¶
- type Client
- func (c *Client) Get(ctx context.Context, name, namespace string) (*corev1.Secret, error)
- func (c *Client) GetValue(ctx context.Context, namespace string, secretRef corev1.SecretKeySelector) (string, error)
- func (c *Client) Upsert(ctx context.Context, secret *corev1.Secret) (controllerutil.OperationResult, error)
- func (c *Client) UpsertWithOwnerReference(ctx context.Context, secret *corev1.Secret, owner client.Object) (controllerutil.OperationResult, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides convenience methods for working with Kubernetes Secrets.
func NewClient ¶
NewClient creates a new secrets Client instance. The scheme is required for operations that need to set owner references.
func (*Client) Get ¶
Get retrieves a Kubernetes Secret by name and namespace. Returns the secret if found, or an error if not found or on failure.
func (*Client) GetValue ¶
func (c *Client) GetValue(ctx context.Context, namespace string, secretRef corev1.SecretKeySelector) (string, error)
GetValue retrieves a specific key's value from a Kubernetes Secret. Uses a SecretKeySelector to identify the secret name and key. Returns the value as a string, or an error if the secret or key is not found.
func (*Client) Upsert ¶
func (c *Client) Upsert(ctx context.Context, secret *corev1.Secret) (controllerutil.OperationResult, error)
Upsert creates or updates a Kubernetes Secret without an owner reference. Uses retry logic to handle conflicts from concurrent modifications. Returns the operation result (Created, Updated, or Unchanged) and any error.
func (*Client) UpsertWithOwnerReference ¶
func (c *Client) UpsertWithOwnerReference( ctx context.Context, secret *corev1.Secret, owner client.Object, ) (controllerutil.OperationResult, error)
UpsertWithOwnerReference creates or updates a Kubernetes Secret with an owner reference. The owner reference ensures the secret is garbage collected when the owner is deleted. Uses retry logic to handle conflicts from concurrent modifications. Returns the operation result (Created, Updated, or Unchanged) and any error.