utils

package
v0.0.0-...-c1275c8 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 51 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendToListIfNotExists

func AppendToListIfNotExists(list []string, value string) []string

func BackupKubeadminPasswordHash

func BackupKubeadminPasswordHash(ctx context.Context, client runtimeclient.Client, cryptoDir string) (bool, error)

func BackupKubeconfigCrypto

func BackupKubeconfigCrypto(ctx context.Context, client runtimeclient.Client, cryptoDir string) error

func BuildKernelArgumentsFromMCOData

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

func BuildKernelArgumentsFromMCOFile

func BuildKernelArgumentsFromMCOFile(path string) ([]string, error)

BuildKernelArguementsFromMCOFile reads the kernel arguments from MCO file and builds the string arguments that ostree admin deploy requires

func BuildKernelArgumentsFromMCOObject

func BuildKernelArgumentsFromMCOObject(mc *mcfgv1.MachineConfig) ([]string, error)

func ConvertToRawExtension

func ConvertToRawExtension(config any) (runtime.RawExtension, error)

func CopyFileIfExists

func CopyFileIfExists(source, dest string) error

func CopyToTempFile

func CopyToTempFile(sourceFileName, directory, pattern string) (string, error)

CopyToTempFile copies a file to a temporary file. WARNING: This function only preserves POSIX permissions to the new file If you want to use it, take that into account and extend it if needed to also preserve other things like owner, extended attributes, selinux contexts or whatever might be needed

func CreateDynamicClient

func CreateDynamicClient(kubeconfig string, isTestEnvAllowed bool, log logr.Logger) (dynamic.Interface, error)

func CreateKubeClient

func CreateKubeClient(scheme *runtime.Scheme, kubeconfig string) (runtimeclient.Client, error)

func CreateKubeClientFromBytes

func CreateKubeClientFromBytes(scheme *runtime.Scheme, kubeconfigData []byte) (runtimeclient.Client, error)

func ExtractBrExUplinkName

func ExtractBrExUplinkName(state NmState) (string, error)

ExtractBrExUplinkName returns the uplink port name connected to the given bridge (excluding the bridge internal and patch ports).

func ExtractBrExVLANID

func ExtractBrExVLANID(state NmState) (*int, error)

ExtractBrExVLANID inspects the bridge uplink port; if it's a VLAN interface, returns its VLAN ID.

func ExtractDNSServers

func ExtractDNSServers(state NmState) []string

ExtractDNSServers returns the ordered DNS server list from nmstate

func ExtractRegistryFromImage

func ExtractRegistryFromImage(image string) string

func FindDefaultGateways

func FindDefaultGateways(state NmState, bridgeName, defaultRouteV4, defaultRouteV6 string) (string, string)

FindDefaultGateways searches nmstate routes to find default IPv4 and IPv6 gateways for the given bridge name and default route destinations.

func FindMatchingCIDR

func FindMatchingCIDR(ipStr string, cidrs []string) string

FindMatchingCIDR returns the first CIDR from the list that matches the given IP's IP family (IPv4 vs IPv6). If none is found, returns an empty string.

func GenerateNMState

func GenerateNMState(
	interfaceName string,
	ips []string,
	machineNetworks []string,
	desiredGatewayV4 string,
	desiredGatewayV6 string,
	dnsServers []string,
	vlanID int,
	currentGatewayV4 string,
	currentGatewayV6 string,
) (string, error)

GenerateNMState generates NMState YAML from IPs and their machine network CIDRs. It derives the prefix length from the provided CIDRs.

func GetAdditionalTrustBundleFromConfigmap

func GetAdditionalTrustBundleFromConfigmap(ctx context.Context, client runtimeclient.Client, configmapName string) (string, error)

func GetCSVDeployment

func GetCSVDeployment(ctx context.Context, client runtimeclient.Client) (*appsv1.Deployment, error)

func GetClusterAdditionalTrustBundleState

func GetClusterAdditionalTrustBundleState(ctx context.Context, client runtimeclient.Client) (bool, string, error)

func GetClusterBaseDomain

func GetClusterBaseDomain(ctx context.Context, client runtimeclient.Client) (string, error)

func GetClusterName

func GetClusterName(ctx context.Context, client runtimeclient.Client) (string, error)

func GetConfigMapData

func GetConfigMapData(ctx context.Context, name, namespace, key string, client runtimeclient.Client) (string, error)

func GetIngressCertificateCN

func GetIngressCertificateCN(ctx context.Context, client runtimeclient.Client) (string, error)

func GetInstallConfig

