Skip to content

Commit

Permalink
IPPool counters
Browse files Browse the repository at this point in the history
Add IPPools usage counters, and expose them via CRD and Prometheus.

Signed-off-by: Kobi Samoray <ksamoray@vmware.com>
  • Loading branch information
ksamoray committed Mar 7, 2022
1 parent 20fd99b commit 3442f71
Show file tree
Hide file tree
Showing 16 changed files with 286 additions and 40 deletions.
7 changes: 7 additions & 0 deletions build/yamls/antrea-aks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,13 @@ spec:
type: string
type: object
type: array
usage:
properties:
total:
type: integer
used:
type: integer
type: object
type: object
required:
- spec
Expand Down
7 changes: 7 additions & 0 deletions build/yamls/antrea-eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,13 @@ spec:
type: string
type: object
type: array
usage:
properties:
total:
type: integer
used:
type: integer
type: object
type: object
required:
- spec
Expand Down
7 changes: 7 additions & 0 deletions build/yamls/antrea-gke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,13 @@ spec:
type: string
type: object
type: array
usage:
properties:
total:
type: integer
used:
type: integer
type: object
type: object
required:
- spec
Expand Down
7 changes: 7 additions & 0 deletions build/yamls/antrea-ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,13 @@ spec:
type: string
type: object
type: array
usage:
properties:
total:
type: integer
used:
type: integer
type: object
type: object
required:
- spec
Expand Down
7 changes: 7 additions & 0 deletions build/yamls/antrea-kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,13 @@ spec:
type: string
type: object
type: array
usage:
properties:
total:
type: integer
used:
type: integer
type: object
type: object
required:
- spec
Expand Down
7 changes: 7 additions & 0 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,13 @@ spec:
type: string
type: object
type: array
usage:
properties:
total:
type: integer
used:
type: integer
type: object
type: object
required:
- spec
Expand Down
7 changes: 7 additions & 0 deletions build/yamls/base/crds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,13 @@ spec:
type: string
type: object
type: array
usage:
properties:
used:
type: integer
total:
type: integer
type: object
type: object
subresources:
status: {}
Expand Down
6 changes: 6 additions & 0 deletions cmd/antrea-controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ func run(o *Options) error {
externalIPController = serviceexternalip.NewServiceExternalIPController(client, serviceInformer, externalIPPoolController)
}

var ipamMetricsHandler *antreaipam.AntreaIPAMMetricsHandler
if features.DefaultFeatureGate.Enabled(features.AntreaIPAM) {
ipamMetricsHandler = antreaipam.NewAntreaIPAMMetricsHandler(crdClient, crdInformerFactory)
}

