@@ -16,7 +16,6 @@ package ipam
1616
1717import (
1818 "context"
19- "fmt"
2019 "net/netip"
2120 "os"
2221 "time"
@@ -36,15 +35,19 @@ func (lipam *LiqoIPAM) sync(ctx context.Context, syncFrequency time.Duration) {
3635 // networks created before this threshold will be removed from the cache if they are not present in the cluster.
3736 expiredThreshold := now .Add (- syncFrequency )
3837
38+ klog .Info ("Syncing networks" )
3939 // Sync networks.
4040 if err := lipam .syncNetworks (ctx , expiredThreshold ); err != nil {
4141 return false , err
4242 }
43+ klog .Info ("Networks synced" )
4344
45+ klog .Info ("Syncing IPs" )
4446 // Sync IPs.
4547 if err := lipam .syncIPs (ctx , expiredThreshold ); err != nil {
4648 return false , err
4749 }
50+ klog .Info ("IPs synced" )
4851
4952 klog .Info ("Completed IPAM cache sync routine" )
5053 return false , nil
@@ -64,10 +67,7 @@ func (lipam *LiqoIPAM) syncNetworks(ctx context.Context, expiredThreshold time.T
6467
6568 // Add networks that are present in the cluster but not in the cache.
6669 for _ , net := range clusterNetworks {
67- prefix := netip .MustParsePrefix (net )
68- if result := lipam .IpamCore .AllocateNetworkWithPrefix (prefix ); result != nil {
69- klog .Infof ("Sync: Acquired network %q -> %q" , net , result .String ())
70- }
70+ _ , _ = lipam .acquireSpecificNetwork (net )
7171 }
7272
7373 // Remove networks that are present in the cache but not in the cluster, and were added before the threshold.
@@ -81,11 +81,7 @@ func (lipam *LiqoIPAM) syncNetworks(ctx context.Context, expiredThreshold time.T
8181 }
8282 }
8383 if ! found {
84- if result := lipam .IpamCore .FreeNetwork (currentNetworks [i ]); result != nil {
85- klog .Infof ("Sync: Released network %q" , result .String ())
86- } else {
87- return fmt .Errorf ("sync: Error while freeing network %q" , currentNetworks [i ].String ())
88- }
84+ lipam .freeNetwork (currentNetworks [i ].String ())
8985 }
9086 }
9187
@@ -100,11 +96,7 @@ func (lipam *LiqoIPAM) syncIPs(ctx context.Context, expiredThreshold time.Time)
10096 }
10197
10298 for i := range ips {
103- prefix := netip .MustParsePrefix (ips [i ].cidr )
104- addr := netip .MustParseAddr (ips [i ].ip )
105- if result := lipam .IpamCore .AllocateIPWithAddr (prefix , addr ); result != nil {
106- klog .Infof ("Sync: Acquired IP %q" , result .String ())
107- }
99+ _ , _ = lipam .acquireIPWithAddress (ips [i ].cidr , ips [i ].ip )
108100 }
109101
110102 ipMap := make (map [netip.Prefix ][]netip.Addr )
@@ -124,11 +116,7 @@ func (lipam *LiqoIPAM) syncIPs(ctx context.Context, expiredThreshold time.Time)
124116 }
125117 }
126118 if ! found {
127- if result := lipam .IpamCore .FreeIP (k , ipMap [k ][i ]); result != nil {
128- klog .Infof ("Sync: Released IP %q" , result .String ())
129- } else {
130- return fmt .Errorf ("sync: Error while freeing IP %q" , ipMap [k ][i ].String ())
131- }
119+ lipam .freeIP (ipCidr {ip : ipMap [k ][i ].String (), cidr : k .String ()})
132120 }
133121 }
134122 }
0 commit comments