Skip to content

Commit e0ad733

Browse files
committed
cleaning up TODOs
1 parent 384e9d8 commit e0ad733

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

cns/restserver/ipusage.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package restserver
2+
3+
import (
4+
"github.com/Azure/azure-container-networking/cns/logger"
5+
"github.com/Azure/azure-container-networking/cns/types"
6+
)
7+
8+
type ipState struct {
9+
// allocatedIPs are all the IPs given to CNS by DNC.
10+
allocatedIPs int64
11+
// assignedIPs are the IPs CNS gives to Pods.
12+
assignedIPs int64
13+
// availableIPs are the IPs in state "Available".
14+
availableIPs int64
15+
// programmingIPs are the IPs in state "PendingProgramming".
16+
programmingIPs int64
17+
// releasingIPs are the IPs in state "PendingReleasr".
18+
releasingIPs int64
19+
}
20+
21+
func (service *HTTPRestService) buildIPState() *ipState {
22+
service.Lock()
23+
defer service.Unlock()
24+
25+
state := ipState{
26+
allocatedIPs: 0,
27+
assignedIPs: 0,
28+
availableIPs: 0,
29+
programmingIPs: 0,
30+
releasingIPs: 0,
31+
}
32+
33+
//nolint:gocritic // This has to iterate over the IP Config state to get the counts.
34+
for _, ipConfig := range service.PodIPConfigState {
35+
state.allocatedIPs++
36+
if ipConfig.GetState() == types.Assigned {
37+
state.assignedIPs++
38+
}
39+
if ipConfig.GetState() == types.Available {
40+
state.availableIPs++
41+
}
42+
if ipConfig.GetState() == types.PendingProgramming {
43+
state.programmingIPs++
44+
}
45+
if ipConfig.GetState() == types.PendingRelease {
46+
state.releasingIPs++
47+
}
48+
}
49+
50+
logger.Printf("[IP Usage] Allocated IPs: %d, Assigned IPs: %d, Available IPs: %d, PendingProgramming IPs: %d, PendingRelease IPs: %d",
51+
state.allocatedIPs,
52+
state.assignedIPs,
53+
state.availableIPs,
54+
state.programmingIPs,
55+
state.releasingIPs,
56+
)
57+
return &state
58+
}

cns/restserver/restserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type imdsClient interface {
5454
GetVMUniqueID(ctx context.Context) (string, error)
5555
}
5656

57-
// HTTPRestService represents http listener for CNS - Container Networking Service.// TODO: Add a new value for IPFamily
57+
// HTTPRestService represents http listener for CNS - Container Networking Service.
5858
// TODO: If we add a new type of Middleware that will be reflected in the IPConfigsHandlerMiddleware value
5959
type HTTPRestService struct {
6060
*cns.Service

0 commit comments

Comments
 (0)