Skip to content

Commit

Permalink
Pools show usage counts
Browse files Browse the repository at this point in the history
InClusterIPPool and GlobalInClusterIPPool receive updates to their
status showing the Total count of IPs in the pool's range, the InUse count,
and the Free count.

IPv6 IP ranges can be enormous (2^128) IPs. Range totals that exceed int
are shown as the value of math.MaxInt (arch dependent).

Adds a new reconciler for pools.
Adds columns to pools for Total, Free, Used

Remove Zap logger remnants.

Co-authored-by: Edwin Xie <[email protected]>
Co-authored-by: Christian Ang <[email protected]>
Co-authored-by: Aidan Obley <[email protected]>
  • Loading branch information
4 people committed Apr 11, 2023
1 parent 72407b7 commit 6783e49
Show file tree
Hide file tree
Showing 14 changed files with 523 additions and 28 deletions.
37 changes: 37 additions & 0 deletions api/v1alpha1/inclusterippool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ type InClusterIPPoolSpec struct {

// InClusterIPPoolStatus defines the observed state of InClusterIPPool.
type InClusterIPPoolStatus struct {
// IPAddresses reports the count of total, free, and used IPs in the pool.
// +optional
IPAddresses InClusterIPPoolStatusIPAddresses `json:"ipAddresses,omitempty"`
}

// InClusterIPPoolStatusIPAddresses contains the count of total, free, and used IPs in a pool
type InClusterIPPoolStatusIPAddresses struct {
// Total is the total number of IPs configured for the pool.
// Counts greater than int can contain will report as math.MaxInt.
// +optional
Total int `json:"total,omitempty"`

// Free is the count of unallocated IPs in the pool.
// Counts greater than int can contain will report as math.MaxInt.
// +optional
Free int `json:"free,omitempty"`

// Used is the count of allocated IPs in the pool.
// Counts greater than int can contain will report as math.MaxInt.
// +optional
Used int `json:"used,omitempty"`
}

// +kubebuilder:object:root=true
Expand All @@ -49,6 +70,9 @@ type InClusterIPPoolStatus struct {
// +kubebuilder:printcolumn:name="First",type="string",JSONPath=".spec.first",description="First address of the range to allocate from"
// +kubebuilder:printcolumn:name="Last",type="string",JSONPath=".spec.last",description="Last address of the range to allocate from"
// +kubebuilder:printcolumn:name="Addresses",type="string",JSONPath=".spec.addresses",description="List of addresses, within the subnet, to allocate from"
// +kubebuilder:printcolumn:name="Total",type="integer",JSONPath=".status.ipAddresses.total",description="Count of IPs configured for the pool"
// +kubebuilder:printcolumn:name="Free",type="integer",JSONPath=".status.ipAddresses.free",description="Count of unallocated IPs in the pool"
// +kubebuilder:printcolumn:name="Used",type="integer",JSONPath=".status.ipAddresses.used",description="Count of allocated IPs in the pool"

// InClusterIPPool is the Schema for the inclusterippools API.
type InClusterIPPool struct {
Expand All @@ -74,6 +98,9 @@ type InClusterIPPoolList struct {
// +kubebuilder:printcolumn:name="Subnet",type="string",JSONPath=".spec.subnet",description="Subnet to allocate IPs from"
// +kubebuilder:printcolumn:name="First",type="string",JSONPath=".spec.first",description="First address of the range to allocate from"
// +kubebuilder:printcolumn:name="Last",type="string",JSONPath=".spec.last",description="Last address of the range to allocate from"
// +kubebuilder:printcolumn:name="Total",type="integer",JSONPath=".status.ipAddresses.total",description="Count of IPs configured for the pool"
// +kubebuilder:printcolumn:name="Free",type="integer",JSONPath=".status.ipAddresses.free",description="Count of unallocated IPs in the pool"
// +kubebuilder:printcolumn:name="Used",type="integer",JSONPath=".status.ipAddresses.used",description="Count of allocated IPs in the pool"

// GlobalInClusterIPPool is the Schema for the global inclusterippools API.
// This pool type is cluster scoped. IPAddressClaims can reference
Expand Down Expand Up @@ -109,7 +136,17 @@ func (p *InClusterIPPool) PoolSpec() *InClusterIPPoolSpec {
return &p.Spec
}

// PoolStatus implements the genericInClusterPool interface.
func (p *InClusterIPPool) PoolStatus() *InClusterIPPoolStatus {
return &p.Status
}

// PoolSpec implements the genericInClusterPool interface.
func (p *GlobalInClusterIPPool) PoolSpec() *InClusterIPPoolSpec {
return &p.Spec
}

// PoolStatus implements the genericInClusterPool interface.
func (p *GlobalInClusterIPPool) PoolStatus() *InClusterIPPoolStatus {
return &p.Status
}
16 changes: 16 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

30 changes: 30 additions & 0 deletions config/crd/bases/ipam.cluster.x-k8s.io_globalinclusterippools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ spec:
jsonPath: .spec.last
name: Last
type: string
- description: Count of IPs configured for the pool
jsonPath: .status.ipAddresses.total
name: Total
type: integer
- description: Count of unallocated IPs in the pool
jsonPath: .status.ipAddresses.free
name: Free
type: integer
- description: Count of allocated IPs in the pool
jsonPath: .status.ipAddresses.used
name: Used
type: integer
name: v1alpha1
schema:
openAPIV3Schema:
Expand Down Expand Up @@ -82,6 +94,24 @@ spec:
type: object
status:
description: InClusterIPPoolStatus defines the observed state of InClusterIPPool.
properties:
ipAddresses:
description: IPAddresses reports the count of total, free, and used
IPs in the pool.
properties:
free:
description: Free is the count of unallocated IPs in the pool.
Counts greater than int can contain will report as math.MaxInt.
type: integer
total:
description: Total is the total number of IPs configured for the
pool. Counts greater than int can contain will report as math.MaxInt.
type: integer
used:
description: Used is the count of allocated IPs in the pool. Counts
greater than int can contain will report as math.MaxInt.
type: integer
type: object
type: object
type: object
served: true
Expand Down
30 changes: 30 additions & 0 deletions config/crd/bases/ipam.cluster.x-k8s.io_inclusterippools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ spec:
jsonPath: .spec.addresses
name: Addresses
type: string
- description: Count of IPs configured for the pool
jsonPath: .status.ipAddresses.total
name: Total
type: integer
- description: Count of unallocated IPs in the pool
jsonPath: .status.ipAddresses.free
name: Free
type: integer
- description: Count of allocated IPs in the pool
jsonPath: .status.ipAddresses.used
name: Used
type: integer
name: v1alpha1
schema:
openAPIV3Schema:
Expand Down Expand Up @@ -84,6 +96,24 @@ spec:
type: object
status:
description: InClusterIPPoolStatus defines the observed state of InClusterIPPool.
properties:
ipAddresses:
description: IPAddresses reports the count of total, free, and used
IPs in the pool.
properties:
free:
description: Free is the count of unallocated IPs in the pool.
Counts greater than int can contain will report as math.MaxInt.
type: integer
total:
description: Total is the total number of IPs configured for the
pool. Counts greater than int can contain will report as math.MaxInt.
type: integer
used:
description: Used is the count of allocated IPs in the pool. Counts
greater than int can contain will report as math.MaxInt.
type: integer
type: object
type: object
type: object
served: true
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ require (
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/zapr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
Expand Down
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk5
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220418222510-f25a4f6275ed h1:ue9pVfIcP+QMEjfgo/Ez4ZjNZfonGgR6NgjMaJMu1Cg=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down Expand Up @@ -125,11 +123,9 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/zapr v1.2.3 h1:a9vnzlIBPQBBkeaR9IuMUfmVOrQlkoC4YfPoFkX3T7A=
github.com/go-logr/zapr v1.2.3/go.mod h1:eIauM6P8qSvTw5o2ez6UEAfGjQKrxQTl5EoK+Qa2oG4=
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
Expand Down Expand Up @@ -352,12 +348,9 @@ go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqe
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
go4.org/netipx v0.0.0-20230303233057-f1b76eb4bb35 h1:nJAwRlGWZZDOD+6wni9KVUNHMpHko/OnRwsrCYeAzPo=
Expand Down Expand Up @@ -537,7 +530,6 @@ golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgw
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
Expand Down
Loading

0 comments on commit 6783e49

Please sign in to comment.