Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions api/compute/v1alpha1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type MachineSpec struct {
// Power is the desired machine power state.
// Defaults to PowerOn.
Power Power `json:"power,omitempty"`
// Deprecated: Use LocalDisk to provide a bootable disk
// Image is the optional URL providing the operating system image of the machine.
// +optional
Image string `json:"image,omitempty"`
Expand Down Expand Up @@ -106,8 +107,11 @@ type Volume struct {
type VolumeSource struct {
// VolumeRef instructs to use the specified Volume as source for the attachment.
VolumeRef *corev1.LocalObjectReference `json:"volumeRef,omitempty"`
// Deprecated: Use LocalDisk instead
// EmptyDisk instructs to use a Volume offered by the machine pool provider.
EmptyDisk *EmptyDiskVolumeSource `json:"emptyDisk,omitempty"`
// LocalDisk instructs to use a Volume offered by the machine pool provider.
LocalDisk *LocalDiskVolumeSource `json:"localDisk,omitempty"`
// Ephemeral instructs to create an ephemeral (i.e. coupled to the lifetime of the surrounding object)
// Volume to use.
Ephemeral *EphemeralVolumeSource `json:"ephemeral,omitempty"`
Expand All @@ -122,6 +126,18 @@ type EmptyDiskVolumeSource struct {
SizeLimit *resource.Quantity `json:"sizeLimit,omitempty"`
}

// LocalDiskVolumeSource is a volume that's offered by the machine pool provider.
// Usually ephemeral (i.e. deleted when the surrounding entity is deleted), with
// varying performance characteristics. Potentially not recoverable.
type LocalDiskVolumeSource struct {
// SizeLimit is the total amount of local storage required for this EmptyDisk volume.
// The default is nil which means that the limit is undefined.
SizeLimit *resource.Quantity `json:"sizeLimit,omitempty"`
// Image is the optional URL providing the operating system image of the machine.
// +optional
Image string `json:"image,omitempty"`
}

// NetworkInterfaceStatus reports the status of a NetworkInterfaceSource.
type NetworkInterfaceStatus struct {
// Name is the name of the NetworkInterface to whom the status belongs to.
Expand Down
26 changes: 26 additions & 0 deletions api/compute/v1alpha1/zz_generated.deepcopy.go

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

11 changes: 8 additions & 3 deletions broker/machinebroker/server/event_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ var _ = Describe("ListEvents", func() {
},
Spec: &iri.MachineSpec{
Power: iri.Power_POWER_ON,
Image: &iri.ImageSpec{
Image: "example.org/foo:latest",
},
Class: machineClass.Name,
Volumes: []*iri.Volume{{
Name: "root",
LocalDisk: &iri.LocalDisk{
Image: &iri.ImageSpec{
Image: "example.org/foo:latest",
},
},
}},
NetworkInterfaces: []*iri.NetworkInterface{
{
Name: "primary-nic",
Expand Down
23 changes: 9 additions & 14 deletions broker/machinebroker/server/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (s *Server) convertIronCoreVolume(
) (*iri.Volume, error) {
var (
connection *iri.VolumeConnection
emptyDisk *iri.EmptyDisk
localDisk *iri.LocalDisk
)
switch {
case ironcoreMachineVolume.VolumeRef != nil:
Expand All @@ -137,22 +137,25 @@ func (s *Server) convertIronCoreVolume(
EffectiveStorageBytes: effectiveStorageBytes,
}
}
case ironcoreMachineVolume.EmptyDisk != nil:
case ironcoreMachineVolume.LocalDisk != nil:
var sizeBytes int64
if sizeLimit := ironcoreMachineVolume.EmptyDisk.SizeLimit; sizeLimit != nil {
if sizeLimit := ironcoreMachineVolume.LocalDisk.SizeLimit; sizeLimit != nil {
sizeBytes = sizeLimit.Value()
}
emptyDisk = &iri.EmptyDisk{
localDisk = &iri.LocalDisk{
SizeBytes: sizeBytes,
Image: &iri.ImageSpec{
Image: ironcoreMachineVolume.LocalDisk.Image,
},
}
default:
return nil, fmt.Errorf("machine volume %#v does neither specify volume ref nor empty disk", ironcoreMachineVolume)
return nil, fmt.Errorf("machine volume %#v does neither specify volume ref nor empty disk, nor local disk", ironcoreMachineVolume)
}

return &iri.Volume{
Name: ironcoreMachineVolume.Name,
Device: *ironcoreMachineVolume.Device,
EmptyDisk: emptyDisk,
LocalDisk: localDisk,
Connection: connection,
}, nil
}
Expand Down Expand Up @@ -195,13 +198,6 @@ func (s *Server) convertAggregateIronCoreMachine(aggIronCoreMachine *AggregateIr
return nil, fmt.Errorf("error converting power state: %w", err)
}

var imageSpec *iri.ImageSpec
if image := aggIronCoreMachine.Machine.Spec.Image; image != "" {
imageSpec = &iri.ImageSpec{
Image: image,
}
}

volumes := make([]*iri.Volume, len(aggIronCoreMachine.Machine.Spec.Volumes))
for i, ironcoreMachineVolume := range aggIronCoreMachine.Machine.Spec.Volumes {
ironcoreVolume := aggIronCoreMachine.Volumes[ironcoreMachineVolume.Name]
Expand Down Expand Up @@ -253,7 +249,6 @@ func (s *Server) convertAggregateIronCoreMachine(aggIronCoreMachine *AggregateIr
Metadata: metadata,
Spec: &iri.MachineSpec{
Power: power,
Image: imageSpec,
Class: aggIronCoreMachine.Machine.Spec.MachineClassRef.Name,
IgnitionData: ignitionData,
Volumes: volumes,
Expand Down
8 changes: 0 additions & 8 deletions broker/machinebroker/server/machine_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type IronCoreMachineConfig struct {
Annotations map[string]string
Power computev1alpha1.Power
MachineClassName string
Image string
IgnitionData []byte
NetworkInterfaceConfigs []*IronCoreNetworkInterfaceConfig
VolumeConfigs []*IronCoreVolumeConfig
Expand Down Expand Up @@ -75,11 +74,6 @@ func (s *Server) getIronCoreMachineConfig(machine *iri.Machine) (*IronCoreMachin
return nil, err
}

var ironcoreImage string
if image := machine.Spec.Image; image != nil {
ironcoreImage = image.Image
}

ironcoreNicCfgs := make([]*IronCoreNetworkInterfaceConfig, len(machine.Spec.NetworkInterfaces))
for i, nic := range machine.Spec.NetworkInterfaces {
ironcoreNicCfg, err := s.getIronCoreNetworkInterfaceConfig(nic)
Expand Down Expand Up @@ -116,7 +110,6 @@ func (s *Server) getIronCoreMachineConfig(machine *iri.Machine) (*IronCoreMachin
Annotations: annotations,
Power: ironcorePower,
MachineClassName: machine.Spec.Class,
Image: ironcoreImage,
IgnitionData: machine.Spec.IgnitionData,
NetworkInterfaceConfigs: ironcoreNicCfgs,
VolumeConfigs: ironcoreVolumeCfgs,
Expand Down Expand Up @@ -199,7 +192,6 @@ func (s *Server) createIronCoreMachine(
MachinePoolSelector: s.cluster.MachinePoolSelector(),
MachinePoolRef: s.ironcoreMachinePoolRef(),
Power: cfg.Power,
Image: cfg.Image,
ImagePullSecretRef: nil, // TODO: Specify as soon as available.
NetworkInterfaces: ironcoreMachineNics,
Volumes: ironcoreMachineVolumes,
Expand Down
12 changes: 8 additions & 4 deletions broker/machinebroker/server/machine_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ var _ = Describe("CreateMachine", func() {
},
Spec: &iri.MachineSpec{
Power: iri.Power_POWER_ON,
Image: &iri.ImageSpec{
Image: "example.org/foo:latest",
},
Class: machineClass.Name,
Volumes: []*iri.Volume{{
Name: "root",
LocalDisk: &iri.LocalDisk{
Image: &iri.ImageSpec{
Image: "example.org/foo:latest",
},
},
}},
},
},
})
Expand Down Expand Up @@ -64,7 +69,6 @@ var _ = Describe("CreateMachine", func() {
machinebrokerv1alpha1.LabelsAnnotation: encodedIRILabels,
}))
Expect(ironcoreMachine.Spec.Power).To(Equal(computev1alpha1.PowerOn))
Expect(ironcoreMachine.Spec.Image).To(Equal("example.org/foo:latest"))
Expect(ironcoreMachine.Spec.MachineClassRef.Name).To(Equal(machineClass.Name))
})
})
12 changes: 9 additions & 3 deletions broker/machinebroker/server/machine_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ var _ = Describe("DeleteMachine", func() {
},
Spec: &iri.MachineSpec{
Power: iri.Power_POWER_ON,
Image: &iri.ImageSpec{
Image: "example.org/foo:latest",
},
Class: machineClass.Name,

NetworkInterfaces: []*iri.NetworkInterface{
{
Name: "primary-nic",
Expand All @@ -43,6 +41,14 @@ var _ = Describe("DeleteMachine", func() {
},
},
Volumes: []*iri.Volume{
{
Name: "root",
LocalDisk: &iri.LocalDisk{
Image: &iri.ImageSpec{
Image: "example.org/foo:latest",
},
},
},
{
Name: "primary-volume",
Device: "oda",
Expand Down
13 changes: 9 additions & 4 deletions broker/machinebroker/server/machine_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ var _ = Describe("ListMachines", func() {
},
Spec: &iri.MachineSpec{
Power: iri.Power_POWER_ON,
Image: &iri.ImageSpec{
Image: "example.org/foo:latest",
},
Class: machineClass.Name,
NetworkInterfaces: []*iri.NetworkInterface{
{
Expand All @@ -41,7 +38,15 @@ var _ = Describe("ListMachines", func() {
Ips: []string{"10.0.0.1"},
},
},
Volumes: []*iri.Volume{

Volumes: []*iri.Volume{{
Name: "root",
LocalDisk: &iri.LocalDisk{
Image: &iri.ImageSpec{
Image: "example.org/foo:latest",
},
},
},
{
Name: "primary-volume",
Device: "oda",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ var _ = Describe("AttachNetworkInterface", func() {
Machine: &iri.Machine{
Spec: &iri.MachineSpec{
Power: iri.Power_POWER_ON,
Image: &iri.ImageSpec{
Image: "example.org/foo:latest",
},
Class: machineClass.Name,
Volumes: []*iri.Volume{{
Name: "root",
LocalDisk: &iri.LocalDisk{
Image: &iri.ImageSpec{
Image: "example.org/foo:latest",
},
},
}},
},
},
})
Expand Down Expand Up @@ -116,9 +121,14 @@ var _ = Describe("AttachNetworkInterface", func() {
Machine: &iri.Machine{
Spec: &iri.MachineSpec{
Power: iri.Power_POWER_ON,
Image: &iri.ImageSpec{
Image: "example.org/foo:latest",
},
Volumes: []*iri.Volume{{
Name: "root",
LocalDisk: &iri.LocalDisk{
Image: &iri.ImageSpec{
Image: "example.org/foo:latest",
},
},
}},
Class: machineClass.Name,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ var _ = Describe("DetachNetworkInterface", func() {
Machine: &iri.Machine{
Spec: &iri.MachineSpec{
Power: iri.Power_POWER_ON,
Image: &iri.ImageSpec{
Image: "example.org/foo:latest",
},
Volumes: []*iri.Volume{{
Name: "root",
LocalDisk: &iri.LocalDisk{
Image: &iri.ImageSpec{
Image: "example.org/foo:latest",
},
},
}},
Class: machineClass.Name,
NetworkInterfaces: []*iri.NetworkInterface{
{
Expand Down
23 changes: 13 additions & 10 deletions broker/machinebroker/server/machine_volume_attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import (
type IronCoreVolumeConfig struct {
Name string
Device string
EmptyDisk *IronCoreVolumeEmptyDiskConfig
LocalDisk *IronCoreVolumeLocalDiskConfig
Remote *IronCoreVolumeRemoteConfig
}

type IronCoreVolumeEmptyDiskConfig struct {
type IronCoreVolumeLocalDiskConfig struct {
SizeLimit *resource.Quantity
Image string
}

type IronCoreVolumeRemoteConfig struct {
Expand All @@ -44,17 +45,18 @@ type IronCoreVolumeRemoteConfig struct {

func (s *Server) getIronCoreVolumeConfig(volume *iri.Volume) (*IronCoreVolumeConfig, error) {
var (
emptyDisk *IronCoreVolumeEmptyDiskConfig
localDisk *IronCoreVolumeLocalDiskConfig
remote *IronCoreVolumeRemoteConfig
)
switch {
case volume.EmptyDisk != nil:
case volume.LocalDisk != nil:
var sizeLimit *resource.Quantity
if sizeBytes := volume.EmptyDisk.SizeBytes; sizeBytes > 0 {
if sizeBytes := volume.LocalDisk.SizeBytes; sizeBytes > 0 {
sizeLimit = resource.NewQuantity(sizeBytes, resource.DecimalSI)
}
emptyDisk = &IronCoreVolumeEmptyDiskConfig{
localDisk = &IronCoreVolumeLocalDiskConfig{
SizeLimit: sizeLimit,
Image: volume.LocalDisk.Image.Image,
}
case volume.Connection != nil:
remote = &IronCoreVolumeRemoteConfig{
Expand All @@ -72,7 +74,7 @@ func (s *Server) getIronCoreVolumeConfig(volume *iri.Volume) (*IronCoreVolumeCon
return &IronCoreVolumeConfig{
Name: volume.Name,
Device: volume.Device,
EmptyDisk: emptyDisk,
LocalDisk: localDisk,
Remote: remote,
}, nil
}
Expand Down Expand Up @@ -205,9 +207,10 @@ func (s *Server) createIronCoreVolume(
AccessSecret: accessSecret,
}
ironcoreVolumeSrc.VolumeRef = &corev1.LocalObjectReference{Name: ironcoreVolume.Name}
case cfg.EmptyDisk != nil:
ironcoreVolumeSrc.EmptyDisk = &computev1alpha1.EmptyDiskVolumeSource{
SizeLimit: cfg.EmptyDisk.SizeLimit,
case cfg.LocalDisk != nil:
ironcoreVolumeSrc.LocalDisk = &computev1alpha1.LocalDiskVolumeSource{
SizeLimit: cfg.LocalDisk.SizeLimit,
Image: cfg.LocalDisk.Image,
}
}
return &computev1alpha1.Volume{
Expand Down
Loading
Loading