utils

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Overview

Package utils implements the util functions

Index

Constants

View Source
const (
	// PrivateKeySecretSuffix is the suffix for private key secrets
	PrivateKeySecretSuffix = "-private-key"
	// TokenSecretSuffix is the suffix for token secrets
	TokenSecretSuffix = "-token"
	// PrivateKeyField is the key for the private key in the secret
	PrivateKeyField = "private-key"
	// TokenField is the key for the token in the secret
	TokenField = "token"
	// ServiceAccountCredentialsSecretSuffix is the suffix for service account credentials secrets
	ServiceAccountCredentialsSecretSuffix = "-credentials"
	// ServiceAccountCredentialsField is the key for the service account credentials in the secret
	ServiceAccountCredentialsField = "credentials.json"
	// ServiceAccountCredentialsType is the type for service account credentials
	//nolint:gosec
	ServiceAccountCredentialsType = "TYPE_SN_CREDENTIALS_FILE"
)
View Source
const (
	// InfiniteDurationValue represents the special value for infinite duration
	InfiniteDurationValue = "-1"
)
View Source
const (
	// InfiniteQuantityValue represents the special value for infinite quantity
	InfiniteQuantityValue = "-1"
)
View Source
const (
	// ManagedAnnotation indicates the object is managed by the controller
	ManagedAnnotation = "cloud.streamnative.io/managed"
)

Variables

This section is empty.

Functions

func CalculateSecretKeyMd5 added in v0.4.5

func CalculateSecretKeyMd5(secret *corev1.Secret, key string) (string, error)

CalculateSecretKeyMd5 calculates the hash of the secret key.

func ConvertJSONToMapStringInterface added in v0.5.0

func ConvertJSONToMapStringInterface(raw *apiextensionsv1.JSON) (map[string]interface{}, error)

ConvertJSONToMapStringInterface converts a JSON object to a map[string]interface{}

func ConvertMap added in v0.5.0

func ConvertMap(input map[string]string) map[string]interface{}

ConvertMap converts a map[string]string to a map[string]interface{}

func CreateOrUpdatePrivateKeySecret added in v0.10.0

func CreateOrUpdatePrivateKeySecret(ctx context.Context, c client.Client, owner metav1.Object, namespace, name, privateKey string) error

CreateOrUpdatePrivateKeySecret creates or updates a secret containing a private key

func CreateOrUpdateServiceAccountCredentialsSecret added in v0.10.0

func CreateOrUpdateServiceAccountCredentialsSecret(ctx context.Context, c client.Client, owner metav1.Object, namespace, name, credentials string) error

CreateOrUpdateServiceAccountCredentialsSecret creates or updates a secret containing service account credentials

func CreateOrUpdateTokenSecret added in v0.10.0

func CreateOrUpdateTokenSecret(ctx context.Context, c client.Client, owner metav1.Object, namespace, name, token, keyID string) error

CreateOrUpdateTokenSecret creates or updates a secret containing a token

func GetPrivateKeyFromSecret added in v0.10.0

func GetPrivateKeyFromSecret(ctx context.Context, c client.Client, namespace, name string) (string, error)

GetPrivateKeyFromSecret retrieves the private key from a secret

func IsInfiniteQuantity added in v0.13.0

func IsInfiniteQuantity(q *resource.Quantity) bool

IsInfiniteQuantity returns true if the quantity represents infinite size ("-1").

func IsManaged

func IsManaged(object metav1.Object) bool

IsManaged returns true if the object is under control of the controller by checking the specific annotation

func NewInfiniteQuantity added in v0.13.0

func NewInfiniteQuantity() *resource.Quantity

NewInfiniteQuantity creates a new quantity with infinite value ("-1").

func QuantityToBytes added in v0.13.0

func QuantityToBytes(q *resource.Quantity) int64

QuantityToBytes returns the quantity value in bytes. Returns -1 for infinite quantity, or the actual bytes for finite quantity.

func ValidateQuantityValue added in v0.13.0

