Documentation
¶
Index ¶
- Constants
- Variables
- func BuildKeychain(ctx context.Context, clientset kubernetes.Interface, secretNamespace string, ...) (authn.Keychain, error)
- func ContainsString(slice []string, str string) bool
- func ConvertMultilineEntrypoint(entrypoint string, isRayJob bool) interface{}
- func Debug(logger logr.Logger, fmt string, keysAndValues ...any)
- func FormatNameWithPostfix(name string, postfix ...string) string
- func GenerateDerivedName(nameParts []string, hashInputs ...any) (string, error)
- func GenerateDerivedNameWithHashLength(nameParts []string, hashLength int, hashInputs ...any) (string, error)
- func GetCurrentUser() (string, error)
- func GetEnv(key, defaultValue string) string
- func GetGVK(scheme runtime.Scheme, object client.Object) (schema.GroupVersionKind, error)
- func LogErrorf(logger logr.Logger, message string, err error) error
- func MakeRFC1123Compliant(input string) string
- func Pointer[T any](d T) *T
- func RemoveString(slice []string, str string) []string
- func SanitizeLabelValue(s string) (string, error)
- func Trace(logger logr.Logger, fmt string, keysAndValues ...any)
- func ValueOrDefault[T any](d *T) T
- type ImageParts
Constants ¶
const ( // MaxKubernetesNameLength is the maximum length for Kubernetes resource names MaxKubernetesNameLength = 63 MaxKubernetesLabelLength = 63 // DefaultHashLength is the default length of the hash suffix DefaultHashLength = 8 )
const ( DebugLogLevel = 1 TraceLogLevel = 2 )
Variables ¶
var ( LabelValueRegex = regexp.MustCompile(`[^a-z0-9._-]+`) // InvalidNameChars matches characters invalid for Kubernetes resource names InvalidNameChars = regexp.MustCompile(`[^a-z0-9-]+`) // MultiDashes matches multiple consecutive dashes MultiDashes = regexp.MustCompile(`-+`) )
Functions ¶
func BuildKeychain ¶
func BuildKeychain( ctx context.Context, clientset kubernetes.Interface, secretNamespace string, imagePullSecrets []corev1.LocalObjectReference, ) (authn.Keychain, error)
BuildKeychain creates an authn.Keychain for authenticating to container registries. It uses Kubernetes image pull secrets if provided, otherwise falls back to the default keychain.
Parameters:
- ctx: Context for the operation
- clientset: Kubernetes clientset for accessing secrets (can be nil)
- secretNamespace: Namespace where secrets are located
- imagePullSecrets: List of secret references for authentication
Returns:
- authn.Keychain: Configured keychain for authentication
- error: Any error encountered during keychain creation
func ContainsString ¶
func FormatNameWithPostfix ¶
func GenerateDerivedName ¶
GenerateDerivedName creates a deterministic name for a derived resource. It combines multiple name parts with an optional hash suffix, ensuring the result is a valid Kubernetes name (max 63 characters, lowercase alphanumeric and hyphens).
Format:
- With hash inputs: {part1}-{part2}-...-{partN}-{hash}
- Without hash inputs: {part1}-{part2}-...-{partN}
If the combined name exceeds 63 characters, the longest part is iteratively truncated until the total length fits. The hash (if present) is never truncated beyond the specified length.
Parameters:
- nameParts: The parts to combine into the name (e.g., ["my-service", "temp", "cache"]). Must not be empty.
- hashInputs: Optional values to hash. Can be strings, structs, slices, or maps. Slices and maps are sorted recursively for deterministic hashing. If empty, no hash suffix is added.
Returns:
- A valid Kubernetes resource name and nil error on success
- Empty string and error if nameParts is empty
Example:
name, err := GenerateDerivedName([]string{"my-service", "temp"}, "metric=latency", "precision=fp16")
// Returns: "my-service-temp-a1b2c3d4", nil
name, err := GenerateDerivedName([]string{"my-service", "temp-cache"})
// Returns: "my-service-temp-cache", nil (no hash)
name, err := GenerateDerivedName([]string{"my-service", "derived"},
map[string]string{"metric": "latency", "precision": "fp16"})
// Returns: "my-service-derived-b2c3d4e5", nil (map sorted before hashing)
func GenerateDerivedNameWithHashLength ¶
func GenerateDerivedNameWithHashLength(nameParts []string, hashLength int, hashInputs ...any) (string, error)
GenerateDerivedNameWithHashLength is like GenerateDerivedName but allows specifying hash length.
Parameters:
- nameParts: The parts to combine into the name. Must not be empty.
- hashLength: The number of characters to use from the hash (recommended: 6-12). Set to 0 to omit the hash suffix.
- hashInputs: Variable number of values to hash (any type)
Returns:
- A valid Kubernetes resource name and nil error on success
- Empty string and error if nameParts is empty
func GetCurrentUser ¶
func LogErrorf ¶
LogErrorf takes care of logging the error message with logr, as well as creating the error object to return
func MakeRFC1123Compliant ¶
func RemoveString ¶
func SanitizeLabelValue ¶
SanitizeLabelValue converts a string to a valid Kubernetes label value. Valid label values must: - Be empty or consist of alphanumeric characters, '-', '_' or '.' - Start and end with an alphanumeric character - Be at most 63 characters Returns an error if the sanitized value is empty.
func ValueOrDefault ¶
func ValueOrDefault[T any](d *T) T
Types ¶
type ImageParts ¶
type ImageParts struct {
Registry string // e.g., "ghcr.io" or "docker.io"
Repository string // e.g., "silogen/llama-3-8b" (full repository path)
Name string // e.g., "llama-3-8b" (just the image name, last component)
Tag string // e.g., "v1.2.0" or "abc123" (first 6 chars of digest)
}
func ExtractImageParts ¶
func ExtractImageParts(image string) (ImageParts, error)