Skip to content

Commit

Permalink
Rename ReferencedResources to Resolved
Browse files Browse the repository at this point in the history
This struct has already moved beyond external references, and seems be
evolving towards a fully-resolved machine spec. For want of a better
name we call it 'resolved', which is more accurate.
  • Loading branch information
mdbooth committed Mar 22, 2024
1 parent 39038b9 commit ada7741
Show file tree
Hide file tree
Showing 22 changed files with 146 additions and 143 deletions.
4 changes: 2 additions & 2 deletions api/v1alpha5/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func Convert_v1alpha5_Instance_To_v1beta1_BastionStatus(in *Instance, out *infra
out.State = infrav1.InstanceState(in.State)
out.IP = in.IP
out.FloatingIP = in.FloatingIP
out.ReferencedResources.ServerGroupID = in.ServerGroupID
out.Resolved.ServerGroupID = in.ServerGroupID
return nil
}

Expand All @@ -467,7 +467,7 @@ func Convert_v1beta1_BastionStatus_To_v1alpha5_Instance(in *infrav1.BastionStatu
out.State = InstanceState(in.State)
out.IP = in.IP
out.FloatingIP = in.FloatingIP
out.ServerGroupID = in.ReferencedResources.ServerGroupID
out.ServerGroupID = in.Resolved.ServerGroupID
return nil
}

Expand Down
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":{"ready":false,"referencedResources":{},"resources":{}}}`,
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"flavor\":\"\",\"image\":{}},\"status\":{\"ready\":false,\"resolved\":{},\"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.

2 changes: 1 addition & 1 deletion api/v1alpha6/openstackcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func restorev1beta1ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst *
dst.BastionSecurityGroup = previous.BastionSecurityGroup

if previous.Bastion != nil {
dst.Bastion.ReferencedResources = previous.Bastion.ReferencedResources
dst.Bastion.Resolved = previous.Bastion.Resolved
}
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 @@ -96,8 +96,8 @@ var v1beta1OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStackM
),
// No equivalent in v1alpha6
"refresources": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackMachine) *infrav1.ReferencedMachineResources {
return &c.Status.ReferencedResources
func(c *infrav1.OpenStackMachine) *infrav1.ResolvedMachineSpec {
return &c.Status.Resolved
},
),
}
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.

2 changes: 1 addition & 1 deletion api/v1alpha7/openstackcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func restorev1alpha7ClusterStatus(previous *OpenStackClusterStatus, dst *OpenSta
func restorev1beta1ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst *infrav1.OpenStackClusterStatus) {
// ReferencedResources have no equivalent in v1alpha7
if previous.Bastion != nil {
dst.Bastion.ReferencedResources = previous.Bastion.ReferencedResources
dst.Bastion.Resolved = previous.Bastion.Resolved
}

if previous.Bastion != nil && previous.Bastion.Resources.Ports != nil {
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 @@ -83,8 +83,8 @@ var v1beta1OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStackM
),
// No equivalent in v1alpha7
"refresources": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackMachine) *infrav1.ReferencedMachineResources {
return &c.Status.ReferencedResources
func(c *infrav1.OpenStackMachine) *infrav1.ResolvedMachineSpec {
return &c.Status.Resolved
},
),
}
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.

