Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Rename Ports fields in status #1938

Merged
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
4 changes: 2 additions & 2 deletions api/v1alpha6/openstackcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ func restorev1beta1ClusterStatus(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
if previous.Bastion != nil && previous.Bastion.DependentResources.Ports != nil {
dst.Bastion.DependentResources.Ports = previous.Bastion.DependentResources.Ports
}
}

Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha7/openstackcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ func restorev1beta1ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst *
dst.Bastion.ReferencedResources = previous.Bastion.ReferencedResources
}

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

Expand Down
8 changes: 4 additions & 4 deletions api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,15 +654,15 @@ type ReferencedMachineResources struct {
// +optional
ImageID string `json:"imageID,omitempty"`

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

type DependentMachineResources struct {
// PortsStatus is the status of the ports created for the machine.
// Ports is the status of the ports created for the machine.
// +optional
PortsStatus []PortStatus `json:"portsStatus,omitempty"`
Ports []PortStatus `json:"ports,omitempty"`
Comment on lines 656 to +665
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it should have documentation entry added?

}

// ValueSpec represents a single value_spec key-value pair.
Expand Down
8 changes: 4 additions & 4 deletions api/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -6201,9 +6201,9 @@ spec:
properties:
dependentResources:
properties:
portsStatus:
description: PortsStatus is the status of the ports created
for the machine.
ports:
description: Ports is the status of the ports created for
the machine.
items:
properties:
id:
Expand All @@ -6230,9 +6230,9 @@ spec:
description: ImageID is the ID of the image to use for the
machine and is calculated based on ImageFilter.
type: string
portsOpts:
description: portsOpts is the list of ports options to create
for the machine.
ports:
description: Ports is the fully resolved list of ports to
create for the machine.
items:
properties:
adminStateUp:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2396,9 +2396,9 @@ spec:
description: DependentResources contains resolved dependent resources
that were created by the machine.
properties:
portsStatus:
description: PortsStatus is the status of the ports created for
the machine.
ports:
description: Ports is the status of the ports created for the
machine.
items:
properties:
id:
Expand Down Expand Up @@ -2449,8 +2449,8 @@ spec:
description: ImageID is the ID of the image to use for the machine
and is calculated based on ImageFilter.
type: string
portsOpts:
description: portsOpts is the list of ports options to create
ports:
description: Ports is the fully resolved list of ports to create
for the machine.
items:
properties:
Expand Down
24 changes: 12 additions & 12 deletions controllers/openstackcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,18 @@ func deleteBastion(scope *scope.WithLogger, cluster *clusterv1.Cluster, openStac
}
}

