Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5f1e521
refactored the spec and how we deal with labels
henderiw Jan 2, 2023
61788a7
added index label key
henderiw Jan 2, 2023
8b6f030
added index in allocation
henderiw Jan 2, 2023
1547750
added discovery
henderiw Jan 6, 2023
6061872
updated alloc client
henderiw Jan 6, 2023
80a9d10
updated alloc client
henderiw Jan 6, 2023
7f4345d
added new alloc grpc
henderiw Jan 6, 2023
ae2223c
reworked the proxy-cache
henderiw Jan 8, 2023
0afdd40
updated the proxy logic
henderiw Jan 9, 2023
87d9bdb
moved ipam proxy client as part of the controller
henderiw Jan 10, 2023
4406fdd
updated proto for watch response
henderiw Jan 10, 2023
97567a4
removed prefix key
henderiw Jan 10, 2023
ef8530d
removed prefix key
henderiw Jan 10, 2023
e995ac2
update makefile
henderiw Jan 10, 2023
2643a6a
added unit test for meta library
henderiw Jan 10, 2023
fcf56f5
major rework of ipam module
henderiw Jan 13, 2023
1cb8225
route handling w/o pointer receiver
henderiw Jan 13, 2023
f70cf18
updated aggregate + reinit handling
henderiw Jan 13, 2023
682b4d5
add watcher
henderiw Jan 13, 2023
038a666
added backend
henderiw Jan 15, 2023
6f943fa
simplified runtime
henderiw Jan 16, 2023
4b17bd5
added more validation logic for dynamic/prefix route overlap
henderiw Jan 16, 2023
21496eb
updated validation check
henderiw Jan 17, 2023
b37a722
reworked the ipam for consistent and simplified implementation
henderiw Jan 19, 2023
cef401f
updated alloc operator to runtime
henderiw Jan 19, 2023
609703f
cleanup + add some test
henderiw Jan 20, 2023
d4ff42d
cleanup + add some test
henderiw Jan 20, 2023
c403f21
added logic for inserting network prefix w/o a parent network prefix
henderiw Jan 21, 2023
cdef919
added extra tests
henderiw Jan 21, 2023
1324e23
added extra tests
henderiw Jan 21, 2023
91fd044
optimized ipam tests
henderiw Jan 22, 2023
53f43f1
fixed gvk string tests
henderiw Jan 24, 2023
a0ea227
fixed gvk string tests
henderiw Jan 24, 2023
46824fc
fixed some issues in ctxt of nephio
henderiw Jan 26, 2023
4f7ea45
added niRef to deal with namespace independent allocations
henderiw Jan 27, 2023
c9561f5
cleanup
henderiw Jan 28, 2023
667437a
added support for /31 and /127
henderiw Jan 28, 2023
2e571d7
split client/server proxy config
henderiw Jan 28, 2023
8bf3419
updated clientproxy
henderiw Jan 29, 2023
a19a96e
added addtional label keys
henderiw Jan 31, 2023
3784107
hided proxy cache from client
henderiw Jan 31, 2023
5c7fa0e
update
steiler Feb 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*.so
*.dylib
bin/*
private.md

# Test binary, built with `go test -c`
*.test
Expand Down
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
VERSION ?= latest
REGISTRY ?= yndd
#REGISTRY ?= gcr.io/jbelamaric-public
REGISTRY ?= europe-docker.pkg.dev/srlinux/eu.gcr.io
PROJECT ?= ipam

KPT_BLUEPRINT_CFG_DIR ?= blueprint/fn-config
Expand All @@ -9,8 +8,6 @@ KPT_BLUEPRINT_PKG_DIR ?= blueprint/${PROJECT}

# Image URL to use all building/pushing image targets
IMG ?= $(REGISTRY)/${PROJECT}-controller:$(VERSION)
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.25.0

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand All @@ -20,6 +17,7 @@ GOBIN=$(shell go env GOBIN)
endif

# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
Expand Down Expand Up @@ -77,7 +75,7 @@ vet: ## Run go vet against code.

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out

##@ Build

Expand Down Expand Up @@ -157,6 +155,8 @@ PROTOC_GO_FAST ?= $(LOCALBIN)/protoc-gen-gofast
PROTOC_GO_GRPC ?= $(LOCALBIN)/protoc-gen-go-grpc

## Tool Versions
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.25.0
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.9.2
KPT_VERSION ?= main
Expand Down Expand Up @@ -193,10 +193,10 @@ $(KPTGEN): $(LOCALBIN)
.PHONY: protoc-gen-gofast
protoc-gen-gofast: $(PROTOC_GO_FAST) ## Download protoc-gen-gofast locally if necessary.
$(PROTOC_GO_FAST): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install github.com/gogo/protobuf/protoc-gen-gofast@$(PROTOC_GO_FAST_VERSION)
test -s $(LOCALBIN)/protoc-gen-gofast || GOBIN=$(LOCALBIN) go install -v github.com/gogo/protobuf/protoc-gen-gofast@$(PROTOC_GO_FAST_VERSION)

.PHONY: protoc-gen-go-grpc
protoc-gen-gogrpc: $(PROTOC_GO_GRPC) ## Download protoc-gen-golang-grpc locally if necessary.
$(PROTOC_GO_GRPC): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$(PROTOC_GO_GRPC_VERSION)
test -s $(LOCALBIN)/protoc-gen-go-grpc || GOBIN=$(LOCALBIN) go install -v google.golang.org/grpc/cmd/protoc-gen-go-grpc@$(PROTOC_GO_GRPC_VERSION)

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ The IPAM is a kubernetes native IP address management, which supports:
![ipam architecture](ipam-architecture.jpg)

## ipam logic and terminology

The IPAM has multiple network contexts (implemented as network-instances) that can have multiple prefixes that can be nested. The top prefix of a nested hierarchy is called an aggregated prefix. At the bottom layer we can have IP ranges or IP addresses that are allocated from within a prefix.

![ipam hierarchy](ipam-hierarchy.jpg)

Prefix - A subnet defined within an aggregate prefix. Prefixes extend the hierarchy by nesting within one another. (For example, 2000:1:1::/64 will appear within 2000:1::/48.)
Prefix - A subnet defined within an aggregate prefix. Prefixes extend the hierarchy by nesting within one another. (For example, 2000:1:1::/64 will appear within 2000:1::/48.)

IP Range - An arbitrary range of individual IP addresses within a prefix, all sharing the same mask. (out of scope for now)

Expand Down
47 changes: 32 additions & 15 deletions apis/ipam/v1alpha1/LabelKeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,36 @@ limitations under the License.
package v1alpha1

const (
NephioNetworkInstanceKey = "nephio.org/network-instance"
NephioPrefixKindKey = "nephio.org/prefix-kind"
NephioPrefixLengthKey = "nephio.org/prefix-length"
NephioAddressFamilyKey = "nephio.org/address-family"
NephioIPPrefixNameKey = "nephio.org/prefix-name"
NephioNetworkNameKey = "nephio.org/network-name"
NephioNetworkKey = "nephio.org/network"
//NephioParentNetKey = "nephio.org/parent-net"
NephioParentPrefixLengthKey = "nephio.org/parent-prefix-length"
NephioIPAllocactionNameKey = "nephio.org/allocation-name"
NephioPoolKey = "nephio.org/pool"
NephioGatewayKey = "nephio.org/gateway"
NephioInterfaceKey = "nephio.org/interface"
NephioApplicationPartOfKey = "app.kubernetes.io/part-of"
NephioOriginKey = "nephio.org/origin"
// ipam system defined
//NephioNetworkInstanceKey = "nephio.org/network-instance"
NephioPrefixKindKey = "nephio.org/prefix-kind"
//NephioPrefixKey = "nephio.org/prefix"
//NephioPrefixLengthKey = "nephio.org/prefix-length"
NephioAddressFamilyKey = "nephio.org/address-family"
NephioSubnetKey = "nephio.org/subnet" // this is the subnet in prefix annotation used for GW selection
//NephioParentPrefixLengthKey = "nephio.org/parent-prefix-length"
NephioPoolKey = "nephio.org/pool"
NephioGatewayKey = "nephio.org/gateway"
NephioOwnerGvkKey = "nephio.org/owner-gvk"
NephioOwnerNsnNameKey = "nephio.org/owner-nsn-name"
NephioOwnerNsnNamespaceKey = "nephio.org/owner-nsn-namespace"
NephioGvkKey = "nephio.org/gvk"
NephioNsnNameKey = "nephio.org/nsn-name"
NephioNsnNamespaceKey = "nephio.org/nsn-namespace"
//NephioIPAllocactionNameKey = "nephio.org/allocation-name"
//NephioIPContributingRouteKey = "nephio.org/contributing-route"
//NephioReplacementNameKey = "nephio.org/replacement-name"
//NephioSubnetNameKey = "nephio.org/subnet-name" // this is the subnet string or name given in the spec/selector
//ipam user defined
NephioInterfaceKey = "nephio.org/interface"
NephioNetworkNameKey = "nephio.org/network-name"
NephioPurposeKey = "nephio.org/purpose"
NephioApplicationPartOfKey = "app.kubernetes.io/part-of"
NephioIndexKey = "nephio.org/index"
NephioSiteKey = "nephio.org/site"
NephioRegionKey = "nephio.org/region"
NephioAvailabilityZoneKey = "nephio.org/availability-zone"
// ipam status
NephioAllocatedPrefix = "nephio.org/allocated-prefix"
NephioAllocatedGateway = "nephio.org/allocated-gateway"
)
53 changes: 38 additions & 15 deletions apis/ipam/v1alpha1/ipallocation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package v1alpha1
import (
"reflect"

"github.com/nokia/k8s-ipam/internal/meta"
"github.com/nokia/k8s-ipam/internal/utils/iputil"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)
Expand All @@ -27,31 +29,47 @@ import (
type IPAllocationSpec struct {
// +kubebuilder:validation:Enum=`network`;`loopback`;`pool`;`aggregate`
// +kubebuilder:default=network
PrefixKind string `json:"kind"`
PrefixKind PrefixKind `json:"kind" yaml:"kind"`
// NetworkInstanceRef identifies the networkInstance for this prefix
NetworkInstanceRef *NetworkInstanceReference `json:"networkInstanceRef"`
// +kubebuilder:validation:Enum=`ipv4`;`ipv6`
AddressFamily string `json:"addressFamily,omitempty"`
AddressFamily iputil.AddressFamily `json:"addressFamily,omitempty" yaml:"addressFamily,omitempty"`
// Prefix allows the client to indicate the prefix that was already allocated and validate if the allocation is still consistent
// +kubebuilder:validation:Pattern=`(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/(([0-9])|([1-2][0-9])|(3[0-2]))|((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))`
Prefix string `json:"prefix,omitempty"`
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
// PrefixLength allows to client to indicate the prefixLength he wants for the allocation
PrefixLength uint8 `json:"prefixLength,omitempty"`
// used for prefixes, if not supplied we use eother /32 for ipv4 and /128 for ipv6
PrefixLength uint8 `json:"prefixLength,omitempty" yaml:"prefixLength,omitempty"`
// index is used for deterministic allocation
Index uint32 `json:"index,omitempty" yaml:"index,omitempty"`
// Label selector for selecting the context from which the IP prefix/address gets allocated
Selector *metav1.LabelSelector `json:"selector,omitempty"`
Selector *metav1.LabelSelector `json:"selector,omitempty" yaml:"selector,omitempty"`
// Labels provide metadata to the prefix. They are part of the spec since the allocation
// selector will use these labels for allocation more specific prefixes/addresses within this prefix
// As such we distinguish clearly between the metadata labels and the labels used in the spec
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
// indicates a prefix has to be created which is not an address
CreatePrefix bool `json:"createPrefix,omitempty" yaml:"createPrefix,omitempty"`
// expiryTime indicated when the allocation expires
ExpiryTime string `json:"expiryTime,omitempty" yaml:"expiryTime,omitempty"`
}

// IPAllocationStatus defines the observed state of IPAllocation
type IPAllocationStatus struct {
ConditionedStatus `json:",inline"`
ConditionedStatus `json:",inline" yaml:",inline"`
// AllocatedPrefix identifies the prefix that was allocated by the IPAM system
AllocatedPrefix string `json:"prefix,omitempty"`
AllocatedPrefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
// Gateway identifies the gatway IP for the network
Gateway string `json:"gateway,omitempty"`
Gateway string `json:"gateway,omitempty" yaml:"gateway,omitempty"`
// expiryTime indicated when the allocation expires
ExpiryTime string `json:"expiryTime,omitempty" yaml:"expiryTime,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="SYNC",type="string",JSONPath=".status.conditions[?(@.kind=='Synced')].status"
// +kubebuilder:printcolumn:name="STATUS",type="string",JSONPath=".status.conditions[?(@.kind=='Ready')].status"
// +kubebuilder:printcolumn:name="NETWORK-INSTANCE",type="string",JSONPath=".spec.networkInstance"
// +kubebuilder:printcolumn:name="KIND",type="string",JSONPath=".spec.kind"
// +kubebuilder:printcolumn:name="AF",type="string",JSONPath=".spec.addressFamily"
// +kubebuilder:printcolumn:name="PREFIXLENGTH",type="string",JSONPath=".spec.prefixLength"
Expand All @@ -62,20 +80,20 @@ type IPAllocationStatus struct {
// +kubebuilder:resource:categories={nephio,ipam}
// IPAllocation is the Schema for the ipallocations API
type IPAllocation struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
metav1.TypeMeta `json:",inline" yaml:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`

Spec IPAllocationSpec `json:"spec,omitempty"`
Status IPAllocationStatus `json:"status,omitempty"`
Spec IPAllocationSpec `json:"spec,omitempty" yaml:"spec,omitempty"`
Status IPAllocationStatus `json:"status,omitempty" yaml:"status,omitempty"`
}

//+kubebuilder:object:root=true

// IPAllocationList contains a list of IPAllocation
type IPAllocationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []IPAllocation `json:"items"`
metav1.TypeMeta `json:",inline" yaml:",inline"`
metav1.ListMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`
Items []IPAllocation `json:"items" yaml:"items"`
}

func init() {
Expand All @@ -87,4 +105,9 @@ var (
IPAllocationGroupKind = schema.GroupKind{Group: GroupVersion.Group, Kind: IPAllocationKind}.String()
IPAllocationKindAPIVersion = IPAllocationKind + "." + GroupVersion.String()
IPAllocationGroupVersionKind = GroupVersion.WithKind(IPAllocationKind)
IPAllocationKindGVKString = meta.GVKToString(&schema.GroupVersionKind{
Group: GroupVersion.Group,
Version: GroupVersion.Version,
Kind: IPAllocationKind,
})
)
Loading