Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattes83 committed Jul 4, 2024
1 parent e9b81fe commit 49f477c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
13 changes: 11 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (a *IONOSClient) RemoveIPFromNode(ctx context.Context, loadBalancerIP, prov
return errors.New("node has no nics")
}

primaryNic := (*nics.Items)[0]
primaryNic := getPrimaryNic(*nics.Items)
ips := *primaryNic.Properties.Ips

for idx, v := range ips {
Expand All @@ -105,6 +105,15 @@ func (a *IONOSClient) RemoveIPFromNode(ctx context.Context, loadBalancerIP, prov
return err
}

func getPrimaryNic(nics []ionoscloud.Nic) *ionoscloud.Nic {
for _, nic := range nics {
if *nic.Properties.PciSlot == 6 {
return &nic
}
}
return nil
}

func (a *IONOSClient) AttachIPToNode(ctx context.Context, loadBalancerIP, providerID string) (bool, error) {
if a.client == nil {
return false, errors.New("client isn't initialized")
Expand All @@ -123,7 +132,7 @@ func (a *IONOSClient) AttachIPToNode(ctx context.Context, loadBalancerIP, provid
return false, errors.New("node has no nics")
}

primaryNic := (*nics.Items)[1]
primaryNic := getPrimaryNic(*nics.Items)
ips := *primaryNic.Properties.Ips
ips = append(ips, loadBalancerIP)

Expand Down
16 changes: 15 additions & 1 deletion pkg/ionos/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ func (l loadbalancer) syncLoadBalancer(ctx context.Context, clusterName string,
return nil, errors.New("we are only handling LoadBalancers with spec.loadBalancerID != ''")
}

if len(service.Status.LoadBalancer.Ingress) > 0 && service.Status.LoadBalancer.Ingress[0].IP != service.Spec.LoadBalancerIP {
klog.Infof("service %s/%s changed IP from %s to %s", service.Namespace, service.Name, service.Status.LoadBalancer.Ingress[0].IP, service.Spec.LoadBalancerIP)
server, err := l.ServerWithLoadBalancer(ctx, service.Status.LoadBalancer.Ingress[0].IP)
if err != nil {
return nil, err
}

if server != nil {
if err := l.deleteLoadBalancerFromNode(ctx, service.Status.LoadBalancer.Ingress[0].IP, server); err != nil {
return nil, err
}
}
}

server, err := l.ServerWithLoadBalancer(ctx, service.Spec.LoadBalancerIP)
if err != nil {
return nil, err
Expand All @@ -159,7 +173,7 @@ func (l loadbalancer) syncLoadBalancer(ctx context.Context, clusterName string,
if loadBalancerNode == nil {
return nil, errors.New("no valid nodes found")
}
klog.Infof("server %s is elected as new loadbalancer node", server)
klog.Infof("server %s is elected as new loadbalancer node", loadBalancerNode)

for _, client := range l.ionosClients {
ok, err := client.AttachIPToNode(ctx, service.Spec.LoadBalancerIP, stripProviderFromID(loadBalancerNode.Spec.ProviderID))
Expand Down

0 comments on commit 49f477c

Please sign in to comment.