func ValidateQuantityValue(s string) error

ValidateQuantityValue validates if a string is a valid quantity or "-1".

Types

type ClientCredentials added in v0.5.5

type ClientCredentials struct {
	IssuerURL  string `json:"issuerUrl,omitempty"`
	Audience   string `json:"audience,omitempty"`
	Scope      string `json:"scope,omitempty"`
	PrivateKey string `json:"privateKey,omitempty"`
	ClientID   string `json:"clientId,omitempty"`
}

ClientCredentials represents the client credentials for OAuth2

type Duration added in v0.4.0

type Duration string

Duration represents a elapsed time in string. Supports standard duration formats (e.g., "1h", "30m", "5s") and special value "-1" for infinite duration.

func (*Duration) IsInfinite added in v0.13.0

func (d *Duration) IsInfinite() bool

IsInfinite returns true if the duration represents infinite duration ("-1").

func (*Duration) Parse added in v0.4.0

func (d *Duration) Parse() (time.Duration, error)

Parse parses a duration from string. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h", "d", "w". Special value "-1" represents infinite duration and returns -1 nanosecond.

func (Duration) String added in v0.13.0

func (d Duration) String() string

String returns the string representation of the duration.

func (*Duration) ToSeconds added in v0.13.0

func (d *Duration) ToSeconds() (int64, error)

ToSeconds returns the duration in seconds. Returns -1 for infinite duration, or the actual seconds for finite duration.

func (*Duration) Validate added in v0.13.0

func (d *Duration) Validate() error

Validate validates the duration format. Accepts standard duration formats and the special value "-1".

type Event added in v0.5.5

type Event struct {
	client.Object
}

Event is a custom event that can be used to trigger reconcile

type EventSource added in v0.5.5

type EventSource struct {
	Log    logr.Logger
	Events chan event.GenericEvent
	// contains filtered or unexported fields
}

EventSource is a custom event source that can be used to trigger reconcile

func NewEventSource added in v0.5.5

func NewEventSource(log logr.Logger) *EventSource

NewEventSource creates a new EventSource

func (*EventSource) Close added in v0.5.5

func (s *EventSource) Close()

Close closes the EventSource

func (*EventSource) Contains added in v0.5.5

func (s *EventSource) Contains(key string) bool

Contains checks if the key exists in the event source

func (*EventSource) CreateIfAbsent added in v0.5.5

func (s *EventSource) CreateIfAbsent(delay time.Duration, obj client.Object, key string)

CreateIfAbsent triggers reconcile after delay, idempotent operation for the same key

func (*EventSource) Remove added in v0.5.5

func (s *EventSource) Remove(key string)

Remove removes the reconcile event

func (*EventSource) Update added in v0.5.5

func (s *EventSource) Update(key string, delay time.Duration)

Update updates the delay of the reconcile event

type ReconcileRetryer added in v0.5.5

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

ReconcileRetryer is a helper to trigger reconcile with retry

func NewReconcileRetryer added in v0.5.5

func NewReconcileRetryer(maxRetries int, source *EventSource) *ReconcileRetryer

NewReconcileRetryer creates a new ReconcileRetryer

func (*ReconcileRetryer) Close added in v0.5.5

func (r *ReconcileRetryer) Close()

Close closes the ReconcileRetryer

func (*ReconcileRetryer) Contains added in v0.5.5

func (r *ReconcileRetryer) Contains(obj client.Object) bool

func (*ReconcileRetryer) CreateIfAbsent added in v0.5.5

func (r *ReconcileRetryer) CreateIfAbsent(obj client.Object)

CreateIfAbsent creates a new task if not exist

func (*ReconcileRetryer) Remove added in v0.5.5

func (r *ReconcileRetryer) Remove(obj client.Object)

Remove removes the task

func (*ReconcileRetryer) Source added in v0.5.5

func (r *ReconcileRetryer) Source() <-chan event.GenericEvent

Source returns the event source

Jump to

Keyboard shortcuts

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