func GetInstallConfig(ctx context.Context, client runtimeclient.Reader) (string, error)

func GetLocalNodeName

func GetLocalNodeName(ctx context.Context, client runtimeclient.Reader) (string, error)

getLocalNodeName returns the current node's name from the hostname.

func GetMCDManagedVarLibFiles

func GetMCDManagedVarLibFiles(mcdConfigPath string) ([]string, error)

GetMCDManagedVarLibFiles parses the MCD currentconfig to get the list of managed files under /var/lib.

func GetMachineNetworks

func GetMachineNetworks(ctx context.Context, client runtimeclient.Reader) ([]string, error)

func GetMirrorRegistrySourceRegistries

func GetMirrorRegistrySourceRegistries(ctx context.Context, client runtimeclient.Client) ([]string, error)

func GetNodeInternalIPs

func GetNodeInternalIPs(ctx context.Context, client runtimeclient.Reader) ([]string, error)

func GetReleaseRegistry

func GetReleaseRegistry(ctx context.Context, client runtimeclient.Client) (string, error)

func GetSNOMasterNode

func GetSNOMasterNode(ctx context.Context, client runtimeclient.Client) (*corev1.Node, error)

func GetSecretData

func GetSecretData(ctx context.Context, name, namespace, key string, client runtimeclient.Client) (string, error)

func GetYamlOrJsonDecoder

func GetYamlOrJsonDecoder(fp string) (*yaml.YAMLOrJSONDecoder, error)

func HandleFilesWithCallback

func HandleFilesWithCallback(folder string, action func(string) error) error

func HasFIPS

func HasFIPS(ctx context.Context, client runtimeclient.Client) (bool, error)

func HasProxy

func HasProxy(ctx context.Context, client runtimeclient.Client) (bool, error)

func InitIBU

func InitIBU(ctx context.Context, c runtimeclient.Client, log *logr.Logger) error

func InitIPConfig

func InitIPConfig(ctx context.Context, c runtimeclient.Client, log *logr.Logger) error

func IsIpv6

func IsIpv6(provideIp string) bool

func LoadGroupedManifestsFromPath

func LoadGroupedManifestsFromPath(basePath string, log *logr.Logger) ([][]*unstructured.Unstructured, error)

func LoadKubeadminPasswordHash

func LoadKubeadminPasswordHash(cryptoDir string) (string, error)

func MarshalToFile

func MarshalToFile(data any, filePath string) error

MarshalToFile marshals anything and writes it to the given file path. file only readable by root

func MarshalToYamlFile

func MarshalToYamlFile(data any, filePath string) error

MarshalToYamlFile marshals any object to YAML and writes it to the given file path file only readable by root

func ReadIBIConfigFile

func ReadIBIConfigFile(configFile string) (*ibiconfig.IBIPrepareConfig, error)

func ReadImageFromStaticPodDefinition

func ReadImageFromStaticPodDefinition(podFile, containerName string) (string, error)

func ReadSeedReconfigurationFromFile

func ReadSeedReconfigurationFromFile(path string) (*seedreconfig.SeedReconfiguration, error)

func ReadYamlOrJSONFile

func ReadYamlOrJSONFile(fp string, into any) error

func RemoveListOfFiles

func RemoveListOfFiles(log *logrus.Logger, files []string) error

func RenderTemplate

func RenderTemplate(templateData string, params any) ([]byte, error)

RenderTemplate render template

func ReplaceImageRegistry

func ReplaceImageRegistry(image, targetRegistry, sourceRegistry string) (string, error)

func RetryMiddleware

func RetryMiddleware(logger logr.Logger) func(rt http.RoundTripper) http.RoundTripper

RetryMiddleware pass this into your client config (with .Wrap()) to make it retriable

func RunOnce

func RunOnce(name, directory string, log *logrus.Logger, f any, args ...any) error

func SeedReconfigurationKubeconfigRetentionFromCluster

func SeedReconfigurationKubeconfigRetentionFromCluster(ctx context.Context, client runtimeclient.Client) (*seedreconfig.KubeConfigCryptoRetention, error)

func SeedReconfigurationKubeconfigRetentionToCryptoDir

func SeedReconfigurationKubeconfigRetentionToCryptoDir(cryptoDir string, kubeconfigCryptoRetention *seedreconfig.KubeConfigCryptoRetention) error

func ShouldOverrideSeedRegistry

func ShouldOverrideSeedRegistry(seedMirrorRegistryConfigured bool, seedReleaseRegistry string, mirrorRegistrySources []string) (bool, error)

