utilities

package
v0.2.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	RotateCertificateRequestAnnotation = "certs.steward.butlerlabs.dev/rotate"

	CertificateX509Label       = "x509"
	CertificateKubeconfigLabel = "kubeconfig"
)

Variables

This section is empty.

Functions

func AddTenantPrefix

func AddTenantPrefix(name string, tenantControlPlane *stewardv1alpha1.TenantControlPlane) string

func AreGatewayResourcesAvailable

func AreGatewayResourcesAvailable(ctx context.Context, c client.Client, discoveryClient discovery.DiscoveryInterface) bool

AreGatewayResourcesAvailable checks if Gateway API is available in the cluster through a discovery Client with fallback to client-based check.

func ArgsAddFlagValue

func ArgsAddFlagValue(args map[string]string, flag, value string) bool

ArgsAddFlagValue performs upsert of a flag in the arguments map, returning true if created.

func ArgsFromMapToSlice

func ArgsFromMapToSlice(args map[string]string) (slice []string)

ArgsFromMapToSlice create the slice of args, and sorting the resulting output in order to make it idempotent. Along with that, if a flag doesn't have a value, it's presented barely without a value assignment.

func ArgsFromSliceToMap

func ArgsFromSliceToMap(args []string) (m map[string]string)

ArgsFromSliceToMap transforms a slice of string into a map, simplifying the subsequent mangling.

func ArgsRemoveFlag

func ArgsRemoveFlag(args map[string]string, flag string) bool

ArgsRemoveFlag removes a flag from the arguments map, returning true if found and removed.

func CalculateMapChecksum

func CalculateMapChecksum(data any) string

CalculateMapChecksum orders the map according to its key, and calculating the overall md5 of the values. It's expected to work with ConfigMap (map[string]string) and Secrets (map[string][]byte).

func CreateOrUpdateWithConflict

func CreateOrUpdateWithConflict(ctx context.Context, client client.Client, resource client.Object, f controllerutil.MutateFn) (res controllerutil.OperationResult, err error)

CreateOrUpdateWithConflict is a helper function that wraps the RetryOnConflict around the CreateOrUpdate function: this allows to fetch from the cache the latest modified object an try to apply the changes defined in the MutateFn without enqueuing back the request in order to get the latest changes of the resource.

func DecodeFromJSON

func DecodeFromJSON(o string, to runtime.Object) (err error)

func DecodeFromYAML

func DecodeFromYAML(o string, to runtime.Object) (err error)

func DecodeKubeconfig

func DecodeKubeconfig(secret corev1.Secret, key string) (*clientcmdapiv1.Config, error)

func DecodeKubeconfigYAML

func DecodeKubeconfigYAML(bytes []byte) (*clientcmdapiv1.Config, error)

func EncodeToJSON

func EncodeToJSON(o runtime.Object) ([]byte, error)

EncodeToJSON returns the given object in JSON format and the error, respecting the Kubernetes struct tags.

func EncodeToYaml

func EncodeToYaml(o runtime.Object) ([]byte, error)

EncodeToYaml returns the given object in yaml format and the error.

func ExtractHost

func ExtractHost(hostPort string) string

ExtractHost extracts the host part from a host:port string.

func ExtractPort

func ExtractPort(hostPort string) string

ExtractPort extracts the port part from a host:port string. Returns "6443" as default if no port is specified.

func GatewayAPIResourcesAvailable

func GatewayAPIResourcesAvailable(ctx context.Context, discoveryClient discovery.DiscoveryInterface) (bool, error)

NOTE: These functions are extremely similar, maybe they can be merged and accept a GVK. Explicit for now. GatewayAPIResourcesAvailable checks if Gateway API is available in the cluster.

func GetControlPlaneAddressAndPortFromHostname

func GetControlPlaneAddressAndPortFromHostname(hostname string, defaultPort int32) (address string, port int32)

func GetObjectChecksum

func GetObjectChecksum(obj client.Object) string

GetObjectChecksum returns the annotation checksum in case this is set, otherwise, an empty string.

func GetRESTClientConfig

func GetRESTClientConfig(ctx context.Context, client client.Client, tenantControlPlane *stewardv1alpha1.TenantControlPlane) (*restclient.Config, error)

func GetTenantClient

func GetTenantClient(ctx context.Context, c client.Client, tenantControlPlane *stewardv1alpha1.TenantControlPlane) (client.Client, error)

func GetTenantClientSet

func GetTenantClientSet(ctx context.Context, client client.Client, tenantControlPlane *stewardv1alpha1.TenantControlPlane) (*clientset.Clientset, error)

func GetTenantKubeconfig

func GetTenantKubeconfig(ctx context.Context, client client.Client, tenantControlPlane *stewardv1alpha1.TenantControlPlane) (*clientcmdapiv1.Config, error)

func HasNamedContainer

func HasNamedContainer(container []corev1.Container, name string) (found bool, index int)

HasNamedContainer finds the Container in the provided slice by its name, returning a boolean if found, and its index.

func HasNamedVolume

func HasNamedVolume(volumes []corev1.Volume, name string) (found bool, index int)

HasNamedVolume finds the Volume in the provided slice by its name, returning a boolean if found, and its index.

func HasNamedVolumeMount

func HasNamedVolumeMount(volumeMounts []corev1.VolumeMount, name string) (found bool, index int)

HasNamedVolumeMount finds the VolumeMount in the provided slice by its name, returning a boolean if found, and its index.

func IsGatewayAPIAvailableViaClient

func IsGatewayAPIAvailableViaClient(ctx context.Context, c client.Client) bool

IsGatewayAPIAvailableViaClient uses client to check Gateway API availability.

func IsRotationRequested

func IsRotationRequested(obj client.Object) bool

func IsTLSRouteAvailable

func IsTLSRouteAvailable(ctx context.Context, c client.Client, discoveryClient discovery.DiscoveryInterface) bool

IsTLSRouteAvailable checks if TLSRoute is available with fallback to client-based check.

func IsTLSRouteAvailableViaClient

func IsTLSRouteAvailableViaClient(ctx context.Context, c client.Client) bool

IsTLSRouteAvailableViaClient uses client to check TLSRoute availability.

func MergeMaps

func MergeMaps(maps ...map[string]string) map[string]string

func SetLastRotationTimestamp

func SetLastRotationTimestamp(obj client.Object)

func SetObjectChecksum

func SetObjectChecksum(obj client.Object, data any)

SetObjectChecksum calculates the checksum for the given map and store it in the object annotations.

func StewardLabels

func StewardLabels(tcpName, resourceName string) map[string]string

func TLSRouteAPIAvailable

func TLSRouteAPIAvailable(ctx context.Context, discoveryClient discovery.DiscoveryInterface) (bool, error)

TLSRouteAPIAvailable checks specifically for TLSRoute resource availability.

Types

This section is empty.

Jump to

Keyboard shortcuts

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