Skip to content

Commit

Permalink
add defaultPortIP to lbm status
Browse files Browse the repository at this point in the history
  • Loading branch information
dergeberl committed Dec 22, 2022
1 parent 1b66247 commit b1c541d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
5 changes: 4 additions & 1 deletion api/v1beta1/loadbalancermachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ type LoadBalancerMachineStatus struct {
// DefaultPortID contains the default openstack port ID for a LoadBalancerMachine.
// +optional
DefaultPortID *string `json:"defaultPortID,omitempty"`
// DefaultPortID contains the default openstack port ID for a LoadBalancerMachine.
// DefaultPortName contains the default openstack port Name for a LoadBalancerMachine.
// +optional
DefaultPortName *string `json:"defaultPortName,omitempty"`
// DefaultPortIP contains the default openstack port IP for a LoadBalancerMachine.
// +optional
DefaultPortIP *string `json:"defaultPortIP,omitempty"`
// ServiceAccountName contains the namespacedName from the ServiceAccount for a LoadBalancerMachine.
// +optional
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
Expand Down
5 changes: 5 additions & 0 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 @@ -266,8 +266,12 @@ spec:
description: DefaultPortID contains the default openstack port ID
for a LoadBalancerMachine.
type: string
defaultPortIP:
description: DefaultPortIP contains the default openstack port IP
for a LoadBalancerMachine.
type: string
defaultPortName:
description: DefaultPortID contains the default openstack port ID
description: DefaultPortName contains the default openstack port Name
for a LoadBalancerMachine.
type: string
lastOpenstackReconcile:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,16 @@ func (r *LoadBalancerMachineReconciler) reconcilePort(
return helper.ErrFailedToCreatePortForLBM
}

// Patch defaultPortIP to status
if len(port.FixedIPs) >= 1 &&
(lbm.Status.DefaultPortIP == nil || *lbm.Status.DefaultPortIP != port.FixedIPs[0].IPAddress) {
if err := helper.PatchLBMStatus(ctx, r.Status(), lbm, yawolv1beta1.LoadBalancerMachineStatus{
DefaultPortIP: &port.FixedIPs[0].IPAddress,
}); err != nil {
return err
}
}

return nil
}

Expand Down Expand Up @@ -808,6 +818,7 @@ func (r *LoadBalancerMachineReconciler) deletePort(
if err = openstackhelper.DeletePort(ctx, portClient, *lbm.Status.DefaultPortID); err != nil {
switch err.(type) {
case gophercloud.ErrDefault404:
_ = helper.RemoveFromLBMStatus(ctx, r.Status(), lbm, "defaultPortIP")
if err := helper.RemoveFromLBMStatus(ctx, r.Client.Status(), lbm, "defaultPortID"); err != nil {
return false, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,14 @@ var _ = Describe("load balancer machine", func() {
g.Expect(k8sClient.Get(ctx, lbmNN, &actual)).To(Succeed())

g.Expect(actual.Status.DefaultPortName).ToNot(BeNil())
g.Expect(actual.Status.DefaultPortIP).ToNot(BeNil())
g.Expect(actual.Status.DefaultPortID).ToNot(BeNil())
port, err := client.PortClientObj.Get(ctx, *actual.Status.DefaultPortID)
g.Expect(err).To(Succeed())
g.Expect(len(port.AllowedAddressPairs)).To(Equal(1))
g.Expect(len(port.AllowedAddressPairs)).To(Equal(1))
g.Expect(len(port.FixedIPs)).To(Equal(1))
g.Expect(port.FixedIPs[0].IPAddress).To(Equal(*actual.Status.DefaultPortIP))

var actualLB yawolv1beta1.LoadBalancer
g.Expect(k8sClient.Get(ctx, lbNN, &actualLB)).To(Succeed())
Expand Down

0 comments on commit b1c541d

Please sign in to comment.