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.

Signed-off-by: Kobi Samoray <ksamoray@vmware.com>
  • Loading branch information
ksamoray committed Aug 1, 2022
1 parent 231b09d commit 0fa4972
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 40 deletions.
7 changes: 7 additions & 0 deletions build/charts/antrea/crds/ippool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ spec:
type: string
type: object
type: array
usage:
properties:
used:
type: integer
total:
type: integer
type: object
type: object
subresources:
status: {}
Expand Down
7 changes: 7 additions & 0 deletions build/yamls/antrea-aks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,13 @@ spec:
type: string
type: object
type: array
usage:
properties:
used:
type: integer
total:
type: integer
type: object
type: object
subresources:
status: {}
Expand Down
7 changes: 7 additions & 0 deletions build/yamls/antrea-crds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,13 @@ spec:
type: string
type: object
type: array
usage:
properties:
used:
type: integer
total:
type: integer
type: object
type: object
subresources:
status: {}
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 @@ -1370,6 +1370,13 @@ spec:
type: string
type: object
type: array
usage:
properties:
used:
type: integer
total:
type: integer
type: object
type: object
subresources:
status: {}
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 @@ -1370,6 +1370,13 @@ spec:
type: string
type: object
type: array
usage:
properties:
used:
type: integer
total:
type: integer
type: object
type: object
subresources:
status: {}
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 @@ -1370,6 +1370,13 @@ spec:
type: string
type: object
type: array
usage:
properties:
used:
type: integer
total:
type: integer
type: object
type: object
subresources:
status: {}
Expand Down
7 changes: 7 additions & 0 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,13 @@ spec:
type: string
type: object
type: array
usage:
properties:
used:
type: integer
total:
type: integer
type: object
type: object
subresources:
status: {}
Expand Down
17 changes: 8 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 @@ -337,9 +330,15 @@ 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

const (
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 0fa4972

Please sign in to comment.