github.com/openshift/installer@v1.4.17/pkg/asset/installconfig/azure/capabilities.go (about)

     1  package azure
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"k8s.io/apimachinery/pkg/util/sets"
     8  
     9  	"github.com/openshift/installer/pkg/types/azure"
    10  )
    11  
    12  // GetHyperVGenerationVersion returns a HyperVGeneration version compatible with that of the image's. If imageHyperVGen is empty, it returns the highest supported version.
    13  func GetHyperVGenerationVersion(capabilities map[string]string, imageHyperVGen string) (string, error) {
    14  	generations, err := GetHyperVGenerationVersions(capabilities)
    15  	if err != nil {
    16  		return "", err
    17  	}
    18  	// If there is a version compatible with the VM image, return it
    19  	if imageHyperVGen != "" && generations.Has(imageHyperVGen) {
    20  		return imageHyperVGen, nil
    21  	} else if generations.Len() > 0 { // otherwise, return the highest version available
    22  		return sets.List(generations)[generations.Len()-1], nil
    23  	}
    24  	if generations.Has("V2") {
    25  		return "V2", nil
    26  	}
    27  	return "V1", nil
    28  }
    29  
    30  // GetHyperVGenerationVersions returns all the HyperVGeneration versions supported by the instance type according to its capabilities as a string set V = {"V1", "V2", ...}
    31  func GetHyperVGenerationVersions(capabilities map[string]string) (sets.Set[string], error) {
    32  	if val, ok := capabilities["HyperVGenerations"]; ok {
    33  		generations := sets.New[string]()
    34  		for _, g := range strings.Split(val, ",") {
    35  			g = strings.TrimSpace(g)
    36  			g = strings.ToUpper(g)
    37  			generations.Insert(g)
    38  		}
    39  		return generations, nil
    40  	}
    41  	return nil, fmt.Errorf("unable to determine HyperVGeneration version")
    42  }
    43  
    44  // GetVMNetworkingCapability returns true if Accelerated networking is supported by the instance type according to its capabilities or false, otherwise
    45  func GetVMNetworkingCapability(capabilities map[string]string) bool {
    46  	val, ok := capabilities[string(azure.AcceleratedNetworkingEnabled)]
    47  	return ok && strings.EqualFold(val, "True")
    48  }