I would like to know how CAPO allocates Floating IPs to virtual machines. To investigate this, I looked into the situations in which the AssociateFloatingIP function is called. Here are my findings, but I lack understanding and would appreciate some advice or guidance on which code files to examine further.
AssociateFloatingIP
floatingip.go
https://github.com/kubernetes-sigs/cluster-api-provider-openstack/blob/25472728f74d30a8188a969e2cd6a3c40c78e0f8/pkg/cloud/services/networking/floatingip.go
Summary:
Associate a Floating IP with a port ID and assign it to a virtual machine in CAPO.
Overview of AssociateFloatingIP processing
- If fp.PortID matches the specified portID, return the values of fp.ID and fp.FloatingIP to the logger.
- If fp.PortID does not match the portID, update fpUpdateOpts and change the port ID to the specified ID.
- If an error occurs during UpdateFloatingIP, return the error.
- If an error occurs during waitForFloatingIP, return the error. If successful, return the values of fp.ID and fp.FloatingIP associated with it to the logger.
Functions referenced by AssociateFloatingIP
AssociateFloatingIP is called in the following three functions:
- controllers/openstackcluster_controller.go: reconcileBastion
- controllers/openstackmachine_controller.go: reconcileNormal
- pkg/cloud/services/loadbalancer/loadbalancer.go: ReconcileLoadBalancer
reconcileBastion:
Uses the GetOrCreateFloatingIP function to obtain a FloatingIP, and the computeService.GetManagementPort function to obtain the bastion's ManagementPort, then associates the FloatingIP with the bastion's ManagementPort using AssociateFloatingIP.
reconcileNormal:
Uses the GetOrCreateFloatingIP function to obtain a FloatingIP, and the computeService.GetManagementPort function to obtain the instance's ManagementPort, then associates the FloatingIP with the instance's ManagementPort using AssociateFloatingIP.
ReconcileLoadBalancer:
LoadBalancer uses a FloatingIP if:
openStackCluster.Spec.DisableAPIServerFloatingIP is false
openStackCluster.Spec.APIServerFloatingIP is not empty, or openStackCluster.Spec.ControlPlaneEndpoint is valid, set floatingIPAddress.
If these conditions are met, call the GetOrCreateFloatingIP function to obtain a FloatingIP, and use the AssociateFloatingIP function to associate lb.VipPortID with it, defining the obtained FloatingIP value as lbFloatingIP.
I would like to know how CAPO allocates Floating IPs to virtual machines. To investigate this, I looked into the situations in which the AssociateFloatingIP function is called. Here are my findings, but I lack understanding and would appreciate some advice or guidance on which code files to examine further.
AssociateFloatingIP
floatingip.go
https://github.com/kubernetes-sigs/cluster-api-provider-openstack/blob/25472728f74d30a8188a969e2cd6a3c40c78e0f8/pkg/cloud/services/networking/floatingip.go
Summary:
Associate a Floating IP with a port ID and assign it to a virtual machine in CAPO.
Overview of AssociateFloatingIP processing
Functions referenced by AssociateFloatingIP
AssociateFloatingIP is called in the following three functions:
reconcileBastion:
Uses the GetOrCreateFloatingIP function to obtain a FloatingIP, and the computeService.GetManagementPort function to obtain the bastion's ManagementPort, then associates the FloatingIP with the bastion's ManagementPort using AssociateFloatingIP.
reconcileNormal:
Uses the GetOrCreateFloatingIP function to obtain a FloatingIP, and the computeService.GetManagementPort function to obtain the instance's ManagementPort, then associates the FloatingIP with the instance's ManagementPort using AssociateFloatingIP.
ReconcileLoadBalancer:
LoadBalancer uses a FloatingIP if:
openStackCluster.Spec.DisableAPIServerFloatingIP is false
openStackCluster.Spec.APIServerFloatingIP is not empty, or openStackCluster.Spec.ControlPlaneEndpoint is valid, set floatingIPAddress.
If these conditions are met, call the GetOrCreateFloatingIP function to obtain a FloatingIP, and use the AssociateFloatingIP function to associate lb.VipPortID with it, defining the obtained FloatingIP value as lbFloatingIP.