Skip to content

Commit

Permalink
API changes for Dependent & Referenced resources
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilienM committed Feb 27, 2024
1 parent 9c7f4a9 commit 0f41913
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 122 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\":{\"dependentResources\":{},\"ready\":false,\"referencedResources\":{}}}",
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\",\"image\":{}},\"status\":{\"ready\":false}}",
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions api/v1alpha6/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ func restorev1alpha8ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst
dst.WorkerSecurityGroup = previous.WorkerSecurityGroup
dst.BastionSecurityGroup = previous.BastionSecurityGroup

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

Expand Down Expand Up @@ -379,13 +379,13 @@ var v1alpha8OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStack
restorev1alpha8MachineSpec,
),
"depresources": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackMachine) *infrav1.DependentMachineResources {
func(c *infrav1.OpenStackMachine) **infrav1.DependentMachineResources {
return &c.Status.DependentResources
},
),
// No equivalent in v1alpha6
"refresources": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackMachine) *infrav1.ReferencedMachineResources {
func(c *infrav1.OpenStackMachine) **infrav1.ReferencedMachineResources {
return &c.Status.ReferencedResources
},
),
Expand Down
10 changes: 5 additions & 5 deletions api/v1alpha7/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ func restorev1alpha8ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst
restorev1alpha8SecurityGroupStatus(previous.BastionSecurityGroup, dst.BastionSecurityGroup)

// ReferencedResources have no equivalent in v1alpha7
if previous.Bastion != nil {
if previous.Bastion != nil && previous.Bastion.ReferencedResources != 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 != nil {
dst.Bastion.DependentResources = previous.Bastion.DependentResources
}
}

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

// No equivalent in v1alpha7
"refresources": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackMachine) *infrav1.ReferencedMachineResources {
func(c *infrav1.OpenStackMachine) **infrav1.ReferencedMachineResources {
return &c.Status.ReferencedResources
},
),
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha8/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ type OpenStackMachineStatus struct {
InstanceState *InstanceState `json:"instanceState,omitempty"`

// ReferencedResources contains resolved references to resources that the machine depends on.
ReferencedResources ReferencedMachineResources `json:"referencedResources,omitempty"`
ReferencedResources *ReferencedMachineResources `json:"referencedResources,omitempty"`

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

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

Expand Down
16 changes: 8 additions & 8 deletions api/v1alpha8/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,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"`
DependentResources DependentMachineResources `json:"dependentResources,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"`
ReferencedResources *ReferencedMachineResources `json:"referencedResources,omitempty"`
DependentResources *DependentMachineResources `json:"dependentResources,omitempty"`
}

