Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions hack/api-reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ string
</tr>
<tr>
<td>
<code>rootDiskAvailabilityZone</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>RootDiskAvailabilityZone is the availability zone of the root disk volume. It is only used if RootDiskType is set.<br />If unset, the availability zone of the machine is used. If set to the empty string, no availability zone is<br />passed to Cinder, which then uses its default availability zone. This allows for differing compute and volume<br />availability zones.</p>
</td>
</tr>
<tr>
<td>
<code>useConfigDrive</code></br>
<em>
boolean
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/openstack/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ type MachineProviderConfigSpec struct {
RootDiskSize int
// The type of the root disk type used for the instance
RootDiskType *string
// RootDiskAvailabilityZone is the availability zone of the root disk volume. It is only used if RootDiskType is set.
// If unset, the availability zone of the machine is used. If set to the empty string, no availability zone is
// passed to Cinder, which then uses its default availability zone.
RootDiskAvailabilityZone *string
// UseConfigDrive enables the use of configuration drives for the instance.
UseConfigDrive *bool
// ServerGroupID is the ID of the server group this instance should belong to.
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/openstack/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ type MachineProviderConfigSpec struct {
// The type of the root disk used for the instance.
// +optional
RootDiskType *string `json:"rootDiskType,omitempty"`
// RootDiskAvailabilityZone is the availability zone of the root disk volume. It is only used if RootDiskType is set.
// If unset, the availability zone of the machine is used. If set to the empty string, no availability zone is
// passed to Cinder, which then uses its default availability zone. This allows for differing compute and volume
// availability zones.
// +optional
RootDiskAvailabilityZone *string `json:"rootDiskAvailabilityZone,omitempty"`
// UseConfigDrive enables the use of configuration drives for the instance.
UseConfigDrive *bool `json:"useConfigDrive,omitempty"`
// ServerGroupID is the ID of the server group this instance should belong to.
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/openstack/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/apis/openstack/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/apis/openstack/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/apis/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func validateMachineProviderConfig(providerConfig *openstack.MachineProviderConf
if providerConfig.Spec.RootDiskSize < 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("rootDiskSize"), "RootDiskSize can not be negative"))
}
if providerConfig.Spec.RootDiskAvailabilityZone != nil && providerConfig.Spec.RootDiskType == nil {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("rootDiskAvailabilityZone"), "\"rootDiskAvailabilityZone\" can only be set together with \"rootDiskType\""))
}

allErrs = append(allErrs, validateNetworks(providerConfig.Spec.Networks, providerConfig.Spec.PodNetworkCidr, providerConfig.Spec.PodNetworkCIDRs, field.NewPath("spec.networks"))...)
allErrs = append(allErrs, validateClassSpecTags(providerConfig.Spec.Tags, field.NewPath("spec.tags"))...)
Expand Down
16 changes: 16 additions & 0 deletions pkg/apis/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

. "github.com/gardener/machine-controller-manager-provider-openstack/pkg/apis/cloudprovider"
api "github.com/gardener/machine-controller-manager-provider-openstack/pkg/apis/openstack"
Expand Down Expand Up @@ -47,6 +48,21 @@ var _ = Describe("Validation", func() {
}
})

Context("rootDiskAvailabilityZone", func() {
It("should fail if set without rootDiskType", func() {
machineProviderConfig.Spec.RootDiskAvailabilityZone = ptr.To("nova")
err := validateMachineProviderConfig(machineProviderConfig).ToAggregate()
Expect(err).To(HaveOccurred())
})

It("should succeed if set together with rootDiskType", func() {
machineProviderConfig.Spec.RootDiskAvailabilityZone = ptr.To("nova")
machineProviderConfig.Spec.RootDiskType = ptr.To("fast")
err := validateMachineProviderConfig(machineProviderConfig).ToAggregate()
Expect(err).ToNot(HaveOccurred())
})
})

Context("required fields", func() {
It("should return no error", func() {
err := validateMachineProviderConfig(machineProviderConfig).ToAggregate()
Expand Down
12 changes: 11 additions & 1 deletion pkg/driver/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,16 @@ func (ex *Executor) addBlockDeviceOpts(ctx context.Context, machineName,
return createOpts, nil
}

// rootDiskAvailabilityZone returns the availability zone to create the root disk volume in.
// It defaults to the availability zone of the machine, but can be overridden (or emptied, to let Cinder choose its
// default) to support clouds where compute and volume availability zones differ.
func (ex *Executor) rootDiskAvailabilityZone() string {
if az := ex.Config.Spec.RootDiskAvailabilityZone; az != nil {
return *az
}
return ex.Config.Spec.AvailabilityZone
}

func (ex *Executor) ensureVolume(ctx context.Context, name, imageID string,
hintOpts volumes.SchedulerHintOptsBuilder) (string, error) {
var (
Expand All @@ -376,7 +386,7 @@ func (ex *Executor) ensureVolume(ctx context.Context, name, imageID string,
VolumeType: *ex.Config.Spec.RootDiskType,
Size: ex.Config.Spec.RootDiskSize,
ImageID: imageID,
AvailabilityZone: ex.Config.Spec.AvailabilityZone,
AvailabilityZone: ex.rootDiskAvailabilityZone(),
Comment thread
aaronfern marked this conversation as resolved.
Metadata: ex.Config.Spec.Tags,
}, hintOpts)
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions pkg/driver/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,18 @@ var _ = Describe("Executor", func() {
Expect(err).ToNot(HaveOccurred())
})
})

Context("rootDiskAvailabilityZone", func() {
DescribeTable("should select the availability zone for the root disk volume",
func(rootDiskAZ *string, expected string) {
cfg.Spec.AvailabilityZone = "AZ1"
cfg.Spec.RootDiskAvailabilityZone = rootDiskAZ
ex := &Executor{Config: cfg}
Expect(ex.rootDiskAvailabilityZone()).To(Equal(expected))
},
Entry("defaults to the machine availability zone", nil, "AZ1"),
Entry("uses the configured volume availability zone", ptr.To("nova"), "nova"),
Entry("omits the availability zone if empty", ptr.To(""), ""),
)
})
})
Loading