├── config ├── manager │ └── kustomization.yaml ├── prometheus │ ├── kustomization.yaml │ └── monitor.yaml ├── samples │ ├── nephio │ │ ├── vpc1.yaml │ │ ├── vpc1-aggregate0.yaml │ │ ├── vpc1-net-n3-prefix1.yaml │ │ ├── vpc1-net-n4-prefix1.yaml │ │ ├── vpc1-net-n6-prefix1.yaml │ │ └── topology.yaml │ ├── ipam2 │ │ ├── vpc2.yaml │ │ ├── vpc1.yaml │ │ ├── vpc1-aggregate0.yaml │ │ ├── vpc1-aggregate1.yaml │ │ ├── vpc1-network1-prefix2.yaml │ │ ├── vpc1-network1-prefix3.yaml │ │ ├── vpc1-network2-prefix1.yaml │ │ ├── vpc1-alloc-pool-dyn1.yaml │ │ ├── vpc1-network1-prefix1.yaml │ │ ├── vpc1-network1-prefix10-static.yaml │ │ ├── vpc1-network1-alloc-dyn1.yaml │ │ ├── vpc2-us-central1-edge1-net1-allocstatic1.yaml │ │ ├── vpcmgmt.yaml │ │ ├── vpcmgmtfabric.yaml │ │ ├── vpc1-network1-alloc-dyn2-n3.yaml │ │ ├── vpcmgmt2-fabric1-prefix1.yaml │ │ ├── vpcmgmt2-fabric2-prefix1.yaml │ │ ├── vpcmgmt2-fabric1-node1-alloc.yaml │ │ ├── vpcmgmt2-fabric1-node2-alloc.yaml │ │ ├── vpcmgmt2.yaml │ │ ├── vpcmgmt2-fabric2-prefix-alloc.yaml │ │ ├── vpc2-us-central1-edge1-net1-alloc1.yaml │ │ ├── vpcmgmt-node1-alloc.yaml │ │ ├── vpcmgmt-node2-alloc.yaml │ │ ├── vpc2-us-central1-edge1-net1-alloc2.yaml │ │ ├── vpc2-us-central1-edge2-net1-alloc1.yaml │ │ ├── vpcmgmt2-fabric3-prefix-alloc.yaml │ │ ├── vpc2-us-central1-edge1-net1-prefix2.yaml │ │ ├── vpc2-us-central1-edge2-net1-prefix2.yaml │ │ ├── vpcmgmt-node3-allocstatic.yaml │ │ ├── vpc2-us-central1-edge1-net1-prefix1.yaml │ │ └── vpc2-us-central1-edge3-net1-allocprefix-dynamic.yaml │ ├── vlan │ │ ├── vlan100.yaml │ │ ├── vlan200.yaml │ │ ├── vlanDynamic1.yaml │ │ ├── vlanDynamic2.yaml │ │ └── vlandb-edge1.yaml │ ├── ipam │ │ ├── vpc1-edge1-prefix1-alloc-dynamic1.yaml │ │ ├── vpc1.yaml │ │ ├── vpc1-edge1-pool.yaml │ │ ├── vpc1-edge1-prefix1.yaml │ │ └── vpc1-edge2-prefix1.yaml │ ├── interconnect │ │ ├── logical_interconnect.yaml │ │ ├── interconnect_dynamic.yaml │ │ ├── interconnect_static.yaml │ │ └── interconnect_static_dynamic.yaml │ ├── topo │ │ ├── nephio-dualleaf.yaml │ │ └── nephio-single.yaml │ └── replicas │ │ └── replica-server.yaml ├── default │ ├── manager_config_patch.yaml │ ├── manager_auth_proxy_patch.yaml │ └── kustomization.yaml ├── crd │ ├── patches │ │ ├── cainjection_in_ipam_ipaddresses.yaml │ │ ├── cainjection_in_ipam_ipprefixes.yaml │ │ ├── cainjection_in_ipam_ipallocations.yaml │ │ ├── cainjection_in_ipam_networkinstances.yaml │ │ ├── cainjection_in_nephio.org_networkinstances.yaml │ │ ├── webhook_in_ipam_ipaddresses.yaml │ │ ├── webhook_in_ipam_ipprefixes.yaml │ │ ├── webhook_in_ipam_ipallocations.yaml │ │ ├── webhook_in_ipam_networkinstances.yaml │ │ └── webhook_in_nephio.org_networkinstances.yaml │ ├── kustomizeconfig.yaml │ └── kustomization.yaml └── rbac │ ├── service_account.yaml │ ├── auth_proxy_client_clusterrole.yaml │ ├── role_binding.yaml │ ├── auth_proxy_role_binding.yaml │ ├── leader_election_role_binding.yaml │ ├── auth_proxy_role.yaml │ ├── auth_proxy_service.yaml │ ├── ipam_ipprefix_viewer_role.yaml │ ├── ipam_ipaddress_viewer_role.yaml │ ├── ipam_ipallocation_viewer_role.yaml │ ├── ipam_networkinstance_viewer_role.yaml │ ├── kustomization.yaml │ ├── nephio.org_networkinstance_viewer_role.yaml │ ├── ipam_ipprefix_editor_role.yaml │ ├── ipam_ipaddress_editor_role.yaml │ ├── ipam_ipallocation_editor_role.yaml │ ├── ipam_networkinstance_editor_role.yaml │ ├── nephio.org_networkinstance_editor_role.yaml │ └── leader_election_role.yaml ├── docs ├── inventory │ └── config.md └── start │ └── install.md ├── .gitattributes ├── ipam-hierarchy.jpg ├── artifacts ├── ns.yaml ├── sa.yaml ├── service.yaml ├── rbac-clusterrolebinding-controller.yaml ├── rbac-rolebinding-leader-election.yaml └── rbac-role-leader-election.yaml ├── ipam-architecture.jpg ├── blueprint ├── resource-backend │ ├── app │ │ ├── README.md │ │ ├── Kptfile │ │ ├── configmaps │ │ │ ├── configmap-server-variants.yaml │ │ │ ├── node_model-x.server.com-server1.yaml │ │ │ ├── node_model-x.server.com-server2.yaml │ │ │ ├── configmap_srlinux-topomac-script.yaml │ │ │ ├── configmap_srlinux-entrypoint.yaml │ │ │ └── node_model-srlinux.nokia.com-ixrd3l.yaml │ │ └── controller │ │ │ ├── serviceaccount-controller.yaml │ │ │ ├── grpc │ │ │ └── service-grpc.yaml │ │ │ ├── clusterrolebinding-controller.yaml │ │ │ ├── rolebinding-leader-election.yaml │ │ │ └── role-leader-election.yaml │ ├── namespace.yaml │ ├── README.md │ ├── crd │ │ ├── Kptfile │ │ └── README.md │ └── Kptfile └── fn-config │ └── controller-grpc-fn-config.yaml ├── .dockerignore ├── pkg ├── backend │ ├── ipam │ │ ├── ipam_suite_test.go │ │ ├── error.go │ │ ├── validator_dynamic.go │ │ └── getter.go │ ├── vlan │ │ ├── vlan_suite_test.go │ │ ├── applogic_get.go │ │ ├── watcher.go │ │ └── applogic_apply.go │ ├── watcher.go │ ├── backend.go │ └── storage.go ├── db │ ├── iterator.go │ ├── entry.go │ ├── vlandb │ │ ├── vlandb_test.go │ │ └── vlandb.go │ ├── entry_test.go │ └── vxlandb │ │ ├── vxlandb.go │ │ └── vxlandb_test.go ├── utils │ └── util │ │ ├── pointer.go │ │ └── util.go ├── meta │ ├── meta.go │ ├── interfaces.go │ ├── namespace_name.go │ ├── labels.go │ ├── errors.go │ ├── annotations.go │ ├── gvr.go │ ├── meta_test.go │ ├── owner.go │ └── unstructured.go ├── resource │ ├── resource.go │ ├── applicator.go │ └── error.go ├── objects │ ├── iterator.go │ └── objects.go ├── proto │ ├── resource │ │ └── config.go │ └── resourcepb │ │ └── resource.proto ├── hash │ └── hash_test.go └── proxy │ ├── beclient │ ├── client_interface.go │ └── client_mock.go │ └── clientproxy │ ├── resp_validator.go │ ├── resource_client.go │ └── vlan │ └── vlan_mock.go ├── .gitignore ├── hack └── boilerplate.go.txt ├── apis ├── topo │ └── v1alpha1 │ │ ├── interconnect_interfaces.go │ │ ├── rawtopology_interfaces.go │ │ ├── groupversion_info.go │ │ └── logical_interconnect_interfaces.go ├── resource │ ├── common │ │ └── v1alpha1 │ │ │ ├── docs.go │ │ │ ├── namespacename.go │ │ │ ├── cache_id.go │ │ │ ├── namespacename_test.go │ │ │ └── LabelKeys.go │ ├── vlan │ │ └── v1alpha1 │ │ │ ├── vlan_claim_types.go │ │ │ ├── groupversion_info.go │ │ │ ├── vlan_interfaces.go │ │ │ └── vlanindex_interfaces.go │ ├── ipam │ │ └── v1alpha1 │ │ │ ├── groupversion_info.go │ │ │ ├── ipam_types.go │ │ │ ├── networkinstance_test.go │ │ │ └── ipprefix_interfaces.go │ └── vxlan │ │ └── v1alpha1 │ │ ├── groupversion_info.go │ │ └── vxlanindex_interfaces.go ├── inv │ └── v1alpha1 │ │ ├── provider_types.go │ │ ├── groupversion_info.go │ │ ├── connectivity.go │ │ ├── logical_endpoint_interfaces.go │ │ ├── node_config_interfaces.go │ │ ├── target_interfaces.go │ │ ├── topology_interfaces.go │ │ ├── node_interfaces.go │ │ ├── link_interfaces.go │ │ └── node_model_types.go └── auto │ └── v1alpha1 │ └── groupversion_info.go ├── controllers ├── node │ └── watch_general.go ├── link-controller │ └── watch_general.go ├── logicalinterconnect-controller │ └── watch_general.go ├── controllers.go ├── ctrlconfig │ └── config.go ├── ipamspecializer │ └── reconciler.go └── vlanspecializer │ └── reconciler.go ├── PROJECT ├── cmd ├── commands.go └── main.go ├── Dockerfile └── internal ├── healthhandler └── subserver.go └── grpcserver ├── health.go ├── config.go └── options.go /config/manager/kustomization.yaml: -------------------------------------------------------------------------------- 1 | resources: 2 | - manager.yaml 3 | -------------------------------------------------------------------------------- /docs/inventory/config.md: -------------------------------------------------------------------------------- 1 | # configuring a low level topology 2 | 3 | -------------------------------------------------------------------------------- /config/prometheus/kustomization.yaml: -------------------------------------------------------------------------------- 1 | resources: 2 | - monitor.yaml 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /ipam-hierarchy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nokia/k8s-ipam/HEAD/ipam-hierarchy.jpg -------------------------------------------------------------------------------- /artifacts/ns.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: backend-system -------------------------------------------------------------------------------- /ipam-architecture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nokia/k8s-ipam/HEAD/ipam-architecture.jpg -------------------------------------------------------------------------------- /blueprint/resource-backend/app/README.md: -------------------------------------------------------------------------------- 1 | # app 2 | 3 | ## Description 4 | resource-backend controller which hold ipam/vlan 5 | -------------------------------------------------------------------------------- /blueprint/resource-backend/namespace.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: backend-system 5 | annotations: {} 6 | -------------------------------------------------------------------------------- /config/samples/nephio/vpc1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: NetworkInstance 3 | metadata: 4 | name: sample-vpc 5 | spec: 6 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | # More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file 2 | # Ignore build and test binaries. 3 | bin/ 4 | testbin/ 5 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpc2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: NetworkInstance 3 | metadata: 4 | name: vpc2 5 | spec: 6 | prefixes: 7 | - prefix: 10.0.0.0/8 -------------------------------------------------------------------------------- /blueprint/resource-backend/README.md: -------------------------------------------------------------------------------- 1 | # resource-backend 2 | 3 | ## Description 4 | resource-backend controller which hold ipam/vlan 5 | 6 | see [ipam](https://github.com/nokia/k8s-ipam) 7 | -------------------------------------------------------------------------------- /config/samples/vlan/vlan100.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: vlan.alloc.nephio.org/v1alpha1 2 | kind: VLAN 3 | metadata: 4 | name: vlan100 5 | spec: 6 | vlanDatabase: 7 | name: edge1 8 | vlanID: 100 9 | -------------------------------------------------------------------------------- /config/samples/vlan/vlan200.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: vlan.alloc.nephio.org/v1alpha1 2 | kind: VLAN 3 | metadata: 4 | name: vlan200 5 | spec: 6 | vlanDatabase: 7 | name: edge1 8 | vlanID: 200 9 | -------------------------------------------------------------------------------- /config/samples/vlan/vlanDynamic1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: vlan.alloc.nephio.org/v1alpha1 2 | kind: VLANAllocation 3 | metadata: 4 | name: dynamic1 5 | spec: 6 | vlanDatabase: 7 | name: edge1 8 | -------------------------------------------------------------------------------- /config/samples/vlan/vlanDynamic2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: vlan.alloc.nephio.org/v1alpha1 2 | kind: VLANAllocation 3 | metadata: 4 | name: dynamic2 5 | spec: 6 | vlanDatabase: 7 | name: edge1 8 | -------------------------------------------------------------------------------- /config/samples/vlan/vlandb-edge1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: vlan.alloc.nephio.org/v1alpha1 2 | kind: VLANDatabase 3 | metadata: 4 | name: edge1 5 | spec: 6 | labels: 7 | nephio.org/site: edge1 8 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpc1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: NetworkInstance 3 | metadata: 4 | name: vpc1 5 | spec: 6 | prefixes: 7 | - prefix: 10.0.0.0/8 8 | - prefix: 10.0.0.0/16 9 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpc1-aggregate0.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: aggregate0 5 | spec: 6 | kind: aggregate 7 | prefix: 10.0.0.0/8 8 | networkInstance: vpc-1 9 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpc1-aggregate1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: aggregate1 5 | spec: 6 | kind: aggregate 7 | prefix: 10.0.0.0/16 8 | networkInstance: vpc-1 9 | -------------------------------------------------------------------------------- /blueprint/resource-backend/crd/Kptfile: -------------------------------------------------------------------------------- 1 | apiVersion: kpt.dev/v1 2 | kind: Kptfile 3 | metadata: 4 | name: crd 5 | annotations: 6 | config.kubernetes.io/local-config: "true" 7 | info: 8 | description: resource-backend crd 9 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpc1-network1-prefix2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: net1-prefix2 5 | spec: 6 | prefix: 10.0.1.2/24 7 | network: net1 8 | networkInstance: vpc-1 9 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpc1-network1-prefix3.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: net1-prefix2 5 | spec: 6 | prefix: 10.0.1.0/24 7 | network: net1 8 | networkInstance: vpc-1 9 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpc1-network2-prefix1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: net2-prefix1 5 | spec: 6 | prefix: 10.0.1.1/24 7 | subnetName: net2 8 | networkInstance: vpc1 9 | -------------------------------------------------------------------------------- /config/samples/nephio/vpc1-aggregate0.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: aggregate0 5 | spec: 6 | kind: aggregate 7 | prefix: 10.0.0.0/8 8 | networkInstance: sample-vpc 9 | -------------------------------------------------------------------------------- /config/default/manager_config_patch.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: controller-manager 5 | namespace: system 6 | spec: 7 | template: 8 | spec: 9 | containers: 10 | - name: manager 11 | -------------------------------------------------------------------------------- /artifacts/sa.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | labels: 5 | app.kubernetes.io/name: resource-backend 6 | app.kubernetes.io/part-of: resource-backend 7 | name: resource-backend-controller 8 | namespace: backend-system 9 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpc1-alloc-pool-dyn1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: alloc-pool1 5 | spec: 6 | kind: pool 7 | prefixLength: 16 8 | selector: 9 | matchLabels: 10 | nephio.org/network-instance: vpc-1 11 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpc1-network1-prefix1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: net1-prefix1 5 | labels: 6 | nephio.org/gateway: "true" 7 | spec: 8 | prefix: 10.0.1.1/24 9 | network: net1 10 | networkInstance: vpc-1 11 | -------------------------------------------------------------------------------- /pkg/backend/ipam/ipam_suite_test.go: -------------------------------------------------------------------------------- 1 | package ipam_test 2 | 3 | import ( 4 | "testing" 5 | 6 | . "github.com/onsi/ginkgo/v2" 7 | . "github.com/onsi/gomega" 8 | ) 9 | 10 | func TestIpam(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "Ipam Suite") 13 | } 14 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpc1-network1-prefix10-static.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: net1-prefix10 5 | labels: 6 | nephio.org/interface: n3 7 | spec: 8 | prefix: 10.0.1.10/24 9 | network: net1 10 | networkInstance: vpc-1 11 | -------------------------------------------------------------------------------- /blueprint/resource-backend/app/Kptfile: -------------------------------------------------------------------------------- 1 | apiVersion: kpt.dev/v1 2 | kind: Kptfile 3 | metadata: 4 | name: app 5 | namespace: resource-backend 6 | annotations: 7 | config.kubernetes.io/local-config: "true" 8 | info: 9 | description: resource-backend controller which hold ipam/vlan 10 | -------------------------------------------------------------------------------- /pkg/backend/vlan/vlan_suite_test.go: -------------------------------------------------------------------------------- 1 | package vlan_test 2 | 3 | import ( 4 | "testing" 5 | 6 | . "github.com/onsi/ginkgo/v2" 7 | . "github.com/onsi/gomega" 8 | ) 9 | 10 | func TestVLANBackend(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "VLAN Backend Suite") 13 | } 14 | -------------------------------------------------------------------------------- /blueprint/resource-backend/Kptfile: -------------------------------------------------------------------------------- 1 | apiVersion: kpt.dev/v1 2 | kind: Kptfile 3 | metadata: 4 | name: resource-backend 5 | namespace: backend-system 6 | annotations: 7 | config.kubernetes.io/local-config: "true" 8 | info: 9 | description: resource-backend controller which hold ipam/vlan 10 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpc1-network1-alloc-dyn1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: alloc1 5 | spec: 6 | kind: network 7 | selector: 8 | matchLabels: 9 | nephio.org/network-instance: vpc-1 10 | nephio.org/network-name: net1 11 | -------------------------------------------------------------------------------- /config/samples/nephio/vpc1-net-n3-prefix1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: sample-n3-net-prefix1 5 | labels: 6 | nephio.org/gateway: "true" 7 | spec: 8 | prefix: 10.0.1.1/24 9 | network: sample-n3-net 10 | networkInstance: sample-vpc 11 | -------------------------------------------------------------------------------- /config/samples/nephio/vpc1-net-n4-prefix1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: sample-n4-net-prefix1 5 | labels: 6 | nephio.org/gateway: "true" 7 | spec: 8 | prefix: 192.168.1.1/24 9 | network: sample-n4-net 10 | networkInstance: sample-vpc 11 | -------------------------------------------------------------------------------- /config/samples/nephio/vpc1-net-n6-prefix1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: sample-n6-net-prefix1 5 | labels: 6 | nephio.org/gateway: "true" 7 | spec: 8 | prefix: 172.1.1.1/24 9 | network: sample-n6-net 10 | networkInstance: sample-vpc 11 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpc2-us-central1-edge1-net1-allocstatic1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: us-central1.edge1.net1.alloc1 5 | spec: 6 | kind: network 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc2 10 | prefix: 10.0.0.100/24 -------------------------------------------------------------------------------- /config/samples/ipam2/vpcmgmt.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: NetworkInstance 3 | metadata: 4 | name: vpc-mgmt 5 | spec: 6 | prefixes: 7 | - prefix: 10.0.0.0/24 8 | labels: 9 | nephio.org/region: us-central1 10 | nephio.org/fabric: fabric1 11 | nephio.org/purpose: mgmt 12 | -------------------------------------------------------------------------------- /config/samples/ipam/vpc1-edge1-prefix1-alloc-dynamic1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.alloc.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: vpc1-edge1-net1-prefix1-dynamic1 5 | spec: 6 | kind: network 7 | networkInstance: 8 | name: vpc1 9 | selector: 10 | matchLabels: 11 | nephio.org/site: edge1 12 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpcmgmtfabric.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: NetworkInstance 3 | metadata: 4 | name: vpc-mgmt-fabric 5 | spec: 6 | prefixes: 7 | - prefix: 10.0.0.0/8 8 | labels: 9 | nephio.org/region: us-central1 10 | nephio.org/fabric: fabric1 11 | nephio.org/purpose: mgmt 12 | -------------------------------------------------------------------------------- /config/samples/ipam/vpc1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.alloc.nephio.org/v1alpha1 2 | kind: NetworkInstance 3 | metadata: 4 | name: vpc1 5 | spec: 6 | prefixes: 7 | - prefix: 1000::/32 8 | - prefix: 10.0.0.0/8 9 | - prefix: 192.168.0.0/16 10 | - prefix: 172.0.0.0/8 11 | labels: 12 | nephio.org/pool: "true" 13 | 14 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpc1-network1-alloc-dyn2-n3.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: alloc2-n3 5 | spec: 6 | kind: network 7 | selector: 8 | matchLabels: 9 | nephio.org/network-instance: vpc-1 10 | nephio.org/network-name: net1 11 | nephio.org/interface: n3 12 | -------------------------------------------------------------------------------- /blueprint/resource-backend/app/configmaps/configmap-server-variants.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2023 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | apiVersion: v1 6 | kind: ConfigMap 7 | metadata: 8 | name: x.server.com-variants 9 | annotations: {} 10 | data: 11 | server1: "" 12 | server2: "" 13 | -------------------------------------------------------------------------------- /blueprint/resource-backend/app/configmaps/node_model-x.server.com-server1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: inv.nephio.org/v1alpha1 2 | kind: NodeModel 3 | metadata: 4 | name: x.server.com-server1 5 | annotations: {} 6 | spec: 7 | provider: x.server.com 8 | interfaces: 9 | - name: "eth0" 10 | speed: "25G" 11 | - name: "eth1" 12 | speed: "25G" 13 | -------------------------------------------------------------------------------- /config/samples/ipam/vpc1-edge1-pool.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.alloc.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: vpc1-edge1-pool1 5 | spec: 6 | kind: pool 7 | networkInstance: 8 | name: vpc1 9 | selector: 10 | matchLabels: 11 | nephio.org/pool: "true" 12 | prefixLength: 16 13 | createPrefix: true 14 | 15 | -------------------------------------------------------------------------------- /config/crd/patches/cainjection_in_ipam_ipaddresses.yaml: -------------------------------------------------------------------------------- 1 | # The following patch adds a directive for certmanager to inject CA into the CRD 2 | apiVersion: apiextensions.k8s.io/v1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | annotations: 6 | cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) 7 | name: ipaddresses.ipam.nephio.org 8 | -------------------------------------------------------------------------------- /config/crd/patches/cainjection_in_ipam_ipprefixes.yaml: -------------------------------------------------------------------------------- 1 | # The following patch adds a directive for certmanager to inject CA into the CRD 2 | apiVersion: apiextensions.k8s.io/v1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | annotations: 6 | cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) 7 | name: ipprefixes.ipam.nephio.org 8 | -------------------------------------------------------------------------------- /config/crd/patches/cainjection_in_ipam_ipallocations.yaml: -------------------------------------------------------------------------------- 1 | # The following patch adds a directive for certmanager to inject CA into the CRD 2 | apiVersion: apiextensions.k8s.io/v1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | annotations: 6 | cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) 7 | name: ipallocations.ipam.nephio.org 8 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpcmgmt2-fabric1-prefix1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: fabric1 5 | spec: 6 | kind: loopback 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc-mgmt2 10 | prefix: 10.0.0.0/24 11 | labels: 12 | nephio.org/purpose: mgmt 13 | nephio.org/fabric: fabric1 14 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpcmgmt2-fabric2-prefix1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: fabric2 5 | spec: 6 | kind: loopback 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc-mgmt2 10 | prefix: 10.0.1.0/24 11 | labels: 12 | nephio.org/purpose: mgmt 13 | nephio.org/fabric: fabric2 14 | -------------------------------------------------------------------------------- /config/crd/patches/cainjection_in_ipam_networkinstances.yaml: -------------------------------------------------------------------------------- 1 | # The following patch adds a directive for certmanager to inject CA into the CRD 2 | apiVersion: apiextensions.k8s.io/v1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | annotations: 6 | cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) 7 | name: networkinstances.ipam.nephio.org 8 | -------------------------------------------------------------------------------- /config/samples/ipam/vpc1-edge1-prefix1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.alloc.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: vpc1-edge1-net1-prefix1 5 | spec: 6 | kind: network 7 | networkInstance: 8 | name: vpc1 9 | prefix: 10.0.0.1/24 10 | labels: 11 | nephio.org/gateway: "true" 12 | nephio.org/site: edge1 13 | nephio.org/network-name: net1 -------------------------------------------------------------------------------- /config/samples/ipam/vpc1-edge2-prefix1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.alloc.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: vpc1-edge2-net1-prefix1 5 | spec: 6 | kind: network 7 | networkInstance: 8 | name: vpc1 9 | prefix: 10.0.1.1/24 10 | labels: 11 | nephio.org/gateway: "true" 12 | nephio.org/site: edge2 13 | nephio.org/network-name: net1 -------------------------------------------------------------------------------- /config/samples/ipam2/vpcmgmt2-fabric1-node1-alloc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: fabric1.node1 5 | spec: 6 | kind: loopback 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc-mgmt2 10 | selector: 11 | matchLabels: 12 | nephio.org/purpose: mgmt 13 | nephio.org/fabric: fabric1 14 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpcmgmt2-fabric1-node2-alloc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: fabric1.node2 5 | spec: 6 | kind: loopback 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc-mgmt2 10 | selector: 11 | matchLabels: 12 | nephio.org/purpose: mgmt 13 | nephio.org/fabric: fabric1 14 | -------------------------------------------------------------------------------- /config/crd/patches/cainjection_in_nephio.org_networkinstances.yaml: -------------------------------------------------------------------------------- 1 | # The following patch adds a directive for certmanager to inject CA into the CRD 2 | apiVersion: apiextensions.k8s.io/v1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | annotations: 6 | cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) 7 | name: networkinstances.nephio.org.nephio.org 8 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpcmgmt2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: NetworkInstance 3 | metadata: 4 | name: vpc-mgmt2 5 | spec: 6 | prefixes: 7 | - prefix: 10.0.0.0/16 8 | labels: 9 | nephio.org/purpose: mgmt 10 | nephio.org/fabric: fabric1 11 | - prefix: 10.10.0.0/16 12 | labels: 13 | nephio.org/purpose: mgmt 14 | nephio.org/fabric: fabric2 15 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpcmgmt2-fabric2-prefix-alloc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: fabric2 5 | spec: 6 | kind: loopback 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc-mgmt2 10 | prefixLength: 24 11 | createPrefix: true 12 | labels: 13 | nephio.org/purpose: mgmt 14 | nephio.org/fabric: fabric2 15 | 16 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpc2-us-central1-edge1-net1-alloc1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: us-central1.edge1.net1.alloc1 5 | spec: 6 | kind: network 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc2 10 | labels: 11 | nephio.org/region: us-central1 12 | nephio.org/site: edge1 13 | nephio.org/network-name: net1 -------------------------------------------------------------------------------- /config/samples/ipam2/vpcmgmt-node1-alloc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: us-central1.fabric1.node1.mgmt.ipv4 5 | spec: 6 | kind: loopback 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc-mgmt 10 | selector: 11 | matchLabels: 12 | nephio.org/region: us-central1 13 | nephio.org/fabric: fabric1 14 | nephio.org/purpose: mgmt -------------------------------------------------------------------------------- /config/samples/ipam2/vpcmgmt-node2-alloc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: us-central1.fabric1.node2.mgmt.ipv4 5 | spec: 6 | kind: loopback 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc-mgmt 10 | selector: 11 | matchLabels: 12 | nephio.org/region: us-central1 13 | nephio.org/fabric: fabric1 14 | nephio.org/purpose: mgmt -------------------------------------------------------------------------------- /config/samples/ipam2/vpc2-us-central1-edge1-net1-alloc2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: us-central1.edge1.net1.alloc2 5 | spec: 6 | kind: network 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc2 10 | selector: 11 | matchLabels: 12 | nephio.org/region: us-central1 13 | nephio.org/site: edge1 14 | nephio.org/network-name: net1 -------------------------------------------------------------------------------- /config/samples/ipam2/vpc2-us-central1-edge2-net1-alloc1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: us-central1.edge2.net1.alloc1 5 | spec: 6 | kind: network 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc2 10 | selector: 11 | matchLabels: 12 | nephio.org/region: us-central1 13 | nephio.org/site: edge2 14 | nephio.org/network-name: net1 -------------------------------------------------------------------------------- /config/samples/ipam2/vpcmgmt2-fabric3-prefix-alloc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: fabric3 5 | spec: 6 | kind: loopback 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc-mgmt2 10 | prefixLength: 24 11 | #addressFamily: ipv4 12 | createPrefix: true 13 | labels: 14 | nephio.org/purpose: mgmt 15 | nephio.org/fabric: fabric3 16 | 17 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpc2-us-central1-edge1-net1-prefix2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: us-central1.edge1.net1.prefix2 5 | spec: 6 | kind: network 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc2 10 | prefix: 10.0.0.2/24 11 | labels: 12 | nephio.org/region: us-central1 13 | nephio.org/site: edge1 14 | nephio.org/network-name: net1 15 | -------------------------------------------------------------------------------- /blueprint/resource-backend/app/configmaps/node_model-x.server.com-server2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: inv.nephio.org/v1alpha1 2 | kind: NodeModel 3 | metadata: 4 | name: x.server.com-server2 5 | annotations: {} 6 | spec: 7 | provider: x.server.com 8 | interfaces: 9 | - name: "eth0" 10 | speed: "25G" 11 | - name: "eth1" 12 | speed: "25G" 13 | - name: "eth2" 14 | speed: "25G" 15 | - name: "eth3" 16 | speed: "25G" 17 | -------------------------------------------------------------------------------- /config/samples/ipam2/vpc2-us-central1-edge2-net1-prefix2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: us-central1.edge2.net1.prefix1 5 | spec: 6 | kind: network 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc2 10 | prefix: 10.0.1.1/24 11 | labels: 12 | nephio.org/gateway: "true" 13 | nephio.org/region: us-central1 14 | nephio.org/site: edge2 15 | nephio.org/network-name: net1 -------------------------------------------------------------------------------- /config/samples/ipam2/vpcmgmt-node3-allocstatic.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: us-central1.fabric1.node100.mgmt.ipv4 5 | spec: 6 | kind: loopback 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc-mgmt 10 | prefix: 10.0.0.100/32 11 | selector: 12 | matchLabels: 13 | nephio.org/region: us-central1 14 | nephio.org/fabric: fabric1 15 | nephio.org/purpose: mgmt -------------------------------------------------------------------------------- /config/samples/ipam2/vpc2-us-central1-edge1-net1-prefix1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPPrefix 3 | metadata: 4 | name: us-central1.edge1.net1.prefix1 5 | spec: 6 | kind: network 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc2 10 | prefix: 10.0.0.1/24 11 | labels: 12 | nephio.org/gateway: "true" 13 | nephio.org/region: us-central1 14 | nephio.org/site: edge1 15 | nephio.org/network-name: net1 16 | -------------------------------------------------------------------------------- /blueprint/fn-config/controller-grpc-fn-config.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: fn.kptgen.dev/v1alpha1 2 | kind: Config 3 | metadata: 4 | name: grpc 5 | annotations: 6 | config.kubernetes.io/local-config: "true" 7 | namespace: backend-system 8 | spec: 9 | selector: 10 | kind: Deployment 11 | name: controller 12 | containerName: controller 13 | services: 14 | - spec: 15 | ports: 16 | - name: grpc 17 | port: 9999 18 | targetPort: 9999 19 | protocol: TCP -------------------------------------------------------------------------------- /config/samples/ipam2/vpc2-us-central1-edge3-net1-allocprefix-dynamic.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: ipam.nephio.org/v1alpha1 2 | kind: IPAllocation 3 | metadata: 4 | name: us-central1.edge3.net1.dynprefix1 5 | spec: 6 | kind: network 7 | networkInstanceRef: 8 | namespace: default 9 | name: vpc2 10 | prefixLength: 24 11 | createPrefix: true 12 | labels: 13 | nephio.org/gateway: "true" 14 | nephio.org/region: us-central1 15 | nephio.org/site: edge3 16 | nephio.org/network-name: net1 -------------------------------------------------------------------------------- /config/crd/patches/webhook_in_ipam_ipaddresses.yaml: -------------------------------------------------------------------------------- 1 | # The following patch enables a conversion webhook for the CRD 2 | apiVersion: apiextensions.k8s.io/v1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | name: ipaddresses.ipam.nephio.org 6 | spec: 7 | conversion: 8 | strategy: Webhook 9 | webhook: 10 | clientConfig: 11 | service: 12 | namespace: system 13 | name: webhook-service 14 | path: /convert 15 | conversionReviewVersions: 16 | - v1 17 | -------------------------------------------------------------------------------- /config/crd/patches/webhook_in_ipam_ipprefixes.yaml: -------------------------------------------------------------------------------- 1 | # The following patch enables a conversion webhook for the CRD 2 | apiVersion: apiextensions.k8s.io/v1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | name: ipprefixes.ipam.nephio.org 6 | spec: 7 | conversion: 8 | strategy: Webhook 9 | webhook: 10 | clientConfig: 11 | service: 12 | namespace: system 13 | name: webhook-service 14 | path: /convert 15 | conversionReviewVersions: 16 | - v1 17 | -------------------------------------------------------------------------------- /config/crd/patches/webhook_in_ipam_ipallocations.yaml: -------------------------------------------------------------------------------- 1 | # The following patch enables a conversion webhook for the CRD 2 | apiVersion: apiextensions.k8s.io/v1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | name: ipallocations.ipam.nephio.org 6 | spec: 7 | conversion: 8 | strategy: Webhook 9 | webhook: 10 | clientConfig: 11 | service: 12 | namespace: system 13 | name: webhook-service 14 | path: /convert 15 | conversionReviewVersions: 16 | - v1 17 | -------------------------------------------------------------------------------- /config/crd/patches/webhook_in_ipam_networkinstances.yaml: -------------------------------------------------------------------------------- 1 | # The following patch enables a conversion webhook for the CRD 2 | apiVersion: apiextensions.k8s.io/v1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | name: networkinstances.ipam.nephio.org 6 | spec: 7 | conversion: 8 | strategy: Webhook 9 | webhook: 10 | clientConfig: 11 | service: 12 | namespace: system 13 | name: webhook-service 14 | path: /convert 15 | conversionReviewVersions: 16 | - v1 17 | -------------------------------------------------------------------------------- /blueprint/resource-backend/app/controller/serviceaccount-controller.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | annotations: {} 5 | creationTimestamp: null 6 | labels: 7 | app.kubernetes.io/component: tbd 8 | app.kubernetes.io/instance: tbd 9 | app.kubernetes.io/managed-by: kpt 10 | app.kubernetes.io/name: resource-backend 11 | app.kubernetes.io/part-of: resource-backend 12 | app.kubernetes.io/version: tbd 13 | name: resource-backend-controller 14 | namespace: backend-system 15 | -------------------------------------------------------------------------------- /config/crd/patches/webhook_in_nephio.org_networkinstances.yaml: -------------------------------------------------------------------------------- 1 | # The following patch enables a conversion webhook for the CRD 2 | apiVersion: apiextensions.k8s.io/v1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | name: networkinstances.nephio.org.nephio.org 6 | spec: 7 | conversion: 8 | strategy: Webhook 9 | webhook: 10 | clientConfig: 11 | service: 12 | namespace: system 13 | name: webhook-service 14 | path: /convert 15 | conversionReviewVersions: 16 | - v1 17 | -------------------------------------------------------------------------------- /artifacts/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | labels: 5 | app.kubernetes.io/name: resource-backend 6 | app.kubernetes.io/part-of: resource-backend 7 | fn.kptgen.dev/grpc: resource-backend-controller 8 | name: resource-backend-controller-grpc-svc 9 | namespace: backend-system 10 | spec: 11 | ports: 12 | - name: grpc 13 | port: 9999 14 | protocol: TCP 15 | targetPort: 9999 16 | selector: 17 | fn.kptgen.dev/grpc: resource-backend-controller 18 | status: 19 | loadBalancer: {} -------------------------------------------------------------------------------- /blueprint/resource-backend/crd/README.md: -------------------------------------------------------------------------------- 1 | # crd 2 | 3 | ## Description 4 | resource-backend crd 5 | 6 | ## Usage 7 | 8 | ### Fetch the package 9 | `kpt pkg get REPO_URI[.git]/PKG_PATH[@VERSION] crd` 10 | Details: https://kpt.dev/reference/cli/pkg/get/ 11 | 12 | ### View package content 13 | `kpt pkg tree crd` 14 | Details: https://kpt.dev/reference/cli/pkg/tree/ 15 | 16 | ### Apply the package 17 | ``` 18 | kpt live init crd 19 | kpt live apply crd --reconcile-timeout=2m --output=table 20 | ``` 21 | Details: https://kpt.dev/reference/cli/live/ 22 | -------------------------------------------------------------------------------- /config/rbac/service_account.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | apiVersion: v1 6 | kind: ServiceAccount 7 | metadata: 8 | labels: 9 | app.kubernetes.io/name: serviceaccount 10 | app.kuberentes.io/instance: controller-manager 11 | app.kubernetes.io/component: rbac 12 | app.kubernetes.io/created-by: ipam 13 | app.kubernetes.io/part-of: ipam 14 | app.kubernetes.io/managed-by: kustomize 15 | name: controller-manager 16 | namespace: system 17 | -------------------------------------------------------------------------------- /artifacts/rbac-clusterrolebinding-controller.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1 2 | kind: ClusterRoleBinding 3 | metadata: 4 | labels: 5 | app.kubernetes.io/name: resource-backend 6 | app.kubernetes.io/part-of: resource-backend 7 | name: resource-backend-controller-controller-role-binding 8 | roleRef: 9 | apiGroup: rbac.authorization.k8s.io 10 | kind: ClusterRole 11 | name: resource-backend-controller-controller-role 12 | subjects: 13 | - kind: ServiceAccount 14 | name: resource-backend-controller 15 | namespace: backend-system 16 | -------------------------------------------------------------------------------- /config/samples/interconnect/logical_interconnect.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: topo.nephio.org/v1alpha1 2 | kind: LogicalInterconnect 3 | metadata: 4 | name: sever2network-bond0 5 | spec: 6 | links: 2 7 | type: lag 8 | lacp: true 9 | endpoints: 10 | - name: bond0 11 | topologies: 12 | - cluster01 13 | selector: 14 | matchLabels: 15 | topo.nephio.org/node-name: 'server' + '-' + index 16 | - topologies: 17 | - dc 18 | selector: 19 | matchLabels: 20 | topo.nephio.org/redundancy-group: rack1 21 | selectorPolicy: 22 | nodeDiversity: 2 -------------------------------------------------------------------------------- /artifacts/rbac-rolebinding-leader-election.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1 2 | kind: RoleBinding 3 | metadata: 4 | labels: 5 | app.kubernetes.io/name: resource-backend 6 | app.kubernetes.io/part-of: resource-backend 7 | name: resource-backend-controller-leader-election-role-binding 8 | namespace: backend-system 9 | roleRef: 10 | apiGroup: rbac.authorization.k8s.io 11 | kind: Role 12 | name: resource-backend-controller-leader-election-role 13 | subjects: 14 | - kind: ServiceAccount 15 | name: resource-backend-controller 16 | namespace: backend-system 17 | -------------------------------------------------------------------------------- /config/crd/kustomizeconfig.yaml: -------------------------------------------------------------------------------- 1 | # This file is for teaching kustomize how to substitute name and namespace reference in CRD 2 | nameReference: 3 | - kind: Service 4 | version: v1 5 | fieldSpecs: 6 | - kind: CustomResourceDefinition 7 | version: v1 8 | group: apiextensions.k8s.io 9 | path: spec/conversion/webhook/clientConfig/service/name 10 | 11 | namespace: 12 | - kind: CustomResourceDefinition 13 | version: v1 14 | group: apiextensions.k8s.io 15 | path: spec/conversion/webhook/clientConfig/service/namespace 16 | create: false 17 | 18 | varReference: 19 | - path: metadata/annotations 20 | -------------------------------------------------------------------------------- /pkg/db/iterator.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import ( 4 | "golang.org/x/exp/constraints" 5 | ) 6 | 7 | type Iterator[T constraints.Integer] struct { 8 | current int 9 | keys []T 10 | db map[T]Entry[T] 11 | } 12 | 13 | func (r *Iterator[T]) Value() Entry[T] { 14 | return r.db[r.keys[r.current]] 15 | } 16 | 17 | func (r *Iterator[T]) Next() bool { 18 | r.current++ 19 | return r.current < len(r.keys) 20 | } 21 | 22 | func (r *Iterator[T]) IsConsecutive() bool { 23 | //fmt.Println("id:", r.current, "prevId", r.keys[r.current-1], "currId", r.keys[r.current]-1) 24 | return r.keys[r.current-1] == r.keys[r.current]-1 25 | } 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # If you prefer the allow list template instead of the deny list, see community template: 2 | # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore 3 | # 4 | # Binaries for programs and plugins 5 | *.exe 6 | *.exe~ 7 | *.dll 8 | *.so 9 | *.dylib 10 | bin/* 11 | private.md 12 | 13 | # Test binary, built with `go test -c` 14 | *.test 15 | 16 | # Output of the go coverage tool, specifically when used with LiteIDE 17 | *.out 18 | 19 | # Dependency directories (remove the comment below to include it) 20 | # vendor/ 21 | 22 | # Go workspace file 23 | go.work 24 | design.md 25 | wimtest 26 | vendor -------------------------------------------------------------------------------- /hack/boilerplate.go.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ -------------------------------------------------------------------------------- /config/rbac/auth_proxy_client_clusterrole.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | apiVersion: rbac.authorization.k8s.io/v1 6 | kind: ClusterRole 7 | metadata: 8 | labels: 9 | app.kubernetes.io/name: clusterrole 10 | app.kubernetes.io/instance: metrics-reader 11 | app.kubernetes.io/component: kube-rbac-proxy 12 | app.kubernetes.io/created-by: ipam 13 | app.kubernetes.io/part-of: ipam 14 | app.kubernetes.io/managed-by: kustomize 15 | name: metrics-reader 16 | rules: 17 | - nonResourceURLs: 18 | - "/metrics" 19 | verbs: 20 | - get 21 | -------------------------------------------------------------------------------- /artifacts/rbac-role-leader-election.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1 2 | kind: Role 3 | metadata: 4 | annotations: {} 5 | labels: 6 | app.kubernetes.io/name: resource-backend 7 | app.kubernetes.io/part-of: resource-backend 8 | name: resource-backend-controller-leader-election-role 9 | namespace: backend-system 10 | rules: 11 | - apiGroups: [""] 12 | resources: [configmaps] 13 | verbs: [get, watch, list, create, update, patch, delete] 14 | - apiGroups: [coordination.k8s.io] 15 | resources: [leases] 16 | verbs: [get, watch, list, create, update, patch, delete] 17 | - apiGroups: [""] 18 | resources: [events] 19 | verbs: [create, patch] -------------------------------------------------------------------------------- /apis/topo/v1alpha1/interconnect_interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | -------------------------------------------------------------------------------- /controllers/node/watch_general.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package node 18 | 19 | type adder interface { 20 | Add(item interface{}) 21 | } 22 | -------------------------------------------------------------------------------- /config/samples/topo/nephio-dualleaf.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: topo.nephio.org/v1alpha1 2 | kind: RawTopology 3 | metadata: 4 | name: fabric1 5 | spec: 6 | nodes: 7 | leaf1: 8 | provider: srl.nokia.com 9 | labels: 10 | inv.nephio.org/rack: rack1 11 | inv.nephio.org/rack-index: "1" 12 | inv.nephio.org/redundancy-group: rack1 13 | leaf2: 14 | provider: srl.nokia.com 15 | labels: 16 | inv.nephio.org/rack: rack1 17 | inv.nephio.org/rack-index: "1" 18 | inv.nephio.org/redundancy-group: rack1 19 | links: 20 | - endpoints: 21 | - { nodeName: leaf1, interfaceName: e1-30} 22 | - { nodeName: leaf2, interfaceName: e1-30} 23 | labels: 24 | nephio.org/purpose: infra 25 | -------------------------------------------------------------------------------- /controllers/link-controller/watch_general.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package link 18 | 19 | type adder interface { 20 | Add(item interface{}) 21 | } 22 | -------------------------------------------------------------------------------- /pkg/backend/vlan/applogic_get.go: -------------------------------------------------------------------------------- 1 | package vlan 2 | 3 | import ( 4 | "fmt" 5 | 6 | vlanv1alpha1 "github.com/nokia/k8s-ipam/apis/resource/vlan/v1alpha1" 7 | "github.com/nokia/k8s-ipam/pkg/db" 8 | "github.com/nokia/k8s-ipam/pkg/utils/util" 9 | ) 10 | 11 | func getHandlerSingleVlan(entries db.Entries[uint16], claim *vlanv1alpha1.VLANClaim) error { 12 | if len(entries) > 1 { 13 | return fmt.Errorf("get for single entry returned multiple: %v", entries) 14 | } 15 | // update the status 16 | claim.Status.VLANID = util.PointerUint16(entries[0].ID()) 17 | return nil 18 | } 19 | 20 | func getHandlerMultipleVlan(entries db.Entries[uint16], claim *vlanv1alpha1.VLANClaim) error { 21 | // TODO update the vlan status with the proper response 22 | return nil 23 | } 24 | -------------------------------------------------------------------------------- /config/rbac/role_binding.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | apiVersion: rbac.authorization.k8s.io/v1 6 | kind: ClusterRoleBinding 7 | metadata: 8 | labels: 9 | app.kubernetes.io/name: clusterrolebinding 10 | app.kubernetes.io/instance: manager-rolebinding 11 | app.kubernetes.io/component: rbac 12 | app.kubernetes.io/created-by: ipam 13 | app.kubernetes.io/part-of: ipam 14 | app.kubernetes.io/managed-by: kustomize 15 | name: manager-rolebinding 16 | roleRef: 17 | apiGroup: rbac.authorization.k8s.io 18 | kind: ClusterRole 19 | name: manager-role 20 | subjects: 21 | - kind: ServiceAccount 22 | name: controller-manager 23 | namespace: system 24 | -------------------------------------------------------------------------------- /config/rbac/auth_proxy_role_binding.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | apiVersion: rbac.authorization.k8s.io/v1 6 | kind: ClusterRoleBinding 7 | metadata: 8 | labels: 9 | app.kubernetes.io/name: clusterrolebinding 10 | app.kubernetes.io/instance: proxy-rolebinding 11 | app.kubernetes.io/component: kube-rbac-proxy 12 | app.kubernetes.io/created-by: ipam 13 | app.kubernetes.io/part-of: ipam 14 | app.kubernetes.io/managed-by: kustomize 15 | name: proxy-rolebinding 16 | roleRef: 17 | apiGroup: rbac.authorization.k8s.io 18 | kind: ClusterRole 19 | name: proxy-role 20 | subjects: 21 | - kind: ServiceAccount 22 | name: controller-manager 23 | namespace: system 24 | -------------------------------------------------------------------------------- /config/rbac/leader_election_role_binding.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | apiVersion: rbac.authorization.k8s.io/v1 6 | kind: RoleBinding 7 | metadata: 8 | labels: 9 | app.kubernetes.io/name: rolebinding 10 | app.kubernetes.io/instance: leader-election-rolebinding 11 | app.kubernetes.io/component: rbac 12 | app.kubernetes.io/created-by: ipam 13 | app.kubernetes.io/part-of: ipam 14 | app.kubernetes.io/managed-by: kustomize 15 | name: leader-election-rolebinding 16 | roleRef: 17 | apiGroup: rbac.authorization.k8s.io 18 | kind: Role 19 | name: leader-election-role 20 | subjects: 21 | - kind: ServiceAccount 22 | name: controller-manager 23 | namespace: system 24 | -------------------------------------------------------------------------------- /controllers/logicalinterconnect-controller/watch_general.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package logicalinterconnect 18 | 19 | type adder interface { 20 | Add(item interface{}) 21 | } 22 | -------------------------------------------------------------------------------- /apis/resource/common/v1alpha1/docs.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package v1 contains core API types used by most ndd resources. 18 | // +kubebuilder:object:generate=true 19 | package v1alpha1 20 | -------------------------------------------------------------------------------- /blueprint/resource-backend/app/controller/grpc/service-grpc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | annotations: {} 5 | creationTimestamp: null 6 | labels: 7 | app.kubernetes.io/component: tbd 8 | app.kubernetes.io/instance: tbd 9 | app.kubernetes.io/managed-by: kpt 10 | app.kubernetes.io/name: resource-backend 11 | app.kubernetes.io/part-of: resource-backend 12 | app.kubernetes.io/version: tbd 13 | fn.kptgen.dev/grpc: resource-backend-controller 14 | name: resource-backend-controller-grpc-svc 15 | namespace: backend-system 16 | spec: 17 | ports: 18 | - name: grpc 19 | port: 9999 20 | protocol: TCP 21 | targetPort: 9999 22 | selector: 23 | fn.kptgen.dev/grpc: resource-backend-controller 24 | status: 25 | loadBalancer: {} 26 | -------------------------------------------------------------------------------- /config/rbac/auth_proxy_role.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | apiVersion: rbac.authorization.k8s.io/v1 6 | kind: ClusterRole 7 | metadata: 8 | labels: 9 | app.kubernetes.io/name: clusterrole 10 | app.kubernetes.io/instance: proxy-role 11 | app.kubernetes.io/component: kube-rbac-proxy 12 | app.kubernetes.io/created-by: ipam 13 | app.kubernetes.io/part-of: ipam 14 | app.kubernetes.io/managed-by: kustomize 15 | name: proxy-role 16 | rules: 17 | - apiGroups: 18 | - authentication.k8s.io 19 | resources: 20 | - tokenreviews 21 | verbs: 22 | - create 23 | - apiGroups: 24 | - authorization.k8s.io 25 | resources: 26 | - subjectaccessreviews 27 | verbs: 28 | - create 29 | -------------------------------------------------------------------------------- /blueprint/resource-backend/app/controller/clusterrolebinding-controller.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1 2 | kind: ClusterRoleBinding 3 | metadata: 4 | annotations: {} 5 | creationTimestamp: null 6 | labels: 7 | app.kubernetes.io/component: tbd 8 | app.kubernetes.io/instance: tbd 9 | app.kubernetes.io/managed-by: kpt 10 | app.kubernetes.io/name: resource-backend 11 | app.kubernetes.io/part-of: resource-backend 12 | app.kubernetes.io/version: tbd 13 | name: resource-backend-controller-controller-role-binding 14 | roleRef: 15 | apiGroup: rbac.authorization.k8s.io 16 | kind: ClusterRole 17 | name: resource-backend-controller-controller-role 18 | subjects: 19 | - kind: ServiceAccount 20 | name: resource-backend-controller 21 | namespace: backend-system 22 | -------------------------------------------------------------------------------- /config/rbac/auth_proxy_service.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | apiVersion: v1 6 | kind: Service 7 | metadata: 8 | labels: 9 | control-plane: controller-manager 10 | app.kubernetes.io/name: service 11 | app.kubernetes.io/instance: controller-manager-metrics-service 12 | app.kubernetes.io/component: kube-rbac-proxy 13 | app.kubernetes.io/created-by: ipam 14 | app.kubernetes.io/part-of: ipam 15 | app.kubernetes.io/managed-by: kustomize 16 | name: controller-manager-metrics-service 17 | namespace: system 18 | spec: 19 | ports: 20 | - name: https 21 | port: 8443 22 | protocol: TCP 23 | targetPort: https 24 | selector: 25 | control-plane: controller-manager 26 | -------------------------------------------------------------------------------- /pkg/utils/util/pointer.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package util 18 | 19 | func PointerUint8(i int) *uint8 { 20 | x := uint8(i) 21 | return &x 22 | } 23 | 24 | func PointerUint16(i uint16) *uint16 { 25 | return &i 26 | } 27 | -------------------------------------------------------------------------------- /blueprint/resource-backend/app/controller/rolebinding-leader-election.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1 2 | kind: RoleBinding 3 | metadata: 4 | annotations: {} 5 | creationTimestamp: null 6 | labels: 7 | app.kubernetes.io/component: tbd 8 | app.kubernetes.io/instance: tbd 9 | app.kubernetes.io/managed-by: kpt 10 | app.kubernetes.io/name: resource-backend 11 | app.kubernetes.io/part-of: resource-backend 12 | app.kubernetes.io/version: tbd 13 | name: resource-backend-controller-leader-election-role-binding 14 | namespace: backend-system 15 | roleRef: 16 | apiGroup: rbac.authorization.k8s.io 17 | kind: Role 18 | name: resource-backend-controller-leader-election-role 19 | subjects: 20 | - kind: ServiceAccount 21 | name: resource-backend-controller 22 | namespace: backend-system 23 | -------------------------------------------------------------------------------- /pkg/meta/meta.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package meta 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | ) 22 | 23 | func WasDeleted(o metav1.Object) bool { 24 | return !o.GetDeletionTimestamp().IsZero() 25 | } 26 | -------------------------------------------------------------------------------- /blueprint/resource-backend/app/configmaps/configmap_srlinux-topomac-script.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2023 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | apiVersion: v1 6 | kind: ConfigMap 7 | metadata: 8 | name: srlinux.nokia.com-topomac-script 9 | annotations: {} 10 | data: 11 | topomac.sh: | 12 | #!/bin/bash 13 | # this script is used to generate random OUI for base mac entry of an SR Linux topology yaml file 14 | 15 | template_path="/tmp/topo/topo-template.yml" 16 | final_path="/tmp/topology.yml" 17 | 18 | # generate random bytes 19 | b1=$(printf "%02X" $(shuf -i 0-255 -n1)) 20 | b2=$(printf "%02X" $(shuf -i 0-255 -n1)) 21 | mac_portion=$b1:$b2 22 | 23 | cp $template_path $final_path 24 | 25 | sed -i s/__RANDMAC__/$mac_portion/g $final_path 26 | -------------------------------------------------------------------------------- /pkg/meta/interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package meta 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | "k8s.io/apimachinery/pkg/runtime" 22 | ) 23 | 24 | type Object interface { 25 | metav1.Object 26 | runtime.Object 27 | } 28 | -------------------------------------------------------------------------------- /pkg/backend/watcher.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package backend 18 | 19 | import ( 20 | "github.com/hansthienpondt/nipam/pkg/table" 21 | "github.com/nokia/k8s-ipam/pkg/proto/resourcepb" 22 | ) 23 | 24 | type CallbackFn func(table.Routes, resourcepb.StatusCode) 25 | -------------------------------------------------------------------------------- /blueprint/resource-backend/app/configmaps/configmap_srlinux-entrypoint.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2023 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # this config maps contains an entrypoint script that ensures that we first call the 6 | # topomac script before executing the main entrypoint 7 | apiVersion: v1 8 | kind: ConfigMap 9 | metadata: 10 | name: srlinux.nokia.com-k8s-entrypoint 11 | annotations: {} 12 | data: 13 | k8s-entrypoint.sh: | 14 | #!/bin/bash 15 | # this entrypoint ensures that we call topomac script before executing the main entrypoint 16 | 17 | sudo bash /tmp/topomac/topomac.sh 18 | echo "topomac.sh" script finished 19 | 20 | # copy potentially provided startup config files 21 | sudo cp -L /tmp/initial-config/* /etc/opt/srlinux/ 22 | 23 | exec /entrypoint.sh "$@" 24 | -------------------------------------------------------------------------------- /pkg/backend/ipam/error.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package ipam 18 | 19 | const ( 20 | errValidateDuplicatePrefix = "cannot create prefix duplicate" 21 | errValidateNetworkPrefixWoNetworkParent = "cannot create network prefix w/o parent network prefix" 22 | ) 23 | -------------------------------------------------------------------------------- /pkg/utils/util/util.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package util 18 | 19 | func RemoveString(slice []string, s string) (result []string) { 20 | for _, v := range slice { 21 | if v != s { 22 | result = append(result, v) 23 | } 24 | } 25 | return result 26 | } 27 | -------------------------------------------------------------------------------- /config/rbac/ipam_ipprefix_viewer_role.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # permissions for end users to view ipprefixes. 6 | apiVersion: rbac.authorization.k8s.io/v1 7 | kind: ClusterRole 8 | metadata: 9 | labels: 10 | app.kubernetes.io/name: clusterrole 11 | app.kubernetes.io/instance: ipprefix-viewer-role 12 | app.kubernetes.io/component: rbac 13 | app.kubernetes.io/created-by: ipam 14 | app.kubernetes.io/part-of: ipam 15 | app.kubernetes.io/managed-by: kustomize 16 | name: ipprefix-viewer-role 17 | rules: 18 | - apiGroups: 19 | - ipam.nephio.org 20 | resources: 21 | - ipprefixes 22 | verbs: 23 | - get 24 | - list 25 | - watch 26 | - apiGroups: 27 | - ipam.nephio.org 28 | resources: 29 | - ipprefixes/status 30 | verbs: 31 | - get 32 | -------------------------------------------------------------------------------- /PROJECT: -------------------------------------------------------------------------------- 1 | domain: nephio.org 2 | layout: 3 | - go.kubebuilder.io/v3 4 | multigroup: true 5 | projectName: ipam 6 | repo: github.com/nephio-project/ipam 7 | resources: 8 | - api: 9 | crdVersion: v1 10 | namespaced: true 11 | controller: true 12 | domain: nephio.org 13 | group: ipam 14 | kind: NetworkInstance 15 | path: github.com/nephio-project/ipam/apis/ipam/v1alpha1 16 | version: v1alpha1 17 | - api: 18 | crdVersion: v1 19 | namespaced: true 20 | controller: true 21 | domain: nephio.org 22 | group: ipam 23 | kind: IPPrefix 24 | path: github.com/nephio-project/ipam/apis/ipam/v1alpha1 25 | version: v1alpha1 26 | - api: 27 | crdVersion: v1 28 | namespaced: true 29 | domain: nephio.org 30 | group: ipam 31 | kind: IPAllocation 32 | path: github.com/nephio-project/ipam/apis/ipam/v1alpha1 33 | version: v1alpha1 34 | version: "3" 35 | -------------------------------------------------------------------------------- /config/rbac/ipam_ipaddress_viewer_role.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # permissions for end users to view ipaddresses. 6 | apiVersion: rbac.authorization.k8s.io/v1 7 | kind: ClusterRole 8 | metadata: 9 | labels: 10 | app.kubernetes.io/name: clusterrole 11 | app.kubernetes.io/instance: ipaddress-viewer-role 12 | app.kubernetes.io/component: rbac 13 | app.kubernetes.io/created-by: ipam 14 | app.kubernetes.io/part-of: ipam 15 | app.kubernetes.io/managed-by: kustomize 16 | name: ipaddress-viewer-role 17 | rules: 18 | - apiGroups: 19 | - ipam.nephio.org 20 | resources: 21 | - ipaddresses 22 | verbs: 23 | - get 24 | - list 25 | - watch 26 | - apiGroups: 27 | - ipam.nephio.org 28 | resources: 29 | - ipaddresses/status 30 | verbs: 31 | - get 32 | -------------------------------------------------------------------------------- /config/prometheus/monitor.yaml: -------------------------------------------------------------------------------- 1 | # Prometheus Monitor Service (Metrics) 2 | apiVersion: monitoring.coreos.com/v1 3 | kind: ServiceMonitor 4 | metadata: 5 | labels: 6 | control-plane: controller-manager 7 | app.kubernetes.io/name: servicemonitor 8 | app.kubernetes.io/instance: controller-manager-metrics-monitor 9 | app.kubernetes.io/component: metrics 10 | app.kubernetes.io/created-by: ipam 11 | app.kubernetes.io/part-of: ipam 12 | app.kubernetes.io/managed-by: kustomize 13 | name: controller-manager-metrics-monitor 14 | namespace: system 15 | spec: 16 | endpoints: 17 | - path: /metrics 18 | port: https 19 | scheme: https 20 | bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token 21 | tlsConfig: 22 | insecureSkipVerify: true 23 | selector: 24 | matchLabels: 25 | control-plane: controller-manager 26 | -------------------------------------------------------------------------------- /config/rbac/ipam_ipallocation_viewer_role.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # permissions for end users to view ipallocations. 6 | apiVersion: rbac.authorization.k8s.io/v1 7 | kind: ClusterRole 8 | metadata: 9 | labels: 10 | app.kubernetes.io/name: clusterrole 11 | app.kubernetes.io/instance: ipallocation-viewer-role 12 | app.kubernetes.io/component: rbac 13 | app.kubernetes.io/created-by: ipam 14 | app.kubernetes.io/part-of: ipam 15 | app.kubernetes.io/managed-by: kustomize 16 | name: ipallocation-viewer-role 17 | rules: 18 | - apiGroups: 19 | - ipam.nephio.org 20 | resources: 21 | - ipallocations 22 | verbs: 23 | - get 24 | - list 25 | - watch 26 | - apiGroups: 27 | - ipam.nephio.org 28 | resources: 29 | - ipallocations/status 30 | verbs: 31 | - get 32 | -------------------------------------------------------------------------------- /pkg/resource/resource.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package resource 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | "k8s.io/apimachinery/pkg/runtime" 22 | ) 23 | 24 | // An Object is a Kubernetes object. 25 | type Object interface { 26 | metav1.Object 27 | runtime.Object 28 | } 29 | -------------------------------------------------------------------------------- /config/rbac/ipam_networkinstance_viewer_role.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # permissions for end users to view networkinstances. 6 | apiVersion: rbac.authorization.k8s.io/v1 7 | kind: ClusterRole 8 | metadata: 9 | labels: 10 | app.kubernetes.io/name: clusterrole 11 | app.kubernetes.io/instance: networkinstance-viewer-role 12 | app.kubernetes.io/component: rbac 13 | app.kubernetes.io/created-by: ipam 14 | app.kubernetes.io/part-of: ipam 15 | app.kubernetes.io/managed-by: kustomize 16 | name: networkinstance-viewer-role 17 | rules: 18 | - apiGroups: 19 | - ipam.nephio.org 20 | resources: 21 | - networkinstances 22 | verbs: 23 | - get 24 | - list 25 | - watch 26 | - apiGroups: 27 | - ipam.nephio.org 28 | resources: 29 | - networkinstances/status 30 | verbs: 31 | - get 32 | -------------------------------------------------------------------------------- /config/rbac/kustomization.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | resources: 6 | # All RBAC will be applied under this service account in 7 | # the deployment namespace. You may comment out this resource 8 | # if your manager will use a service account that exists at 9 | # runtime. Be sure to update RoleBinding and ClusterRoleBinding 10 | # subjects if changing service account names. 11 | - service_account.yaml 12 | - role.yaml 13 | - role_binding.yaml 14 | - leader_election_role.yaml 15 | - leader_election_role_binding.yaml 16 | # Comment the following 4 lines if you want to disable 17 | # the auth proxy (https://github.com/brancz/kube-rbac-proxy) 18 | # which protects your /metrics endpoint. 19 | - auth_proxy_service.yaml 20 | - auth_proxy_role.yaml 21 | - auth_proxy_role_binding.yaml 22 | - auth_proxy_client_clusterrole.yaml 23 | -------------------------------------------------------------------------------- /config/rbac/nephio.org_networkinstance_viewer_role.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # permissions for end users to view networkinstances. 6 | apiVersion: rbac.authorization.k8s.io/v1 7 | kind: ClusterRole 8 | metadata: 9 | labels: 10 | app.kubernetes.io/name: clusterrole 11 | app.kubernetes.io/instance: networkinstance-viewer-role 12 | app.kubernetes.io/component: rbac 13 | app.kubernetes.io/created-by: ipam 14 | app.kubernetes.io/part-of: ipam 15 | app.kubernetes.io/managed-by: kustomize 16 | name: networkinstance-viewer-role 17 | rules: 18 | - apiGroups: 19 | - nephio.org.nephio.org 20 | resources: 21 | - networkinstances 22 | verbs: 23 | - get 24 | - list 25 | - watch 26 | - apiGroups: 27 | - nephio.org.nephio.org 28 | resources: 29 | - networkinstances/status 30 | verbs: 31 | - get 32 | -------------------------------------------------------------------------------- /config/rbac/ipam_ipprefix_editor_role.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # permissions for end users to edit ipprefixes. 6 | apiVersion: rbac.authorization.k8s.io/v1 7 | kind: ClusterRole 8 | metadata: 9 | labels: 10 | app.kubernetes.io/name: clusterrole 11 | app.kubernetes.io/instance: ipprefix-editor-role 12 | app.kubernetes.io/component: rbac 13 | app.kubernetes.io/created-by: ipam 14 | app.kubernetes.io/part-of: ipam 15 | app.kubernetes.io/managed-by: kustomize 16 | name: ipprefix-editor-role 17 | rules: 18 | - apiGroups: 19 | - ipam.nephio.org 20 | resources: 21 | - ipprefixes 22 | verbs: 23 | - create 24 | - delete 25 | - get 26 | - list 27 | - patch 28 | - update 29 | - watch 30 | - apiGroups: 31 | - ipam.nephio.org 32 | resources: 33 | - ipprefixes/status 34 | verbs: 35 | - get 36 | -------------------------------------------------------------------------------- /pkg/db/entry.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import ( 4 | "fmt" 5 | 6 | "golang.org/x/exp/constraints" 7 | "k8s.io/apimachinery/pkg/labels" 8 | ) 9 | 10 | type Entry[T constraints.Integer] interface { 11 | ID() T 12 | Labels() labels.Set 13 | String() string 14 | } 15 | 16 | type entry[T constraints.Integer] struct { 17 | id T 18 | labels labels.Set 19 | } 20 | type Entries[T constraints.Integer] []Entry[T] 21 | 22 | func (v entry[T]) ID() T { return v.id } 23 | func (v entry[T]) Labels() labels.Set { return v.labels } 24 | func (v entry[T]) String() string { return fmt.Sprintf("%v %s", v.ID(), v.Labels().String()) } 25 | 26 | func NewEntry[T constraints.Integer](id T, l map[string]string) Entry[T] { 27 | var label labels.Set 28 | 29 | if l == nil { 30 | label = labels.Set{} 31 | } else { 32 | label = labels.Set(l) 33 | } 34 | return entry[T]{ 35 | id: id, 36 | labels: label, 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /pkg/objects/iterator.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package objects 18 | 19 | type iterator[T any] struct { 20 | curIdx int 21 | items []T 22 | } 23 | 24 | func (r *iterator[T]) HasNext() bool { 25 | r.curIdx++ 26 | return r.curIdx < len(r.items) 27 | } 28 | 29 | func (r *iterator[T]) Value() T { 30 | return r.items[r.curIdx] 31 | } 32 | -------------------------------------------------------------------------------- /config/rbac/ipam_ipaddress_editor_role.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # permissions for end users to edit ipaddresses. 6 | apiVersion: rbac.authorization.k8s.io/v1 7 | kind: ClusterRole 8 | metadata: 9 | labels: 10 | app.kubernetes.io/name: clusterrole 11 | app.kubernetes.io/instance: ipaddress-editor-role 12 | app.kubernetes.io/component: rbac 13 | app.kubernetes.io/created-by: ipam 14 | app.kubernetes.io/part-of: ipam 15 | app.kubernetes.io/managed-by: kustomize 16 | name: ipaddress-editor-role 17 | rules: 18 | - apiGroups: 19 | - ipam.nephio.org 20 | resources: 21 | - ipaddresses 22 | verbs: 23 | - create 24 | - delete 25 | - get 26 | - list 27 | - patch 28 | - update 29 | - watch 30 | - apiGroups: 31 | - ipam.nephio.org 32 | resources: 33 | - ipaddresses/status 34 | verbs: 35 | - get 36 | -------------------------------------------------------------------------------- /pkg/proto/resource/config.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package resource 18 | 19 | type Config struct { 20 | Address string 21 | Username string 22 | Password string 23 | Proxy bool 24 | NoTLS bool 25 | TLSCA string 26 | TLSCert string 27 | TLSKey string 28 | SkipVerify bool 29 | Insecure bool 30 | MaxMsgSize int 31 | } 32 | -------------------------------------------------------------------------------- /apis/resource/vlan/v1alpha1/vlan_claim_types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | type VLANClaimType string 20 | 21 | const ( 22 | VLANClaimTypeDynamic VLANClaimType = "dynamic" 23 | VLANClaimTypeStatic VLANClaimType = "static" 24 | VLANClaimTypeSize VLANClaimType = "size" 25 | VLANClaimTypeRange VLANClaimType = "range" 26 | ) 27 | -------------------------------------------------------------------------------- /config/rbac/ipam_ipallocation_editor_role.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # permissions for end users to edit ipallocations. 6 | apiVersion: rbac.authorization.k8s.io/v1 7 | kind: ClusterRole 8 | metadata: 9 | labels: 10 | app.kubernetes.io/name: clusterrole 11 | app.kubernetes.io/instance: ipallocation-editor-role 12 | app.kubernetes.io/component: rbac 13 | app.kubernetes.io/created-by: ipam 14 | app.kubernetes.io/part-of: ipam 15 | app.kubernetes.io/managed-by: kustomize 16 | name: ipallocation-editor-role 17 | rules: 18 | - apiGroups: 19 | - ipam.nephio.org 20 | resources: 21 | - ipallocations 22 | verbs: 23 | - create 24 | - delete 25 | - get 26 | - list 27 | - patch 28 | - update 29 | - watch 30 | - apiGroups: 31 | - ipam.nephio.org 32 | resources: 33 | - ipallocations/status 34 | verbs: 35 | - get 36 | -------------------------------------------------------------------------------- /config/rbac/ipam_networkinstance_editor_role.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # permissions for end users to edit networkinstances. 6 | apiVersion: rbac.authorization.k8s.io/v1 7 | kind: ClusterRole 8 | metadata: 9 | labels: 10 | app.kubernetes.io/name: clusterrole 11 | app.kubernetes.io/instance: networkinstance-editor-role 12 | app.kubernetes.io/component: rbac 13 | app.kubernetes.io/created-by: ipam 14 | app.kubernetes.io/part-of: ipam 15 | app.kubernetes.io/managed-by: kustomize 16 | name: networkinstance-editor-role 17 | rules: 18 | - apiGroups: 19 | - ipam.nephio.org 20 | resources: 21 | - networkinstances 22 | verbs: 23 | - create 24 | - delete 25 | - get 26 | - list 27 | - patch 28 | - update 29 | - watch 30 | - apiGroups: 31 | - ipam.nephio.org 32 | resources: 33 | - networkinstances/status 34 | verbs: 35 | - get 36 | -------------------------------------------------------------------------------- /config/samples/topo/nephio-single.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: topo.nephio.org/v1alpha1 2 | kind: RawTopology 3 | metadata: 4 | name: nephio 5 | spec: 6 | nodes: 7 | srl: 8 | provider: srl.nokia.com 9 | mgmt: 10 | provider: docker.io 11 | cluster01: 12 | provider: docker.io 13 | labels: 14 | nephio.org/cluster-name: cluster01 15 | cluster02: 16 | provider: docker.io 17 | labels: 18 | nephio.org/cluster-name: cluster02 19 | cluster03: 20 | provider: docker.io 21 | labels: 22 | nephio.org/cluster-name: cluster03 23 | links: 24 | - endpoints: 25 | - { nodeName: srl, interfaceName: e1-2} 26 | - { nodeName: cluster01, interfaceName: eth1} 27 | - endpoints: 28 | - { nodeName: srl, interfaceName: e1-3} 29 | - { nodeName: cluster02, interfaceName: eth1} 30 | - endpoints: 31 | - { nodeName: srl, interfaceName: e1-4} 32 | - { nodeName: cluster03, interfaceName: eth1} 33 | -------------------------------------------------------------------------------- /apis/resource/common/v1alpha1/namespacename.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/types" 21 | ) 22 | 23 | const seperator = "-" 24 | 25 | func GetGenericNamespacedName(nsn types.NamespacedName) string { 26 | if nsn.Namespace == "" { 27 | return nsn.Name 28 | } 29 | return nsn.Namespace + seperator + nsn.Name 30 | } 31 | -------------------------------------------------------------------------------- /config/rbac/nephio.org_networkinstance_editor_role.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # permissions for end users to edit networkinstances. 6 | apiVersion: rbac.authorization.k8s.io/v1 7 | kind: ClusterRole 8 | metadata: 9 | labels: 10 | app.kubernetes.io/name: clusterrole 11 | app.kubernetes.io/instance: networkinstance-editor-role 12 | app.kubernetes.io/component: rbac 13 | app.kubernetes.io/created-by: ipam 14 | app.kubernetes.io/part-of: ipam 15 | app.kubernetes.io/managed-by: kustomize 16 | name: networkinstance-editor-role 17 | rules: 18 | - apiGroups: 19 | - nephio.org.nephio.org 20 | resources: 21 | - networkinstances 22 | verbs: 23 | - create 24 | - delete 25 | - get 26 | - list 27 | - patch 28 | - update 29 | - watch 30 | - apiGroups: 31 | - nephio.org.nephio.org 32 | resources: 33 | - networkinstances/status 34 | verbs: 35 | - get 36 | -------------------------------------------------------------------------------- /apis/resource/common/v1alpha1/cache_id.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | corev1 "k8s.io/api/core/v1" 21 | ) 22 | 23 | func GetCacheID(ref corev1.ObjectReference) corev1.ObjectReference { 24 | namespace := ref.Namespace 25 | if namespace == "" { 26 | namespace = "default" 27 | } 28 | return corev1.ObjectReference{Name: ref.Name, Namespace: namespace} 29 | } 30 | -------------------------------------------------------------------------------- /config/samples/nephio/topology.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: nf.nephio.org/v1alpha1 2 | kind: FiveGCoreTopology 3 | metadata: 4 | name: fivegcoretopology-sample 5 | spec: 6 | upfs: 7 | - name: "agg-layer" 8 | selector: 9 | matchLabels: 10 | nephio.org/region: us-central1 11 | nephio.org/site-type: edge 12 | namespace: "upf" 13 | upf: 14 | upfClassName: "free5gc-upf" 15 | capacity: 16 | uplinkThroughput: "1G" 17 | downlinkThroughput: "10G" 18 | n3: 19 | - networkInstance: "sample-vpc" 20 | networkName: "sample-n3-net" 21 | n4: 22 | - networkInstance: "sample-vpc" 23 | networkName: "sample-n4-net" 24 | n6: 25 | - dnn: "internet" 26 | uePool: 27 | networkInstance: "sample-vpc" 28 | networkName: "ue-net" 29 | prefixSize: "/64" 30 | endpoint: 31 | networkInstance: "sample-vpc" 32 | networkName: "sample-n6-net" -------------------------------------------------------------------------------- /pkg/meta/namespace_name.go: -------------------------------------------------------------------------------- 1 | package meta 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/nokia/k8s-ipam/pkg/proto/resourcepb" 7 | "k8s.io/apimachinery/pkg/types" 8 | ) 9 | 10 | func ResourcePbNsnToString(nsn *resourcepb.NSN) string { 11 | return types.NamespacedName{Namespace: nsn.Namespace, Name: nsn.Name}.String() 12 | } 13 | 14 | func StringToResourcePbNsn(s string) *resourcepb.NSN { 15 | split := strings.Split(s, "/") 16 | if len(split) > 1 { 17 | return &resourcepb.NSN{ 18 | Namespace: split[0], 19 | Name: split[1], 20 | } 21 | } 22 | return &resourcepb.NSN{ 23 | Namespace: "default", 24 | Name: s, 25 | } 26 | } 27 | 28 | func GetResourcePbGVKFromTypeNSN(nsn types.NamespacedName) *resourcepb.NSN { 29 | return &resourcepb.NSN{ 30 | Namespace: nsn.Namespace, 31 | Name: nsn.Name, 32 | } 33 | } 34 | 35 | func GetTypeNSNFromResourcePbNSN(nsn *resourcepb.NSN) types.NamespacedName { 36 | return types.NamespacedName{ 37 | Namespace: nsn.Namespace, 38 | Name: nsn.Name, 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /blueprint/resource-backend/app/controller/role-leader-election.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1 2 | kind: Role 3 | metadata: 4 | annotations: {} 5 | creationTimestamp: null 6 | labels: 7 | app.kubernetes.io/component: tbd 8 | app.kubernetes.io/instance: tbd 9 | app.kubernetes.io/managed-by: kpt 10 | app.kubernetes.io/name: resource-backend 11 | app.kubernetes.io/part-of: resource-backend 12 | app.kubernetes.io/version: tbd 13 | name: resource-backend-controller-leader-election-role 14 | namespace: backend-system 15 | rules: 16 | - apiGroups: 17 | - '*' 18 | resources: 19 | - configmaps 20 | verbs: 21 | - get 22 | - list 23 | - watch 24 | - update 25 | - patch 26 | - create 27 | - delete 28 | - apiGroups: 29 | - coordination.k8s.io 30 | resources: 31 | - leases 32 | verbs: 33 | - get 34 | - list 35 | - watch 36 | - update 37 | - patch 38 | - create 39 | - delete 40 | - apiGroups: 41 | - '*' 42 | resources: 43 | - events 44 | verbs: 45 | - create 46 | - patch 47 | -------------------------------------------------------------------------------- /pkg/db/vlandb/vlandb_test.go: -------------------------------------------------------------------------------- 1 | package vlandb 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/nokia/k8s-ipam/pkg/db" 7 | "github.com/stretchr/testify/assert" 8 | ) 9 | 10 | func TestNew(t *testing.T) { 11 | cases := map[string]struct { 12 | id uint16 13 | expectedErr bool 14 | }{ 15 | "New": { 16 | id: 1111, 17 | expectedErr: false, 18 | }, 19 | "NewReserved1": { 20 | id: 1, 21 | expectedErr: true, 22 | }, 23 | "NewReserved4095": { 24 | id: 4095, 25 | expectedErr: true, 26 | }, 27 | "NewReserved40": { 28 | id: 0, 29 | expectedErr: true, 30 | }, 31 | } 32 | for name, tc := range cases { 33 | t.Run(name, func(t *testing.T) { 34 | d := New() 35 | err := d.Set(db.NewEntry(tc.id, nil)) 36 | if !tc.expectedErr { 37 | assert.NoError(t, err) 38 | } else { 39 | assert.Error(t, err) 40 | } 41 | err = d.Delete(tc.id) 42 | if !tc.expectedErr { 43 | assert.NoError(t, err) 44 | } else { 45 | assert.Error(t, err) 46 | } 47 | }) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /cmd/commands.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "context" 21 | 22 | "github.com/nokia/k8s-ipam/cmd/generate" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | // GetCommands returns the set of commands to be registered 27 | func GetCommands(ctx context.Context, name, version string) []*cobra.Command { 28 | var c []*cobra.Command 29 | generateCmd := generate.NewCommand(ctx, name, version) 30 | 31 | c = append(c, generateCmd) 32 | return c 33 | } 34 | -------------------------------------------------------------------------------- /config/rbac/leader_election_role.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the BSD 3-Clause License. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # permissions to do leader election. 6 | apiVersion: rbac.authorization.k8s.io/v1 7 | kind: Role 8 | metadata: 9 | labels: 10 | app.kubernetes.io/name: role 11 | app.kubernetes.io/instance: leader-election-role 12 | app.kubernetes.io/component: rbac 13 | app.kubernetes.io/created-by: ipam 14 | app.kubernetes.io/part-of: ipam 15 | app.kubernetes.io/managed-by: kustomize 16 | name: leader-election-role 17 | rules: 18 | - apiGroups: 19 | - "" 20 | resources: 21 | - configmaps 22 | verbs: 23 | - get 24 | - list 25 | - watch 26 | - create 27 | - update 28 | - patch 29 | - delete 30 | - apiGroups: 31 | - coordination.k8s.io 32 | resources: 33 | - leases 34 | verbs: 35 | - get 36 | - list 37 | - watch 38 | - create 39 | - update 40 | - patch 41 | - delete 42 | - apiGroups: 43 | - "" 44 | resources: 45 | - events 46 | verbs: 47 | - create 48 | - patch 49 | -------------------------------------------------------------------------------- /apis/inv/v1alpha1/provider_types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import corev1 "k8s.io/api/core/v1" 20 | 21 | type Provider struct { 22 | // ParametersRef points to the vendor or implementation specific params for the 23 | // network. 24 | // +optional 25 | ParametersRef *corev1.ObjectReference `json:"parametersRef,omitempty" yaml:"parametersRef,omitempty"` 26 | 27 | // Provider specifies the provider implementing this network. 28 | Provider string `json:"provider" yaml:"provider"` 29 | } 30 | -------------------------------------------------------------------------------- /config/samples/interconnect/interconnect_dynamic.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: topo.nephio.org/v1alpha1 2 | kind: Interconnect 3 | metadata: 4 | name: dynamic 5 | spec: 6 | topologies: 7 | - cluster0 8 | - nephio 9 | links: 10 | - name: logical-link1 11 | links: 2 12 | type: lag 13 | endpoints: 14 | - selector: 15 | topo.nephio.org/topology: cluster01 16 | topo.nephio.org/node-name: 'server' + '-' + index 17 | logicalEndpointName: bond0 18 | - selector: 19 | topo.nephio.org/topology: dc 20 | topo.nephio.org/redundancy-group: rack1 21 | inv.nephio.org/interface-index: index 22 | selectorPolicy: 23 | multiHomedNodes: 2 24 | - name: logical-link2 25 | links: 2 26 | type: lag 27 | endpoints: 28 | - selector: 29 | topo.nephio.org/topology: cluster01 30 | topo.nephio.org/node-name: 'server' + '-' + index 31 | selectorPolicy: 32 | logicalEndpointName: bond1 33 | - selector: 34 | topo.nephio.org/topology: dc 35 | topo.nephio.org/redundancy-group: rack1 36 | selectorPolicy: 37 | multiHomedNodes: 2 -------------------------------------------------------------------------------- /pkg/db/entry_test.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestNewEntry(t *testing.T) { 8 | cases := map[string]struct { 9 | id uint16 10 | l map[string]string 11 | expectedLabels string 12 | expectedString string 13 | }{ 14 | "NewEntry": { 15 | id: 1111, 16 | l: map[string]string{"a": "b"}, 17 | expectedLabels: "a=b", 18 | expectedString: "1111 a=b", 19 | }, 20 | "NewEntryEmptyLabel": { 21 | id: 1111, 22 | l: nil, 23 | expectedLabels: "", 24 | expectedString: "1111 ", 25 | }, 26 | } 27 | for name, tc := range cases { 28 | t.Run(name, func(t *testing.T) { 29 | e := NewEntry(tc.id, tc.l) 30 | if e.ID() != tc.id { 31 | t.Errorf("TestNewEntry: -want %d, +got: %d\n", e.ID(), tc.id) 32 | } 33 | if e.Labels().String() != tc.expectedLabels { 34 | t.Errorf("TestNewEntry: -want %s, +got: %s\n", e.Labels(), tc.expectedLabels) 35 | } 36 | if e.String() != tc.expectedString { 37 | t.Errorf("TestNewEntry: -want %s, +got: %s\n", e.String(), tc.expectedString) 38 | } 39 | }) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /pkg/backend/vlan/watcher.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package vlan 18 | 19 | import ( 20 | "context" 21 | 22 | "github.com/hansthienpondt/nipam/pkg/table" 23 | "github.com/nokia/k8s-ipam/pkg/backend" 24 | "github.com/nokia/k8s-ipam/pkg/proto/resourcepb" 25 | ) 26 | 27 | type CallbackFn func(table.Routes, resourcepb.StatusCode) 28 | 29 | type Watcher interface { 30 | addWatch(ownerGvkKey, ownerGvk string, fn backend.CallbackFn) 31 | deleteWatch(ownerGvkKey, ownerGvk string) 32 | handleUpdate(ctx context.Context, routes table.Routes, statusCode resourcepb.StatusCode) 33 | } 34 | -------------------------------------------------------------------------------- /pkg/meta/labels.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package meta 18 | 19 | import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 20 | 21 | func AddLabels(o metav1.Object, labels map[string]string) { 22 | l := o.GetLabels() 23 | if l == nil { 24 | o.SetLabels(labels) 25 | return 26 | } 27 | for k, v := range labels { 28 | l[k] = v 29 | } 30 | o.SetLabels(l) 31 | } 32 | 33 | func RemoveLabels(o metav1.Object, labels ...string) { 34 | l := o.GetLabels() 35 | if l == nil { 36 | return 37 | } 38 | for _, k := range labels { 39 | delete(l, k) 40 | } 41 | o.SetLabels(l) 42 | } 43 | -------------------------------------------------------------------------------- /pkg/meta/errors.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package meta 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/api/errors" 21 | ) 22 | 23 | const ( 24 | errUpdateObject = "cannot update k8s resource" 25 | ) 26 | 27 | type ErrorIs func(err error) bool 28 | 29 | func Ignore(is ErrorIs, err error) error { 30 | if is(err) { 31 | return nil 32 | } 33 | return err 34 | } 35 | 36 | // IgnoreNotFound returns the supplied error, or nil if the error indicates a 37 | // Kubernetes resource was not found. 38 | func IgnoreNotFound(err error) error { 39 | return Ignore(errors.IsNotFound, err) 40 | } 41 | -------------------------------------------------------------------------------- /config/samples/interconnect/interconnect_static.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: topo.nephio.org/v1alpha1 2 | kind: Interconnect 3 | metadata: 4 | name: static 5 | spec: 6 | links: 7 | - name: 'server' + '-' + index + eth0 + switch1 + e1-1 8 | logicalRef: 9 | endpoints: 10 | - nodeName: 'server' + '-' + index 11 | interfaceName: eth0 12 | #logicalEndpointName: bond0 13 | - nodeName: switch 14 | interfaceName: e1-1 15 | - name: 'server' + '-' + index + eth1 + switch2 + e1-1 16 | logicalLinkIdx: 0 17 | endpoints: 18 | - nodeName: 'server' + '-' + index 19 | interfaceName: eth0 20 | #logicalEndpointName: bond0 21 | - nodeName: switch 22 | interfaceName: e1-1 23 | - name: 'server' + '-' + index + eth3 + switch1 + e1-2 24 | endpoints: 25 | - nodeName: 'server' + '-' + index 26 | interfaceName: eth3 27 | logicalEndpointName: bond1 28 | - nodeName: switch 29 | interfaceName: e1-2 30 | - name: 'server' + '-' + index + eth4 + switch2 + e1-2 31 | endpoints: 32 | - nodeName: 'server' + '-' + index 33 | interfaceName: eth4 34 | logicalEndpointName: bond1 35 | - nodeName: switch 36 | interfaceName: e1-2 -------------------------------------------------------------------------------- /pkg/meta/annotations.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package meta 18 | 19 | import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 20 | 21 | func AddAnnotations(o metav1.Object, annotations map[string]string) { 22 | a := o.GetAnnotations() 23 | if a == nil { 24 | o.SetAnnotations(annotations) 25 | return 26 | } 27 | for k, v := range annotations { 28 | a[k] = v 29 | } 30 | o.SetAnnotations(a) 31 | } 32 | 33 | func RemoveAnnotations(o metav1.Object, annotations ...string) { 34 | a := o.GetAnnotations() 35 | if a == nil { 36 | return 37 | } 38 | for _, k := range annotations { 39 | delete(a, k) 40 | } 41 | o.SetAnnotations(a) 42 | } 43 | -------------------------------------------------------------------------------- /apis/topo/v1alpha1/rawtopology_interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | resourcev1alpha1 "github.com/nokia/k8s-ipam/apis/resource/common/v1alpha1" 21 | ) 22 | 23 | // GetCondition returns the condition based on the condition kind 24 | func (r *RawTopology) GetCondition(t resourcev1alpha1.ConditionType) resourcev1alpha1.Condition { 25 | return r.Status.GetCondition(t) 26 | } 27 | 28 | // SetConditions sets the conditions on the resource. it allows for 0, 1 or more conditions 29 | // to be set at once 30 | func (r *RawTopology) SetConditions(c ...resourcev1alpha1.Condition) { 31 | r.Status.SetConditions(c...) 32 | } 33 | -------------------------------------------------------------------------------- /pkg/db/vxlandb/vxlandb.go: -------------------------------------------------------------------------------- 1 | package vxlandb 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/nokia/k8s-ipam/pkg/db" 7 | ) 8 | 9 | type Config[T uint32] struct { 10 | Offset T 11 | MaxEntryID T 12 | } 13 | 14 | func New[T uint32](cfg *Config[T]) db.DB[T] { 15 | r := &vxlan[T]{cfg: cfg} 16 | return db.NewDB(&db.DBConfig[T]{ 17 | Offset: cfg.Offset, 18 | MaxEntries: cfg.MaxEntryID - cfg.Offset, 19 | SetValidation: r.setVLANValidation, 20 | DeleteValidation: r.deleteVLANValidation, 21 | }) 22 | } 23 | 24 | type vxlan[T uint32] struct { 25 | cfg *Config[T] 26 | } 27 | 28 | func (r *vxlan[T]) setVLANValidation(id T) error { 29 | if id < r.cfg.Offset { 30 | return fmt.Errorf("VXLAN %d is lower than the lowest offset %d", id, r.cfg.Offset) 31 | } 32 | if id > r.cfg.MaxEntryID { 33 | return fmt.Errorf("VXLAN %d is higher than the max offset %d", id, r.cfg.MaxEntryID) 34 | } 35 | return nil 36 | } 37 | 38 | func (r *vxlan[T]) deleteVLANValidation(id T) error { 39 | if id < r.cfg.Offset { 40 | return fmt.Errorf("VXLAN %d is lower than the lowest offset %d", id, r.cfg.Offset) 41 | } 42 | if id > r.cfg.MaxEntryID { 43 | return fmt.Errorf("VXLAN %d is higher than the max offset %d", id, r.cfg.MaxEntryID) 44 | } 45 | return nil 46 | } 47 | -------------------------------------------------------------------------------- /pkg/hash/hash_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package hash 18 | 19 | import ( 20 | "fmt" 21 | "strconv" 22 | "testing" 23 | ) 24 | 25 | func TestInsert(t *testing.T) { 26 | cases := map[string]struct { 27 | names []string 28 | }{ 29 | "Normal": { 30 | names: []string{"a", "b", "x"}, 31 | }, 32 | "VPC": { 33 | names: []string{"vpc-internal-e1-srl ", "vpc-internal-f1-srl"}, 34 | }, 35 | } 36 | for name, tc := range cases { 37 | t.Run(name, func(t *testing.T) { 38 | h := New(10000) 39 | 40 | for idx, name := range tc.names { 41 | x := h.Insert(name, strconv.Itoa(idx), map[string]string{}) 42 | fmt.Println(x) 43 | } 44 | }) 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /config/samples/replicas/replica-server.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: auto.nephio.org/v1alpha1 2 | kind: ReplicaSet 3 | metadata: 4 | name: server 5 | namespace: default 6 | spec: 7 | replicas: 10 8 | pipeline: 9 | - variables: 10 | nodepool: 11 | cluster: cluster01 12 | apiVersion: v1 13 | kind: ConfigMap 14 | name: cluster01-nodepool01 15 | - expression: nodepool.data.cluster + '-' + nodepool.data.nodepool + '-' + 'server' + '-' + index 16 | templatefields: 17 | - metadata.name 18 | - metadata.labels.topo.nephio.org/node-name 19 | templates: 20 | - apiVersion: inv.nephio.org/v1alpha1 21 | kind: Node 22 | metadata: 23 | name: empty 24 | namespace: default 25 | labels: 26 | topo.nephio.org/position: server 27 | topo.nephio.org/rack: rack1 28 | topo.nephio.org/node-name: empty 29 | topo.nephio.org/node-pool: 1 30 | spec: 31 | provider: server.nephio.com 32 | - apiVersion: topo.nephio.org/v1alpha1 33 | kind: Interconnect 34 | metadata: 35 | name: empty 36 | namespace: default 37 | labels: 38 | topo.nephio.org/position: server 39 | topo.nephio.org/rack: rack1 40 | topo.nephio.org/node-name: empty 41 | topo.nephio.org/node-pool: 1 42 | spec: 43 | provider: server.nephio.com -------------------------------------------------------------------------------- /pkg/meta/gvr.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package meta 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/runtime/schema" 21 | "k8s.io/client-go/rest" 22 | "sigs.k8s.io/controller-runtime/pkg/client/apiutil" 23 | ) 24 | 25 | func GetGVKfromGVR(c *rest.Config, gvr schema.GroupVersionResource) (schema.GroupVersionKind, error) { 26 | 27 | httpClient, err := rest.HTTPClientFor(c) 28 | if err != nil { 29 | return schema.GroupVersionKind{}, err 30 | } 31 | mapper, err := apiutil.NewDynamicRESTMapper(c, httpClient) 32 | //mapper, err := apiutil.NewDynamicRESTMapper(c) 33 | if err != nil { 34 | return schema.GroupVersionKind{}, err 35 | } 36 | gvk, err := mapper.KindFor(gvr) 37 | if err != nil { 38 | return schema.GroupVersionKind{}, err 39 | } 40 | return gvk, nil 41 | } 42 | -------------------------------------------------------------------------------- /apis/auto/v1alpha1/groupversion_info.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package v1alpha1 contains API Schema definitions for the ipam v1alpha1 API group 18 | // +kubebuilder:object:generate=true 19 | // +groupName=auto.nephio.org 20 | package v1alpha1 21 | 22 | import ( 23 | "k8s.io/apimachinery/pkg/runtime/schema" 24 | "sigs.k8s.io/controller-runtime/pkg/scheme" 25 | ) 26 | 27 | var ( 28 | // GroupVersion is group version used to register these objects 29 | GroupVersion = schema.GroupVersion{Group: "auto.nephio.org", Version: "v1alpha1"} 30 | 31 | // SchemeBuilder is used to add go types to the GroupVersionKind scheme 32 | SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} 33 | 34 | // AddToScheme adds the types in this group-version to the given scheme. 35 | AddToScheme = SchemeBuilder.AddToScheme 36 | ) 37 | -------------------------------------------------------------------------------- /apis/inv/v1alpha1/groupversion_info.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package v1alpha1 contains API Schema definitions for the ipam v1alpha1 API group 18 | // +kubebuilder:object:generate=true 19 | // +groupName=inv.nephio.org 20 | package v1alpha1 21 | 22 | import ( 23 | "k8s.io/apimachinery/pkg/runtime/schema" 24 | "sigs.k8s.io/controller-runtime/pkg/scheme" 25 | ) 26 | 27 | var ( 28 | // GroupVersion is group version used to register these objects 29 | GroupVersion = schema.GroupVersion{Group: "inv.nephio.org", Version: "v1alpha1"} 30 | 31 | // SchemeBuilder is used to add go types to the GroupVersionKind scheme 32 | SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} 33 | 34 | // AddToScheme adds the types in this group-version to the given scheme. 35 | AddToScheme = SchemeBuilder.AddToScheme 36 | ) 37 | -------------------------------------------------------------------------------- /apis/topo/v1alpha1/groupversion_info.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package v1alpha1 contains API Schema definitions for the ipam v1alpha1 API group 18 | // +kubebuilder:object:generate=true 19 | // +groupName=topo.nephio.org 20 | package v1alpha1 21 | 22 | import ( 23 | "k8s.io/apimachinery/pkg/runtime/schema" 24 | "sigs.k8s.io/controller-runtime/pkg/scheme" 25 | ) 26 | 27 | var ( 28 | // GroupVersion is group version used to register these objects 29 | GroupVersion = schema.GroupVersion{Group: "topo.nephio.org", Version: "v1alpha1"} 30 | 31 | // SchemeBuilder is used to add go types to the GroupVersionKind scheme 32 | SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} 33 | 34 | // AddToScheme adds the types in this group-version to the given scheme. 35 | AddToScheme = SchemeBuilder.AddToScheme 36 | ) 37 | -------------------------------------------------------------------------------- /apis/resource/ipam/v1alpha1/groupversion_info.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package v1alpha1 contains API Schema definitions for the ipam v1alpha1 API group 18 | // +kubebuilder:object:generate=true 19 | // +groupName=ipam.resource.nephio.org 20 | package v1alpha1 21 | 22 | import ( 23 | "k8s.io/apimachinery/pkg/runtime/schema" 24 | "sigs.k8s.io/controller-runtime/pkg/scheme" 25 | ) 26 | 27 | var ( 28 | // GroupVersion is group version used to register these objects 29 | GroupVersion = schema.GroupVersion{Group: "ipam.resource.nephio.org", Version: "v1alpha1"} 30 | 31 | // SchemeBuilder is used to add go types to the GroupVersionKind scheme 32 | SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} 33 | 34 | // AddToScheme adds the types in this group-version to the given scheme. 35 | AddToScheme = SchemeBuilder.AddToScheme 36 | ) 37 | -------------------------------------------------------------------------------- /apis/resource/vlan/v1alpha1/groupversion_info.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package v1alpha1 contains API Schema definitions for the ipam v1alpha1 API group 18 | // +kubebuilder:object:generate=true 19 | // +groupName=vlan.resource.nephio.org 20 | package v1alpha1 21 | 22 | import ( 23 | "k8s.io/apimachinery/pkg/runtime/schema" 24 | "sigs.k8s.io/controller-runtime/pkg/scheme" 25 | ) 26 | 27 | var ( 28 | // GroupVersion is group version used to register these objects 29 | GroupVersion = schema.GroupVersion{Group: "vlan.resource.nephio.org", Version: "v1alpha1"} 30 | 31 | // SchemeBuilder is used to add go types to the GroupVersionKind scheme 32 | SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} 33 | 34 | // AddToScheme adds the types in this group-version to the given scheme. 35 | AddToScheme = SchemeBuilder.AddToScheme 36 | ) 37 | -------------------------------------------------------------------------------- /apis/resource/vxlan/v1alpha1/groupversion_info.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package v1alpha1 contains API Schema definitions for the ipam v1alpha1 API group 18 | // +kubebuilder:object:generate=true 19 | // +groupName=vxlan.resource.nephio.org 20 | package v1alpha1 21 | 22 | import ( 23 | "k8s.io/apimachinery/pkg/runtime/schema" 24 | "sigs.k8s.io/controller-runtime/pkg/scheme" 25 | ) 26 | 27 | var ( 28 | // GroupVersion is group version used to register these objects 29 | GroupVersion = schema.GroupVersion{Group: "vxlan.resource.nephio.org", Version: "v1alpha1"} 30 | 31 | // SchemeBuilder is used to add go types to the GroupVersionKind scheme 32 | SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} 33 | 34 | // AddToScheme adds the types in this group-version to the given scheme. 35 | AddToScheme = SchemeBuilder.AddToScheme 36 | ) 37 | -------------------------------------------------------------------------------- /pkg/proxy/beclient/client_interface.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package beclient 18 | 19 | import ( 20 | "context" 21 | 22 | "sigs.k8s.io/controller-runtime/pkg/client" 23 | ) 24 | 25 | type Client interface { 26 | //AddEventChs(map[schema.GroupVersionKind]chan event.GenericEvent) 27 | // Create creates the cache instance in the backend 28 | CreateIndex(ctx context.Context, cr client.Object) error 29 | // Delete deletes the cache instance in the backend 30 | DeleteIndex(ctx context.Context, cr client.Object) error 31 | // Get returns the claimed resource 32 | GetClaim(ctx context.Context, cr client.Object, d any) (client.Object, error) 33 | // Claim claims a resource 34 | Claim(ctx context.Context, cr client.Object, d any) (client.Object, error) 35 | // DeleteClaim deletes the claim 36 | DeleteClaim(ctx context.Context, cr client.Object, d any) error 37 | } 38 | -------------------------------------------------------------------------------- /apis/resource/common/v1alpha1/namespacename_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | "testing" 21 | 22 | "github.com/google/go-cmp/cmp" 23 | "k8s.io/apimachinery/pkg/types" 24 | ) 25 | 26 | func TestGetGenericNamespacedName(t *testing.T) { 27 | cases := map[string]struct { 28 | nsn types.NamespacedName 29 | want string 30 | }{ 31 | "NamespaceName": { 32 | nsn: types.NamespacedName{Namespace: "a", Name: "b"}, 33 | want: "a-b", 34 | }, 35 | 36 | "NameOnly": { 37 | nsn: types.NamespacedName{Name: "b"}, 38 | want: "b", 39 | }, 40 | } 41 | 42 | for name, tc := range cases { 43 | t.Run(name, func(t *testing.T) { 44 | got := GetGenericNamespacedName(tc.nsn) 45 | if diff := cmp.Diff(tc.want, got); diff != "" { 46 | t.Errorf("TestGetGenericNamespacedName(...): -want, +got:\n%s", diff) 47 | } 48 | }) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /config/crd/kustomization.yaml: -------------------------------------------------------------------------------- 1 | # This kustomization.yaml is not intended to be run by itself, 2 | # since it depends on service name and namespace that are out of this kustomize package. 3 | # It should be run by config/default 4 | resources: 5 | - bases/nephio.org.nephio.org_networkinstances.yaml 6 | - bases/ipam.nephio.org_networkinstances.yaml 7 | - bases/ipam.nephio.org_ipprefixes.yaml 8 | - bases/ipam.nephio.org_ipaddresses.yaml 9 | - bases/ipam.nephio.org_ipallocations.yaml 10 | #+kubebuilder:scaffold:crdkustomizeresource 11 | 12 | patchesStrategicMerge: 13 | # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. 14 | # patches here are for enabling the conversion webhook for each CRD 15 | #- patches/webhook_in_networkinstances.yaml 16 | #- patches/webhook_in_ipprefixes.yaml 17 | #- patches/webhook_in_ipaddresses.yaml 18 | #- patches/webhook_in_ipallocations.yaml 19 | #+kubebuilder:scaffold:crdkustomizewebhookpatch 20 | 21 | # [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. 22 | # patches here are for enabling the CA injection for each CRD 23 | #- patches/cainjection_in_networkinstances.yaml 24 | #- patches/cainjection_in_ipprefixes.yaml 25 | #- patches/cainjection_in_ipaddresses.yaml 26 | #- patches/cainjection_in_ipallocations.yaml 27 | #+kubebuilder:scaffold:crdkustomizecainjectionpatch 28 | 29 | # the following config is for teaching kustomize how to do kustomization for CRDs. 30 | configurations: 31 | - kustomizeconfig.yaml 32 | -------------------------------------------------------------------------------- /apis/topo/v1alpha1/logical_interconnect_interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | resourcev1alpha1 "github.com/nokia/k8s-ipam/apis/resource/common/v1alpha1" 21 | ) 22 | 23 | // GetCondition returns the condition based on the condition kind 24 | func (r *LogicalInterconnect) GetCondition(t resourcev1alpha1.ConditionType) resourcev1alpha1.Condition { 25 | return r.Status.GetCondition(t) 26 | } 27 | 28 | // SetConditions sets the conditions on the resource. it allows for 0, 1 or more conditions 29 | // to be set at once 30 | func (r *LogicalInterconnect) SetConditions(c ...resourcev1alpha1.Condition) { 31 | r.Status.SetConditions(c...) 32 | } 33 | 34 | func (r *LogicalInterconnect) GetTopologies() []string { 35 | topologies := []string{} 36 | for _, ep := range r.Spec.Endpoints { 37 | topologies = append(topologies, ep.Topologies...) 38 | } 39 | return topologies 40 | } 41 | -------------------------------------------------------------------------------- /pkg/meta/meta_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package meta 18 | 19 | import ( 20 | corev1 "k8s.io/api/core/v1" 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | "testing" 23 | 24 | "github.com/google/go-cmp/cmp" 25 | ) 26 | 27 | func TestWasDeleted(t *testing.T) { 28 | now := metav1.Now() 29 | 30 | cases := map[string]struct { 31 | o metav1.Object 32 | want bool 33 | }{ 34 | "ObjectWasDeleted": { 35 | o: &corev1.Pod{ObjectMeta: metav1.ObjectMeta{DeletionTimestamp: &now}}, 36 | want: true, 37 | }, 38 | "ObjectWasNotDeleted": { 39 | o: &corev1.Pod{ObjectMeta: metav1.ObjectMeta{DeletionTimestamp: nil}}, 40 | want: false, 41 | }, 42 | } 43 | 44 | for name, tc := range cases { 45 | t.Run(name, func(t *testing.T) { 46 | got := WasDeleted(tc.o) 47 | if diff := cmp.Diff(tc.want, got); diff != "" { 48 | t.Errorf("WasDeleted(...): -want, +got:\n%s", diff) 49 | } 50 | }) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /apis/resource/ipam/v1alpha1/ipam_types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | const ( 20 | OriginSystem = "system" 21 | SubnetPrefix = "subnet" 22 | SubnetFirstAddress = "first" 23 | SubnetLastAddress = "last" 24 | ) 25 | 26 | type PrefixKind string 27 | 28 | const ( 29 | PrefixKindUnknown PrefixKind = "unknown" 30 | PrefixKindNetwork PrefixKind = "network" 31 | PrefixKindLoopback PrefixKind = "loopback" 32 | PrefixKindPool PrefixKind = "pool" 33 | PrefixKindAggregate PrefixKind = "aggregate" 34 | ) 35 | 36 | func GetPrefixKindFromString(s string) PrefixKind { 37 | switch s { 38 | case string(PrefixKindNetwork): 39 | return PrefixKindNetwork 40 | case string(PrefixKindLoopback): 41 | return PrefixKindLoopback 42 | case string(PrefixKindPool): 43 | return PrefixKindPool 44 | case string(PrefixKindAggregate): 45 | return PrefixKindAggregate 46 | default: 47 | return PrefixKindUnknown 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /pkg/db/vlandb/vlandb.go: -------------------------------------------------------------------------------- 1 | package vlandb 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/nokia/k8s-ipam/pkg/db" 7 | ) 8 | 9 | func New[T uint16]() db.DB[T] { 10 | return db.NewDB(&db.DBConfig[T]{ 11 | MaxEntries: 4096, 12 | InitEntries: db.Entries[T]{ 13 | db.NewEntry(T(0), map[string]string{"type": "untagged", "status": "reserved"}), 14 | db.NewEntry(T(1), map[string]string{"type": "default", "status": "reserved"}), 15 | db.NewEntry(T(4095), map[string]string{"type": "reserved", "status": "reserved"}), 16 | }, 17 | SetValidation: setVLANValidation[T], 18 | DeleteValidation: deleteVLANValidation[T], 19 | }) 20 | } 21 | 22 | func setVLANValidation[T uint16](id T) error { 23 | // TODO validate max entries 24 | switch id { 25 | case 0: 26 | return fmt.Errorf("VLAN %d is the untagged VLAN, cannot be added to the database", id) 27 | case 1: 28 | return fmt.Errorf("VLAN %d is the default VLAN, cannot be added to the database", id) 29 | case 4095: 30 | return fmt.Errorf("VLAN %d is reserved, cannot be added to the database", id) 31 | } 32 | return nil 33 | } 34 | 35 | func deleteVLANValidation[T uint16](id T) error { 36 | // TODO validate max entries 37 | switch id { 38 | case 0: 39 | return fmt.Errorf("VLAN %d is the untagged VLAN, cannot be deleted from the database", id) 40 | case 1: 41 | return fmt.Errorf("VLAN %d is the default VLAN, cannot be deleted from the database", id) 42 | case 4095: 43 | return fmt.Errorf("VLAN %d is reserved, cannot be deleted from the database", id) 44 | } 45 | return nil 46 | } 47 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Nokia 2 | # Licensed under the Apache License 2.0 3 | # SPDX-License-Identifier: Apache-2.0 4 | 5 | # Build the manager binary 6 | FROM golang:1.20 as builder 7 | ARG TARGETOS 8 | ARG TARGETARCH 9 | 10 | WORKDIR /workspace 11 | # Copy the Go Modules manifests 12 | COPY go.mod go.mod 13 | COPY go.sum go.sum 14 | # cache deps before building and copying source so that we don't need to re-download as much 15 | # and so that source changes don't invalidate our downloaded layer 16 | RUN go mod download 17 | 18 | # Copy the go source 19 | COPY main.go main.go 20 | COPY apis/ apis/ 21 | COPY controllers/ controllers/ 22 | COPY internal/ internal/ 23 | COPY pkg/ pkg/ 24 | 25 | # Build 26 | # the GOARCH has not a default value to allow the binary be built according to the host where the command 27 | # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO 28 | # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore, 29 | # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. 30 | RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go 31 | 32 | # Use distroless as minimal base image to package the manager binary 33 | # Refer to https://github.com/GoogleContainerTools/distroless for more details 34 | #FROM gcr.io/distroless/static:nonroot 35 | FROM alpine:latest 36 | WORKDIR / 37 | COPY --from=builder /workspace/manager . 38 | USER 65532:65532 39 | 40 | ENTRYPOINT ["/manager"] 41 | -------------------------------------------------------------------------------- /pkg/backend/backend.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package backend 18 | 19 | import ( 20 | "context" 21 | ) 22 | 23 | type Backend interface { 24 | // CreateIndex creates a backend index 25 | CreateIndex(ctx context.Context, cr []byte) error 26 | // DeleteIndex deletes a backend index 27 | DeleteIndex(ctx context.Context, cr []byte) error 28 | // List the data from the backend index 29 | List(ctx context.Context, cr []byte) (any, error) 30 | // Add a dynamic watch with callback to the backend index 31 | AddWatch(ownerGvkKey, ownerGvk string, fn CallbackFn) 32 | // Delete a dynamic watch with callback deom the backend index 33 | DeleteWatch(ownerGvkKey, ownerGvk string) 34 | //GetClaim return the claim if it exists 35 | GetClaim(ctx context.Context, cr []byte) ([]byte, error) 36 | // Claim claims an entry in the backend index 37 | Claim(ctx context.Context, cr []byte) ([]byte, error) 38 | // DeleteClaim delete a claim in the backend index 39 | DeleteClaim(ctx context.Context, cr []byte) error 40 | } 41 | -------------------------------------------------------------------------------- /controllers/controllers.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package controllers 18 | 19 | import ( 20 | "context" 21 | 22 | "github.com/nokia/k8s-ipam/controllers/ctrlconfig" 23 | "k8s.io/apimachinery/pkg/runtime/schema" 24 | ctrl "sigs.k8s.io/controller-runtime" 25 | 26 | "sigs.k8s.io/controller-runtime/pkg/event" 27 | "sigs.k8s.io/controller-runtime/pkg/reconcile" 28 | ) 29 | 30 | type Reconciler interface { 31 | reconcile.Reconciler 32 | 33 | // InitDefaults populates default values into our options 34 | //InitDefaults() 35 | 36 | // BindFlags binds options to flags 37 | //BindFlags(prefix string, flags *flag.FlagSet) 38 | 39 | // Setup registers the reconciler to run under the specified manager 40 | Setup(ctx context.Context, mgr ctrl.Manager, cfg *ctrlconfig.ControllerConfig) (map[schema.GroupVersionKind]chan event.GenericEvent, error) 41 | } 42 | 43 | var Reconcilers = map[string]Reconciler{} 44 | 45 | func Register(name string, r Reconciler) { 46 | Reconcilers[name] = r 47 | } 48 | -------------------------------------------------------------------------------- /pkg/meta/owner.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package meta 18 | 19 | import ( 20 | "strings" 21 | 22 | "k8s.io/apimachinery/pkg/types" 23 | ) 24 | 25 | type OwnerRef struct { 26 | APIVersion string `json:"apiVersion" yaml:"apiVersion"` 27 | Kind string `json:"kind" yaml:"kind"` 28 | Namespace string `json:"namespace" yaml:"namespace"` 29 | Name string `json:"name" yaml:"name"` 30 | UID types.UID `json:"uid" yaml:"uid"` 31 | } 32 | 33 | func (r *OwnerRef) String() string { 34 | var sb strings.Builder 35 | sb.WriteString("ref") 36 | if r.APIVersion != "" { 37 | sb.WriteString("." + r.APIVersion) 38 | } 39 | if r.Kind != "" { 40 | sb.WriteString("." + r.Kind) 41 | } 42 | if r.Namespace != "" { 43 | sb.WriteString("." + r.Namespace) 44 | } 45 | if r.Name != "" { 46 | sb.WriteString("." + r.Name) 47 | } 48 | /* 49 | if ownerref.UID != "" { 50 | sb.WriteString("." + string(ownerref.UID)) 51 | } 52 | */ 53 | return strings.ReplaceAll(sb.String(), "/", "_") 54 | } 55 | -------------------------------------------------------------------------------- /cmd/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "context" 21 | "fmt" 22 | "os" 23 | 24 | "github.com/spf13/cobra" 25 | "k8s.io/component-base/cli" 26 | "k8s.io/klog" 27 | ) 28 | 29 | func main() { 30 | os.Exit(runMain()) 31 | } 32 | 33 | // runMain does the initial setup in order to run kpt-gen. The return value from 34 | // this function will be the exit code when kpt-gen terminates. 35 | func runMain() int { 36 | var err error 37 | 38 | ctx := context.Background() 39 | 40 | // Enable commandline flags for klog. 41 | // logging will help in collecting debugging information from users 42 | klog.InitFlags(nil) 43 | 44 | cmd := getMain(ctx) 45 | 46 | err = cli.RunNoErrOutput(cmd) 47 | if err != nil { 48 | return handleErr(cmd, err) 49 | } 50 | return 0 51 | } 52 | 53 | // handleErr takes care of printing an error message for a given error. 54 | func handleErr(cmd *cobra.Command, err error) int { 55 | fmt.Fprintf(cmd.ErrOrStderr(), "%s \n", err.Error()) 56 | return 1 57 | } 58 | -------------------------------------------------------------------------------- /apis/inv/v1alpha1/connectivity.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | type ClusterConnectivity string 20 | 21 | const ( 22 | ClusterConnectivityUnknown ClusterConnectivity = "unknown" 23 | ClusterConnectivityLocal ClusterConnectivity = "local" 24 | ClusterConnectivityRemote ClusterConnectivity = "remote" 25 | ) 26 | 27 | type HostConnectivity string 28 | 29 | const ( 30 | HostConnectivityUnknown HostConnectivity = "unknown" 31 | HostConnectivityLocal HostConnectivity = "local" 32 | HostConnectivityRemote HostConnectivity = "remote" 33 | ) 34 | 35 | type Connectivity struct { 36 | ClusterConnectivity ClusterConnectivity 37 | HostConnectivity HostConnectivity 38 | } 39 | 40 | func GetClusterConnectivity(topology string, clusterTopologies map[string]struct{}) ClusterConnectivity { 41 | if len(clusterTopologies) == 0 { 42 | return ClusterConnectivityLocal 43 | } 44 | if _, ok := clusterTopologies[topology]; !ok { 45 | return ClusterConnectivityRemote 46 | } 47 | return ClusterConnectivityLocal 48 | } 49 | -------------------------------------------------------------------------------- /controllers/ctrlconfig/config.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package ctrlconfig 18 | 19 | import ( 20 | "time" 21 | 22 | "github.com/henderiw-nephio/network-node-operator/pkg/node" 23 | ipamv1alpha1 "github.com/nokia/k8s-ipam/apis/resource/ipam/v1alpha1" 24 | vlanv1alpha1 "github.com/nokia/k8s-ipam/apis/resource/vlan/v1alpha1" 25 | "github.com/nokia/k8s-ipam/pkg/backend" 26 | "github.com/nokia/k8s-ipam/pkg/proxy/clientproxy" 27 | "sigs.k8s.io/controller-runtime/pkg/client" 28 | "sigs.k8s.io/controller-runtime/pkg/controller" 29 | ) 30 | 31 | type ControllerConfig struct { 32 | PorchClient client.Client 33 | Address string // backend server address 34 | IpamClientProxy clientproxy.Proxy[*ipamv1alpha1.NetworkInstance, *ipamv1alpha1.IPClaim] 35 | VlanClientProxy clientproxy.Proxy[*vlanv1alpha1.VLANIndex, *vlanv1alpha1.VLANClaim] 36 | Poll time.Duration 37 | Copts controller.Options 38 | Ipam backend.Backend 39 | Vlan backend.Backend 40 | Noderegistry node.NodeRegistry 41 | } 42 | -------------------------------------------------------------------------------- /pkg/proxy/clientproxy/resp_validator.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package clientproxy 18 | 19 | import ( 20 | "sync" 21 | 22 | "github.com/nokia/k8s-ipam/pkg/proto/resourcepb" 23 | ) 24 | 25 | type RefreshRespValidatorFn func(origResp *resourcepb.ClaimResponse, newResp *resourcepb.ClaimResponse) bool 26 | 27 | // validates the response from the grpc server with the specific validate fn 28 | type ResponseValidator interface { 29 | Add(string, RefreshRespValidatorFn) 30 | Get(string) RefreshRespValidatorFn 31 | } 32 | 33 | func NewResponseValidator() ResponseValidator { 34 | return &respValidator{ 35 | v: map[string]RefreshRespValidatorFn{}, 36 | } 37 | } 38 | 39 | type respValidator struct { 40 | m sync.RWMutex 41 | v map[string]RefreshRespValidatorFn 42 | } 43 | 44 | func (r *respValidator) Add(key string, fn RefreshRespValidatorFn) { 45 | r.m.Lock() 46 | defer r.m.Unlock() 47 | r.v[key] = fn 48 | } 49 | 50 | func (r *respValidator) Get(key string) RefreshRespValidatorFn { 51 | r.m.RLock() 52 | defer r.m.RUnlock() 53 | return r.v[key] 54 | } 55 | -------------------------------------------------------------------------------- /internal/healthhandler/subserver.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package healthhandler 17 | 18 | import ( 19 | "context" 20 | "sync" 21 | 22 | "github.com/go-logr/logr" 23 | healthpb "google.golang.org/grpc/health/grpc_health_v1" 24 | ) 25 | 26 | type SubServer interface { 27 | Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) 28 | Watch(in *healthpb.HealthCheckRequest, stream healthpb.Health_WatchServer) error 29 | } 30 | 31 | func New() SubServer { 32 | s := &subServer{ 33 | mu: sync.RWMutex{}, 34 | statusMap: map[string]healthpb.HealthCheckResponse_ServingStatus{"": healthpb.HealthCheckResponse_SERVING}, 35 | updates: make(map[string]map[healthpb.Health_WatchServer]chan healthpb.HealthCheckResponse_ServingStatus), 36 | } 37 | return s 38 | } 39 | 40 | type subServer struct { 41 | l logr.Logger 42 | mu sync.RWMutex 43 | statusMap map[string]healthpb.HealthCheckResponse_ServingStatus 44 | updates map[string]map[healthpb.Health_WatchServer]chan healthpb.HealthCheckResponse_ServingStatus 45 | } 46 | -------------------------------------------------------------------------------- /pkg/meta/unstructured.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package meta 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 21 | "k8s.io/apimachinery/pkg/runtime/schema" 22 | "sigs.k8s.io/yaml" 23 | ) 24 | 25 | func GetUnstructuredFromGVK(gvk *schema.GroupVersionKind) *unstructured.Unstructured { 26 | var u unstructured.Unstructured 27 | u.SetAPIVersion(gvk.GroupVersion().String()) 28 | u.SetKind(gvk.Kind) 29 | uCopy := u.DeepCopy() 30 | return uCopy 31 | } 32 | 33 | func GetUnstructuredListFromGVK(gvk *schema.GroupVersionKind) *unstructured.UnstructuredList { 34 | var u unstructured.UnstructuredList 35 | u.SetAPIVersion(gvk.GroupVersion().String()) 36 | u.SetKind(gvk.Kind) 37 | uCopy := u.DeepCopy() 38 | return uCopy 39 | } 40 | 41 | func MarshalData(o *unstructured.Unstructured) (any, error) { 42 | b, err := yaml.Marshal(o.UnstructuredContent()) 43 | if err != nil { 44 | return nil, err 45 | } 46 | 47 | rj := map[string]interface{}{} 48 | if err := yaml.Unmarshal(b, &rj); err != nil { 49 | return nil, err 50 | } 51 | return rj, nil 52 | } 53 | -------------------------------------------------------------------------------- /config/samples/interconnect/interconnect_static_dynamic.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: topo.nephio.org/v1alpha1 2 | kind: Interconnect 3 | metadata: 4 | name: static 5 | spec: 6 | links: 7 | - name: 'server' + '-' + index + eth0 + switch1 + e1-1 8 | endpoints: 9 | - nodeName: 'server' + '-' + index 10 | interfaceName: eth0 11 | logicalEndpointName: bond0 12 | topology: cluster01 13 | - topology: dc 14 | selector: 15 | inv.nephio.org/redundancy-group: rack1 16 | inv.nephio.org/rack-index: 0 17 | inv.nephio.org/interface-index: index 18 | - name: 'server' + '-' + index + eth1 + switch2 + e1-1 19 | endpoints: 20 | - nodeName: 'server' + '-' + index 21 | interfaceName: eth0 22 | logicalEndpointName: bond0 23 | - topology: dc 24 | selector: 25 | topo.nephio.org/redundancy-group: rack1 26 | topo.nephio.org/rack-index: 1 27 | inv.nephio.org/interface-index: index 28 | - name: 'server' + '-' + index + eth3 + switch1 + e1-2 29 | endpoints: 30 | - nodeName: 'server' + '-' + index 31 | interfaceName: eth3 32 | logicalEndpointName: bond1 33 | - topology: dc 34 | selector: 35 | topo.nephio.org/redundancy-group: rack1 36 | topo.nephio.org/rack-index: 1 37 | inv.nephio.org/interface-index: index 38 | - name: 'server' + '-' + index + eth4 + switch2 + e1-2 39 | endpoints: 40 | - nodeName: 'server' + '-' + index 41 | interfaceName: eth4 42 | logicalEndpointName: bond1 43 | - topology: dc 44 | selector: 45 | topo.nephio.org/redundancy-group: rack1 46 | topo.nephio.org/rack-index: 1 47 | inv.nephio.org/interface-index: index -------------------------------------------------------------------------------- /internal/grpcserver/health.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package grpcserver 18 | 19 | import ( 20 | "context" 21 | 22 | "google.golang.org/grpc/codes" 23 | healthpb "google.golang.org/grpc/health/grpc_health_v1" 24 | "google.golang.org/grpc/status" 25 | ) 26 | 27 | // Check implements `service Health`. 28 | func (s *GrpcServer) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) { 29 | ctx, cancel := context.WithTimeout(ctx, s.config.Timeout) 30 | defer cancel() 31 | err := s.acquireSem(ctx) 32 | if err != nil { 33 | return nil, err 34 | } 35 | defer s.sem.Release(1) 36 | 37 | if s.checkHandler != nil { 38 | return s.checkHandler(ctx, in) 39 | } 40 | 41 | return &healthpb.HealthCheckResponse{}, nil 42 | } 43 | 44 | // Watch implements `service Health`. 45 | func (s *GrpcServer) Watch(in *healthpb.HealthCheckRequest, stream healthpb.Health_WatchServer) error { 46 | err := s.acquireSem(stream.Context()) 47 | if err != nil { 48 | return err 49 | } 50 | defer s.sem.Release(1) 51 | 52 | if s.watchHandler != nil { 53 | return s.watchHandler(in, stream) 54 | } 55 | return status.Error(codes.Unimplemented, "") 56 | } 57 | -------------------------------------------------------------------------------- /blueprint/resource-backend/app/configmaps/node_model-srlinux.nokia.com-ixrd3l.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: inv.nephio.org/v1alpha1 2 | kind: NodeModel 3 | metadata: 4 | name: srlinux.nokia.com-ixrd3l 5 | annotations: {} 6 | spec: 7 | provider: srlinux.nokia.com 8 | interfaces: 9 | - name: "e1-1" 10 | speed: "10G" 11 | - name: "e1-2" 12 | speed: "10G" 13 | - name: "e1-3" 14 | speed: "100G" 15 | - name: "e1-4" 16 | speed: "100G" 17 | - name: "e1-5" 18 | speed: "100G" 19 | - name: "e1-6" 20 | speed: "100G" 21 | - name: "e1-7" 22 | speed: "100G" 23 | - name: "e1-8" 24 | speed: "100G" 25 | - name: "e1-9" 26 | speed: "100G" 27 | - name: "e1-10" 28 | speed: "100G" 29 | - name: "e1-11" 30 | speed: "100G" 31 | - name: "e1-12" 32 | speed: "100G" 33 | - name: "e1-13" 34 | speed: "100G" 35 | - name: "e1-14" 36 | speed: "100G" 37 | - name: "e1-15" 38 | speed: "100G" 39 | - name: "e1-16" 40 | speed: "100G" 41 | - name: "e1-17" 42 | speed: "100G" 43 | - name: "e1-18" 44 | speed: "100G" 45 | - name: "e1-19" 46 | speed: "100G" 47 | - name: "e1-20" 48 | speed: "100G" 49 | - name: "e1-21" 50 | speed: "100G" 51 | - name: "e1-22" 52 | speed: "100G" 53 | - name: "e1-23" 54 | speed: "100G" 55 | - name: "e1-24" 56 | speed: "100G" 57 | - name: "e1-25" 58 | speed: "100G" 59 | - name: "e1-26" 60 | speed: "100G" 61 | - name: "e1-27" 62 | speed: "100G" 63 | - name: "e1-28" 64 | speed: "100G" 65 | - name: "e1-29" 66 | speed: "100G" 67 | - name: "e1-30" 68 | speed: "100G" 69 | - name: "e1-31" 70 | speed: "100G" 71 | - name: "e1-32" 72 | speed: "100G" 73 | - name: "e1-33" 74 | speed: "100G" 75 | - name: "e1-34" 76 | speed: "100G" 77 | -------------------------------------------------------------------------------- /apis/inv/v1alpha1/logical_endpoint_interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | resourcev1alpha1 "github.com/nokia/k8s-ipam/apis/resource/common/v1alpha1" 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | ) 23 | 24 | // GetCondition returns the condition based on the condition kind 25 | func (r *LogicalEndpoint) GetCondition(t resourcev1alpha1.ConditionType) resourcev1alpha1.Condition { 26 | return r.Status.GetCondition(t) 27 | } 28 | 29 | // SetConditions sets the conditions on the resource. it allows for 0, 1 or more conditions 30 | // to be set at once 31 | func (r *LogicalEndpoint) SetConditions(c ...resourcev1alpha1.Condition) { 32 | r.Status.SetConditions(c...) 33 | } 34 | 35 | // BuildLogicalEndpoint returns a logical from a client Object a crName and 36 | // a Link Spec/Status 37 | func BuildLogicalEndpoint(meta metav1.ObjectMeta, spec LogicalEndpointSpec, status LogicalEndpointStatus) *LogicalEndpoint { 38 | return &LogicalEndpoint{ 39 | TypeMeta: metav1.TypeMeta{ 40 | APIVersion: SchemeBuilder.GroupVersion.Identifier(), 41 | Kind: LogicalEndpointKind, 42 | }, 43 | ObjectMeta: meta, 44 | Spec: spec, 45 | Status: status, 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /apis/inv/v1alpha1/node_config_interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package v1alpha1 17 | 18 | import ( 19 | corev1 "k8s.io/api/core/v1" 20 | "k8s.io/apimachinery/pkg/api/resource" 21 | ) 22 | 23 | func (r *NodeConfig) GetModel(defaultModel string) string { 24 | model := defaultModel 25 | if r.Spec.Model != nil { 26 | model = *r.Spec.Model 27 | } 28 | return model 29 | } 30 | 31 | func (r *NodeConfig) GetImage(defaultImageName string) string { 32 | image := defaultImageName 33 | if r.Spec.Image != nil { 34 | image = *r.Spec.Image 35 | } 36 | return image 37 | } 38 | 39 | func (r *NodeConfig) GetResourceRequirements(defaultResourceLimits, defaultResourceRequests map[string]string) corev1.ResourceRequirements { 40 | if len(r.Spec.Resources.Limits) == 0 { 41 | r.Spec.Resources.Limits = corev1.ResourceList{} 42 | for k, v := range defaultResourceLimits { 43 | r.Spec.Resources.Limits[corev1.ResourceName(k)] = resource.MustParse(v) 44 | } 45 | } 46 | 47 | if len(r.Spec.Resources.Requests) == 0 { 48 | r.Spec.Resources.Requests = corev1.ResourceList{} 49 | for k, v := range defaultResourceRequests { 50 | r.Spec.Resources.Requests[corev1.ResourceName(k)] = resource.MustParse(v) 51 | } 52 | } 53 | return r.Spec.Resources 54 | } 55 | -------------------------------------------------------------------------------- /config/default/manager_auth_proxy_patch.yaml: -------------------------------------------------------------------------------- 1 | # This patch inject a sidecar container which is a HTTP proxy for the 2 | # controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews. 3 | apiVersion: apps/v1 4 | kind: Deployment 5 | metadata: 6 | name: controller-manager 7 | namespace: system 8 | spec: 9 | template: 10 | spec: 11 | affinity: 12 | nodeAffinity: 13 | requiredDuringSchedulingIgnoredDuringExecution: 14 | nodeSelectorTerms: 15 | - matchExpressions: 16 | - key: kubernetes.io/arch 17 | operator: In 18 | values: 19 | - amd64 20 | - arm64 21 | - ppc64le 22 | - s390x 23 | - key: kubernetes.io/os 24 | operator: In 25 | values: 26 | - linux 27 | containers: 28 | - name: kube-rbac-proxy 29 | securityContext: 30 | allowPrivilegeEscalation: false 31 | capabilities: 32 | drop: 33 | - "ALL" 34 | image: gcr.io/kubebuilder/kube-rbac-proxy:v0.13.0 35 | args: 36 | - "--secure-listen-address=0.0.0.0:8443" 37 | - "--upstream=http://127.0.0.1:8080/" 38 | - "--logtostderr=true" 39 | - "--v=0" 40 | ports: 41 | - containerPort: 8443 42 | protocol: TCP 43 | name: https 44 | resources: 45 | limits: 46 | cpu: 500m 47 | memory: 128Mi 48 | requests: 49 | cpu: 5m 50 | memory: 64Mi 51 | - name: manager 52 | args: 53 | - "--health-probe-bind-address=:8081" 54 | - "--metrics-bind-address=127.0.0.1:8080" 55 | - "--leader-elect" 56 | -------------------------------------------------------------------------------- /docs/start/install.md: -------------------------------------------------------------------------------- 1 | # getting started 2 | 3 | The resource backend is an application that runs within a kubernetes cluster. Through customer resources it enables a declarative management of resources, such as ip addresses, vlans, autonomous-systems, lag, esi, etc as well as inventory 4 | 5 | ## Pre-requisites 6 | 7 | ### Install a Kubernetest Cluster 8 | 9 | Install a kubernetes cluster based on your preferences. Some examples are provided here for reference, but if you would use another kubernetes cluster flavor you can skip this step. 10 | 11 | === "kind cluster" 12 | 13 | Install the kind sw 14 | 15 | [install kind](https://kind.sigs.k8s.io/docs/user/quick-start/#installation) 16 | 17 | Create the kind cluster 18 | 19 | ```markdown 20 | kind create cluster 21 | ``` 22 | 23 | Check if the cluster is running 24 | 25 | ```markdown 26 | kubectl get node 27 | ``` 28 | 29 | Expected output or similar 30 | 31 | ```markdown 32 | kubectl get node 33 | NAME STATUS ROLES AGE VERSION 34 | kind-control-plane Ready control-plane 8h v1.27.3 35 | ``` 36 | 37 | ### Install resource-backend 38 | 39 | Install resource-backend using kpt 40 | 41 | ``` 42 | kpt pkg get --for-deployment "https://github.com/nokia/k8s-ipam.git/blueprint/resource-backend" resource-backend 43 | kpt fn render resource-backend 44 | kpt live init resource-backend 45 | kpt live apply resource-backend 46 | ``` 47 | 48 | check if the resource-backend is running 49 | 50 | ``` 51 | kubectl get pods -n backend-system 52 | ``` 53 | 54 | a similar output is expected 55 | 56 | NAME READY STATUS RESTARTS AGE 57 | resource-backend-controller-5fd6976bdf-57knl 2/2 Running 0 6h13m 58 | ``` 59 | 60 | 61 | When all of this succeeded we can starrt provisioning inventory resources -------------------------------------------------------------------------------- /pkg/backend/ipam/validator_dynamic.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package ipam 18 | 19 | import ( 20 | "context" 21 | 22 | "github.com/go-logr/logr" 23 | "github.com/hansthienpondt/nipam/pkg/table" 24 | ipamv1alpha1 "github.com/nokia/k8s-ipam/apis/resource/ipam/v1alpha1" 25 | "sigs.k8s.io/controller-runtime/pkg/log" 26 | ) 27 | 28 | type DynamicValidatorFunctionConfig struct { 29 | validateInputFn validateInputFn 30 | } 31 | 32 | type ClaimValidatorConfig struct { 33 | claim *ipamv1alpha1.IPClaim 34 | rib *table.RIB 35 | fnc *DynamicValidatorFunctionConfig 36 | } 37 | 38 | func NewClaimValidator(c *ClaimValidatorConfig) Validator { 39 | return &claimvalidator{ 40 | claim: c.claim, 41 | rib: c.rib, 42 | fnc: c.fnc, 43 | } 44 | } 45 | 46 | type claimvalidator struct { 47 | claim *ipamv1alpha1.IPClaim 48 | rib *table.RIB 49 | fnc *DynamicValidatorFunctionConfig 50 | l logr.Logger 51 | } 52 | 53 | func (r *claimvalidator) Validate(ctx context.Context) (string, error) { 54 | r.l = log.FromContext(ctx).WithValues("prefixkind", r.claim.Spec.Kind, "cr", r.claim.GetGenericNamespacedName()) 55 | r.l.Info("validate claim without prefix") 56 | 57 | // validate input 58 | if msg := r.fnc.validateInputFn(r.claim, nil); msg != "" { 59 | return msg, nil 60 | } 61 | 62 | return "", nil 63 | } 64 | -------------------------------------------------------------------------------- /pkg/db/vxlandb/vxlandb_test.go: -------------------------------------------------------------------------------- 1 | package vxlandb 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/nokia/k8s-ipam/pkg/db" 8 | "github.com/stretchr/testify/assert" 9 | ) 10 | 11 | func TestNew(t *testing.T) { 12 | cases := map[string]struct { 13 | id uint32 14 | expectedErr bool 15 | }{ 16 | "New": { 17 | id: 1111, 18 | expectedErr: false, 19 | }, 20 | "AboveMax": { 21 | id: 1000000000, 22 | expectedErr: true, 23 | }, 24 | "Max": { 25 | id: 65536, 26 | expectedErr: false, 27 | }, 28 | "Max+1": { 29 | id: 65537, 30 | expectedErr: true, 31 | }, 32 | "OK": { 33 | id: 10000, 34 | expectedErr: false, 35 | }, 36 | } 37 | for name, tc := range cases { 38 | t.Run(name, func(t *testing.T) { 39 | d := New(&Config[uint32]{Offset: 100, MaxEntryID: 65536}) 40 | err := d.Set(db.NewEntry(tc.id, nil)) 41 | if !tc.expectedErr { 42 | assert.NoError(t, err) 43 | } else { 44 | assert.Error(t, err) 45 | } 46 | err = d.Delete(tc.id) 47 | if !tc.expectedErr { 48 | assert.NoError(t, err) 49 | } else { 50 | assert.Error(t, err) 51 | } 52 | }) 53 | } 54 | } 55 | 56 | func TestFree(t *testing.T) { 57 | cases := map[string]struct { 58 | }{ 59 | "Free": {}, 60 | } 61 | for name := range cases { 62 | t.Run(name, func(t *testing.T) { 63 | d := New(&Config[uint32]{Offset: 100, MaxEntryID: 65536}) 64 | var e db.Entry[uint32] 65 | var err error 66 | e, err = d.FindFree() 67 | if err != nil { 68 | assert.Error(t, err) 69 | } 70 | fmt.Println(e) 71 | if err := d.Set(e); err != nil { 72 | assert.NoError(t, err) 73 | } 74 | e, err = d.FindFree() 75 | if err != nil { 76 | assert.NoError(t, err) 77 | } 78 | fmt.Println(e) 79 | err = d.Delete(e.ID()) 80 | if err != nil { 81 | assert.NoError(t, err) 82 | } 83 | }) 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /apis/inv/v1alpha1/target_interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | resourcev1alpha1 "github.com/nokia/k8s-ipam/apis/resource/common/v1alpha1" 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | "sigs.k8s.io/controller-runtime/pkg/client" 23 | ) 24 | 25 | // GetCondition returns the condition based on the condition kind 26 | func (r *Target) GetCondition(t resourcev1alpha1.ConditionType) resourcev1alpha1.Condition { 27 | return r.Status.GetCondition(t) 28 | } 29 | 30 | // SetConditions sets the conditions on the resource. it allows for 0, 1 or more conditions 31 | // to be set at once 32 | func (r *Target) SetConditions(c ...resourcev1alpha1.Condition) { 33 | r.Status.SetConditions(c...) 34 | } 35 | 36 | func (r *TargetList) GetItems() []client.Object { 37 | objs := []client.Object{} 38 | for _, r := range r.Items { 39 | objs = append(objs, &r) 40 | } 41 | return objs 42 | } 43 | 44 | // BuildTarget returns a Target from a client Object a crName and 45 | // an Target Spec/Status 46 | func BuildTarget(meta metav1.ObjectMeta, spec TargetSpec, status TargetStatus) *Target { 47 | return &Target{ 48 | TypeMeta: metav1.TypeMeta{ 49 | APIVersion: SchemeBuilder.GroupVersion.Identifier(), 50 | Kind: TargetKind, 51 | }, 52 | ObjectMeta: meta, 53 | Spec: spec, 54 | Status: status, 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /apis/inv/v1alpha1/topology_interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | resourcev1alpha1 "github.com/nokia/k8s-ipam/apis/resource/common/v1alpha1" 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | "sigs.k8s.io/controller-runtime/pkg/client" 23 | ) 24 | 25 | // GetCondition returns the condition based on the condition kind 26 | func (r *Topology) GetCondition(t resourcev1alpha1.ConditionType) resourcev1alpha1.Condition { 27 | return r.Status.GetCondition(t) 28 | } 29 | 30 | // SetConditions sets the conditions on the resource. it allows for 0, 1 or more conditions 31 | // to be set at once 32 | func (r *Topology) SetConditions(c ...resourcev1alpha1.Condition) { 33 | r.Status.SetConditions(c...) 34 | } 35 | 36 | func (r *TopologyList) GetItems() []client.Object { 37 | objs := []client.Object{} 38 | for _, r := range r.Items { 39 | objs = append(objs, &r) 40 | } 41 | return objs 42 | } 43 | 44 | // BuildTopology returns a Topology from a client Object a crName and 45 | // an Topology Spec/Status 46 | func BuildTopology(meta metav1.ObjectMeta, spec TopologySpec, status TopologyStatus) *Topology { 47 | return &Topology{ 48 | TypeMeta: metav1.TypeMeta{ 49 | APIVersion: SchemeBuilder.GroupVersion.Identifier(), 50 | Kind: TopologyKind, 51 | }, 52 | ObjectMeta: meta, 53 | Spec: spec, 54 | Status: status, 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /pkg/proxy/clientproxy/resource_client.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package clientproxy 18 | 19 | import ( 20 | "context" 21 | "fmt" 22 | 23 | "github.com/nokia/k8s-ipam/pkg/proto/resource" 24 | "github.com/nokia/k8s-ipam/pkg/proto/resourcepb" 25 | ) 26 | 27 | func (r *clientproxy[T1, T2]) getClient() (resourcepb.ResourceClient, error) { 28 | r.m.RLock() 29 | defer r.m.RUnlock() 30 | if r.resourceClient == nil { 31 | return nil, fmt.Errorf("backend server unreachable") 32 | } 33 | return r.resourceClient.Get(), nil 34 | } 35 | 36 | func (r *clientproxy[T1, T2]) deleteClient(ctx context.Context) error { 37 | r.m.Lock() 38 | defer r.m.Unlock() 39 | if r.resourceClient != nil { 40 | // cancel the watch 41 | r.stopWatches() 42 | if err := r.resourceClient.Delete(); err != nil { 43 | r.l.Error(err, "cannot delete client") 44 | return err 45 | } 46 | } 47 | r.resourceClient = nil 48 | return nil 49 | } 50 | 51 | func (r *clientproxy[T1, T2]) createClient(ctx context.Context) error { 52 | r.m.Lock() 53 | defer r.m.Unlock() 54 | r.l.Info("create client", "address", r.address) 55 | ac, err := resource.New(&resource.Config{ 56 | Address: r.address, 57 | Insecure: true, 58 | }) 59 | if err != nil { 60 | r.l.Error(err, "cannot create client") 61 | r.resourceClient = nil 62 | return err 63 | } 64 | 65 | r.startWatches(ctx) 66 | 67 | r.resourceClient = ac 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /pkg/backend/storage.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package backend 18 | 19 | import ( 20 | "context" 21 | 22 | corev1 "k8s.io/api/core/v1" 23 | ) 24 | 25 | type Storage[T1, T2 any] interface { 26 | Restore(ctx context.Context, ref corev1.ObjectReference) error 27 | // only used in configmap 28 | SaveAll(ctx context.Context, ref corev1.ObjectReference) error 29 | // Destroy removes the store db 30 | Destroy(ctx context.Context, ref corev1.ObjectReference) error 31 | 32 | Get(ctx context.Context, claim T1) ([]T2, error) 33 | Set(ctx context.Context, claim T1) error 34 | Delete(ctx context.Context, claim T1) error 35 | } 36 | 37 | func NewNopStorage[T1, T2 any]() Storage[T1, T2] { 38 | return &nopStorage[T1, T2]{} 39 | } 40 | 41 | type nopStorage[T1, T2 any] struct{} 42 | 43 | func (r *nopStorage[T1, T2]) Restore(ctx context.Context, ref corev1.ObjectReference) error { 44 | return nil 45 | } 46 | func (r *nopStorage[T1, T2]) SaveAll(ctx context.Context, ref corev1.ObjectReference) error { 47 | return nil 48 | } 49 | func (r *nopStorage[T1, T2]) Destroy(ctx context.Context, ref corev1.ObjectReference) error { 50 | return nil 51 | } 52 | func (r *nopStorage[T1, T2]) Get(ctx context.Context, claim T1) ([]T2, error) { return nil, nil } 53 | func (r *nopStorage[T1, T2]) Set(ctx context.Context, claim T1) error { return nil } 54 | func (r *nopStorage[T1, T2]) Delete(ctx context.Context, claim T1) error { return nil } 55 | -------------------------------------------------------------------------------- /apis/resource/vlan/v1alpha1/vlan_interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | resourcev1alpha1 "github.com/nokia/k8s-ipam/apis/resource/common/v1alpha1" 21 | corev1 "k8s.io/api/core/v1" 22 | "k8s.io/apimachinery/pkg/types" 23 | ) 24 | 25 | // GetCondition returns the condition based on the condition kind 26 | func (r *VLAN) GetCondition(t resourcev1alpha1.ConditionType) resourcev1alpha1.Condition { 27 | return r.Status.GetCondition(t) 28 | } 29 | 30 | // SetConditions sets the conditions on the resource. it allows for 0, 1 or more conditions 31 | // to be set at once 32 | func (r *VLAN) SetConditions(c ...resourcev1alpha1.Condition) { 33 | r.Status.SetConditions(c...) 34 | } 35 | 36 | // GetGenericNamespacedName return a namespace and name 37 | // as string, compliant to the k8s api naming convention 38 | func (r *VLAN) GetGenericNamespacedName() string { 39 | return resourcev1alpha1.GetGenericNamespacedName(types.NamespacedName{ 40 | Namespace: r.GetNamespace(), 41 | Name: r.GetName(), 42 | }) 43 | } 44 | 45 | // GetCacheID return the cache id validating the namespace 46 | func (r *VLAN) GetCacheID() corev1.ObjectReference { 47 | return resourcev1alpha1.GetCacheID(r.Spec.VLANIndex) 48 | } 49 | 50 | // GetUserDefinedLabels returns the user defined labels in the spec 51 | func (r *VLAN) GetUserDefinedLabels() map[string]string { 52 | return r.Spec.GetUserDefinedLabels() 53 | } 54 | -------------------------------------------------------------------------------- /pkg/resource/applicator.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package resource 18 | 19 | import ( 20 | "context" 21 | 22 | "k8s.io/apimachinery/pkg/runtime" 23 | "sigs.k8s.io/controller-runtime/pkg/client" 24 | ) 25 | 26 | // A ClientApplicator may be used to build a single 'client' that satisfies both 27 | // client.Client and Applicator. 28 | type ClientApplicator struct { 29 | client.Client 30 | Applicator 31 | } 32 | 33 | // An ApplyFn is a function that satisfies the Applicator interface. 34 | type ApplyFn func(context.Context, client.Object, ...ApplyOption) error 35 | 36 | // Apply changes to the supplied object. 37 | func (fn ApplyFn) Apply(ctx context.Context, o client.Object, ao ...ApplyOption) error { 38 | return fn(ctx, o, ao...) 39 | } 40 | 41 | // An Applicator applies changes to an object. 42 | type Applicator interface { 43 | Apply(context.Context, client.Object, ...ApplyOption) error 44 | } 45 | 46 | // An ApplyOption is called before patching the current object to match the 47 | // desired object. ApplyOptions are not called if no current object exists. 48 | type ApplyOption func(ctx context.Context, current, desired runtime.Object) error 49 | 50 | // UpdateFn returns an ApplyOption that is used to modify the current object to 51 | // match fields of the desired. 52 | func UpdateFn(fn func(current, desired runtime.Object)) ApplyOption { 53 | return func(_ context.Context, c, d runtime.Object) error { 54 | fn(c, d) 55 | return nil 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /internal/grpcserver/config.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package grpcserver 18 | 19 | import ( 20 | "time" 21 | ) 22 | 23 | const ( 24 | defaultAddress = ":9999" 25 | defaultMaxRPC = 600 26 | defaultTimeout = time.Minute 27 | ) 28 | 29 | type Config struct { 30 | // gRPC server address 31 | Address string 32 | 33 | // insecure server 34 | Insecure bool 35 | 36 | // MaxRPC 37 | MaxRPC int64 38 | 39 | // request timeout 40 | Timeout time.Duration 41 | 42 | // CertDir is the directory that contains the server key and certificate. The 43 | // server key and certificate. 44 | CertDir string 45 | 46 | // CertName is the server certificate name. Defaults to tls.crt. 47 | CertName string 48 | 49 | // KeyName is the server key name. Defaults to tls.key. 50 | KeyName string 51 | 52 | // CaName is the ca certificate name. Defaults to ca.crt. 53 | CaName string 54 | } 55 | 56 | func (c *Config) setDefaults() { 57 | if c.Address == "" { 58 | c.Address = ":" + defaultAddress 59 | } 60 | if c.MaxRPC <= 0 { 61 | c.MaxRPC = defaultMaxRPC 62 | } 63 | 64 | /* 65 | if len(c.CertDir) == 0 { 66 | c.CertDir = filepath.Join(os.TempDir(), "k8s-grpc-server", "serving-certs") 67 | } 68 | 69 | if len(c.CertName) == 0 { 70 | c.CertName = "tls.crt" 71 | } 72 | 73 | if len(c.KeyName) == 0 { 74 | c.KeyName = "tls.key" 75 | } 76 | if len(c.CaName) == 0 { 77 | c.CaName = "ca.crt" 78 | } 79 | */ 80 | if c.Timeout <= 0 { 81 | c.Timeout = defaultTimeout 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /apis/inv/v1alpha1/node_interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | resourcev1alpha1 "github.com/nokia/k8s-ipam/apis/resource/common/v1alpha1" 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | "sigs.k8s.io/controller-runtime/pkg/client" 23 | ) 24 | 25 | // GetCondition returns the condition based on the condition kind 26 | func (r *Node) GetCondition(t resourcev1alpha1.ConditionType) resourcev1alpha1.Condition { 27 | return r.Status.GetCondition(t) 28 | } 29 | 30 | // SetConditions sets the conditions on the resource. it allows for 0, 1 or more conditions 31 | // to be set at once 32 | func (r *Node) SetConditions(c ...resourcev1alpha1.Condition) { 33 | r.Status.SetConditions(c...) 34 | } 35 | 36 | func (r *NodeList) GetItems() []client.Object { 37 | objs := []client.Object{} 38 | for _, r := range r.Items { 39 | objs = append(objs, &r) 40 | } 41 | return objs 42 | } 43 | 44 | // BuildNode returns a Node from a client Object a crName and 45 | // an Node Spec/Status 46 | func BuildNode(meta metav1.ObjectMeta, spec NodeSpec, status NodeStatus) *Node { 47 | return &Node{ 48 | TypeMeta: metav1.TypeMeta{ 49 | APIVersion: SchemeBuilder.GroupVersion.Identifier(), 50 | Kind: NodeKind, 51 | }, 52 | ObjectMeta: meta, 53 | Spec: spec, 54 | Status: status, 55 | } 56 | } 57 | 58 | /* 59 | func (r NodeSpec) GetTopology(topoName string) string { 60 | if r.Topology == "" { 61 | return topoName 62 | } 63 | return r.Topology 64 | } 65 | */ 66 | -------------------------------------------------------------------------------- /pkg/proxy/beclient/client_mock.go: -------------------------------------------------------------------------------- 1 | package beclient 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | ipamv1alpha1 "github.com/nokia/k8s-ipam/apis/resource/ipam/v1alpha1" 8 | vlanv1alpha1 "github.com/nokia/k8s-ipam/apis/resource/vlan/v1alpha1" 9 | "github.com/nokia/k8s-ipam/pkg/proxy/clientproxy" 10 | "github.com/nokia/k8s-ipam/pkg/proxy/clientproxy/ipam" 11 | "github.com/nokia/k8s-ipam/pkg/proxy/clientproxy/vlan" 12 | "sigs.k8s.io/controller-runtime/pkg/client" 13 | ) 14 | 15 | func NewMock() Client { 16 | return &mock{ 17 | ipam: ipam.NewMock(), 18 | vlan: vlan.NewMock(), 19 | } 20 | } 21 | 22 | type mock struct { 23 | ipam clientproxy.Proxy[*ipamv1alpha1.NetworkInstance, *ipamv1alpha1.IPClaim] 24 | vlan clientproxy.Proxy[*vlanv1alpha1.VLANIndex, *vlanv1alpha1.VLANClaim] 25 | } 26 | 27 | func (r *mock) CreateIndex(ctx context.Context, cr client.Object) error { 28 | return fmt.Errorf("unsupported") 29 | } 30 | 31 | // Delete deletes the cache instance in the backend 32 | func (r *mock) DeleteIndex(ctx context.Context, cr client.Object) error { 33 | return fmt.Errorf("unsupported") 34 | } 35 | 36 | // Get returns the claimed resource 37 | func (r *mock) GetClaim(ctx context.Context, cr client.Object, d any) (client.Object, error) { 38 | switch cr.GetObjectKind().GroupVersionKind().Group { 39 | case ipamv1alpha1.GroupVersion.Group: 40 | return r.ipam.GetClaim(ctx, cr, d) 41 | case vlanv1alpha1.GroupVersion.Group: 42 | return r.vlan.GetClaim(ctx, cr, d) 43 | default: 44 | return nil, fmt.Errorf("unsupported") 45 | } 46 | } 47 | 48 | // Claim claims a resource 49 | func (r *mock) Claim(ctx context.Context, cr client.Object, d any) (client.Object, error) { 50 | switch cr.GetObjectKind().GroupVersionKind().Group { 51 | case ipamv1alpha1.GroupVersion.Group: 52 | return r.ipam.Claim(ctx, cr, d) 53 | case vlanv1alpha1.GroupVersion.Group: 54 | return r.vlan.Claim(ctx, cr, d) 55 | default: 56 | return nil, fmt.Errorf("unsupported") 57 | } 58 | } 59 | 60 | // DeleteClaim deletes the claim 61 | func (r *mock) DeleteClaim(ctx context.Context, cr client.Object, d any) error { 62 | return fmt.Errorf("unsupported") 63 | } 64 | -------------------------------------------------------------------------------- /pkg/objects/objects.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package objects 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | "k8s.io/apimachinery/pkg/labels" 22 | "k8s.io/apimachinery/pkg/types" 23 | "sigs.k8s.io/controller-runtime/pkg/client" 24 | ) 25 | 26 | type ExtObjects interface { 27 | client.ObjectList 28 | 29 | // GetItems returns the list of managed resources. 30 | GetItems() []client.Object 31 | } 32 | 33 | type Objects struct { 34 | ExtObjects 35 | } 36 | 37 | func (r Objects) iterator() *iterator[client.Object] { 38 | return &iterator[client.Object]{curIdx: -1, items: r.GetItems()} 39 | } 40 | 41 | func (r Objects) GetAllObjects() []client.Object { 42 | objs := []client.Object{} 43 | 44 | iter := r.iterator() 45 | for iter.HasNext() { 46 | objs = append(objs, iter.Value()) 47 | } 48 | return objs 49 | } 50 | 51 | func (r Objects) GetSelectedObjects(s *metav1.LabelSelector) ([]client.Object, error) { 52 | selector, err := metav1.LabelSelectorAsSelector(s) 53 | if err != nil { 54 | return nil, err 55 | } 56 | 57 | objs := []client.Object{} 58 | uniqueValues := map[string]struct{}{} 59 | 60 | iter := r.iterator() 61 | for iter.HasNext() { 62 | v := iter.Value() 63 | if selector.Matches(labels.Set(v.GetLabels())) { 64 | name := types.NamespacedName{Name: v.GetName(), Namespace: v.GetNamespace()} 65 | if _, ok := uniqueValues[name.String()]; !ok { 66 | objs = append(objs, iter.Value()) 67 | } 68 | uniqueValues[name.String()] = struct{}{} 69 | } 70 | } 71 | return objs, nil 72 | } 73 | -------------------------------------------------------------------------------- /pkg/proxy/clientproxy/vlan/vlan_mock.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package vlan 18 | 19 | import ( 20 | "context" 21 | "fmt" 22 | "reflect" 23 | 24 | vlanv1alpha1 "github.com/nokia/k8s-ipam/apis/resource/vlan/v1alpha1" 25 | "github.com/nokia/k8s-ipam/pkg/proxy/clientproxy" 26 | "github.com/nokia/k8s-ipam/pkg/utils/util" 27 | "k8s.io/apimachinery/pkg/runtime/schema" 28 | "sigs.k8s.io/controller-runtime/pkg/client" 29 | "sigs.k8s.io/controller-runtime/pkg/event" 30 | ) 31 | 32 | func NewMock() clientproxy.Proxy[*vlanv1alpha1.VLANIndex, *vlanv1alpha1.VLANClaim] { 33 | return &mock{} 34 | } 35 | 36 | type mock struct{} 37 | 38 | func (r *mock) AddEventChs(map[schema.GroupVersionKind]chan event.GenericEvent) {} 39 | func (r *mock) CreateIndex(ctx context.Context, cr *vlanv1alpha1.VLANIndex) error { return nil } 40 | func (r *mock) DeleteIndex(ctx context.Context, cr *vlanv1alpha1.VLANIndex) error { return nil } 41 | func (r *mock) GetClaim(ctx context.Context, cr client.Object, d any) (*vlanv1alpha1.VLANClaim, error) { 42 | return r.getClaim(cr) 43 | } 44 | func (r *mock) Claim(ctx context.Context, cr client.Object, d any) (*vlanv1alpha1.VLANClaim, error) { 45 | return r.getClaim(cr) 46 | } 47 | func (r *mock) DeleteClaim(ctx context.Context, cr client.Object, d any) error { return nil } 48 | 49 | func (r *mock) getClaim(cr client.Object) (*vlanv1alpha1.VLANClaim, error) { 50 | claim, ok := cr.(*vlanv1alpha1.VLANClaim) 51 | if !ok { 52 | return nil, fmt.Errorf("expecting VLANClaim, got: %v", reflect.TypeOf(cr)) 53 | } 54 | claim.Status.VLANID = util.PointerUint16(10) 55 | return claim, nil 56 | } 57 | -------------------------------------------------------------------------------- /pkg/resource/error.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package resource 18 | 19 | import ( 20 | "github.com/pkg/errors" 21 | kerrors "k8s.io/apimachinery/pkg/api/errors" 22 | ) 23 | 24 | // Error strings. 25 | const ( 26 | errUpdateObject = "cannot update object" 27 | ) 28 | 29 | // An ErrorIs function returns true if an error satisfies a particular condition. 30 | type ErrorIs func(err error) bool 31 | 32 | // Ignore any errors that satisfy the supplied ErrorIs function by returning 33 | // nil. Errors that do not satisfy the supplied function are returned unmodified. 34 | func Ignore(is ErrorIs, err error) error { 35 | if is(err) { 36 | return nil 37 | } 38 | return err 39 | } 40 | 41 | // IgnoreAny ignores errors that satisfy any of the supplied ErrorIs functions 42 | // by returning nil. Errors that do not satisfy any of the supplied functions 43 | // are returned unmodified. 44 | func IgnoreAny(err error, is ...ErrorIs) error { 45 | for _, f := range is { 46 | if f(err) { 47 | return nil 48 | } 49 | } 50 | return err 51 | } 52 | 53 | // IgnoreNotFound returns the supplied error, or nil if the error indicates a 54 | // Kubernetes resource was not found. 55 | func IgnoreNotFound(err error) error { 56 | return Ignore(kerrors.IsNotFound, err) 57 | } 58 | 59 | // IsAPIError returns true if the given error's type is of Kubernetes API error. 60 | func IsAPIError(err error) bool { 61 | _, ok := err.(kerrors.APIStatus) 62 | return ok 63 | } 64 | 65 | // IsAPIErrorWrapped returns true if err is a K8s API error, or recursively wraps a K8s API error 66 | func IsAPIErrorWrapped(err error) bool { 67 | return IsAPIError(errors.Cause(err)) 68 | } 69 | -------------------------------------------------------------------------------- /apis/resource/common/v1alpha1/LabelKeys.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | const ( 20 | // app 21 | NephioApp = "nephio.org/app" 22 | // action 23 | NephioAPIAction = "nephio.org/action" // values get 24 | // system defined common 25 | NephioOwnerGvkKey = "nephio.org/owner-gvk" 26 | NephioOwnerNsnNameKey = "nephio.org/owner-nsn-name" 27 | NephioOwnerNsnNamespaceKey = "nephio.org/owner-nsn-namespace" 28 | NephioGvkKey = "nephio.org/gvk" 29 | NephioNsnNameKey = "nephio.org/nsn-name" 30 | NephioNsnNamespaceKey = "nephio.org/nsn-namespace" 31 | NephioOwnerRefKey = "nephio.org/owner-ref" 32 | // system defined ipam 33 | NephioPrefixKindKey = "nephio.org/prefix-kind" 34 | NephioAddressFamilyKey = "nephio.org/address-family" 35 | NephioSubnetKey = "nephio.org/subnet" // this is the subnet in prefix annotation used for GW selection 36 | NephioPoolKey = "nephio.org/pool" 37 | NephioGatewayKey = "nephio.org/gateway" 38 | // user defined common 39 | NephioClusterNameKey = "nephio.org/cluster-name" 40 | NephioSiteNameKey = "nephio.org/site-name" 41 | NephioRegionKey = "nephio.org/region" 42 | NephioAvailabilityZoneKey = "nephio.org/availability-zone" 43 | NephioInterfaceKey = "nephio.org/interface" 44 | NephioNetworkNameKey = "nephio.org/network-name" 45 | NephioPurposeKey = "nephio.org/purpose" 46 | NephioApplicationPartOfKey = "app.kubernetes.io/part-of" 47 | NephioIndexKey = "nephio.org/index" 48 | // status ipam 49 | NephioClaimedPrefix = "nephio.org/claimed-prefix" 50 | NephioClaimedGateway = "nephio.org/claimed-gateway" 51 | ) 52 | -------------------------------------------------------------------------------- /apis/inv/v1alpha1/link_interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | "fmt" 21 | 22 | resourcev1alpha1 "github.com/nokia/k8s-ipam/apis/resource/common/v1alpha1" 23 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | "sigs.k8s.io/controller-runtime/pkg/client" 25 | ) 26 | 27 | // GetCondition returns the condition based on the condition kind 28 | func (r *Link) GetCondition(t resourcev1alpha1.ConditionType) resourcev1alpha1.Condition { 29 | return r.Status.GetCondition(t) 30 | } 31 | 32 | // SetConditions sets the conditions on the resource. it allows for 0, 1 or more conditions 33 | // to be set at once 34 | func (r *Link) SetConditions(c ...resourcev1alpha1.Condition) { 35 | r.Status.SetConditions(c...) 36 | } 37 | 38 | func (r *LinkList) GetItems() []client.Object { 39 | objs := []client.Object{} 40 | for _, r := range r.Items { 41 | objs = append(objs, &r) 42 | } 43 | return objs 44 | } 45 | 46 | func (r *Link) GetTopologies() []string { 47 | topologies := []string{} 48 | for _, ep := range r.Spec.Endpoints { 49 | topologies = append(topologies, ep.Topology) 50 | } 51 | return topologies 52 | } 53 | 54 | func (r *Link) Validate() error { 55 | if len(r.Spec.Endpoints) != 2 { 56 | return fmt.Errorf("a link requires exactly 2 endpoints, got: %v", len(r.Spec.Endpoints)) 57 | } 58 | return nil 59 | } 60 | 61 | // BuildLink returns a Link from a client Object a crName and 62 | // a Link Spec/Status 63 | func BuildLink(meta metav1.ObjectMeta, spec LinkSpec, status LinkStatus) *Link { 64 | return &Link{ 65 | TypeMeta: metav1.TypeMeta{ 66 | APIVersion: SchemeBuilder.GroupVersion.Identifier(), 67 | Kind: LinkKind, 68 | }, 69 | ObjectMeta: meta, 70 | Spec: spec, 71 | Status: status, 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /internal/grpcserver/options.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package grpcserver 18 | 19 | import ( 20 | "context" 21 | "crypto/tls" 22 | "crypto/x509" 23 | "fmt" 24 | "os" 25 | "path/filepath" 26 | 27 | "google.golang.org/grpc" 28 | "google.golang.org/grpc/credentials" 29 | "google.golang.org/grpc/credentials/insecure" 30 | "sigs.k8s.io/controller-runtime/pkg/certwatcher" 31 | ) 32 | 33 | func (s *GrpcServer) serverOpts(ctx context.Context) ([]grpc.ServerOption, error) { 34 | if s.config.Insecure { 35 | return []grpc.ServerOption{ 36 | grpc.Creds(insecure.NewCredentials()), 37 | }, nil 38 | } 39 | 40 | tlsConfig, err := s.createTLSConfig(ctx) 41 | if err != nil { 42 | return nil, err 43 | } 44 | return []grpc.ServerOption{ 45 | grpc.Creds(credentials.NewTLS(tlsConfig)), 46 | }, nil 47 | 48 | } 49 | 50 | func (s *GrpcServer) createTLSConfig(ctx context.Context) (*tls.Config, error) { 51 | 52 | caPath := filepath.Join(s.config.CertDir, s.config.CaName) 53 | 54 | ca, err := os.ReadFile(caPath) 55 | if err != nil { 56 | return nil, fmt.Errorf("failed to read client CA cert: %w", err) 57 | } 58 | 59 | certPath := filepath.Join(s.config.CertDir, s.config.CertName) 60 | keyPath := filepath.Join(s.config.CertDir, s.config.KeyName) 61 | 62 | certWatcher, err := certwatcher.New(certPath, keyPath) 63 | if err != nil { 64 | return nil, err 65 | } 66 | 67 | go func() { 68 | if err := certWatcher.Start(ctx); err != nil { 69 | s.l.Info("certificate watcher", "error", err) 70 | } 71 | }() 72 | 73 | tlsConfig := &tls.Config{ 74 | GetCertificate: certWatcher.GetCertificate, 75 | } 76 | if len(ca) != 0 { 77 | caCertPool := x509.NewCertPool() 78 | caCertPool.AppendCertsFromPEM(ca) 79 | tlsConfig.RootCAs = caCertPool 80 | } 81 | 82 | return tlsConfig, nil 83 | } 84 | -------------------------------------------------------------------------------- /apis/resource/ipam/v1alpha1/networkinstance_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | "testing" 21 | 22 | "github.com/google/go-cmp/cmp" 23 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | ) 25 | 26 | func TestNiGetNameFromNetworkInstancePrefix(t *testing.T) { 27 | tests := map[string]struct { 28 | input *NetworkInstance 29 | inputPrefix string 30 | want string 31 | }{ 32 | "OK": { 33 | input: &NetworkInstance{ 34 | ObjectMeta: metav1.ObjectMeta{ 35 | Name: "a", 36 | Namespace: "b", 37 | }, 38 | }, 39 | inputPrefix: "10.0.0.1/24", 40 | want: "10.0.0.1-24-a-aggregate", 41 | }, 42 | } 43 | 44 | for name, tc := range tests { 45 | t.Run(name, func(t *testing.T) { 46 | got := tc.input.GetNameFromNetworkInstancePrefix(tc.inputPrefix) 47 | 48 | if diff := cmp.Diff(tc.want, got); diff != "" { 49 | t.Errorf("-want, +got:\n%s", diff) 50 | } 51 | 52 | }) 53 | } 54 | } 55 | 56 | func TestNiGetNetworkInstanceNameSpace(t *testing.T) { 57 | tests := map[string]struct { 58 | input *NetworkInstance 59 | want string 60 | }{ 61 | "NamespaceNAme": { 62 | input: &NetworkInstance{ 63 | ObjectMeta: metav1.ObjectMeta{ 64 | Name: "a", 65 | Namespace: "b", 66 | }, 67 | }, 68 | want: "b-a", 69 | }, 70 | "NoNamespace": { 71 | input: &NetworkInstance{ 72 | ObjectMeta: metav1.ObjectMeta{ 73 | Name: "a", 74 | }, 75 | }, 76 | want: "a", 77 | }, 78 | } 79 | 80 | for name, tc := range tests { 81 | t.Run(name, func(t *testing.T) { 82 | got := tc.input.GetGenericNamespacedName() 83 | 84 | if diff := cmp.Diff(tc.want, got); diff != "" { 85 | t.Errorf("TestNiGetNetworkInstanceNameSpace: -want, +got:\n%s", diff) 86 | } 87 | 88 | }) 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /pkg/proto/resourcepb/resource.proto: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | syntax = "proto3"; 18 | 19 | //import "google/protobuf/any.proto"; 20 | 21 | package resource; 22 | option go_package = "github.com/nephio-project/ipam/pkg/resource/resourcepb"; 23 | 24 | service Resource { 25 | // create an index in the ressource backend 26 | rpc CreateIndex (ClaimRequest) returns (EmptyResponse) {} 27 | rpc DeleteIndex (ClaimRequest) returns (EmptyResponse) {} 28 | // services within an index in the resource backend 29 | rpc GetClaim (ClaimRequest) returns (ClaimResponse) {} 30 | rpc Claim (ClaimRequest) returns (ClaimResponse) {} 31 | rpc DeleteClaim (ClaimRequest) returns (EmptyResponse) {} 32 | rpc WatchClaim (WatchRequest) returns (stream WatchResponse) {} 33 | } 34 | 35 | message Instance { 36 | NSN nsn = 1; 37 | } 38 | 39 | message ClaimRequest { 40 | Header header = 1; 41 | string spec = 2; 42 | string expiryTime = 3; 43 | } 44 | 45 | message EmptyResponse{} 46 | 47 | message ClaimResponse { 48 | Header header = 1; 49 | string spec = 2; 50 | string status = 3; 51 | StatusCode statusCode = 4; 52 | string expiryTime = 5; 53 | } 54 | 55 | message WatchResponse { 56 | Header header = 1; 57 | //string spec = 2; 58 | //string status = 3; 59 | StatusCode statusCode = 2; 60 | //string expiryTime = 3; 61 | } 62 | 63 | message WatchRequest { 64 | Header header = 1; 65 | } 66 | 67 | message Header { 68 | GVK gvk = 1; 69 | NSN nsn = 2; 70 | GVK ownerGvk = 3; 71 | NSN ownerNsn = 4; 72 | } 73 | 74 | message GVK { 75 | string group = 1; 76 | string version = 2; 77 | string kind = 3; 78 | } 79 | 80 | message NSN { 81 | string namespace = 1; 82 | string name = 2; 83 | } 84 | 85 | enum StatusCode { 86 | Valid = 0; // the status is OK 87 | InValid = 1; // the entry is no longer in the system 88 | Unknown = 2; // means the client should refresh the status 89 | } -------------------------------------------------------------------------------- /apis/resource/ipam/v1alpha1/ipprefix_interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | resourcev1alpha1 "github.com/nokia/k8s-ipam/apis/resource/common/v1alpha1" 21 | corev1 "k8s.io/api/core/v1" 22 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 | "k8s.io/apimachinery/pkg/types" 24 | ) 25 | 26 | // GetCondition returns the condition based on the condition kind 27 | func (r *IPPrefix) GetCondition(t resourcev1alpha1.ConditionType) resourcev1alpha1.Condition { 28 | return r.Status.GetCondition(t) 29 | } 30 | 31 | // SetConditions sets the conditions on the resource. it allows for 0, 1 or more conditions 32 | // to be set at once 33 | func (r *IPPrefix) SetConditions(c ...resourcev1alpha1.Condition) { 34 | r.Status.SetConditions(c...) 35 | } 36 | 37 | // GetGenericNamespacedName return a namespace and name 38 | // as string, compliant to the k8s api naming convention 39 | func (r *IPPrefix) GetGenericNamespacedName() string { 40 | return resourcev1alpha1.GetGenericNamespacedName(types.NamespacedName{ 41 | Namespace: r.GetNamespace(), 42 | Name: r.GetName(), 43 | }) 44 | } 45 | 46 | // GetCacheID return the cache id validating the namespace 47 | func (r *IPPrefix) GetCacheID() corev1.ObjectReference { 48 | return resourcev1alpha1.GetCacheID(r.Spec.NetworkInstance) 49 | } 50 | 51 | // GetUserDefinedLabels returns the user defined labels in the spec 52 | func (r *IPPrefix) GetUserDefinedLabels() map[string]string { 53 | return r.Spec.GetUserDefinedLabels() 54 | } 55 | 56 | // BuildIPPrefix returns an IP Prefix from a client Object a crName and 57 | // an IpPrefix Spec/Status 58 | func BuildIPPrefix(meta metav1.ObjectMeta, spec IPPrefixSpec, status IPPrefixStatus) *IPPrefix { 59 | return &IPPrefix{ 60 | TypeMeta: metav1.TypeMeta{ 61 | APIVersion: SchemeBuilder.GroupVersion.Identifier(), 62 | Kind: IPPrefixKind, 63 | }, 64 | ObjectMeta: meta, 65 | Spec: spec, 66 | Status: status, 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /apis/inv/v1alpha1/node_model_types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package v1alpha1 17 | 18 | import ( 19 | "reflect" 20 | 21 | corev1 "k8s.io/api/core/v1" 22 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 | "k8s.io/apimachinery/pkg/runtime/schema" 24 | ) 25 | 26 | type NodeModelSpec struct { 27 | // Provider specifies the provider implementing this node config. 28 | Provider string `json:"provider" yaml:"provider"` 29 | // Interfaces defines the interfaces belonging to the node model 30 | Interfaces []NodeModelInterface `json:"interfaces" yaml:"interfaces"` 31 | // ParametersRef points to the vendor or implementation specific params for the 32 | // node. 33 | // +optional 34 | ParametersRef *corev1.ObjectReference `json:"parametersRef,omitempty" yaml:"parametersRef,omitempty"` 35 | } 36 | 37 | type NodeModelInterface struct { 38 | Name string `json:"name,omitempty" yaml:"name,omitempty"` 39 | Speed *string `json:"speed" yaml:"speed"` 40 | } 41 | 42 | //+kubebuilder:object:root=true 43 | 44 | // NodeModel is the Schema for the srlinux node model API. 45 | type NodeModel struct { 46 | metav1.TypeMeta `json:",inline"` 47 | metav1.ObjectMeta `json:"metadata,omitempty"` 48 | 49 | Spec NodeModelSpec `json:"spec,omitempty"` 50 | } 51 | 52 | //+kubebuilder:object:root=true 53 | 54 | // NodeModelList contains a list of srlinux NodeModels. 55 | type NodeModelList struct { 56 | metav1.TypeMeta `json:",inline"` 57 | metav1.ListMeta `json:"metadata,omitempty"` 58 | Items []NodeModel `json:"items"` 59 | } 60 | 61 | func init() { 62 | SchemeBuilder.Register(&NodeModel{}, &NodeModelList{}) 63 | } 64 | 65 | // Node type metadata. 66 | var ( 67 | NodeModelKind = reflect.TypeOf(NodeModel{}).Name() 68 | NodeModelGroupKind = schema.GroupKind{Group: GroupVersion.Group, Kind: NodeModelKind}.String() 69 | NodeModelKindAPIVersion = NodeModelKind + "." + GroupVersion.String() 70 | NodeModelGroupVersionKind = GroupVersion.WithKind(NodeModelKind) 71 | ) 72 | -------------------------------------------------------------------------------- /config/default/kustomization.yaml: -------------------------------------------------------------------------------- 1 | # Adds namespace to all resources. 2 | namespace: ipam-system 3 | 4 | # Value of this field is prepended to the 5 | # names of all resources, e.g. a deployment named 6 | # "wordpress" becomes "alices-wordpress". 7 | # Note that it should also match with the prefix (text before '-') of the namespace 8 | # field above. 9 | namePrefix: ipam- 10 | 11 | # Labels to add to all resources and selectors. 12 | #commonLabels: 13 | # someName: someValue 14 | 15 | bases: 16 | - ../crd 17 | - ../rbac 18 | - ../manager 19 | # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in 20 | # crd/kustomization.yaml 21 | #- ../webhook 22 | # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required. 23 | #- ../certmanager 24 | # [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'. 25 | #- ../prometheus 26 | 27 | patchesStrategicMerge: 28 | # Protect the /metrics endpoint by putting it behind auth. 29 | # If you want your controller-manager to expose the /metrics 30 | # endpoint w/o any authn/z, please comment the following line. 31 | - manager_auth_proxy_patch.yaml 32 | 33 | 34 | 35 | # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in 36 | # crd/kustomization.yaml 37 | #- manager_webhook_patch.yaml 38 | 39 | # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 40 | # Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks. 41 | # 'CERTMANAGER' needs to be enabled to use ca injection 42 | #- webhookcainjection_patch.yaml 43 | 44 | # the following config is for teaching kustomize how to do var substitution 45 | vars: 46 | # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix. 47 | #- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR 48 | # objref: 49 | # kind: Certificate 50 | # group: cert-manager.io 51 | # version: v1 52 | # name: serving-cert # this name should match the one in certificate.yaml 53 | # fieldref: 54 | # fieldpath: metadata.namespace 55 | #- name: CERTIFICATE_NAME 56 | # objref: 57 | # kind: Certificate 58 | # group: cert-manager.io 59 | # version: v1 60 | # name: serving-cert # this name should match the one in certificate.yaml 61 | #- name: SERVICE_NAMESPACE # namespace of the service 62 | # objref: 63 | # kind: Service 64 | # version: v1 65 | # name: webhook-service 66 | # fieldref: 67 | # fieldpath: metadata.namespace 68 | #- name: SERVICE_NAME 69 | # objref: 70 | # kind: Service 71 | # version: v1 72 | # name: webhook-service 73 | -------------------------------------------------------------------------------- /pkg/backend/ipam/getter.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Nokia. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package ipam 18 | 19 | import ( 20 | "context" 21 | 22 | "github.com/go-logr/logr" 23 | "github.com/hansthienpondt/nipam/pkg/table" 24 | ipamv1alpha1 "github.com/nokia/k8s-ipam/apis/resource/ipam/v1alpha1" 25 | "github.com/nokia/k8s-ipam/pkg/iputil" 26 | "k8s.io/utils/pointer" 27 | "sigs.k8s.io/controller-runtime/pkg/log" 28 | ) 29 | 30 | type Getter interface { 31 | GetIPClaim(ctx context.Context) error 32 | } 33 | 34 | type GetterConfig struct { 35 | claim *ipamv1alpha1.IPClaim 36 | rib *table.RIB 37 | } 38 | 39 | func NewGetter(c *GetterConfig) Getter { 40 | return &getter{ 41 | claim: c.claim, 42 | rib: c.rib, 43 | } 44 | } 45 | 46 | type getter struct { 47 | claim *ipamv1alpha1.IPClaim 48 | rib *table.RIB 49 | l logr.Logger 50 | } 51 | 52 | func (r *getter) GetIPClaim(ctx context.Context) error { 53 | r.l = log.FromContext(ctx).WithValues("name", r.claim.GetName(), "kind", r.claim.Spec.Kind) 54 | r.l.Info("dynamic claim") 55 | 56 | labelSelector, err := r.claim.GetLabelSelector() 57 | if err != nil { 58 | return err 59 | } 60 | routes := r.rib.GetByLabel(labelSelector) 61 | if len(routes) != 0 { 62 | // update the status 63 | r.claim.Status.Prefix = pointer.String(routes[0].Prefix().String()) 64 | if r.claim.Spec.Kind == ipamv1alpha1.PrefixKindNetwork { 65 | if r.claim.Spec.CreatePrefix == nil { 66 | r.claim.Status.Gateway = pointer.String(r.getGateway(*r.claim.Status.Prefix)) 67 | } 68 | } 69 | } 70 | return nil 71 | } 72 | 73 | func (r *getter) getGateway(prefix string) string { 74 | pi, err := iputil.New(prefix) 75 | if err != nil { 76 | r.l.Error(err, "cannot get gateway parent rpefix") 77 | return "" 78 | } 79 | gatewaySelector, err := r.claim.GetGatewayLabelSelector(string(pi.GetSubnetName())) 80 | if err != nil { 81 | r.l.Error(err, "cannot get gateway label selector") 82 | return "" 83 | } 84 | r.l.Info("gateway", "gatewaySelector", gatewaySelector) 85 | routes := r.rib.GetByLabel(gatewaySelector) 86 | if len(routes) > 0 { 87 | r.l.Info("gateway", "routes", routes) 88 | return routes[0].Prefix().Addr().String() 89 | } 90 | return "" 91 | } 92 | -------------------------------------------------------------------------------- /pkg/backend/vlan/applogic_apply.go: -------------------------------------------------------------------------------- 1 | package vlan 2 | 3 | import ( 4 | "fmt" 5 | 6 | vlanv1alpha1 "github.com/nokia/k8s-ipam/apis/resource/vlan/v1alpha1" 7 | "github.com/nokia/k8s-ipam/pkg/db" 8 | "k8s.io/utils/ptr" 9 | ) 10 | 11 | func applyHandlerDynamicVlan(entries db.Entries[uint16], claim *vlanv1alpha1.VLANClaim) error { 12 | if len(entries) > 1 { 13 | return fmt.Errorf("claim for single entry returned multiple: %v", entries) 14 | } 15 | // update the status 16 | claim.Status.VLANID = ptr.To[uint16](entries[0].ID()) 17 | return nil 18 | } 19 | 20 | func applyHandlerStaticVlan(entries db.Entries[uint16], claim *vlanv1alpha1.VLANClaim) error { 21 | if len(entries) > 1 { 22 | return fmt.Errorf("claim for single entry returned multiple: %v", entries) 23 | } 24 | // update the status 25 | 26 | if claim.Status.VLANID == nil || *claim.Status.VLANID == entries[0].ID() { 27 | claim.Status.VLANID = ptr.To[uint16](entries[0].ID()) 28 | } else { 29 | return fmt.Errorf("vlan claim with a different vlan ID") 30 | } 31 | return nil 32 | } 33 | 34 | func applyHandlerMultipleVlan(entries db.Entries[uint16], claim *vlanv1alpha1.VLANClaim) error { 35 | // TODO update the vlan status with the proper response 36 | // TODO check if they match the claim 37 | return nil 38 | } 39 | 40 | func applyHandlerNewDynamicVlan(table db.DB[uint16], vctx *vlanv1alpha1.VLANClaimCtx, claim *vlanv1alpha1.VLANClaim) error { 41 | e, err := table.FindFree() 42 | if err != nil { 43 | return err 44 | } 45 | e = db.NewEntry(e.ID(), claim.GetUserDefinedLabels()) 46 | if err := table.Set(e); err != nil { 47 | return err 48 | } 49 | claim.Status.VLANID = ptr.To[uint16](e.ID()) 50 | return nil 51 | } 52 | 53 | func applyHandlerNewStaticVlan(table db.DB[uint16], vctx *vlanv1alpha1.VLANClaimCtx, claim *vlanv1alpha1.VLANClaim) error { 54 | e, err := table.FindFreeID(vctx.Start) 55 | if err != nil { 56 | return err 57 | } 58 | e = db.NewEntry(e.ID(), claim.GetUserDefinedLabels()) 59 | if err := table.Set(e); err != nil { 60 | return err 61 | } 62 | claim.Status.VLANID = ptr.To[uint16](e.ID()) 63 | return nil 64 | } 65 | 66 | func applyHandlerNewVlanRange(table db.DB[uint16], vctx *vlanv1alpha1.VLANClaimCtx, claim *vlanv1alpha1.VLANClaim) error { 67 | _, err := table.FindFreeRange(vctx.Start, vctx.Size) 68 | if err != nil { 69 | return err 70 | } 71 | claim.Status.VLANRange = ptr.To[string](fmt.Sprintf("%d:%d", vctx.Start, vctx.Start+vctx.Size-1)) 72 | return nil 73 | } 74 | 75 | func applyHandlerNewVlanSize(table db.DB[uint16], vctx *vlanv1alpha1.VLANClaimCtx, claim *vlanv1alpha1.VLANClaim) error { 76 | _, err := table.FindFreeSize(vctx.Size) 77 | if err != nil { 78 | return err 79 | } 80 | claim.Status.VLANRange = ptr.To[string]("TBD update status ") 81 | return nil 82 | } 83 | -------------------------------------------------------------------------------- /controllers/ipamspecializer/reconciler.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package ipamspecializer 17 | 18 | /* 19 | import ( 20 | "context" 21 | 22 | "github.com/GoogleContainerTools/kpt-functions-sdk/go/fn" 23 | porchv1alpha1 "github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1" 24 | ipamv1alpha1 "github.com/nokia/k8s-ipam/apis/resource/ipam/v1alpha1" 25 | "github.com/nokia/k8s-ipam/controllers" 26 | "github.com/nokia/k8s-ipam/controllers/ctrlrconfig" 27 | "github.com/nokia/k8s-ipam/controllers/specializerreconciler" 28 | function "github.com/nokia/k8s-ipam/pkg/fn/ipam-fn/fn" 29 | "github.com/nokia/k8s-ipam/pkg/proxy/clientproxy" 30 | "github.com/nokia/k8s-ipam/pkg/proxy/clientproxy/ipam" 31 | corev1 "k8s.io/api/core/v1" 32 | "k8s.io/apimachinery/pkg/runtime/schema" 33 | ctrl "sigs.k8s.io/controller-runtime" 34 | "sigs.k8s.io/controller-runtime/pkg/event" 35 | ) 36 | 37 | func init() { 38 | controllers.Register("ipspecializer", &reconciler{}) 39 | } 40 | 41 | // +kubebuilder:rbac:groups=porch.kpt.dev,resources=packagerevisions,verbs=get;list;watch;create;update;patch;delete 42 | // +kubebuilder:rbac:groups=porch.kpt.dev,resources=packagerevisions/status,verbs=get;update;patch 43 | // SetupWithManager sets up the controller with the Manager. 44 | func (r *reconciler) Setup(ctx context.Context, mgr ctrl.Manager, cfg *ctrlrconfig.ControllerConfig) (map[schema.GroupVersionKind]chan event.GenericEvent, error) { 45 | // register scheme 46 | if err := porchv1alpha1.AddToScheme(mgr.GetScheme()); err != nil { 47 | return nil, err 48 | } 49 | 50 | fnr := &function.FnR{ClientProxy: ipam.New( 51 | ctx, clientproxy.Config{Address: cfg.Address}, 52 | )} 53 | 54 | r.Client = mgr.GetClient() 55 | r.PorchClient = cfg.PorchClient 56 | r.For = corev1.ObjectReference{ 57 | APIVersion: ipamv1alpha1.SchemeBuilder.GroupVersion.Identifier(), 58 | Kind: ipamv1alpha1.IPClaimKind, 59 | } 60 | r.Krmfn = fn.ResourceListProcessorFunc(fnr.Run) 61 | 62 | return nil, ctrl.NewControllerManagedBy(mgr). 63 | For(&porchv1alpha1.PackageRevision{}). 64 | Complete(r) 65 | 66 | } 67 | 68 | // reconciler reconciles a object 69 | type reconciler struct { 70 | specializerreconciler.Reconciler 71 | } 72 | */ 73 | -------------------------------------------------------------------------------- /controllers/vlanspecializer/reconciler.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package vlanspecializer 18 | 19 | /* 20 | import ( 21 | "context" 22 | 23 | "github.com/GoogleContainerTools/kpt-functions-sdk/go/fn" 24 | porchv1alpha1 "github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1" 25 | vlanv1alpha1 "github.com/nokia/k8s-ipam/apis/resource/vlan/v1alpha1" 26 | "github.com/nokia/k8s-ipam/controllers" 27 | "github.com/nokia/k8s-ipam/controllers/ctrlrconfig" 28 | "github.com/nokia/k8s-ipam/controllers/specializerreconciler" 29 | function "github.com/nokia/k8s-ipam/pkg/fn/vlan-fn/fn" 30 | "github.com/nokia/k8s-ipam/pkg/proxy/clientproxy" 31 | "github.com/nokia/k8s-ipam/pkg/proxy/clientproxy/vlan" 32 | corev1 "k8s.io/api/core/v1" 33 | "k8s.io/apimachinery/pkg/runtime/schema" 34 | ctrl "sigs.k8s.io/controller-runtime" 35 | "sigs.k8s.io/controller-runtime/pkg/event" 36 | ) 37 | 38 | func init() { 39 | controllers.Register("vlanspecializer", &reconciler{}) 40 | } 41 | 42 | // +kubebuilder:rbac:groups=porch.kpt.dev,resources=packagerevisions,verbs=get;list;watch;create;update;patch;delete 43 | // +kubebuilder:rbac:groups=porch.kpt.dev,resources=packagerevisions/status,verbs=get;update;patch 44 | // SetupWithManager sets up the controller with the Manager. 45 | func (r *reconciler) Setup(ctx context.Context, mgr ctrl.Manager, cfg *ctrlrconfig.ControllerConfig) (map[schema.GroupVersionKind]chan event.GenericEvent, error) { 46 | // register scheme 47 | if err := porchv1alpha1.AddToScheme(mgr.GetScheme()); err != nil { 48 | return nil, err 49 | } 50 | 51 | fnr := &function.FnR{ClientProxy: vlan.New( 52 | ctx, clientproxy.Config{Address: cfg.Address}, 53 | )} 54 | 55 | r.Client = mgr.GetClient() 56 | r.PorchClient = cfg.PorchClient 57 | r.For = corev1.ObjectReference{ 58 | APIVersion: vlanv1alpha1.SchemeBuilder.GroupVersion.Identifier(), 59 | Kind: vlanv1alpha1.VLANClaimKind, 60 | } 61 | r.Krmfn = fn.ResourceListProcessorFunc(fnr.Run) 62 | 63 | return nil, ctrl.NewControllerManagedBy(mgr). 64 | For(&porchv1alpha1.PackageRevision{}). 65 | Complete(r) 66 | 67 | } 68 | 69 | // reconciler reconciles a object 70 | type reconciler struct { 71 | specializerreconciler.Reconciler 72 | } 73 | */ 74 | -------------------------------------------------------------------------------- /apis/resource/vlan/v1alpha1/vlanindex_interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | resourcev1alpha1 "github.com/nokia/k8s-ipam/apis/resource/common/v1alpha1" 21 | corev1 "k8s.io/api/core/v1" 22 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 | "k8s.io/apimachinery/pkg/types" 24 | ) 25 | 26 | // GetCondition returns the condition based on the condition type 27 | func (r *VLANIndex) GetCondition(ct resourcev1alpha1.ConditionType) resourcev1alpha1.Condition { 28 | return r.Status.GetCondition(ct) 29 | } 30 | 31 | // SetConditions sets the conditions on the resource. it allows for 0, 1 or more conditions 32 | // to be set at once 33 | func (r *VLANIndex) SetConditions(c ...resourcev1alpha1.Condition) { 34 | r.Status.SetConditions(c...) 35 | } 36 | 37 | // GetNamespacedName returns the namespace and name 38 | func (r *VLANIndex) GetNamespacedName() types.NamespacedName { 39 | return types.NamespacedName{ 40 | Name: r.Name, 41 | Namespace: r.Namespace, 42 | } 43 | } 44 | 45 | // GetGenericNamespacedName return a namespace and name 46 | // as string, compliant to the k8s api naming convention 47 | func (r *VLANIndex) GetGenericNamespacedName() string { 48 | return resourcev1alpha1.GetGenericNamespacedName(types.NamespacedName{ 49 | Namespace: r.GetNamespace(), 50 | Name: r.GetName(), 51 | }) 52 | } 53 | 54 | // GetUserDefinedLabels returns the user defined labels in the spec 55 | func (r *VLANIndex) GetUserDefinedLabels() map[string]string { 56 | return r.Spec.GetUserDefinedLabels() 57 | } 58 | 59 | // GetCacheID returns a CacheID as an objectReference 60 | func (r *VLANIndex) GetCacheID() corev1.ObjectReference { 61 | return resourcev1alpha1.GetCacheID(corev1.ObjectReference{Name: r.GetName(), Namespace: r.GetNamespace()}) 62 | } 63 | 64 | // BuildVLANIndex returns a VLANIndex from a client Object a crName and 65 | // an VLANIndex Spec/Status 66 | func BuildVLANIndex(meta metav1.ObjectMeta, spec VLANIndexSpec, status VLANIndexStatus) *VLANIndex { 67 | return &VLANIndex{ 68 | TypeMeta: metav1.TypeMeta{ 69 | APIVersion: SchemeBuilder.GroupVersion.Identifier(), 70 | Kind: VLANIndexKind, 71 | }, 72 | ObjectMeta: meta, 73 | Spec: spec, 74 | Status: status, 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /apis/resource/vxlan/v1alpha1/vxlanindex_interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Nephio Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1alpha1 18 | 19 | import ( 20 | resourcev1alpha1 "github.com/nokia/k8s-ipam/apis/resource/common/v1alpha1" 21 | corev1 "k8s.io/api/core/v1" 22 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 | "k8s.io/apimachinery/pkg/types" 24 | ) 25 | 26 | // GetCondition returns the condition based on the condition type 27 | func (r *VXLANIndex) GetCondition(ct resourcev1alpha1.ConditionType) resourcev1alpha1.Condition { 28 | return r.Status.GetCondition(ct) 29 | } 30 | 31 | // SetConditions sets the conditions on the resource. it allows for 0, 1 or more conditions 32 | // to be set at once 33 | func (r *VXLANIndex) SetConditions(c ...resourcev1alpha1.Condition) { 34 | r.Status.SetConditions(c...) 35 | } 36 | 37 | // GetNamespacedName returns the namespace and name 38 | func (r *VXLANIndex) GetNamespacedName() types.NamespacedName { 39 | return types.NamespacedName{ 40 | Name: r.Name, 41 | Namespace: r.Namespace, 42 | } 43 | } 44 | 45 | // GetGenericNamespacedName return a namespace and name 46 | // as string, compliant to the k8s api naming convention 47 | func (r *VXLANIndex) GetGenericNamespacedName() string { 48 | return resourcev1alpha1.GetGenericNamespacedName(types.NamespacedName{ 49 | Namespace: r.GetNamespace(), 50 | Name: r.GetName(), 51 | }) 52 | } 53 | 54 | // GetUserDefinedLabels returns the user defined labels in the spec 55 | func (r *VXLANIndex) GetUserDefinedLabels() map[string]string { 56 | return r.Spec.GetUserDefinedLabels() 57 | } 58 | 59 | // GetCacheID returns a CacheID as an objectReference 60 | func (r *VXLANIndex) GetCacheID() corev1.ObjectReference { 61 | return resourcev1alpha1.GetCacheID(corev1.ObjectReference{Name: r.GetName(), Namespace: r.GetNamespace()}) 62 | } 63 | 64 | // BuildVXLANIndex returns a VXLANIndex from a client Object a crName and 65 | // an VXLANIndex Spec/Status 66 | func BuildVXLANIndex(meta metav1.ObjectMeta, spec VXLANIndexSpec, status VXLANIndexStatus) *VXLANIndex { 67 | return &VXLANIndex{ 68 | TypeMeta: metav1.TypeMeta{ 69 | APIVersion: SchemeBuilder.GroupVersion.Identifier(), 70 | Kind: VXLANIndexKind, 71 | }, 72 | ObjectMeta: meta, 73 | Spec: spec, 74 | Status: status, 75 | } 76 | } 77 | --------------------------------------------------------------------------------