util

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 37 Imported by: 1

Documentation

Overview

Package util contains utils.

Index

Constants

View Source
const (
	// ProviderIDPrefix is the string data prefixed to a BIOS UUID in order
	// to build a provider ID.
	ProviderIDPrefix = "vsphere://"

	// ProviderIDPattern is a regex pattern and is used by ConvertProviderIDToUUID
	// to convert a providerID into a UUID string.
	ProviderIDPattern = `(?i)^` + ProviderIDPrefix + `([a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12})$`

	// UUIDPattern is a regex pattern and is used by ConvertUUIDToProviderID
	// to convert a UUID into a providerID string.
	UUIDPattern = `(?i)^[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}$`
)
View Source
const (
	// NCPSNATKey is the key used for the NCPSNAT annotation.
	NCPSNATKey = "ncp/snat_ip"
	// NCPVersionKey is the key used for version information in the NCP configmap.
	NCPVersionKey = "version"
	// NCPNamespace is the namespace of the NCP configmap.
	NCPNamespace = "vmware-system-nsx"
	// NCPVersionConfigMap is a name of the NCP config map.
	NCPVersionConfigMap = "nsx-ncp-version-config"
	// NCPVersionSupportFW 3.0.1 is where NCP starts to support "whitelist_source_ranges" specification in VNET and enforce FW rules on GC T1.
	NCPVersionSupportFW = "3.0.1"
	// NCPVersionSupportFWEnded 3.1.0 is where NCP stopped to support "whitelist_source_ranges" specification in VNET.
	NCPVersionSupportFWEnded = "3.1.0"

	// EmptyAnnotationErrorMsg is an error message returned when no annotations are found.
	EmptyAnnotationErrorMsg = "annotation not found"
	// EmptyNCPSNATKeyMsg is an error message returned when the annotation can not be found.
	EmptyNCPSNATKeyMsg = NCPSNATKey + " key not found"
)

Variables

View Source
var (
	// NCPVersionSupportFWSemver is the SemVer representation of the minimum NCPVersion for enforcing FW rules.
	NCPVersionSupportFWSemver = semver.MustParse(NCPVersionSupportFW)
	// NCPVersionSupportFWEndedSemver is the SemVer representation of the maximum NCPVersion for enforcing FW rules.
	NCPVersionSupportFWEndedSemver = semver.MustParse(NCPVersionSupportFWEnded)
)
View Source
var ErrNoMachineIPAddr = errors.New("no IP addresses found for machine")

ErrNoMachineIPAddr indicates that no valid IP addresses were found in a machine context.

Functions

func ConvertProviderIDToUUID

func ConvertProviderIDToUUID(providerID *string) string

ConvertProviderIDToUUID transforms a provider ID into a UUID string. If providerID is nil, empty, or invalid, then an empty string is returned. A valid providerID should adhere to the format specified by ProviderIDPattern.

func ConvertUUIDToProviderID

func ConvertUUIDToProviderID(uuid string) string

ConvertUUIDToProviderID transforms a UUID string into a provider ID. If the supplied UUID is empty or invalid then an empty string is returned. A valid UUID should adhere to the format specified by UUIDPattern.

func CreateCluster added in v1.1.0

func CreateCluster(clusterName string) *clusterv1.Cluster

func CreateClusterContext added in v1.1.0

func CreateClusterContext(cluster *clusterv1.Cluster, vsphereCluster *vmwarev1.VSphereCluster) (*vmware.ClusterContext, *capvcontext.ControllerManagerContext)

func CreateMachine added in v1.1.0

func CreateMachine(machineName, clusterName, k8sVersion string, controlPlaneLabel bool) *clusterv1.Machine

func CreateMachineContext added in v1.1.0

func CreateMachineContext(clusterContext *vmware.ClusterContext, machine *clusterv1.Machine,
	vsphereMachine *vmwarev1.VSphereMachine) *vmware.SupervisorMachineContext

func CreateVSphereCluster added in v1.1.0

func CreateVSphereCluster(clusterName string) *vmwarev1.VSphereCluster

func CreateVSphereMachine added in v1.1.0

func CreateVSphereMachine(machineName, clusterName, className, imageName, storageClass string, controlPlaneLabel bool) *vmwarev1.VSphereMachine

func FetchControlPlaneOwnerObject added in v1.3.2

func FetchControlPlaneOwnerObject(ctx context.Context, input FetchObjectInput) (ctrlclient.Object, error)

FetchControlPlaneOwnerObject returns the ControlPlane owner for a Machine.

func FetchMachineDeploymentOwnerObject added in v1.3.2

func FetchMachineDeploymentOwnerObject(ctx context.Context, input FetchObjectInput) (ctrlclient.Object, error)

FetchMachineDeploymentOwnerObject returns the MachineDeployment owner for a Machine.

func GetMachineMetadata

func GetMachineMetadata(hostname string, vsphereVM infrav1.VSphereVM, ipamState map[string]infrav1.NetworkDeviceSpec, networkStatuses ...infrav1.NetworkStatus) ([]byte, error)

GetMachineMetadata the cloud-init metadata as a base-64 encoded string for a given VSphereMachine. IPAM state includes IP and Gateways that should be added to each device.

