util

package
v0.1.86 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPullSecretUnavailable = errors.New("pull secret unavailable")

ErrPullSecretUnavailable indicates the pull secret is missing or malformed.

Functions

func ApplyClusterIDLabel

func ApplyClusterIDLabel(ep *prometheusoperatorv1.Endpoint, clusterID string)

func ApplyClusterIDLabelToPodMonitor

func ApplyClusterIDLabelToPodMonitor(ep *prometheusoperatorv1.PodMetricsEndpoint, clusterID string)

func ApplyClusterIDLabelToRecordingRule

func ApplyClusterIDLabelToRecordingRule(rule *prometheusoperatorv1.Rule, clusterID string)

func ClampToInt32 added in v0.1.83

func ClampToInt32(v float64) int32

ClampToInt32 clamps a float64 value into a valid non-negative int32 range. Negative values are clamped to 0 and values exceeding math.MaxInt32 are capped.

func Compress

func Compress(payload []byte) (*bytes.Buffer, error)

Compress compresses a given byte array.

func CompressAndEncode

func CompressAndEncode(payload []byte) (*bytes.Buffer, error)

CompressAndEncode compresses and base-64 encodes a given byte array. Ideal for loading an arbitrary byte array into a ConfigMap or Secret.

func ComputeHash

func ComputeHash(s string) string

func CountAvailableNodes added in v0.1.71

func CountAvailableNodes(ctx context.Context, client client.Client) (int32, error)

CountAvailableNodes counts the number of available nodes in the cluster. Available nodes are defined as Ready nodes that are not cordoned (Unschedulable).

func DecodeAndDecompress

func DecodeAndDecompress(payload []byte) (*bytes.Buffer, error)

DecodeAndDecompress decompresses and base-64 decodes a given byte array. Ideal for consuming a gzipped / base64-encoded byte array from a ConfigMap or Secret.

func DetermineHostedClusterPayloadArch added in v0.1.48

func DetermineHostedClusterPayloadArch(ctx context.Context, c client.Client, hc *hyperv1.HostedCluster, imageMetadataProvider imageregistry.ImageMetadataProvider) (hyperv1.PayloadArchType, error)

DetermineHostedClusterPayloadArch returns the HostedCluster payload's CPU architecture type

func EnableIfCustomKubeconfig added in v0.1.58

func EnableIfCustomKubeconfig(hcp *hyperv1.HostedControlPlane) bool

EnableIfCustomKubeconfig returns true if the hosted control plane has a custom kubeconfig defined

func GetKubeClientSet added in v0.1.48

func GetKubeClientSet() (kubeclient.Interface, error)

func GetKubeClientSetWithKubeconfig added in v0.1.78

func GetKubeClientSetWithKubeconfig(kubeconfigPath string) (kubeclient.Interface, error)

GetKubeClientSetWithKubeconfig creates a Kubernetes clientset using the specified kubeconfig file path. If kubeconfigPath is empty, it falls back to the default kubeconfig resolution.

func GetMgmtClusterCPUArch added in v0.1.23

func GetMgmtClusterCPUArch(kc kubeclient.Interface) (string, error)

func GetPullSecretBytes added in v0.1.48

func GetPullSecretBytes(ctx context.Context, c client.Client, hc *hyperv1.HostedCluster) ([]byte, error)

func HashBytes added in v0.1.55

func HashBytes(data []byte) (string, error)

HashBytes takes a byte array and returns a 32-bit FNV-1a hashed version of the byte array as a string

func HashConfigMapData added in v0.1.80

func HashConfigMapData(data map[string]string) string

HashConfigMapData hashes the key-value pairs of a ConfigMap's Data field deterministically, using null-byte delimiters to prevent key/value collisions. Returns an empty string for nil or empty maps.

func HashSimple added in v0.1.23

func HashSimple(o interface{}) string

HashSimple takes a value, typically a string, and returns a 32-bit FNV-1a hashed version of the value as a string

func HashStruct

func HashStruct(data interface{}) (string, error)

HashStruct takes a struct and returns a 32-bit FNV-1a hashed version of the struct as a string The struct is first marshaled to JSON before hashing

func HashStructWithJSONMapper added in v0.1.55

func HashStructWithJSONMapper(data interface{}, mapper JSONMapper) (string, error)

HashStructWithJSONMapper takes a struct and returns a 32-bit FNV-1a hashed version of the struct as a string after The struct is first marshaled to JSON before hashing. You can provide a JSONMapper that transforms the marshaled JSON before computing the hash or nil if no transformation is needed.

func InsecureHTTPClient added in v0.1.10

func InsecureHTTPClient() *http.Client

InsecureHTTPClient return a http.Client which skips server certificate verification

func LogLevelToEtcdLevel added in v0.1.83

func LogLevelToEtcdLevel(level hyperv1.LogLevel) string

LogLevelToEtcdLevel maps a LogLevel enum to the ETCD_LOG_LEVEL environment variable. etcd only supports "info" and "debug"; Trace and TraceAll are not valid for etcd and are rejected at the API level (CEL), so they are treated as unhandled here and panic. An unhandled value panics so that expanding the enum without updating this switch is caught loudly rather than silently mishandled.

func LogLevelToKlogVerbosity added in v0.1.83

func LogLevelToKlogVerbosity(level hyperv1.LogLevel) int

LogLevelToKlogVerbosity maps a LogLevel enum value to a klog verbosity integer. The LogLevel enum is the source of truth; every value must be handled here. An unhandled value panics so that expanding the enum without updating this switch is caught loudly rather than silently mishandled.

func MapsDiff added in v0.1.64

func MapsDiff(current, input map[string]string) (changed map[string]string, deleted map[string]string, different bool)

MapsDiff compares two maps and returns a map of changed/created keys with their new values, a map of deleted keys, and a boolean indicating if there are any differences.

func ParseNamespacedName

func ParseNamespacedName(name string) types.NamespacedName

ParseNamespacedName expects a string with the format "namespace/name" and returns the proper types.NamespacedName. This is useful when watching a CR annotated with the format above to requeue the CR described in the annotation.

func RemoveEmptyJSONField added in v0.1.55

func RemoveEmptyJSONField(stringData string, field string) string

RemoveEmptyJSONField removes a field from a given JSON if it's empty regardless of its position

func SanitizeIgnitionPayload added in v0.1.48

func SanitizeIgnitionPayload(payload []byte) error

SanitizeIgnitionPayload make sure the IgnitionPayload is valid and does not contain inconsistencies.

func StringListContains

func StringListContains(list string, s string) bool

Contains checks if a comma-delimited string contains a specific string.

Types

type JSONMapper added in v0.1.55

type JSONMapper func(jsonData []byte) []byte

func NewOmitFieldIfEmptyJSONMapper added in v0.1.55

func NewOmitFieldIfEmptyJSONMapper(field string) JSONMapper

NewOmitFieldIfEmptyJSONMapper is a JSONMapper that omits the given field in case it was empty.

Directories

Path Synopsis
Package registryoverride applies registry-prefix overrides to image references with strict, deterministic matching semantics.
Package registryoverride applies registry-prefix overrides to image references with strict, deterministic matching semantics.

Jump to

Keyboard shortcuts

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