type RootVolume struct {
Expand Down
24 changes: 20 additions & 4 deletions api/v1alpha8/zz_generated.deepcopy.go

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

28 changes: 15 additions & 13 deletions controllers/openstackcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,22 @@ func (r *OpenStackClusterReconciler) Reconcile(ctx context.Context, req ctrl.Req
if openStackCluster.Status.Bastion == nil {
openStackCluster.Status.Bastion = &infrav1.BastionStatus{}
}
changed, err := compute.ResolveReferencedMachineResources(scope, openStackCluster, &openStackCluster.Spec.Bastion.Instance, &openStackCluster.Status.Bastion.ReferencedResources)
if err != nil {
return reconcile.Result{}, err
}
if changed {
if openStackCluster.Status.Bastion.ReferencedResources == nil {
openStackCluster.Status.Bastion.ReferencedResources = &infrav1.ReferencedMachineResources{}
err := compute.ResolveReferencedMachineResources(scope, openStackCluster, &openStackCluster.Spec.Bastion.Instance, openStackCluster.Status.Bastion.ReferencedResources)
if err != nil {
return reconcile.Result{}, err
}
// If the referenced resources have changed, we need to update the OpenStackCluster status now.
return reconcile.Result{}, nil
}

changed, err = compute.ResolveDependentBastionResources(scope, openStackCluster, bastionName(cluster.Name))
if err != nil {
return reconcile.Result{}, err
}
if changed {
if openStackCluster.Status.Bastion.DependentResources == nil {
openStackCluster.Status.Bastion.DependentResources = &infrav1.DependentMachineResources{}
err = compute.ResolveDependentBastionResources(scope, openStackCluster, bastionName(cluster.Name))
if err != nil {
return reconcile.Result{}, err
}
// If the dependent resources have changed, we need to update the OpenStackCluster status now.
return reconcile.Result{}, nil
}
Expand Down Expand Up @@ -291,7 +293,7 @@ func deleteBastion(scope scope.Scope, cluster *clusterv1.Cluster, openStackClust
}
}

if openStackCluster.Status.Bastion != nil && len(openStackCluster.Status.Bastion.DependentResources.PortsStatus) > 0 {
if openStackCluster.Status.Bastion != nil && openStackCluster.Status.Bastion.DependentResources != nil && len(openStackCluster.Status.Bastion.DependentResources.PortsStatus) > 0 {
trunkSupported, err := networkingService.IsTrunkExtSupported()
if err != nil {
return err
Expand Down Expand Up @@ -402,7 +404,7 @@ func reconcileBastion(scope scope.Scope, cluster *clusterv1.Cluster, openStackCl
}
}

err = getOrCreateBastionPorts(scope, cluster, openStackCluster, networkingService, cluster.Name)
err = getOrCreateBastionPorts(cluster, openStackCluster, networkingService, cluster.Name)
if err != nil {
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)
Expand Down Expand Up @@ -542,7 +544,7 @@ func getBastionSecurityGroups(openStackCluster *infrav1.OpenStackCluster) []infr
return instanceSpecSecurityGroups
}

func getOrCreateBastionPorts(scope scope.Scope, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster, networkingService *networking.Service, clusterName string) error {
func getOrCreateBastionPorts(cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster, networkingService *networking.Service, clusterName string) error {
if openStackCluster.Status.Bastion == nil {
openStackCluster.Status.Bastion = &infrav1.BastionStatus{}
}
Expand Down
30 changes: 15 additions & 15 deletions controllers/openstackcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ var _ = Describe("OpenStackCluster controller", func() {
Expect(err).To(BeNil())
testCluster.Status = infrav1.OpenStackClusterStatus{
Bastion: &infrav1.BastionStatus{
ReferencedResources: infrav1.ReferencedMachineResources{
ReferencedResources: &infrav1.ReferencedMachineResources{
ImageID: "imageID",
PortsOpts: []infrav1.PortOpts{
{
Expand All @@ -240,7 +240,7 @@ var _ = Describe("OpenStackCluster controller", func() {
},
},
},
DependentResources: infrav1.DependentMachineResources{
DependentResources: &infrav1.DependentMachineResources{
PortsStatus: []infrav1.PortStatus{
{
ID: "portID1",
Expand Down Expand Up @@ -279,7 +279,7 @@ var _ = Describe("OpenStackCluster controller", func() {
Expect(testCluster.Status.Bastion).To(Equal(&infrav1.BastionStatus{
ID: "adopted-bastion-uuid",
State: "ACTIVE",
ReferencedResources: infrav1.ReferencedMachineResources{
ReferencedResources: &infrav1.ReferencedMachineResources{
ImageID: "imageID",
PortsOpts: []infrav1.PortOpts{
{
Expand All @@ -289,7 +289,7 @@ var _ = Describe("OpenStackCluster controller", func() {
},
},
},
DependentResources: infrav1.DependentMachineResources{
DependentResources: &infrav1.DependentMachineResources{
PortsStatus: []infrav1.PortStatus{
{
ID: "portID1",
Expand Down Expand Up @@ -320,7 +320,7 @@ var _ = Describe("OpenStackCluster controller", func() {
},
Bastion: &infrav1.BastionStatus{
ID: "adopted-fip-bastion-uuid",
ReferencedResources: infrav1.ReferencedMachineResources{
ReferencedResources: &infrav1.ReferencedMachineResources{
ImageID: "imageID",
PortsOpts: []infrav1.PortOpts{
{
Expand All @@ -330,7 +330,7 @@ var _ = Describe("OpenStackCluster controller", func() {
},
},
},
DependentResources: infrav1.DependentMachineResources{
DependentResources: &infrav1.DependentMachineResources{
PortsStatus: []infrav1.PortStatus{
{
ID: "portID1",
Expand Down Expand Up @@ -362,7 +362,7 @@ var _ = Describe("OpenStackCluster controller", func() {
ID: "adopted-fip-bastion-uuid",
FloatingIP: "1.2.3.4",
State: "ACTIVE",
ReferencedResources: infrav1.ReferencedMachineResources{
ReferencedResources: &infrav1.ReferencedMachineResources{
ImageID: "imageID",
PortsOpts: []infrav1.PortOpts{
{
Expand All @@ -372,7 +372,7 @@ var _ = Describe("OpenStackCluster controller", func() {
},
},
},
DependentResources: infrav1.DependentMachineResources{
DependentResources: &infrav1.DependentMachineResources{
PortsStatus: []infrav1.PortStatus{
{
ID: "portID1",
Expand Down Expand Up @@ -403,7 +403,7 @@ var _ = Describe("OpenStackCluster controller", func() {
},
Bastion: &infrav1.BastionStatus{
ID: "requeue-bastion-uuid",
ReferencedResources: infrav1.ReferencedMachineResources{
ReferencedResources: &infrav1.ReferencedMachineResources{
ImageID: "imageID",
PortsOpts: []infrav1.PortOpts{
{
Expand All @@ -413,7 +413,7 @@ var _ = Describe("OpenStackCluster controller", func() {
},
},
},
DependentResources: infrav1.DependentMachineResources{
DependentResources: &infrav1.DependentMachineResources{
PortsStatus: []infrav1.PortStatus{
{
ID: "portID1",
Expand All @@ -439,7 +439,7 @@ var _ = Describe("OpenStackCluster controller", func() {
Expect(testCluster.Status.Bastion).To(Equal(&infrav1.BastionStatus{
ID: "requeue-bastion-uuid",
State: "BUILD",
ReferencedResources: infrav1.ReferencedMachineResources{
ReferencedResources: &infrav1.ReferencedMachineResources{
ImageID: "imageID",
PortsOpts: []infrav1.PortOpts{
{
Expand All @@ -449,7 +449,7 @@ var _ = Describe("OpenStackCluster controller", func() {
},
},
},
DependentResources: infrav1.DependentMachineResources{
DependentResources: &infrav1.DependentMachineResources{
PortsStatus: []infrav1.PortStatus{
{
ID: "portID1",
Expand All @@ -471,7 +471,7 @@ var _ = Describe("OpenStackCluster controller", func() {
Expect(err).To(BeNil())
testCluster.Status = infrav1.OpenStackClusterStatus{
Bastion: &infrav1.BastionStatus{
ReferencedResources: infrav1.ReferencedMachineResources{
ReferencedResources: &infrav1.ReferencedMachineResources{
ImageID: "imageID",
},
},
Expand Down Expand Up @@ -521,7 +521,7 @@ var _ = Describe("OpenStackCluster controller", func() {
}
testCluster.Status = infrav1.OpenStackClusterStatus{
Bastion: &infrav1.BastionStatus{
DependentResources: infrav1.DependentMachineResources{
DependentResources: &infrav1.DependentMachineResources{
PortsStatus: []infrav1.PortStatus{
{
ID: "port-id",
Expand Down Expand Up @@ -601,7 +601,7 @@ var _ = Describe("OpenStackCluster controller", func() {
}
testCluster.Status = infrav1.OpenStackClusterStatus{
Bastion: &infrav1.BastionStatus{
DependentResources: infrav1.DependentMachineResources{
DependentResources: &infrav1.DependentMachineResources{
PortsStatus: []infrav1.PortStatus{
{
ID: "port-id",
Expand Down
Loading

0 comments on commit 0f41913

Please sign in to comment.