if openStackCluster.Status.Bastion != nil && len(openStackCluster.Status.Bastion.DependentResources.PortsStatus) > 0 {
if openStackCluster.Status.Bastion != nil && len(openStackCluster.Status.Bastion.DependentResources.Ports) > 0 {
trunkSupported, err := networkingService.IsTrunkExtSupported()
if err != nil {
return err
}
for _, port := range openStackCluster.Status.Bastion.DependentResources.PortsStatus {
for _, port := range openStackCluster.Status.Bastion.DependentResources.Ports {
if err := networkingService.DeleteInstanceTrunkAndPort(openStackCluster, port, trunkSupported); err != nil {
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to delete port: %w", err))
return fmt.Errorf("failed to delete port: %w", err)
}
}
openStackCluster.Status.Bastion.DependentResources.PortsStatus = nil
openStackCluster.Status.Bastion.DependentResources.Ports = nil
}

scope.Logger().Info("Deleted Bastion for cluster %s", cluster.Name)
Expand Down Expand Up @@ -375,7 +375,7 @@ func reconcileBastion(scope *scope.WithLogger, cluster *clusterv1.Cluster, openS

// If ports options aren't in the status, we'll re-trigger the reconcile to get them
// via adopting the referenced resources.
if len(openStackCluster.Status.Bastion.ReferencedResources.PortsOpts) == 0 {
if len(openStackCluster.Status.Bastion.ReferencedResources.Ports) == 0 {
return reconcile.Result{}, nil
}

Expand Down Expand Up @@ -409,7 +409,7 @@ func reconcileBastion(scope *scope.WithLogger, cluster *clusterv1.Cluster, openS
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to get or create ports for bastion: %w", err))
return ctrl.Result{}, fmt.Errorf("failed to get or create ports for bastion: %w", err)
}
bastionPortIDs := GetPortIDs(openStackCluster.Status.Bastion.DependentResources.PortsStatus)
bastionPortIDs := GetPortIDs(openStackCluster.Status.Bastion.DependentResources.Ports)

var instanceStatus *compute.InstanceStatus
if openStackCluster.Status.Bastion != nil && openStackCluster.Status.Bastion.ID != "" {
Expand Down Expand Up @@ -555,12 +555,12 @@ func getOrCreateBastionPorts(scope *scope.WithLogger, cluster *clusterv1.Cluster
openStackCluster.Status.Bastion = &infrav1.BastionStatus{}
}

desiredPorts := openStackCluster.Status.Bastion.ReferencedResources.PortsOpts
portsToCreate := networking.MissingPorts(openStackCluster.Status.Bastion.DependentResources.PortsStatus, desiredPorts)
desiredPorts := openStackCluster.Status.Bastion.ReferencedResources.Ports
portsToCreate := networking.MissingPorts(openStackCluster.Status.Bastion.DependentResources.Ports, desiredPorts)

// Sanity check that the number of desired ports is equal to the addition of ports to create and ports that already exist.
if len(desiredPorts) != len(portsToCreate)+len(openStackCluster.Status.Bastion.DependentResources.PortsStatus) {
return fmt.Errorf("length of desired ports (%d) is not equal to the length of ports to create (%d) + the length of ports that already exist (%d)", len(desiredPorts), len(portsToCreate), len(openStackCluster.Status.Bastion.DependentResources.PortsStatus))
if len(desiredPorts) != len(portsToCreate)+len(openStackCluster.Status.Bastion.DependentResources.Ports) {
return fmt.Errorf("length of desired ports (%d) is not equal to the length of ports to create (%d) + the length of ports that already exist (%d)", len(desiredPorts), len(portsToCreate), len(openStackCluster.Status.Bastion.DependentResources.Ports))
}

if len(portsToCreate) > 0 {
Expand All @@ -570,12 +570,12 @@ func getOrCreateBastionPorts(scope *scope.WithLogger, cluster *clusterv1.Cluster
return fmt.Errorf("failed to create ports for bastion %s: %w", bastionName(openStackCluster.Name), err)
}

openStackCluster.Status.Bastion.DependentResources.PortsStatus = append(openStackCluster.Status.Bastion.DependentResources.PortsStatus, bastionPortsStatus...)
openStackCluster.Status.Bastion.DependentResources.Ports = append(openStackCluster.Status.Bastion.DependentResources.Ports, bastionPortsStatus...)
}

// Sanity check that the number of ports that have been put into PortsStatus is equal to the number of desired ports now that we have created them all.
if len(openStackCluster.Status.Bastion.DependentResources.PortsStatus) != len(desiredPorts) {
return fmt.Errorf("length of ports that already exist (%d) is not equal to the length of desired ports (%d)", len(openStackCluster.Status.Bastion.DependentResources.PortsStatus), len(desiredPorts))
if len(openStackCluster.Status.Bastion.DependentResources.Ports) != len(desiredPorts) {
return fmt.Errorf("length of ports that already exist (%d) is not equal to the length of desired ports (%d)", len(openStackCluster.Status.Bastion.DependentResources.Ports), len(desiredPorts))
}

return nil
Expand Down
28 changes: 14 additions & 14 deletions controllers/openstackcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ var _ = Describe("OpenStackCluster controller", func() {
Bastion: &infrav1.BastionStatus{
ReferencedResources: infrav1.ReferencedMachineResources{
ImageID: "imageID",
PortsOpts: []infrav1.PortOpts{
Ports: []infrav1.PortOpts{
{
Network: &infrav1.NetworkFilter{
ID: "network-id",
Expand All @@ -243,7 +243,7 @@ var _ = Describe("OpenStackCluster controller", func() {
},
},
DependentResources: infrav1.DependentMachineResources{
PortsStatus: []infrav1.PortStatus{
Ports: []infrav1.PortStatus{
{
ID: "portID1",
},
Expand Down Expand Up @@ -285,7 +285,7 @@ var _ = Describe("OpenStackCluster controller", func() {
State: "ACTIVE",
ReferencedResources: infrav1.ReferencedMachineResources{
ImageID: "imageID",
PortsOpts: []infrav1.PortOpts{
Ports: []infrav1.PortOpts{
{
Network: &infrav1.NetworkFilter{
ID: "network-id",
Expand All @@ -294,7 +294,7 @@ var _ = Describe("OpenStackCluster controller", func() {
},
},
DependentResources: infrav1.DependentMachineResources{
PortsStatus: []infrav1.PortStatus{
Ports: []infrav1.PortStatus{
{
ID: "portID1",
},
Expand Down Expand Up @@ -326,7 +326,7 @@ var _ = Describe("OpenStackCluster controller", func() {
ID: "adopted-fip-bastion-uuid",
ReferencedResources: infrav1.ReferencedMachineResources{
ImageID: "imageID",
PortsOpts: []infrav1.PortOpts{
Ports: []infrav1.PortOpts{
{
Network: &infrav1.NetworkFilter{
ID: "network-id",
Expand All @@ -335,7 +335,7 @@ var _ = Describe("OpenStackCluster controller", func() {
},
},
DependentResources: infrav1.DependentMachineResources{
PortsStatus: []infrav1.PortStatus{
Ports: []infrav1.PortStatus{
{
ID: "portID1",
},
Expand Down Expand Up @@ -370,7 +370,7 @@ var _ = Describe("OpenStackCluster controller", func() {
State: "ACTIVE",
ReferencedResources: infrav1.ReferencedMachineResources{
ImageID: "imageID",
PortsOpts: []infrav1.PortOpts{
Ports: []infrav1.PortOpts{
{
Network: &infrav1.NetworkFilter{
ID: "network-id",
Expand All @@ -379,7 +379,7 @@ var _ = Describe("OpenStackCluster controller", func() {
},
},
DependentResources: infrav1.DependentMachineResources{
PortsStatus: []infrav1.PortStatus{
Ports: []infrav1.PortStatus{
{
ID: "portID1",
},
Expand Down Expand Up @@ -411,7 +411,7 @@ var _ = Describe("OpenStackCluster controller", func() {
ID: "requeue-bastion-uuid",
ReferencedResources: infrav1.ReferencedMachineResources{
ImageID: "imageID",
PortsOpts: []infrav1.PortOpts{
Ports: []infrav1.PortOpts{
{
Network: &infrav1.NetworkFilter{
ID: "network-id",
Expand All @@ -420,7 +420,7 @@ var _ = Describe("OpenStackCluster controller", func() {
},
},
DependentResources: infrav1.DependentMachineResources{
PortsStatus: []infrav1.PortStatus{
Ports: []infrav1.PortStatus{
{
ID: "portID1",
},
Expand Down Expand Up @@ -449,7 +449,7 @@ var _ = Describe("OpenStackCluster controller", func() {
State: "BUILD",
ReferencedResources: infrav1.ReferencedMachineResources{
ImageID: "imageID",
PortsOpts: []infrav1.PortOpts{
Ports: []infrav1.PortOpts{
{
Network: &infrav1.NetworkFilter{
ID: "network-id",
Expand All @@ -458,7 +458,7 @@ var _ = Describe("OpenStackCluster controller", func() {
},
},
DependentResources: infrav1.DependentMachineResources{
PortsStatus: []infrav1.PortStatus{
Ports: []infrav1.PortStatus{
{
ID: "portID1",
},
Expand Down Expand Up @@ -532,7 +532,7 @@ var _ = Describe("OpenStackCluster controller", func() {
testCluster.Status = infrav1.OpenStackClusterStatus{
Bastion: &infrav1.BastionStatus{
DependentResources: infrav1.DependentMachineResources{
PortsStatus: []infrav1.PortStatus{
Ports: []infrav1.PortStatus{
{
ID: "port-id",
},
Expand Down Expand Up @@ -616,7 +616,7 @@ var _ = Describe("OpenStackCluster controller", func() {
testCluster.Status = infrav1.OpenStackClusterStatus{
Bastion: &infrav1.BastionStatus{
DependentResources: infrav1.DependentMachineResources{
PortsStatus: []infrav1.PortStatus{
Ports: []infrav1.PortStatus{
{
ID: "port-id",
},
Expand Down
18 changes: 9 additions & 9 deletions controllers/openstackmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (r *OpenStackMachineReconciler) reconcileDelete(scope *scope.WithLogger, cl
return ctrl.Result{}, err
}

portsStatus := openStackMachine.Status.DependentResources.PortsStatus
portsStatus := openStackMachine.Status.DependentResources.Ports
for _, port := range portsStatus {
if err := networkingService.DeleteInstanceTrunkAndPort(openStackMachine, port, trunkSupported); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to delete port %q: %w", port.ID, err)
Expand Down Expand Up @@ -383,7 +383,7 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope
if err != nil {
return ctrl.Result{}, err
}
portIDs := GetPortIDs(openStackMachine.Status.DependentResources.PortsStatus)
portIDs := GetPortIDs(openStackMachine.Status.DependentResources.Ports)

instanceStatus, err := r.getOrCreateInstance(scope.Logger(), openStackCluster, machine, openStackMachine, computeService, userData, portIDs)
if err != nil || instanceStatus == nil {
Expand Down Expand Up @@ -498,12 +498,12 @@ func getOrCreateMachinePorts(scope *scope.WithLogger, openStackCluster *infrav1.
var machinePortsStatus []infrav1.PortStatus
var err error

desiredPorts := openStackMachine.Status.ReferencedResources.PortsOpts
portsToCreate := networking.MissingPorts(openStackMachine.Status.DependentResources.PortsStatus, desiredPorts)
desiredPorts := openStackMachine.Status.ReferencedResources.Ports
portsToCreate := networking.MissingPorts(openStackMachine.Status.DependentResources.Ports, desiredPorts)

// Sanity check that the number of desired ports is equal to the addition of ports to create and ports that already exist.
if len(desiredPorts) != len(portsToCreate)+len(openStackMachine.Status.DependentResources.PortsStatus) {
return fmt.Errorf("length of desired ports (%d) is not equal to the length of ports to create (%d) + the length of ports that already exist (%d)", len(desiredPorts), len(portsToCreate), len(openStackMachine.Status.DependentResources.PortsStatus))
if len(desiredPorts) != len(portsToCreate)+len(openStackMachine.Status.DependentResources.Ports) {
return fmt.Errorf("length of desired ports (%d) is not equal to the length of ports to create (%d) + the length of ports that already exist (%d)", len(desiredPorts), len(portsToCreate), len(openStackMachine.Status.DependentResources.Ports))
}

if len(portsToCreate) > 0 {
Expand All @@ -513,12 +513,12 @@ func getOrCreateMachinePorts(scope *scope.WithLogger, openStackCluster *infrav1.
if err != nil {
return fmt.Errorf("create ports: %w", err)
}
openStackMachine.Status.DependentResources.PortsStatus = append(openStackMachine.Status.DependentResources.PortsStatus, machinePortsStatus...)
openStackMachine.Status.DependentResources.Ports = append(openStackMachine.Status.DependentResources.Ports, machinePortsStatus...)
}

// Sanity check that the number of ports that have been put into PortsStatus is equal to the number of desired ports now that we have created them all.
if len(openStackMachine.Status.DependentResources.PortsStatus) != len(desiredPorts) {
return fmt.Errorf("length of ports that already exist (%d) is not equal to the length of desired ports (%d)", len(openStackMachine.Status.DependentResources.PortsStatus), len(desiredPorts))
if len(openStackMachine.Status.DependentResources.Ports) != len(desiredPorts) {
return fmt.Errorf("length of ports that already exist (%d) is not equal to the length of desired ports (%d)", len(openStackMachine.Status.DependentResources.Ports), len(desiredPorts))
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions docs/book/src/api/v1beta1/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ further information.</p>
<tbody>
<tr>
<td>
<code>portsStatus</code><br/>
<code>ports</code><br/>
<em>
<a href="#infrastructure.cluster.x-k8s.io/v1beta1.PortStatus">
[]PortStatus
Expand All @@ -1405,7 +1405,7 @@ further information.</p>
</td>
<td>
<em>(Optional)</em>
<p>PortsStatus is the status of the ports created for the machine.</p>
<p>Ports is the status of the ports created for the machine.</p>
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -3895,7 +3895,7 @@ string
</tr>
<tr>
<td>
<code>portsOpts</code><br/>
<code>ports</code><br/>
<em>
<a href="#infrastructure.cluster.x-k8s.io/v1beta1.PortOpts">
[]PortOpts
Expand All @@ -3904,7 +3904,7 @@ string
</td>
<td>
<em>(Optional)</em>
<p>portsOpts is the list of ports options to create for the machine.</p>
<p>Ports is the fully resolved list of ports to create for the machine.</p>
</td>
</tr>
</tbody>
Expand Down
Loading