Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #23 from stoyanr/fix-worker-zones
Browse files Browse the repository at this point in the history
Accept a single zone in provider spec
  • Loading branch information
mfranczy authored Oct 7, 2020
2 parents 8ea688c + 8cabbc6 commit e2ce1ee
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
19 changes: 10 additions & 9 deletions pkg/kubevirt/apis/provider_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import (
// KubeVirtProviderSpec is the spec to be used while parsing the calls.
type KubeVirtProviderSpec struct {
// SourceURL is the HTTP URL of the source image imported by CDI.
SourceURL string `json:"sourceURL,omitempty"`
SourceURL string `json:"sourceURL"`
// StorageClassName is the name which CDI uses to in order to create claims.
StorageClassName string `json:"storageClassName,omitempty"`
StorageClassName string `json:"storageClassName"`
// PVCSize is the size of the PersistentVolumeClaim that is created during the image import by CDI.
PVCSize string `json:"pvcSize,omitempty"`
PVCSize string `json:"pvcSize"`
// CPUs is the number of CPUs requested by the VM.
CPUs string `json:"cpus,omitempty"`
CPUs string `json:"cpus"`
// Memory is the amount of memory requested by the VM.
Memory string `json:"memory,omitempty"`
Memory string `json:"memory"`
// DNSConfig is the DNS configuration of the VM pod.
// The parameters specified here will be merged with the generated DNS configuration based on DNSPolicy.
// +optional
Expand All @@ -48,10 +48,10 @@ type KubeVirtProviderSpec struct {
// +optional
Networks []NetworkSpec `json:"networks,omitempty"`
// Region is the name of the region for the VM.
Region string
// Zones is a list of availability zones for the VM.
Region string `json:"region"`
// Zone is the name of the zone for the VM.
// +optional
Zones []string
Zone string `json:"zone,omitempty"`
// Tags is an optional map of tags that is added to the VM as labels.
// +optional
Tags map[string]string `json:"tags,omitempty"`
Expand All @@ -60,7 +60,8 @@ type KubeVirtProviderSpec struct {
// For hugepages take a look at:
// k8s - https://kubernetes.io/docs/tasks/manage-hugepages/scheduling-hugepages/
// okd - https://docs.okd.io/3.9/scaling_performance/managing_hugepages.html#huge-pages-prerequisites
MemoryFeatures *kubevirtv1.Memory
// +optional
MemoryFeatures *kubevirtv1.Memory `json:"memoryFeatures,omitempty"`
}

// NetworkSpec contains information about a network.
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubevirt/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (p PluginSPIImpl) CreateMachine(ctx context.Context, machineName string, pr
return "", fmt.Errorf("failed to get server version: %v", err)
}

affinity := buildAffinity(providerSpec.Region, providerSpec.Zones, k8sVersion)
affinity := buildAffinity(providerSpec.Region, providerSpec.Zone, k8sVersion)

userData := string(secret.Data["userData"])
if len(providerSpec.SSHKeys) > 0 {
Expand Down
10 changes: 5 additions & 5 deletions pkg/kubevirt/core/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const (
defaultZone = "default"
)

func buildAffinity(region string, zones []string, k8sVersion string) *corev1.Affinity {
func buildAffinity(region, zone, k8sVersion string) *corev1.Affinity {
var affinity *corev1.Affinity
if region != "" {
// Get region and zone labels
Expand All @@ -199,13 +199,13 @@ func buildAffinity(region string, zones []string, k8sVersion string) *corev1.Aff
})
}

// If there are zones, add match expression for the zone label
if len(zones) > 0 {
if len(zones) > 1 || zones[0] != defaultZone {
// If there is a zone, add match expression for the zone label
if zone != "" {
if zone != defaultZone {
matchExpressions = append(matchExpressions, corev1.NodeSelectorRequirement{
Key: zoneLabel,
Operator: corev1.NodeSelectorOpIn,
Values: zones,
Values: []string{zone},
})
} else {
matchExpressions = append(matchExpressions, corev1.NodeSelectorRequirement{
Expand Down

0 comments on commit e2ce1ee

Please sign in to comment.