Skip to content

Commit

Permalink
Rename DependentResources to Resources
Browse files Browse the repository at this point in the history
The intent of this structure is to hold all OpenStack resources created
for the machine, including the server. 'dependent' was redundant.
  • Loading branch information
mdbooth committed Mar 22, 2024
1 parent cb99e17 commit 5f09ba2
Show file tree
Hide file tree
Showing 20 changed files with 165 additions and 165 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha5/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestConvertFrom(t *testing.T) {
Spec: OpenStackMachineSpec{},
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"flavor\":\"\",\"image\":{}},\"status\":{\"dependentResources\":{},\"ready\":false,\"referencedResources\":{}}}",
"cluster.x-k8s.io/conversion-data": `{"spec":{"flavor":"","image":{}},"status":{"ready":false,"referencedResources":{},"resources":{}}}`,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha5/zz_generated.conversion.go

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

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.Ports != nil {
dst.Bastion.DependentResources.Ports = previous.Bastion.DependentResources.Ports
if previous.Bastion != nil && previous.Bastion.Resources.Ports != nil {
dst.Bastion.Resources.Ports = previous.Bastion.Resources.Ports
}
}

Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha6/openstackmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ var v1beta1OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStackM
restorev1beta1MachineSpec,
),
"depresources": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackMachine) *infrav1.DependentMachineResources {
return &c.Status.DependentResources
func(c *infrav1.OpenStackMachine) *infrav1.MachineResources {
return &c.Status.Resources
},
),
// No equivalent in v1alpha6
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha6/zz_generated.conversion.go

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha7/openstackmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ var v1beta1OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStackM
restorev1beta1MachineSpec,
),
"depresources": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackMachine) *infrav1.DependentMachineResources {
return &c.Status.DependentResources
func(c *infrav1.OpenStackMachine) *infrav1.MachineResources {
return &c.Status.Resources
},
),
// No equivalent in v1alpha7
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha7/zz_generated.conversion.go

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

4 changes: 2 additions & 2 deletions api/v1beta1/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ 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"`
// Resources contains references to OpenStack resources created for the machine.
Resources MachineResources `json:"resources,omitempty"`

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

Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ type BastionStatus struct {
IP string `json:"ip,omitempty"`
FloatingIP string `json:"floatingIP,omitempty"`
ReferencedResources ReferencedMachineResources `json:"referencedResources,omitempty"`
DependentResources DependentMachineResources `json:"dependentResources,omitempty"`
Resources MachineResources `json:"resources,omitempty"`
}

type RootVolume struct {
Expand Down Expand Up @@ -673,7 +673,7 @@ type ReferencedMachineResources struct {
Ports []ResolvedPortSpec `json:"ports,omitempty"`
}

type DependentMachineResources struct {
type MachineResources struct {
// Ports is the status of the ports created for the machine.
// +optional
Ports []PortStatus `json:"ports,omitempty"`
Expand Down
44 changes: 22 additions & 22 deletions api/v1beta1/zz_generated.deepcopy.go

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

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

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

20 changes: 10 additions & 10 deletions controllers/openstackcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func contains(arr []string, target string) bool {
}

func resolveBastionResources(scope *scope.WithLogger, clusterResourceName string, openStackCluster *infrav1.OpenStackCluster) (bool, error) {
// Resolve and store referenced & dependent resources for the bastion
// Resolve and store resources for the bastion
if openStackCluster.Spec.Bastion != nil && openStackCluster.Spec.Bastion.Enabled {
if openStackCluster.Status.Bastion == nil {
openStackCluster.Status.Bastion = &infrav1.BastionStatus{}
Expand All @@ -239,9 +239,9 @@ func resolveBastionResources(scope *scope.WithLogger, clusterResourceName string
return true, nil
}

err = compute.AdoptDependentMachineResources(scope,
err = compute.AdoptMachineResources(scope,
&openStackCluster.Status.Bastion.ReferencedResources,
&openStackCluster.Status.Bastion.DependentResources)
&openStackCluster.Status.Bastion.Resources)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -308,18 +308,18 @@ func deleteBastion(scope *scope.WithLogger, cluster *clusterv1.Cluster, openStac
}
}

if openStackCluster.Status.Bastion != nil && len(openStackCluster.Status.Bastion.DependentResources.Ports) > 0 {
if openStackCluster.Status.Bastion != nil && len(openStackCluster.Status.Bastion.Resources.Ports) > 0 {
trunkSupported, err := networkingService.IsTrunkExtSupported()
if err != nil {
return err
}
for _, port := range openStackCluster.Status.Bastion.DependentResources.Ports {
for _, port := range openStackCluster.Status.Bastion.Resources.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.Ports = nil
openStackCluster.Status.Bastion.Resources.Ports = nil
}

scope.Logger().Info("Deleted Bastion")
Expand Down Expand Up @@ -445,7 +445,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 nil, fmt.Errorf("failed to get or create ports for bastion: %w", err)
}
bastionPortIDs := GetPortIDs(openStackCluster.Status.Bastion.DependentResources.Ports)
bastionPortIDs := GetPortIDs(openStackCluster.Status.Bastion.Resources.Ports)

var instanceStatus *compute.InstanceStatus
if openStackCluster.Status.Bastion != nil && openStackCluster.Status.Bastion.ID != "" {
Expand Down Expand Up @@ -579,13 +579,13 @@ func getBastionSecurityGroupID(openStackCluster *infrav1.OpenStackCluster) *stri

func getOrCreateBastionPorts(openStackCluster *infrav1.OpenStackCluster, networkingService *networking.Service) error {
desiredPorts := openStackCluster.Status.Bastion.ReferencedResources.Ports
dependentResources := &openStackCluster.Status.Bastion.DependentResources
resources := &openStackCluster.Status.Bastion.Resources

if len(desiredPorts) == len(dependentResources.Ports) {
if len(desiredPorts) == len(resources.Ports) {
return nil
}

err := networkingService.CreatePorts(openStackCluster, desiredPorts, dependentResources)
err := networkingService.CreatePorts(openStackCluster, desiredPorts, resources)
if err != nil {
return fmt.Errorf("failed to create ports for bastion %s: %w", bastionName(openStackCluster.Name), err)
}
Expand Down
Loading

0 comments on commit 5f09ba2

Please sign in to comment.