Skip to content

Commit 08ab91c

Browse files
committed
fixup! fixup! fixup! feature: reserve n IPs on Networks
1 parent 4a36187 commit 08ab91c

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

pkg/ipam/initialize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (lipam *LiqoIPAM) initializeNetworks(ctx context.Context) error {
4545

4646
// Initialize the networks.
4747
for _, net := range nets {
48-
if err := lipam.reserveNetwork(&net); err != nil {
48+
if err := lipam.reserveNetwork(net); err != nil {
4949
klog.Errorf("Failed to reserve network %q: %v", net, err)
5050
return err
5151
}

pkg/ipam/ipam.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ func (lipam *LiqoIPAM) NetworkAcquire(_ context.Context, req *NetworkAcquireRequ
100100

101101
// NetworkRelease releases a network.
102102
func (lipam *LiqoIPAM) NetworkRelease(_ context.Context, req *NetworkReleaseRequest) (*NetworkReleaseResponse, error) {
103-
lipam.freeNetwork(&network{cidr: req.GetCidr()})
103+
lipam.freeNetwork(network{cidr: req.GetCidr()})
104104

105105
return &NetworkReleaseResponse{}, nil
106106
}
107107

108108
// NetworkIsAvailable checks if a network is available.
109109
func (lipam *LiqoIPAM) NetworkIsAvailable(_ context.Context, req *NetworkAvailableRequest) (*NetworkAvailableResponse, error) {
110-
available := lipam.isNetworkAvailable(&network{cidr: req.GetCidr()})
110+
available := lipam.isNetworkAvailable(network{cidr: req.GetCidr()})
111111

112112
return &NetworkAvailableResponse{Available: available}, nil
113113
}

pkg/ipam/networks.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (n network) String() string {
3939
}
4040

4141
// reserveNetwork reserves a network, saving it in the cache.
42-
func (lipam *LiqoIPAM) reserveNetwork(nw *network) error {
42+
func (lipam *LiqoIPAM) reserveNetwork(nw network) error {
4343
lipam.mutex.Lock()
4444
defer lipam.mutex.Unlock()
4545

@@ -48,7 +48,7 @@ func (lipam *LiqoIPAM) reserveNetwork(nw *network) error {
4848
lipam.cacheNetworks = make(map[string]networkInfo)
4949
}
5050
lipam.cacheNetworks[nw.String()] = networkInfo{
51-
network: *nw,
51+
network: nw,
5252
creationTimestamp: time.Now(),
5353
}
5454

@@ -80,7 +80,7 @@ func (lipam *LiqoIPAM) acquireNetwork(cidr string, preAllocated uint, immutable
8080
}
8181

8282
// freeNetwork frees a network, removing it from the cache.
83-
func (lipam *LiqoIPAM) freeNetwork(nw *network) {
83+
func (lipam *LiqoIPAM) freeNetwork(nw network) {
8484
lipam.mutex.Lock()
8585
defer lipam.mutex.Unlock()
8686

@@ -90,7 +90,7 @@ func (lipam *LiqoIPAM) freeNetwork(nw *network) {
9090
}
9191

9292
// isNetworkAvailable checks if a network is available.
93-
func (lipam *LiqoIPAM) isNetworkAvailable(nw *network) bool {
93+
func (lipam *LiqoIPAM) isNetworkAvailable(nw network) bool {
9494
lipam.mutex.Lock()
9595
defer lipam.mutex.Unlock()
9696

pkg/ipam/sync.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121

2222
"k8s.io/apimachinery/pkg/util/wait"
2323
klog "k8s.io/klog/v2"
24-
"k8s.io/utils/ptr"
2524
)
2625

2726
// +kubebuilder:rbac:groups=ipam.liqo.io,resources=ips,verbs=get;list;watch
@@ -65,8 +64,7 @@ func (lipam *LiqoIPAM) syncNetworks(ctx context.Context, expiredThreshold time.T
6564
setClusterNetworks := make(map[string]struct{})
6665

6766
// Add networks that are present in the cluster but not in the cache.
68-
for i := range clusterNetworks {
69-
net := &clusterNetworks[i]
67+
for _, net := range clusterNetworks {
7068
if _, inCache := lipam.cacheNetworks[net.String()]; !inCache {
7169
if err := lipam.reserveNetwork(net); err != nil {
7270
return err
@@ -78,7 +76,7 @@ func (lipam *LiqoIPAM) syncNetworks(ctx context.Context, expiredThreshold time.T
7876
// Remove networks that are present in the cache but not in the cluster, and were added before the threshold.
7977
for key := range lipam.cacheNetworks {
8078
if _, inCluster := setClusterNetworks[key]; !inCluster && lipam.cacheNetworks[key].creationTimestamp.Before(expiredThreshold) {
81-
lipam.freeNetwork(ptr.To(lipam.cacheNetworks[key].network))
79+
lipam.freeNetwork(lipam.cacheNetworks[key].network)
8280
}
8381
}
8482

0 commit comments

Comments
 (0)