func GetMachinePreferredIPAddress

func GetMachinePreferredIPAddress(machine *infrav1.VSphereMachine) (string, error)

GetMachinePreferredIPAddress returns the preferred IP address for a VSphereMachine resource.

func GetNCPVersion added in v1.1.0

func GetNCPVersion(ctx context.Context, controllerClient client.Client) (string, error)

GetNCPVersion finds out the running ncp's version from its configmap. If the version contains more than 3 segments, it will get trimmed down to 3.

func GetNamespaceNetSnatIP added in v1.1.0

func GetNamespaceNetSnatIP(ctx context.Context, controllerClient client.Client, namespace string) (string, error)

GetNamespaceNetSnatIP finds out the namespace's corresponding network's SNAT IP.

func GetOwnerVMWareMachine added in v1.10.0

func GetOwnerVMWareMachine(ctx context.Context, c client.Client, obj metav1.ObjectMeta) (*vmwarev1.VSphereMachine, error)

GetOwnerVMWareMachine returns the vmwarev1.VSphereMachine owner for the passed object.

func GetOwnerVSphereMachine added in v0.7.9

func GetOwnerVSphereMachine(ctx context.Context, c client.Client, obj metav1.ObjectMeta) (*infrav1.VSphereMachine, error)

GetOwnerVSphereMachine returns the VSphereMachine owner for the passed object.

func GetVSphereClusterFromVMwareMachine added in v1.3.2

func GetVSphereClusterFromVMwareMachine(ctx context.Context, c client.Client, machine *vmwarev1.VSphereMachine) (*vmwarev1.VSphereCluster, error)

GetVSphereClusterFromVMwareMachine gets the vmware.infrastructure.cluster.x-k8s.io.VSphereCluster resource for the given VSphereMachine. TODO (srm09): Rename this to a more appropriate name.

func GetVSphereClusterFromVSphereMachine added in v1.1.0

func GetVSphereClusterFromVSphereMachine(ctx context.Context, c client.Client, machine *infrav1.VSphereMachine) (*infrav1.VSphereCluster, error)

GetVSphereClusterFromVSphereMachine gets the infrastructure.cluster.x-k8s.io.VSphereCluster resource for the given VSphereMachine.

func GetVSphereMachine

func GetVSphereMachine(
	ctx context.Context,
	controllerClient client.Client,
	namespace, machineName string) (*vmwarev1.VSphereMachine, error)

GetVSphereMachine gets a vmware.infrastructure.cluster.x-k8s.io.VSphereMachine resource for the given CAPI Machine.

func IPAddressClaimName added in v1.7.0

func IPAddressClaimName(vmName string, deviceIndex, poolIndex int) string

IPAddressClaimName returns a name given a VsphereVM name, deviceIndex, and poolIndex.

func IsControlPlaneMachine

func IsControlPlaneMachine(machine metav1.Object) bool

IsControlPlaneMachine returns true if the provided resource is a member of the control plane.

func LessThan added in v1.5.0

func LessThan(version1, version2 string) (bool, error)

LessThan compares the integer values of the supplied VMX versions and returns whether the first version is less than the second. It returns an error if an invalid vmx version is passed.

func MachinesAsString added in v1.0.2

func MachinesAsString(machines []*clusterv1.Machine) string

MachinesAsString constructs a string (with correct punctuations) to be used in logging and error messages.

func NCPSupportFW added in v1.1.0

func NCPSupportFW(ctx context.Context, controllerClient client.Client) (bool, error)

NCPSupportFW checks the version of running NCP and return true if it supports FW rule enforcement on GC T1 Router.

func NewKubeClient

func NewKubeClient(
	ctx context.Context,
	controllerClient client.Client,
	cluster *clusterv1.Cluster) (kubernetes.Interface, error)

NewKubeClient returns a new client for the target cluster using the KubeConfig secret stored in the management cluster.

func ParseHardwareVersion added in v1.8.6

func ParseHardwareVersion(version string) (int, error)

ParseHardwareVersion returns the virtual machine hardware version from the input. It expects the input formatted as vmx-17, where the trailing number is virtual machine hardware version.

func SanitizeHostInfoLabel added in v1.3.5

func SanitizeHostInfoLabel(info string) string

SanitizeHostInfoLabel ensures that the ESXi host information passed as a parameter confirms to the label value constraints documented at https://k8s.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set

The expected inputs for the object are IP addresses or FQDNs of the ESXi hosts.

func SetControllerReferenceWithOverride added in v1.7.0

func SetControllerReferenceWithOverride(owner, controlled metav1.Object, scheme *runtime.Scheme) error

SetControllerReferenceWithOverride sets owner as a Controller OwnerReference on controlled. This is used for garbage collection of the controlled object and for reconciling the owner object on changes to controlled (with a Watch + EnqueueRequestForOwner). Since only one OwnerReference can be a controller, it returns an error if there is another OwnerReference with Controller flag set unless it was a legacy controller owner.

Types

type FetchObjectInput added in v1.3.2

type FetchObjectInput struct {
	ctrlclient.Client
	Object ctrlclient.Object
}

FetchObjectInput contains data to fetch objects.

Jump to

Keyboard shortcuts

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