Documentation
¶
Index ¶
- Constants
- func ExtractDataSourceInfo(obj *unstructured.Unstructured) string
- func MatchInstancetypeBySize(instancetypes []InstancetypeInfo, size, performance string) string
- func SearchDataSources(ctx context.Context, dynamicClient dynamic.Interface) map[string]DataSourceInfo
- type DataSourceInfo
- type InstancetypeInfo
- func FilterInstancetypesBySize(instancetypes []InstancetypeInfo, normalizedSize string) []InstancetypeInfo
- func ResolveInstancetype(instancetypes []InstancetypeInfo, ...) *InstancetypeInfo
- func SearchInstancetypes(ctx context.Context, dynamicClient dynamic.Interface, namespace string) []InstancetypeInfo
- type PreferenceInfo
Constants ¶
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:
- Filter instancetypes by size (e.g., "medium" matches "*.medium")
- Try to match by performance family prefix (e.g., "c1" matches "c1.medium")
- Try to match by performance family label (instancetype.kubevirt.io/class)
- 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:
- Exact name match (case-insensitive)
- 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:
- Explicit instancetype parameter (if provided)
- DataSource default instancetype (if DataSource matched, has default, and no size specified)
- 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 ¶
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:
- Explicit preference parameter (if provided)
- DataSource default preference (if DataSource matched and has default)
- 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.