func UpdatePullSecretFromDockerConfig

func UpdatePullSecretFromDockerConfig(ctx context.Context, c runtimeclient.Client, dockerConfigJSON []byte) (*corev1.Secret, error)

func ValidateIPFamilyConfig

func ValidateIPFamilyConfig(
	family string,
	addr string,
	networkCIDR string,
	gateway string,
) error

ValidateIPFamilyConfig performs family-specific validation for addr, CIDR, gateway and DNS.

func WaitForApi

func WaitForApi(ctx context.Context, client runtimeclient.Client, log *logrus.Logger)

Types

type ClusterInfo

type ClusterInfo struct {
	BaseDomain               string
	ClusterName              string
	ClusterID                string
	OCPVersion               string
	NodeIPs                  []string
	ReleaseRegistry          string
	Hostname                 string
	MirrorRegistryConfigured bool
	ClusterNetworks          []string
	ServiceNetworks          []string
	MachineNetworks          []string
	NodeLabels               map[string]string
	IngressCertificateCN     string
}

func GetClusterInfo

func GetClusterInfo(ctx context.Context, client runtimeclient.Client) (*ClusterInfo, error)

type IPConfig

type IPConfig struct {
	Address        string
	PrefixLen      int
	Enabled        bool
	DHCPEnabled    bool
	DesiredGateway string
	CurrentGateway string
}

IPConfig represents IP configuration for a specific protocol

type NMStateConfig

type NMStateConfig struct {
	InterfaceName string
	VLAN          bool
	VLANID        int
	IPv4Config    *IPConfig
	IPv6Config    *IPConfig
	DNSServers    []string
}

NMStateConfig represents the configuration for generating NMState YAML

type NMStateTemplateData

type NMStateTemplateData struct {
	InterfaceName string
	VLANID        int
	IPv4          IPConfig
	IPv6          IPConfig
	DNSServers    []string
}

NMStateTemplateData represents the template data for NMState YAML generation

type NmAddr

type NmAddr struct {
	IP           string `json:"ip"`
	PrefixLength int    `json:"prefix-length"`
}

NmAddr represents an IP address in nmstate output.

type NmBridge

type NmBridge struct {
	Port []struct {
		Name string `json:"name"`
	} `json:"port"`
}

NmBridge represents bridge configuration for an interface.

type NmDNS

type NmDNS struct {
	Running NmDNSList `json:"running"`
	Config  NmDNSList `json:"config"`
}

NmDNS represents DNS resolver configuration in nmstate output.

type NmDNSList

type NmDNSList struct {
	Server []string `json:"server"`
}

NmDNSList represents a list of DNS servers in nmstate output.

type NmIPConf

type NmIPConf struct {
	Enabled  bool     `json:"enabled"`
	DHCP     bool     `json:"dhcp"`
	Autoconf bool     `json:"autoconf,omitempty"`
	Address  []NmAddr `json:"address"`
}

NmIPConf represents IPv4/IPv6 configuration for an interface.

type NmIf

type NmIf struct {
	Name   string   `json:"name"`
	Type   string   `json:"type"`
	IPv4   NmIPConf `json:"ipv4"`
	IPv6   NmIPConf `json:"ipv6"`
	Bridge NmBridge `json:"bridge,omitempty"`
	VLAN   *NmVLAN  `json:"vlan,omitempty"`
}

NmIf represents a network interface in nmstate output.

func GetBrExInterface

func GetBrExInterface(state NmState) (*NmIf, error)

type NmRoute

type NmRoute struct {
	Destination      string `json:"destination"`
	NextHopAddress   string `json:"next-hop-address"`
	NextHopInterface string `json:"next-hop-interface"`
}

NmRoute represents a route entry in nmstate output.

type NmRoutes

type NmRoutes struct {
	Running []NmRoute `json:"running"`
	Config  []NmRoute `json:"config"`
}

NmRoutes represents running and configured routes in nmstate output.

type NmState

type NmState struct {
	Interfaces  []NmIf   `json:"interfaces"`
	Routes      NmRoutes `json:"routes"`
	DNSResolver NmDNS    `json:"dns-resolver"`
}

NmState is the top-level nmstate JSON structure.

func ParseNmstate

func ParseNmstate(output string) (NmState, error)

ParseNmstate parses nmstate JSON output into NmState.

type NmVLAN

type NmVLAN struct {
	BaseIface string `json:"base-iface"`
	ID        int    `json:"id"`
}

NmVLAN represents VLAN configuration for an interface.

Jump to

Keyboard shortcuts

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