5 changes: 3 additions & 2 deletions api/v1beta1/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ type OpenStackMachineStatus struct {
// +optional
InstanceState *InstanceState `json:"instanceState,omitempty"`

// ReferencedResources contains resolved references to resources that the machine depends on.
ReferencedResources ReferencedMachineResources `json:"referencedResources,omitempty"`
// Resolved contains parts of the machine spec with all external
// references fully resolved.
Resolved ResolvedMachineSpec `json:"resolved,omitempty"`

// Resources contains references to OpenStack resources created for the machine.
Resources MachineResources `json:"resources,omitempty"`
Expand Down
20 changes: 10 additions & 10 deletions api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,14 @@ type AddressPair struct {
}

type BastionStatus struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
SSHKeyName string `json:"sshKeyName,omitempty"`
State InstanceState `json:"state,omitempty"`
IP string `json:"ip,omitempty"`
FloatingIP string `json:"floatingIP,omitempty"`
ReferencedResources ReferencedMachineResources `json:"referencedResources,omitempty"`
Resources MachineResources `json:"resources,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
SSHKeyName string `json:"sshKeyName,omitempty"`
State InstanceState `json:"state,omitempty"`
IP string `json:"ip,omitempty"`
FloatingIP string `json:"floatingIP,omitempty"`
Resolved ResolvedMachineSpec `json:"resolved,omitempty"`
Resources MachineResources `json:"resources,omitempty"`
}

type RootVolume struct {
Expand Down Expand Up @@ -658,8 +658,8 @@ func (s *APIServerLoadBalancer) IsEnabled() bool {
return s != nil && (s.Enabled == nil || *s.Enabled)
}

// ReferencedMachineResources contains resolved references to resources required by the machine.
type ReferencedMachineResources struct {
// ResolvedMachineSpec contains resolved references to resources required by the machine.
type ResolvedMachineSpec struct {
// ServerGroupID is the ID of the server group the machine should be added to and is calculated based on ServerGroupFilter.
// +optional
ServerGroupID string `json:"serverGroupID,omitempty"`
Expand Down
48 changes: 24 additions & 24 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.

16 changes: 8 additions & 8 deletions controllers/openstackcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,20 @@ func resolveBastionResources(scope *scope.WithLogger, clusterResourceName string
if openStackCluster.Spec.Bastion.Spec == nil {
return false, fmt.Errorf("bastion spec is nil when bastion is enabled, this shouldn't happen")
}
changed, err := compute.ResolveReferencedMachineResources(scope,
openStackCluster.Spec.Bastion.Spec, &openStackCluster.Status.Bastion.ReferencedResources,
changed, err := compute.ResolveMachineSpec(scope,
openStackCluster.Spec.Bastion.Spec, &openStackCluster.Status.Bastion.Resolved,
clusterResourceName, bastionName(clusterResourceName),
openStackCluster, getBastionSecurityGroupID(openStackCluster))
if err != nil {
return false, err
}
if changed {
// If the referenced resources have changed, we need to update the OpenStackCluster status now.
// If the resolved machine spec changed we need to restart the reconcile to avoid inconsistencies between reconciles.
return true, nil
}

err = compute.AdoptMachineResources(scope,
&openStackCluster.Status.Bastion.ReferencedResources,
&openStackCluster.Status.Bastion.Resolved,
&openStackCluster.Status.Bastion.Resources)
if err != nil {
return false, err
Expand Down Expand Up @@ -542,16 +542,16 @@ func bastionToInstanceSpec(openStackCluster *infrav1.OpenStackCluster, cluster *
// v1beta1 API validations prevent this from happening in normal circumstances.
bastion.Spec = &infrav1.OpenStackMachineSpec{}
}
referencedResources := &openStackCluster.Status.Bastion.ReferencedResources
resolved := &openStackCluster.Status.Bastion.Resolved

machineSpec := bastion.Spec
instanceSpec := &compute.InstanceSpec{
Name: bastionName(cluster.Name),
Flavor: machineSpec.Flavor,
SSHKeyName: machineSpec.SSHKeyName,
ImageID: referencedResources.ImageID,
ImageID: resolved.ImageID,
RootVolume: machineSpec.RootVolume,
ServerGroupID: referencedResources.ServerGroupID,
ServerGroupID: resolved.ServerGroupID,
Tags: compute.InstanceTags(machineSpec, openStackCluster),
}
if bastion.AvailabilityZone != nil {
Expand All @@ -578,7 +578,7 @@ func getBastionSecurityGroupID(openStackCluster *infrav1.OpenStackCluster) *stri
}

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

if len(desiredPorts) == len(resources.Ports) {
Expand Down
14 changes: 7 additions & 7 deletions controllers/openstackcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ var _ = Describe("OpenStackCluster controller", func() {
Expect(err).To(BeNil())
testCluster.Status = infrav1.OpenStackClusterStatus{
Bastion: &infrav1.BastionStatus{
ReferencedResources: infrav1.ReferencedMachineResources{
Resolved: infrav1.ResolvedMachineSpec{
ImageID: "imageID",
Ports: []infrav1.ResolvedPortSpec{
{
Expand Down Expand Up @@ -286,7 +286,7 @@ var _ = Describe("OpenStackCluster controller", func() {
expectedStatus := &infrav1.BastionStatus{
ID: "adopted-bastion-uuid",
State: "ACTIVE",
ReferencedResources: infrav1.ReferencedMachineResources{
Resolved: infrav1.ResolvedMachineSpec{
ImageID: "imageID",
Ports: []infrav1.ResolvedPortSpec{
{
Expand Down Expand Up @@ -327,7 +327,7 @@ var _ = Describe("OpenStackCluster controller", func() {
},
Bastion: &infrav1.BastionStatus{
ID: "adopted-fip-bastion-uuid",
ReferencedResources: infrav1.ReferencedMachineResources{
Resolved: infrav1.ResolvedMachineSpec{
ImageID: "imageID",
Ports: []infrav1.ResolvedPortSpec{
{
Expand Down Expand Up @@ -369,7 +369,7 @@ var _ = Describe("OpenStackCluster controller", func() {
ID: "adopted-fip-bastion-uuid",
FloatingIP: "1.2.3.4",
State: "ACTIVE",
ReferencedResources: infrav1.ReferencedMachineResources{
Resolved: infrav1.ResolvedMachineSpec{
ImageID: "imageID",
Ports: []infrav1.ResolvedPortSpec{
{
Expand Down Expand Up @@ -409,7 +409,7 @@ var _ = Describe("OpenStackCluster controller", func() {
},
Bastion: &infrav1.BastionStatus{
ID: "requeue-bastion-uuid",
ReferencedResources: infrav1.ReferencedMachineResources{
Resolved: infrav1.ResolvedMachineSpec{
ImageID: "imageID",
Ports: []infrav1.ResolvedPortSpec{
{
Expand Down Expand Up @@ -445,7 +445,7 @@ var _ = Describe("OpenStackCluster controller", func() {
Expect(testCluster.Status.Bastion).To(Equal(&infrav1.BastionStatus{
ID: "requeue-bastion-uuid",
State: "BUILD",
ReferencedResources: infrav1.ReferencedMachineResources{
Resolved: infrav1.ResolvedMachineSpec{
ImageID: "imageID",
Ports: []infrav1.ResolvedPortSpec{
{
Expand Down Expand Up @@ -475,7 +475,7 @@ var _ = Describe("OpenStackCluster controller", func() {
Expect(err).To(BeNil())
testCluster.Status = infrav1.OpenStackClusterStatus{
Bastion: &infrav1.BastionStatus{
ReferencedResources: infrav1.ReferencedMachineResources{
Resolved: infrav1.ResolvedMachineSpec{
ImageID: "imageID",
},
},
Expand Down
Loading

0 comments on commit ada7741

Please sign in to comment.