@@ -25,29 +25,39 @@ import (
2525)
2626
2727type networkInfo struct {
28- cidr string
28+ network
2929 creationTimestamp time.Time
3030}
3131
32+ type network struct {
33+ cidr string
34+ preAllocated uint
35+ }
36+
37+ func (n network ) String () string {
38+ return n .cidr
39+ }
40+
3241// reserveNetwork reserves a network, saving it in the cache.
33- func (lipam * LiqoIPAM ) reserveNetwork (cidr string ) error {
42+ func (lipam * LiqoIPAM ) reserveNetwork (nw network ) error {
3443 lipam .mutex .Lock ()
3544 defer lipam .mutex .Unlock ()
3645
46+ // TODO: implement real network reserve logic
3747 if lipam .cacheNetworks == nil {
3848 lipam .cacheNetworks = make (map [string ]networkInfo )
3949 }
40- lipam .cacheNetworks [cidr ] = networkInfo {
41- cidr : cidr ,
50+ lipam .cacheNetworks [nw . String () ] = networkInfo {
51+ network : nw ,
4252 creationTimestamp : time .Now (),
4353 }
4454
45- klog .Infof ("Reserved network %q" , cidr )
55+ klog .Infof ("Reserved network %q" , nw )
4656 return nil
4757}
4858
4959// acquireNetwork acquires a network, eventually remapped if conflicts are found.
50- func (lipam * LiqoIPAM ) acquireNetwork (cidr string , immutable bool ) (string , error ) {
60+ func (lipam * LiqoIPAM ) acquireNetwork (cidr string , preAllocated uint , immutable bool ) (string , error ) {
5161 lipam .mutex .Lock ()
5262 defer lipam .mutex .Unlock ()
5363
@@ -56,39 +66,45 @@ func (lipam *LiqoIPAM) acquireNetwork(cidr string, immutable bool) (string, erro
5666 if lipam .cacheNetworks == nil {
5767 lipam .cacheNetworks = make (map [string ]networkInfo )
5868 }
59- lipam .cacheNetworks [cidr ] = networkInfo {
60- cidr : cidr ,
69+ nw := network {
70+ cidr : cidr ,
71+ preAllocated : preAllocated ,
72+ }
73+ lipam .cacheNetworks [nw .String ()] = networkInfo {
74+ network : nw ,
6175 creationTimestamp : time .Now (),
6276 }
6377
64- klog .Infof ("Acquired network %q" , cidr )
65- return cidr , nil
78+ klog .Infof ("Acquired network %q" , nw )
79+ return nw . cidr , nil
6680}
6781
6882// freeNetwork frees a network, removing it from the cache.
69- func (lipam * LiqoIPAM ) freeNetwork (cidr string ) {
83+ func (lipam * LiqoIPAM ) freeNetwork (nw network ) {
7084 lipam .mutex .Lock ()
7185 defer lipam .mutex .Unlock ()
7286
73- delete (lipam .cacheNetworks , cidr )
74- klog .Infof ("Freed network %q" , cidr )
87+ // TODO: implement real network free logic
88+ delete (lipam .cacheNetworks , nw .String ())
89+ klog .Infof ("Freed network %q" , nw .cidr )
7590}
7691
7792// isNetworkAvailable checks if a network is available.
78- func (lipam * LiqoIPAM ) isNetworkAvailable (cidr string ) bool {
93+ func (lipam * LiqoIPAM ) isNetworkAvailable (nw network ) bool {
7994 lipam .mutex .Lock ()
8095 defer lipam .mutex .Unlock ()
8196
97+ // TODO: implement real network availability check logic
8298 if lipam .cacheNetworks == nil {
8399 return true
84100 }
85- _ , ok := lipam .cacheNetworks [cidr ]
101+ _ , ok := lipam .cacheNetworks [nw . String () ]
86102
87103 return ok
88104}
89105
90- func listNetworksOnCluster (ctx context.Context , cl client.Client ) ([]string , error ) {
91- var nets []string
106+ func listNetworksOnCluster (ctx context.Context , cl client.Client ) ([]network , error ) {
107+ var nets []network
92108 var networks ipamv1alpha1.NetworkList
93109 if err := cl .List (ctx , & networks ); err != nil {
94110 return nil , err
@@ -103,7 +119,10 @@ func listNetworksOnCluster(ctx context.Context, cl client.Client) ([]string, err
103119 continue
104120 }
105121
106- nets = append (nets , cidr )
122+ nets = append (nets , network {
123+ cidr : cidr ,
124+ preAllocated : net .Spec .PreAllocated ,
125+ })
107126 }
108127
109128 return nets , nil
0 commit comments