Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/azure/api/providerspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ type AzureVirtualMachineProperties struct {
MachineSet *AzureMachineSetConfig `json:"machineSet,omitempty"`
// SecurityProfile specifies the security profile to be used for the virtual machine.
SecurityProfile *AzureSecurityProfile `json:"securityProfile,omitempty"`
// CapacityReservation represents the configuration for capacity reservations on Azure.
CapacityReservation *CapacityReservation `json:"capacityReservation,omitempty"`
}

// CapacityReservation represents the configuration for capacity reservations on Azure.
type CapacityReservation struct {
// CapacityReservationGroupID is the resource ID of the capacity reservation group to use.
CapacityReservationGroupID *string `json:"capacityReservationGroupID,omitempty"`
}

// AzureSecurityProfile specifies the security profile to be used for the virtual machine.
Expand Down
20 changes: 20 additions & 0 deletions pkg/azure/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"slices"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
"github.com/gardener/machine-controller-manager/pkg/apis/machine/v1alpha1"
"github.com/gardener/machine-controller-manager/pkg/util/provider/machinecodes/codes"
Expand Down Expand Up @@ -128,6 +129,7 @@ func validateProperties(properties api.AzureVirtualMachineProperties, fldPath *f
allErrs = append(allErrs, validateOSProfile(properties.OsProfile, fldPath.Child("osProfile"))...)
// validate availability set and vmss
allErrs = append(allErrs, validateAvailabilityAndScalingConfig(properties, fldPath)...)
allErrs = append(allErrs, validateCapacityReservationConfig(properties.CapacityReservation, fldPath.Child("capacityReservation"))...)
allErrs = append(allErrs, validateSecurityProfile(properties.SecurityProfile, fldPath.Child("securityProfile"))...)
return allErrs
}
Expand Down Expand Up @@ -294,6 +296,24 @@ func validateAvailabilityAndScalingConfig(properties api.AzureVirtualMachineProp
return allErrs
}

func validateCapacityReservationConfig(capacityReservationConfig *api.CapacityReservation, fldPath *field.Path) field.ErrorList {
var allErrs field.ErrorList

if capacityReservationConfig == nil {
return allErrs
}

if capacityReservationGroupID := capacityReservationConfig.CapacityReservationGroupID; capacityReservationGroupID != nil {
resourceID, err := arm.ParseResourceID(*capacityReservationGroupID)
if err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("capacityReservationGroupID"), *capacityReservationGroupID, fmt.Sprintf("invalid Azure resource ID: %v", err)))
} else if resourceID.ResourceType.Type != "CapacityReservationGroups" {
allErrs = append(allErrs, field.Invalid(fldPath.Child("capacityReservationGroupID"), *capacityReservationGroupID, "provided resource ID must be of a capacity reservation group"))
}
}
return allErrs
}

func validateTags(tags map[string]string, fldPath *field.Path) field.ErrorList {
const (
clusterKeyPrefix = "kubernetes.io-cluster-"
Expand Down
7 changes: 7 additions & 0 deletions pkg/azure/provider/helpers/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ func createVMCreationParams(providerSpec api.AzureProviderSpec, imageRef armcomp
}
}
}

if diskSecurityProfile := providerSpec.Properties.StorageProfile.OsDisk.ManagedDisk.SecurityProfile; diskSecurityProfile != nil {
if diskSecurityProfile.SecurityEncryptionType != nil {
securityEncryptionType := armcompute.SecurityEncryptionTypes(*diskSecurityProfile.SecurityEncryptionType)
Expand All @@ -780,6 +781,12 @@ func createVMCreationParams(providerSpec api.AzureProviderSpec, imageRef armcomp
}
}

if capacityReservationConfig := providerSpec.Properties.CapacityReservation; capacityReservationConfig != nil {
vm.Properties.CapacityReservation = &armcompute.CapacityReservationProfile{
CapacityReservationGroup: &armcompute.SubResource{ID: capacityReservationConfig.CapacityReservationGroupID},
}
}

return vm, nil
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/azure/testhelp/providerspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ func (b *ProviderSpecBuilder) WithSecurityProfile(sec *api.AzureSecurityProfile)
return b
}

// WithCapacityReservation configures the capacity reservation settings for the VM
func (b *ProviderSpecBuilder) WithCapacityReservation(capacityReservationConfig *api.CapacityReservation) *ProviderSpecBuilder {
b.spec.Properties.CapacityReservation = capacityReservationConfig
return b
}

// WithDefaultOsProfile sets a default OS profile in the provider spec.
func (b *ProviderSpecBuilder) WithDefaultOsProfile() *ProviderSpecBuilder {
b.spec.Properties.OsProfile = api.AzureOSProfile{
Expand Down
Loading