Skip to content

Commit

Permalink
Move ports management outside of instances
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilienM committed Feb 20, 2024
1 parent 5b2cc5b commit 8ac779d
Show file tree
Hide file tree
Showing 25 changed files with 2,365 additions and 1,293 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha5/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestConvertFrom(t *testing.T) {
Spec: OpenStackMachineSpec{},
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\",\"image\":{}},\"status\":{\"ready\":false,\"referencedResources\":{}}}",
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\",\"image\":{}},\"status\":{\"dependentResources\":{},\"ready\":false,\"referencedResources\":{}}}",
},
},
},
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha5/zz_generated.conversion.go

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

10 changes: 9 additions & 1 deletion api/v1alpha6/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ func restorev1alpha8ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst
if previous.Bastion != nil {
dst.Bastion.ReferencedResources = previous.Bastion.ReferencedResources
}

if previous.Bastion != nil && previous.Bastion.DependentResources.PortsStatus != nil {
dst.Bastion.DependentResources.PortsStatus = previous.Bastion.DependentResources.PortsStatus
}
}

func restorev1alpha6ClusterSpec(previous *OpenStackClusterSpec, dst *OpenStackClusterSpec) {
Expand Down Expand Up @@ -328,7 +332,11 @@ var v1alpha8OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStack
},
restorev1alpha8MachineSpec,
),

"depresources": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackMachine) *infrav1.DependentMachineResources {
return &c.Status.DependentResources
},
),
// No equivalent in v1alpha6
"refresources": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackMachine) *infrav1.ReferencedMachineResources {
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha6/zz_generated.conversion.go

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

36 changes: 28 additions & 8 deletions api/v1alpha7/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,11 @@ var v1alpha8OpenStackClusterRestorer = conversion.RestorerFor[*infrav1.OpenStack
},
),
),

// No equivalent in v1alpha7
"bastionrefresources": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackCluster) *infrav1.ReferencedMachineResources {
if c.Status.Bastion == nil {
return nil
}
return &c.Status.Bastion.ReferencedResources
"status": conversion.HashedFieldRestorer(
func(c *infrav1.OpenStackCluster) *infrav1.OpenStackClusterStatus {
return &c.Status
},
restorev1alpha8ClusterStatus,
),
}

Expand Down Expand Up @@ -167,6 +163,16 @@ func restorev1alpha8ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *inf
dst.ManagedSubnets = previous.ManagedSubnets
}

func restorev1alpha8ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst *infrav1.OpenStackClusterStatus) {
if previous.Bastion != nil {
dst.Bastion.ReferencedResources = previous.Bastion.ReferencedResources
}

if previous.Bastion != nil && previous.Bastion.DependentResources.PortsStatus != nil {
dst.Bastion.DependentResources.PortsStatus = previous.Bastion.DependentResources.PortsStatus
}
}

func (r *OpenStackCluster) ConvertTo(dstRaw ctrlconversion.Hub) error {
dst := dstRaw.(*infrav1.OpenStackCluster)

Expand Down Expand Up @@ -269,6 +275,11 @@ var v1alpha8OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStack
},
restorev1alpha8MachineSpec,
),
"depresources": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackMachine) *infrav1.DependentMachineResources {
return &c.Status.DependentResources
},
),

// No equivalent in v1alpha7
"refresources": conversion.UnconditionalFieldRestorer(
Expand Down Expand Up @@ -535,3 +546,12 @@ func Convert_v1alpha8_OpenStackClusterSpec_To_v1alpha7_OpenStackClusterSpec(in *

return nil
}

func Convert_v1alpha8_OpenStackClusterStatus_To_v1alpha7_OpenStackClusterStatus(in *infrav1.OpenStackClusterStatus, out *OpenStackClusterStatus, s apiconversion.Scope) error {
err := autoConvert_v1alpha8_OpenStackClusterStatus_To_v1alpha7_OpenStackClusterStatus(in, out, s)
if err != nil {
return err
}

return nil
}
17 changes: 7 additions & 10 deletions api/v1alpha7/zz_generated.conversion.go

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

3 changes: 3 additions & 0 deletions api/v1alpha8/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ type OpenStackMachineStatus struct {
// ReferencedResources contains resolved references to resources that the machine depends on.
ReferencedResources ReferencedMachineResources `json:"referencedResources,omitempty"`

// DependentResources contains resolved dependent resources that were created by the machine.
DependentResources DependentMachineResources `json:"dependentResources,omitempty"`

FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"`

// FailureMessage will be set in the event that there is a terminal problem
Expand Down
17 changes: 17 additions & 0 deletions api/v1alpha8/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ type PortOpts struct {
ValueSpecs []ValueSpec `json:"valueSpecs,omitempty"`
}

type PortStatus struct {
// ID is the unique identifier of the port.
// +required
ID string `json:"id"`
}

type BindingProfile struct {
// OVSHWOffload enables or disables the OVS hardware offload feature.
OVSHWOffload bool `json:"ovsHWOffload,omitempty"`
Expand Down Expand Up @@ -175,6 +181,7 @@ type BastionStatus struct {
IP string `json:"ip,omitempty"`
FloatingIP string `json:"floatingIP,omitempty"`
ReferencedResources ReferencedMachineResources `json:"referencedResources,omitempty"`
DependentResources DependentMachineResources `json:"dependentResources,omitempty"`
}

type RootVolume struct {
Expand Down Expand Up @@ -399,6 +406,16 @@ type ReferencedMachineResources struct {
// ImageID is the ID of the image to use for the machine and is calculated based on ImageFilter.
// +optional
ImageID string `json:"imageID,omitempty"`

// portsOpts is the list of ports options to create for the machine.
// +optional
PortsOpts []PortOpts `json:"portsOpts,omitempty"`
}

type DependentMachineResources struct {
// PortsStatus is the status of the ports created for the machine.
// +optional
PortsStatus []PortStatus `json:"portsStatus,omitempty"`
}

// ValueSpec represents a single value_spec key-value pair.
Expand Down
50 changes: 47 additions & 3 deletions api/v1alpha8/zz_generated.deepcopy.go

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

Loading

0 comments on commit 8ac779d

Please sign in to comment.