kubevirt

package
v0.0.55 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultInstancetypeLabel = "instancetype.kubevirt.io/default-instancetype"
	DefaultPreferenceLabel   = "instancetype.kubevirt.io/default-preference"
)

Variables

This section is empty.

Functions

func ExtractDataSourceInfo

func ExtractDataSourceInfo(obj *unstructured.Unstructured) string

ExtractDataSourceInfo extracts source information from a DataSource object.

Supports multiple source types:

  • PVC: Returns "PVC: namespace/name" or "PVC: name"
  • Registry: Returns "Registry: url"
  • HTTP: Returns "HTTP: url"

Parameters:

  • obj: Unstructured DataSource object

Returns a human-readable string describing the source, or "unknown source"/"DataSource (type unknown)" if the source cannot be determined.

func MatchInstancetypeBySize

func MatchInstancetypeBySize(instancetypes []InstancetypeInfo, size, performance string) string

MatchInstancetypeBySize finds an instancetype that matches the size and performance hints.

Matching strategy:

  1. Filter instancetypes by size (e.g., "medium" matches "*.medium")
  2. Try to match by performance family prefix (e.g., "c1" matches "c1.medium")
  3. Try to match by performance family label (instancetype.kubevirt.io/class)
  4. Fall back to first instancetype that matches size

Parameters:

  • instancetypes: List of available instancetypes
  • size: Size hint (e.g., "small", "medium", "large")
  • performance: Performance class hint (e.g., "u1", "c1", "m1")

Returns the matched instancetype name, or empty string if no match found.

func SearchDataSources

func SearchDataSources(ctx context.Context, dynamicClient dynamic.Interface) map[string]DataSourceInfo

SearchDataSources searches for DataSource resources in the cluster.

It searches in well-known namespaces first (openshift-virtualization-os-images, kubevirt-os-images), then performs a cluster-wide search. Duplicate DataSources are filtered by namespace/name key.

Returns a map of DataSourceInfo indexed by "namespace/name". If no DataSources are found, returns a placeholder entry indicating no sources are available.

Types

type DataSourceInfo

type DataSourceInfo struct {
	Name                string
	Namespace           string
	Source              string
	DefaultInstancetype string
	DefaultPreference   string
}

DataSourceInfo contains information about a KubeVirt DataSource

func MatchDataSource

func MatchDataSource(dataSources map[string]DataSourceInfo, workload string) *DataSourceInfo

MatchDataSource finds a DataSource that matches the workload input.

Matching strategy:

  1. Exact name match (case-insensitive)
  2. Partial match for DataSources with namespaces (real cluster resources) e.g., "rhel" matches "rhel9"

Built-in containerdisks (without namespaces) are excluded from partial matching to avoid ambiguous matches.

Parameters:

  • dataSources: Map of available DataSources keyed by "namespace/name"
  • workload: User input (OS name, DataSource name, or container image)

Returns a pointer to matched DataSourceInfo, or nil if no match found.

type InstancetypeInfo

type InstancetypeInfo struct {
	Name      string
	Namespace string // Empty for cluster-scoped instancetypes
	Labels    map[string]string
}

InstancetypeInfo contains information about a VirtualMachineInstancetype

func FilterInstancetypesBySize

func FilterInstancetypesBySize(instancetypes []InstancetypeInfo, normalizedSize string) []InstancetypeInfo

FilterInstancetypesBySize filters instancetypes that contain the size hint in their name.

Parameters:

  • instancetypes: List of available instancetypes
  • normalizedSize: Lowercase size hint (e.g., "small", "medium", "large")

Returns a filtered list of instancetypes whose names contain the size string. For example, "medium" matches "u1.medium", "c1.medium", etc.

func ResolveInstancetype

func ResolveInstancetype(instancetypes []InstancetypeInfo, explicitInstancetype, size, performance string, matchedDataSource *DataSourceInfo) *InstancetypeInfo

ResolveInstancetype determines the instancetype to use from DataSource defaults or size/performance hints.

Resolution priority:

  1. Explicit instancetype parameter (if provided)
  2. DataSource default instancetype (if DataSource matched, has default, and no size specified)
  3. Auto-match by size and performance hints e.g., size="large" + performance="c1" matches "c1.large"

Parameters:

  • instancetypes: List of available instancetypes from the cluster
  • explicitInstancetype: User-specified instancetype name (may be empty)
  • size: Size hint (e.g., "small", "medium", "large") - may be empty
  • performance: Performance class hint (e.g., "u1", "c1", "m1") - may be empty
  • matchedDataSource: Matched DataSource (may be nil)

Returns a pointer to InstancetypeInfo with name and scope, or nil if no match found. If an instancetype name is provided but not found in available instancetypes, assumes it's cluster-scoped.

func SearchInstancetypes

func SearchInstancetypes(ctx context.Context, dynamicClient dynamic.Interface, namespace string) []InstancetypeInfo

SearchInstancetypes searches for both cluster-wide and namespaced VirtualMachineInstancetype resources.

It queries both VirtualMachineClusterInstancetypes (cluster-scoped) and VirtualMachineInstancetypes (namespaced) resources. Each InstancetypeInfo includes a Namespace field that is empty for cluster-scoped resources, plus Labels for filtering by performance class.

Parameters:

  • ctx: Context for the API calls
  • dynamicClient: Kubernetes dynamic client
  • namespace: Namespace to search for namespaced instancetypes

Returns a list of InstancetypeInfo objects. Returns empty list if no instancetypes found or if API calls fail.

type PreferenceInfo

type PreferenceInfo struct {
	Name      string
	Namespace string // Empty for cluster-scoped preferences
}

PreferenceInfo contains information about a VirtualMachinePreference

func ResolvePreference

func ResolvePreference(preferences []PreferenceInfo, explicitPreference, workload string, matchedDataSource *DataSourceInfo) *PreferenceInfo

ResolvePreference determines the preference to use from DataSource defaults or cluster resources.

Resolution priority:

  1. Explicit preference parameter (if provided)
  2. DataSource default preference (if DataSource matched and has default)
  3. Auto-match preference name against workload input e.g., "rhel" matches "rhel.9"

Parameters:

  • preferences: List of available preferences from the cluster
  • explicitPreference: User-specified preference name (may be empty)
  • workload: Workload/OS name used for auto-matching
  • matchedDataSource: Matched DataSource (may be nil)

Returns a pointer to PreferenceInfo with name and scope, or nil if no match found. If a preference name is provided but not found in available preferences, assumes it's cluster-scoped.

func SearchPreferences

func SearchPreferences(ctx context.Context, dynamicClient dynamic.Interface, namespace string) []PreferenceInfo

SearchPreferences searches for both cluster-wide and namespaced VirtualMachinePreference resources.

It queries both VirtualMachineClusterPreferences (cluster-scoped) and VirtualMachinePreferences (namespaced) resources. Each PreferenceInfo includes a Namespace field that is empty for cluster-scoped resources.

Parameters:

  • ctx: Context for the API calls
  • dynamicClient: Kubernetes dynamic client
  • namespace: Namespace to search for namespaced preferences

Returns a list of PreferenceInfo objects. Returns empty list if no preferences found or if API calls fail.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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