var traceflowController *traceflow.Controller
if features.DefaultFeatureGate.Enabled(features.Traceflow) {
traceflowController = traceflow.NewTraceflowController(crdClient, podInformer, tfInformer)
Expand Down Expand Up @@ -310,6 +315,7 @@ func run(o *Options) error {

if antreaIPAMController != nil {
go antreaIPAMController.Run(stopCh)
go ipamMetricsHandler.Run(stopCh)
}

<-stopCh
Expand Down
18 changes: 9 additions & 9 deletions pkg/apis/crd/v1alpha2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,7 @@ type IPRange struct {
}

type ExternalIPPoolStatus struct {
Usage ExternalIPPoolUsage `json:"usage,omitempty"`
}

type ExternalIPPoolUsage struct {
// Total number of IPs.
Total int `json:"total"`
// Number of allocated IPs.
Used int `json:"used"`
Usage IPPoolUsage `json:"usage,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -330,7 +323,14 @@ type SubnetIPRange struct {

type IPPoolStatus struct {
IPAddresses []IPAddressState `json:"ipAddresses,omitempty"`
// TODO: add usage statistics
Usage IPPoolUsage `json:"usage,omitempty"`
}

type IPPoolUsage struct {
// Total number of IPs.
Total int `json:"total"`
// Number of allocated IPs.
Used int `json:"used"`
}

type IPAddressPhase string
Expand Down
33 changes: 17 additions & 16 deletions pkg/apis/crd/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/controller/externalippool/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (c *ExternalIPPoolController) updateExternalIPPoolStatus(poolName string) e
var getErr error
if err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
actualStatus := eip.Status
usage := antreacrds.ExternalIPPoolUsage{Total: total, Used: used}
usage := antreacrds.IPPoolUsage{Total: total, Used: used}
if actualStatus.Usage == usage {
return nil
}
Expand Down
24 changes: 12 additions & 12 deletions pkg/controller/externalippool/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestAllocateIPFromPool(t *testing.T) {
allocateFrom string
expectedIP string
expectError bool
expectedIPPoolStatus []antreacrds.ExternalIPPoolUsage
expectedIPPoolStatus []antreacrds.IPPoolUsage
}{
{
name: "allocate from proper IP pool",
Expand All @@ -90,7 +90,7 @@ func TestAllocateIPFromPool(t *testing.T) {
allocateFrom: "eip1",
expectedIP: "10.10.10.2",
expectError: false,
expectedIPPoolStatus: []antreacrds.ExternalIPPoolUsage{
expectedIPPoolStatus: []antreacrds.IPPoolUsage{
{Total: 2, Used: 1},
},
},
Expand All @@ -109,7 +109,7 @@ func TestAllocateIPFromPool(t *testing.T) {
allocateFrom: "eip1",
expectedIP: "",
expectError: true,
expectedIPPoolStatus: []antreacrds.ExternalIPPoolUsage{
expectedIPPoolStatus: []antreacrds.IPPoolUsage{
{Total: 2, Used: 2},
},
},
Expand All @@ -122,7 +122,7 @@ func TestAllocateIPFromPool(t *testing.T) {
allocateFrom: "eip2",
expectedIP: "",
expectError: true,
expectedIPPoolStatus: []antreacrds.ExternalIPPoolUsage{
expectedIPPoolStatus: []antreacrds.IPPoolUsage{
{Total: 2, Used: 0},
},
},
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestReleaseIP(t *testing.T) {
ipPoolToRelease string
ipToRelease string
expectError bool
expectedIPPoolStatus []antreacrds.ExternalIPPoolUsage
expectedIPPoolStatus []antreacrds.IPPoolUsage
}{
{
name: "release IP to pool",
Expand All @@ -181,7 +181,7 @@ func TestReleaseIP(t *testing.T) {
ipPoolToRelease: "eip1",
ipToRelease: "10.10.10.2",
expectError: false,
expectedIPPoolStatus: []antreacrds.ExternalIPPoolUsage{
expectedIPPoolStatus: []antreacrds.IPPoolUsage{
{Total: 2, Used: 1},
},
},
Expand All @@ -200,7 +200,7 @@ func TestReleaseIP(t *testing.T) {
ipPoolToRelease: "eip1",
ipToRelease: "10.10.11.2",
expectError: true,
expectedIPPoolStatus: []antreacrds.ExternalIPPoolUsage{
expectedIPPoolStatus: []antreacrds.IPPoolUsage{
{Total: 2, Used: 2},
},
},
Expand Down Expand Up @@ -455,7 +455,7 @@ func TestIPPoolHasIP(t *testing.T) {
}
}

func checkExternalIPPoolStatus(t *testing.T, controller *controller, poolName string, expectedStatus antreacrds.ExternalIPPoolUsage) {
func checkExternalIPPoolStatus(t *testing.T, controller *controller, poolName string, expectedStatus antreacrds.IPPoolUsage) {
exists := controller.IPPoolExists(poolName)
require.True(t, exists)
err := wait.PollImmediate(50*time.Millisecond, 2*time.Second, func() (found bool, err error) {
Expand All @@ -475,7 +475,7 @@ func TestExternalIPPoolController_RestoreIPAllocations(t *testing.T) {
allocations []IPAllocation
allocationsToRestore []IPAllocation
expectedSucceeded []IPAllocation
expectedIPPoolStatus []antreacrds.ExternalIPPoolUsage
expectedIPPoolStatus []antreacrds.IPPoolUsage
}{
{
name: "restore all IP successfully",
Expand Down Expand Up @@ -516,7 +516,7 @@ func TestExternalIPPoolController_RestoreIPAllocations(t *testing.T) {
net.ParseIP("10.10.11.2"),
},
},
expectedIPPoolStatus: []antreacrds.ExternalIPPoolUsage{
expectedIPPoolStatus: []antreacrds.IPPoolUsage{
{Total: 2, Used: 1},
{Total: 2, Used: 1},
},
Expand Down Expand Up @@ -561,7 +561,7 @@ func TestExternalIPPoolController_RestoreIPAllocations(t *testing.T) {
net.ParseIP("10.10.11.2"),
},
},
expectedIPPoolStatus: []antreacrds.ExternalIPPoolUsage{
expectedIPPoolStatus: []antreacrds.IPPoolUsage{
{Total: 2, Used: 1},
{Total: 2, Used: 1},
},
Expand Down Expand Up @@ -598,7 +598,7 @@ func TestExternalIPPoolController_RestoreIPAllocations(t *testing.T) {
net.ParseIP("10.10.11.2"),
},
},
expectedIPPoolStatus: []antreacrds.ExternalIPPoolUsage{
expectedIPPoolStatus: []antreacrds.IPPoolUsage{
{Total: 2, Used: 0},
{Total: 2, Used: 1},
},
Expand Down
Loading

0 comments on commit 3442f71

Please sign in to comment.