Skip to content

Commit

Permalink
feat: ipam timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
cheina97 committed Dec 2, 2024
1 parent b38a260 commit d7f6531
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 81 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- master
- release
- ipam
- frc/ipamtimespamt
repository_dispatch:
types:
- test-command
Expand Down
4 changes: 3 additions & 1 deletion cmd/ipam/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ func main() {

// Server options.
cmd.Flags().IntVar(&options.ServerOpts.Port, "port", consts.IpamPort, "The port on which to listen for incoming gRPC requests.")
cmd.Flags().DurationVar(&options.ServerOpts.SyncFrequency, "sync-interval", consts.SyncInterval,
cmd.Flags().DurationVar(&options.ServerOpts.SyncInterval, "sync-interval", consts.SyncInterval,
"The interval at which the IPAM will synchronize the IPAM storage.")
cmd.Flags().DurationVar(&options.ServerOpts.SyncGracePeriod, "sync-graceperiod", consts.SyncGracePeriod,
"The grace period the sync routine wait before releasing an ip or a network.")
cmd.Flags().BoolVar(&options.ServerOpts.GraphvizEnabled, "enable-graphviz", false, "Enable the graphviz output for the IPAM.")
cmd.Flags().StringSliceVar(&options.ServerOpts.Pools, "pools",
[]string{"10.0.0.0/8", "192.168.0.0/16", "172.16.0.0/12"}, "The pools used by the IPAM.",
Expand Down
31 changes: 16 additions & 15 deletions deployments/liqo/README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions deployments/liqo/templates/liqo-ipam-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ spec:
- --pod-name=$(POD_NAME)
- --port=6000
- --sync-interval={{ .Values.ipam.internal.syncInterval }}
- --sync-graceperiod={{ .Values.ipam.internal.syncGracePeriod }}
{{- if $ha }}
- --leader-election
- --leader-election-namespace=$(POD_NAMESPACE)
Expand Down
34 changes: 18 additions & 16 deletions deployments/liqo/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ networking:
gateway:
image:
# -- Image repository for the gateway container.
name: "ghcr.io/liqotech/gateway"
name: "ghcr.io/cheina97/gateway"
# -- Custom version for the gateway image. If not specified, the global tag is used.
version: ""
wireguard:
image:
# -- Image repository for the wireguard container.
name: "ghcr.io/liqotech/gateway/wireguard"
name: "ghcr.io/cheina97/gateway/wireguard"
# -- Custom version for the wireguard image. If not specified, the global tag is used.
version: ""
geneve:
image:
# -- Image repository for the geneve container.
name: "ghcr.io/liqotech/gateway/geneve"
name: "ghcr.io/cheina97/gateway/geneve"
# -- Custom version for the geneve image. If not specified, the global tag is used.
version: ""
fabric:
Expand All @@ -113,7 +113,7 @@ networking:
priorityClassName: ""
image:
# -- Image repository for the fabric pod.
name: "ghcr.io/liqotech/fabric"
name: "ghcr.io/cheina97/fabric"
# -- Custom version for the fabric image. If not specified, the global tag is used.
version: ""
# -- Extra tolerations for the fabric daemonset.
Expand Down Expand Up @@ -326,7 +326,7 @@ controllerManager:
priorityClassName: ""
image:
# -- Image repository for the controller-manager pod.
name: "ghcr.io/liqotech/liqo-controller-manager"
name: "ghcr.io/cheina97/liqo-controller-manager"
# -- Custom version for the controller-manager image. If not specified, the global tag is used.
version: ""
config:
Expand Down Expand Up @@ -384,7 +384,7 @@ webhook:
priorityClassName: ""
image:
# -- Image repository for the webhook pod.
name: "ghcr.io/liqotech/webhook"
name: "ghcr.io/cheina97/webhook"
# -- Custom version for the webhook image. If not specified, the global tag is used.
version: ""
metrics:
Expand Down Expand Up @@ -423,7 +423,7 @@ ipam:
internal:
image:
# -- Image repository for the IPAM pod.
name: "ghcr.io/liqotech/ipam"
name: "ghcr.io/cheina97/ipam"
# -- Custom version for the IPAM image. If not specified, the global tag is used.
version: ""
# -- The number of IPAM instances to run, which can be increased for active/passive high availability.
Expand All @@ -448,13 +448,15 @@ ipam:
graphviz: false
# -- Set the interval at which the IPAM pod will synchronize it's in-memory status with the local cluster.
# If you want to disable the synchronization, set the interval to 0.
syncInterval: 2m
syncInterval: 5s
## -- Set the grace period the sync routine will wait before deleting an ip or a network.
syncGracePeriod: 15s
# -- The subnet used by the pods in your cluster, in CIDR notation (e.g., 10.0.0.0/16).
podCIDR: ""
# -- The subnet used by the services in you cluster, in CIDR notation (e.g., 172.16.0.0/16).
serviceCIDR: ""
# -- The subnet used for the external CIDR.
externalCIDR: "10.70.0.0/16"
externalCIDR: "10.70.0.0/27"
# -- The subnet used for the internal CIDR.
# These IPs are assigned to the Liqo internal-network interfaces.
internalCIDR: "10.80.0.0/16"
Expand Down Expand Up @@ -498,7 +500,7 @@ crdReplicator:
labels: {}
image:
# -- Image repository for the crdReplicator pod.
name: "ghcr.io/liqotech/crd-replicator"
name: "ghcr.io/cheina97/crd-replicator"
# -- Custom version for the crdReplicator image. If not specified, the global tag is used.
version: ""

Expand Down Expand Up @@ -537,13 +539,13 @@ metricAgent:
priorityClassName: ""
image:
# -- Image repository for the metricAgent pod.
name: "ghcr.io/liqotech/metric-agent"
name: "ghcr.io/cheina97/metric-agent"
# -- Custom version for the metricAgent image. If not specified, the global tag is used.
version: ""
initContainer:
image:
# --Image repository for the init container of the metricAgent pod.
name: "ghcr.io/liqotech/cert-creator"
name: "ghcr.io/cheina97/cert-creator"
# -- Custom version for the init container image of the metricAgent pod. If not specified, the global tag is used.
version: ""

Expand All @@ -563,7 +565,7 @@ telemetry:
requests: {}
image:
# -- Image repository for the telemetry pod.
name: "ghcr.io/liqotech/telemetry"
name: "ghcr.io/cheina97/telemetry"
# -- Custom version for the telemetry image. If not specified, the global tag is used.
version: ""
config:
Expand All @@ -576,7 +578,7 @@ virtualKubelet:
replicas: 1
image:
# -- Image repository for the virtual kubelet pod.
name: "ghcr.io/liqotech/virtual-kubelet"
name: "ghcr.io/cheina97/virtual-kubelet"
# -- Custom version for the virtual kubelet image. If not specified, the global tag is used.
version: ""
# Additional values that are added to virtual kubelet deployments and pods.
Expand Down Expand Up @@ -624,7 +626,7 @@ uninstaller:
requests: {}
image:
# -- Image repository for the uninstaller pod.
name: "ghcr.io/liqotech/uninstaller"
name: "ghcr.io/cheina97/uninstaller"
# -- Custom version for the uninstaller image. If not specified, the global tag is used.
version: ""

Expand All @@ -650,7 +652,7 @@ proxy:
priorityClassName: ""
image:
# -- Image repository for the proxy pod.
name: "ghcr.io/liqotech/proxy"
name: "ghcr.io/cheina97/proxy"
# -- Custom version for the proxy image. If not specified, the global tag is used.
version: ""
service:
Expand Down
3 changes: 2 additions & 1 deletion pkg/consts/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const (
IpamPort = 6000
// SyncInterval is the frequency at which the IPAM should periodically sync its status.
SyncInterval = 2 * time.Minute

// SyncGracePeriod is the time the IPAM sync routine should wait before performing a deletion.
SyncGracePeriod = 1 * time.Minute
// NetworkNotRemappedLabelKey is the label key used to mark a Network that does not need CIDR remapping.
NetworkNotRemappedLabelKey = "ipam.liqo.io/network-not-remapped"
// NetworkNotRemappedLabelValue is the label value used to mark a Network that does not need CIDR remapping.
Expand Down
16 changes: 10 additions & 6 deletions pkg/ipam/core/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package ipamcore
import (
"fmt"
"net/netip"
"slices"
"time"
)

// Ipam represents the IPAM core structure.
Expand Down Expand Up @@ -72,10 +72,10 @@ func (ipam *Ipam) NetworkAcquireWithPrefix(prefix netip.Prefix) *netip.Prefix {

// NetworkRelease frees the network with the given prefix.
// It returns the freed network or nil if the network is not found.
func (ipam *Ipam) NetworkRelease(prefix netip.Prefix) *netip.Prefix {
func (ipam *Ipam) NetworkRelease(prefix netip.Prefix, gracePeriod time.Duration) *netip.Prefix {
for i := range ipam.roots {
if isPrefixChildOf(ipam.roots[i].prefix, prefix) {
if result := networkRelease(prefix, &ipam.roots[i]); result != nil {
if result := networkRelease(prefix, &ipam.roots[i], gracePeriod); result != nil {
return result
}
}
Expand Down Expand Up @@ -137,13 +137,13 @@ func (ipam *Ipam) IPAcquireWithAddr(prefix netip.Prefix, addr netip.Addr) (*neti

// IPRelease frees the IP address from the given prefix.
// It returns the freed IP address or nil if the IP address is not found.
func (ipam *Ipam) IPRelease(prefix netip.Prefix, addr netip.Addr) (*netip.Addr, error) {
func (ipam *Ipam) IPRelease(prefix netip.Prefix, addr netip.Addr, gracePeriod time.Duration) (*netip.Addr, error) {
node, err := ipam.search(prefix)
if err != nil {
return nil, err
}
if node != nil {
return node.ipRelease(addr), nil
return node.ipRelease(addr, gracePeriod), nil
}
return nil, nil
}
Expand All @@ -155,7 +155,11 @@ func (ipam *Ipam) ListIPs(prefix netip.Prefix) ([]netip.Addr, error) {
return nil, err
}
if node != nil {
return slices.Clone(node.ips), nil
addrs := make([]netip.Addr, len(node.ips))
for i := range node.ips {
addrs[i] = node.ips[i].addr
}
return addrs, nil
}
return nil, nil
}
Expand Down
Loading

0 comments on commit d7f6531

Please sign in to comment.