diff --git a/.env b/.env index bfa1ff4e3af5c19fd88e70b885c1f2bf2285ca7d..88f8641257b5f794b55d326edbe3341785f3d461 100644 --- a/.env +++ b/.env @@ -1,3 +1,2 @@ -CONTROLLER_IP=10.152.183.155 -CONTROLLER_PORT=8181 -SWITCHES_NAMESPACE=l2sm-system +CONTROLLER_IP=localhost +CONTROLLER_PORT=30000 diff --git a/.github/workflows/sync_to_nemo.yaml b/.github/workflows/sync_to_nemo.yaml index ddf8f7a2a09b17b530f6af34099d883f9f0e1779..345e35099717fb76a9e94aa88e8b4b64c8b66fff 100644 --- a/.github/workflows/sync_to_nemo.yaml +++ b/.github/workflows/sync_to_nemo.yaml @@ -1,3 +1,17 @@ +# Copyright 2024 Universidad Carlos III de Madrid +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: Sync to GitLab on: diff --git a/.gitignore b/.gitignore index ebf2498d8fc36bea5439cf9012ac80a43d1d3aec..e3c7e8f399f277b818c58c49a34d80adf51951e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ .vscode tls.b64 -bin/ \ No newline at end of file +bin/ +plugins/ +.env +examples2/ \ No newline at end of file diff --git a/Makefile b/Makefile index 835dd67a2c9d9d7259e0bc006c531f93ecb2cd8d..79d33ecb05c1d2326f6fe29a2d6bfc30e3774245 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ # Image URL to use all building/pushing image targets -IMG ?= alexdecb/l2sm-controller-manager:2.7.1 +IMG ?= alexdecb/l2sm-controller-manager:2.7.2 # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. ENVTEST_K8S_VERSION = 1.29.0 +DEV_IP = 163.117.139.220 # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) GOBIN=$(shell go env GOPATH)/bin @@ -15,7 +16,7 @@ endif # Be aware that the target commands are only tested with Docker which is # scaffolded by default. However, you might want to replace it to use other # tools. (i.e. podman) -CONTAINER_TOOL ?= sudo docker +CONTAINER_TOOL ?= docker # Setting SHELL to bash allows bash commands to be executed by recipes. # Options are set to exit when a recipe line exits non-zero or a piped command fails. @@ -125,8 +126,6 @@ build-installer: manifests generate kustomize ## Generate a consolidated YAML wi echo "---" >> deployments/l2sm-deployment.yaml # Add a document separator before appending cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} $(KUSTOMIZE) build config/default >> deployments/l2sm-deployment.yaml - echo "---" >> deployments/l2sm-deployment.yaml # Add a document separator before appending - $(KUSTOMIZE) build config/tmp >> deployments/l2sm-deployment.yaml ##@ Deployment @@ -147,39 +146,40 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} $(KUSTOMIZE) build config/default | $(KUBECTL) apply -f - - $(KUSTOMIZE) build config/tmp | $(KUBECTL) apply -f - .PHONY: undeploy undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. - $(KUSTOMIZE) build config/tmp | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f - $(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f - .PHONY: webhook-certs webhook-certs: ## generate self-signed cert and key for local webhook development mkdir -p /tmp/k8s-webhook-server/serving-certs - openssl req -x509 -newkey rsa:2048 -nodes -keyout /tmp/k8s-webhook-server/serving-certs/tls.key -out /tmp/k8s-webhook-server/serving-certs/tls.crt -days 365 -config ./config/dev/openssl.cnf -batch -subj '/CN=local-webhook' + sed -e 's/{{IP_2}}/$(DEV_IP)/' ./config/dev/openssl.cnf > /tmp/openssl.cnf + openssl req -x509 -newkey rsa:2048 -nodes -keyout /tmp/k8s-webhook-server/serving-certs/tls.key -out /tmp/k8s-webhook-server/serving-certs/tls.crt -days 365 -config /tmp/openssl.cnf -batch -subj '/CN=local-webhook' cat /tmp/k8s-webhook-server/serving-certs/tls.crt | base64 -w0 > /tmp/k8s-webhook-server/tls.b64 -# $(eval B64_CERT := $(shell cat /tmp/k8s-webhook-server/tls.b64)) -# echo $(B64_CERT) -# cat /tmp/k8s-webhook-server/tls.b64 -# openssl req -x509 \ -# -newkey rsa:2048 \ -# -nodes \ -# -keyout /tmp/k8s-webhook-server/serving-certs/tls.key \ -# -out /tmp/k8s-webhook-server/serving-certs/tls.crt \ -# -days 365 \ -# -subj '/CN=local-webhook' -##@ Webhook + + +.PHONY: create-cluster +create-cluster: + kind create cluster --config ./examples/quickstart/kind-cluster.yaml + ./hack/install_dependencies.sh + +.PHONY: delete-cluster +delete-cluster: + kind delete cluster --name l2sm-test + sudo rm -r ./plugins/ + .PHONY: deploy-dev -deploy-dev: webhook-certs manifests kustomize ## Deploy validating and mutating webhooks to the K8s cluster specified in ~/.kube/config. +deploy-dev: webhook-certs install manifests kustomize ## Deploy validating and mutating webhooks to the K8s cluster specified in ~/.kube/config. sed -i'' -e 's/caBundle: .*/caBundle: $(shell cat /tmp/k8s-webhook-server/tls.b64)/' ./config/dev/webhookcainjection_patch.yaml + sed -i'' -e 's|url: .*|url: https://$(DEV_IP):9443/mutate-v1-pod|' ./config/dev/webhookcainjection_patch.yaml $(KUSTOMIZE) build config/dev | $(KUBECTL) apply -f - - - + echo -e "CONTROLLER_IP=localhost\nCONTROLLER_PORT=30000" > .env + .PHONY: undeploy-dev undeploy-dev: kustomize ## Undeploy validating and mutating webhooks from the K8s cluster specified in ~/.kube/config. $(KUSTOMIZE) build config/dev | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f - @@ -191,7 +191,7 @@ FILES := $(shell find . -type f \( -name "*.go" -o -name "*.json" -o -name "*.ya # Install the addlicense tool if not installed .PHONY: install-tools install-tools: - @go install github.com/google/addlicense@latest + GOBIN=$(LOCALBIN) go install github.com/google/addlicense@latest # Add license headers to the files .PHONY: add-license @@ -216,7 +216,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION) GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION) ## Tool Versions -KUSTOMIZE_VERSION ?= v5.3.0 +KUSTOMIZE_VERSION ?= v5.5.0 CONTROLLER_TOOLS_VERSION ?= v0.14.0 ENVTEST_VERSION ?= latest GOLANGCI_LINT_VERSION ?= v1.54.2 diff --git a/api/v1/overlay_types.go b/api/v1/overlay_types.go index 191aaf340e611d5e8445be13fd31e3a3565516cc..31b827f0c7a168b9a3aaf900fcbae01609d01015 100644 --- a/api/v1/overlay_types.go +++ b/api/v1/overlay_types.go @@ -45,11 +45,12 @@ type OverlaySpec struct { // selecting the nodes that are going to be linked. Topology *TopologySpec `json:"topology,omitempty"` - // Field exclusive to the multi-domain overlay type. If specified in other types of overlays, the reosurce will launch an error and won't be created. - Neighbors []NeighborSpec `json:"neighbors,omitempty"` - // Template describes the virtual switch pod that will be created. SwitchTemplate *SwitchTemplateSpec `json:"switchTemplate"` + + // Interface number specifies how many interfaces the switch should have predefined (if used with multus) + //+kubebuilder:default:value=10 + InterfaceNumber int `json:"interfaceNumber,omitempty"` } // OverlayStatus defines the observed state of Overlay diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index deb5ad3c723a3cca4c5a06c4f96a1eb5f233c398..985631a02df812eca758caa2c156cf0b25dcfab7 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -388,11 +388,6 @@ func (in *OverlaySpec) DeepCopyInto(out *OverlaySpec) { *out = new(TopologySpec) (*in).DeepCopyInto(*out) } - if in.Neighbors != nil { - in, out := &in.Neighbors, &out.Neighbors - *out = make([]NeighborSpec, len(*in)) - copy(*out, *in) - } if in.SwitchTemplate != nil { in, out := &in.SwitchTemplate, &out.SwitchTemplate *out = new(SwitchTemplateSpec) diff --git a/cmd/main.go b/cmd/main.go index 25b2c4eb53587247ef69d67220117cbcd205c45b..ef5ffdbaa08c15ea9d2f710978ee5922dedb4137 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -54,6 +54,7 @@ func init() { } func main() { + var metricsAddr string var enableLeaderElection bool var probeAddr string diff --git a/config/crd/bases/l2sm.l2sm.k8s.local_overlays.yaml b/config/crd/bases/l2sm.l2sm.k8s.local_overlays.yaml index e2c5e8508943ddfca9e725952e5cbae98cb694ea..810e9698559cc9103f22a1dd3266ba29fe198629 100644 --- a/config/crd/bases/l2sm.l2sm.k8s.local_overlays.yaml +++ b/config/crd/bases/l2sm.l2sm.k8s.local_overlays.yaml @@ -53,26 +53,11 @@ spec: spec: description: OverlaySpec defines the desired state of Overlay properties: - neighbors: - description: Field exclusive to the multi-domain overlay type. If - specified in other types of overlays, the reosurce will launch - an error and won't be created. - items: - properties: - domain: - description: |- - Domain where the neighbor's NED switch can be reached at. Must be a valid IP Address or Domain name, reachable from the node the NED - is going to be deployed at. - type: string - node: - description: Name of the cluster the link is going to be made - upon. - type: string - required: - - domain - - node - type: object - type: array + interfaceNumber: + default: 10 + description: Interface number specifies how many interfaces the switch + should have predefined (if used with multus) + type: integer networkController: description: The SDN Controller that manages the overlay network. Must specify a domain and a name. diff --git a/config/dev/kustomization.yaml b/config/dev/kustomization.yaml index 5b65a642b0813388314dedcd4388700b1215189c..ea135d9242bc040c1f325ce0bfbcbc05c1b73207 100644 --- a/config/dev/kustomization.yaml +++ b/config/dev/kustomization.yaml @@ -27,7 +27,8 @@ resources: # crd/kustomization.yaml - ../webhook - ../sdncontroller -- ../tmp +# - ../tmp patches: - path: webhookcainjection_patch.yaml +- path: sdncontroller_patch.yaml diff --git a/config/dev/openssl.cnf b/config/dev/openssl.cnf index 73f4ad5b760d9ebab50749fc9d084ce914ad080c..7ff343a794fffe343e39e6e094c9bc6d52e0547b 100644 --- a/config/dev/openssl.cnf +++ b/config/dev/openssl.cnf @@ -28,6 +28,6 @@ extendedKeyUsage = serverAuth [ alt_names ] IP.1 = 127.0.0.1 -IP.2 = 192.168.122.60 +IP.2 = {{IP_2}} DNS.1 = localhost DNS.2 = webhook-server.local diff --git a/config/tmp/kustomization.yaml b/config/dev/sdncontroller_patch.yaml similarity index 74% rename from config/tmp/kustomization.yaml rename to config/dev/sdncontroller_patch.yaml index a9303b4e2868f4d48ea3d24697ac067455f38c81..b257f0183567d79c30896d9e0c5d37b433b0bf62 100644 --- a/config/tmp/kustomization.yaml +++ b/config/dev/sdncontroller_patch.yaml @@ -12,15 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -namespace: l2sm-system -resources: -- vhost1.yaml -- vhost2.yaml -- vhost3.yaml -- vhost4.yaml -- vhost5.yaml -- vhost6.yaml -- vhost7.yaml -- vhost8.yaml -- vhost9.yaml -- vhost10.yaml \ No newline at end of file +apiVersion: v1 +kind: Service +metadata: + name: controller-service +spec: + type: NodePort + ports: + - name: http-port + protocol: TCP + port: 8181 + targetPort: 8181 + nodePort: 30000 diff --git a/config/dev/webhookcainjection_patch.yaml b/config/dev/webhookcainjection_patch.yaml index 0f98e68e16fdfc182efaf7404f3f4e9f1d1d6dfe..8f404c48a2eba0e1706b9b4728f83d24cf8a214b 100644 --- a/config/dev/webhookcainjection_patch.yaml +++ b/config/dev/webhookcainjection_patch.yaml @@ -26,8 +26,8 @@ metadata: webhooks: - name: mpod.kb.io clientConfig: - url: https://192.168.122.60:9443/mutate-v1-pod - caBundle: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURIVENDQWdXZ0F3SUJBZ0lVS1B3bFFOc0RrOTc2Uk5NMGRVQ2l4c2dxNk5Fd0RRWUpLb1pJaHZjTkFRRUwKQlFBd0dERVdNQlFHQTFVRUF3d05iRzlqWVd3dGQyVmlhRzl2YXpBZUZ3MHlOREV3TURNd05ESXdOREJhRncweQpOVEV3TURNd05ESXdOREJhTUJneEZqQVVCZ05WQkFNTURXeHZZMkZzTFhkbFltaHZiMnN3Z2dFaU1BMEdDU3FHClNJYjNEUUVCQVFVQUE0SUJEd0F3Z2dFS0FvSUJBUUM4aDQ5S0Y0Y0hvS1dDVVU2ZmdJdXdvWXNvVm1mZkFSRjYKYVF1ZHlCektZaVRaNUxlYUZjUlp6dmg0U2RLZllhQmI5ZW9RU1hsUUhWU3lXVjN2MWFrRWRpcWxiWXJpRzhRLwp0UWFIZHpZT05rcEc0aHQyRW04cDN5Q08vTkhlRHNtZ3JBQ1pYWEFxNDFuai9qcHFQd2xDUkdwQk9Sa3dTeXZZCjJmUWM3Z1pKbFY3ZmUzbE9LcTA1UzFYSElqdU9zbnArMHdqa1I1VnIyQ1J3a0ZGYkIvTnBRRnZtbWhwQWJQNEIKYmJlT0Q5Y1FCakVPWjN5aVlJQWZ5RVp0MEIyZUo5S1EzUlcrbTFlSHFYSnFEakhrVXlpZUZuRE5hdzdCMXpjTwo1bGcxVGxZQWRxNWZoV21KTlBZbjNjdWtvS0tKL2xiQk80Z2pjL3AzY2tnY3VMWGMydlRYQWdNQkFBR2pYekJkCk1EWUdBMVVkRVFRdk1DMkhCSDhBQUFHSEJNQ29lanlDQ1d4dlkyRnNhRzl6ZElJVWQyVmlhRzl2YXkxelpYSjIKWlhJdWJHOWpZV3d3RGdZRFZSMFBBUUgvQkFRREFnV2dNQk1HQTFVZEpRUU1NQW9HQ0NzR0FRVUZCd01CTUEwRwpDU3FHU0liM0RRRUJDd1VBQTRJQkFRQ3kwNlZGOEgzMG5vVVpwSW9STWQwSG5NRzA3aHdpNzZOU1hvZFZjN1E4CndHR09qR3h5czZ6M0NJQmEySEp2M0VRUWhzajEvN0VrM1EyVUorRWlweDNpNTlocDNRYWw2SzFvdzFXRlowNEEKTHh0Mm03eCs4Nmh3Q2NaWGpDNmVNdnhORTFEUmJuRnJTRElaR044akNtZHN2WjdqOXUrSUV0cVEwSWNML3AzWgpIdHJoc0ZzTU5BdnU2MDRZSmhPdTlid1NoOVNNQlo1bHcwOTRJU2Z4NDdFVXQzM1F2UXZWMkVncDNoa2lWR1A2Ci91YnhXWWpJQzd3Zk9wZ0dsc2tEZ1RUSnlZTWM1WEI2UlAwaWdZdGhoWlpNVWhtV1g1VEpKZWV5c2RLa0oyMkEKRkptZ1c5em1kNHVlb05IM0JPcjZlK3YyVlhHcUxuME54RlFXaUl2NUsyRFMKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo= + url: https://163.117.139.220:9443/mutate-v1-pod + caBundle: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURIVENDQWdXZ0F3SUJBZ0lVVEJSVEJESVY0QmRWcGZVTjJLa1ZwUFFpK0U0d0RRWUpLb1pJaHZjTkFRRUwKQlFBd0dERVdNQlFHQTFVRUF3d05iRzlqWVd3dGQyVmlhRzl2YXpBZUZ3MHlOREV4TVRVd09ESXpNRE5hRncweQpOVEV4TVRVd09ESXpNRE5hTUJneEZqQVVCZ05WQkFNTURXeHZZMkZzTFhkbFltaHZiMnN3Z2dFaU1BMEdDU3FHClNJYjNEUUVCQVFVQUE0SUJEd0F3Z2dFS0FvSUJBUUMvQXJmY3g1bk5rN3VWSzJ5UktyenNRaFRpYmNlN0JTZkwKY05KVUloT3BuSFQzZ3c1VHNoVkhkQloxdkNzRWJCSUpQR0dEcHNyZk9URFFIQ0FKYm5kRFdjVU1NZ2U1VE1tUQpvb2dEZ042T2JDM3NNT1BleEdKcXhobjRoL1dsd3l6Q0s0Qkgyc2Z6NkdmaWRyYloyTUZxbi9TQ09DS25OYSsrCnBZZFR3bEF4emJONEJsM0V5TGdnekJHckRTSnpYdEZkbGw1dG1ZSEx4TVhjdlpGZDNqaENoSnllTy90aVVSdVMKbDdRR3AvOFFKYzRUNThTQkdVUm01R05VVklWQXdsQzNHK3RIc210V0tFL3lZQVlhbG5QcHFZaHVRTUZ0TjVCdwpyUDJTWVlqVDRMRUo1YmFsV0ZCeWFEZllsdWcrZzI3SVdXbXgwM1RwazNzNEpseHdUelQ5QWdNQkFBR2pYekJkCk1EWUdBMVVkRVFRdk1DMkhCSDhBQUFHSEJLTjFpOXlDQ1d4dlkyRnNhRzl6ZElJVWQyVmlhRzl2YXkxelpYSjIKWlhJdWJHOWpZV3d3RGdZRFZSMFBBUUgvQkFRREFnV2dNQk1HQTFVZEpRUU1NQW9HQ0NzR0FRVUZCd01CTUEwRwpDU3FHU0liM0RRRUJDd1VBQTRJQkFRQ3hLZndCMXBlclNOK3JDSE1qeTAxZjg3b3Uvb2NmdVlyQy9lbUwyb0hjCm5LUFRqZE1iMlhoYm80TUxXOUp0SjIxcHZoL2daS0hKUWZRdDZySW54TmR2UW9aTTFNUW1oR1NodUVxMWt2eU8KZ0ltZDA1UkZqZVVyUHk1ZFlQdGdaZmE1VWh6eWIybmZHN2NodzZlRTFkWlg4eDBYVWJTZGNkVkVHY2pJV1pmMQpUbEZiSnk2cWo1OG5BTWJ0TzdPaEd6RHRQK3lhUnA4d0VwTHJlVlZIajFhOHNJQzRRQjRrQ3JmWjBYbXdqTWR2CjdjSjZDVll4UkhzTllCYktmM2pRUEx2TnJEWmM0L215cXNoK29kWU1KRlg1c09SbExwTmE5aHpVK2NkZnJScC8KVktHZjh2QzhGS2dkdTljNEJ4WStralZwbEgyV01EdzVLbVVOS2czdkxtdzYKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo= rules: - operations: [ "CREATE", "UPDATE" ] apiGroups: [""] diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index aaf2697b620f746e34ee021ffdf017fc6ba22f15..27d44a356d9b437d17ab390c48d6f973a3e2b3bf 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -19,4 +19,4 @@ kind: Kustomization images: - name: controller newName: alexdecb/l2sm-controller-manager - newTag: 2.7.1 + newTag: 2.7.2 diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 40b53d310fa2898a804d5d7d75cc5716c271af5a..dc0f8ecf89dec4a8e3c7920b24699cf68c3e7ed5 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -89,8 +89,8 @@ spec: value: l2sm-controller-service.l2sm-system.svc.cluster.local - name: CONTROLLER_PORT value: "8181" - - name: SWITCHES_NAMESPACE - value: "l2sm-system" + # - name: SWITCHES_NAMESPACE + # value: "l2sm-system" image: controller:latest name: manager securityContext: diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 41f6e90320c7937247a52bc7789dc86e76d0b484..e5beab3288dd533acca6c21a50df38480086fb23 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -30,6 +30,18 @@ rules: - patch - update - watch +- apiGroups: + - "" + resources: + - configmaps + verbs: + - create + - delete + - get + - list + - patch + - update + - watch - apiGroups: - "" resources: @@ -56,6 +68,30 @@ rules: - get - patch - update +- apiGroups: + - "" + resources: + - services + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - k8s.cni.cncf.io + resources: + - network-attachment-definitions + verbs: + - create + - delete + - get + - list + - patch + - update + - watch - apiGroups: - l2sm.l2sm.k8s.local resources: diff --git a/config/samples/l2sm_v1_overlay.yaml b/config/samples/l2sm_v1_overlay.yaml index 8df97f3501fb0d79cf2e0bb5d5ca6f9e52169761..626efb84690c2f56f826130be7f529bd9bfcd5bb 100644 --- a/config/samples/l2sm_v1_overlay.yaml +++ b/config/samples/l2sm_v1_overlay.yaml @@ -44,14 +44,6 @@ spec: valueFrom: fieldRef: fieldPath: spec.nodeName - - name: NVETHS - value: "10" - - name: CONTROLLERIP - value: "l2sm-controller-service" - - name: PODNAME - valueFrom: - fieldRef: - fieldPath: metadata.name imagePullPolicy: Always securityContext: capabilities: diff --git a/config/tmp/vhost1.yaml b/config/tmp/vhost1.yaml deleted file mode 100644 index 1d2e76dfa7d566c0347a6f15d36b2eb055cda9c5..0000000000000000000000000000000000000000 --- a/config/tmp/vhost1.yaml +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2024 Universidad Carlos III de Madrid -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: veth1 - labels: - app: l2sm -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "bridge", - "bridge": "br1", - "mtu": 1400, - "device": "veth1", - "ipam": { - "type":"static" - } - }' diff --git a/config/tmp/vhost10.yaml b/config/tmp/vhost10.yaml deleted file mode 100644 index ba43d7f0e6068e479dbca36944752018b48038d4..0000000000000000000000000000000000000000 --- a/config/tmp/vhost10.yaml +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2024 Universidad Carlos III de Madrid -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: veth10 - labels: - app: l2sm -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "bridge", - "bridge": "br10", - "mtu": 1400, - "device": "veth10", - "ipam": { - "type":"static" - } - }' diff --git a/config/tmp/vhost2.yaml b/config/tmp/vhost2.yaml deleted file mode 100644 index 49d690aaf65c0c01e2b8a923b80a0754d9a2333d..0000000000000000000000000000000000000000 --- a/config/tmp/vhost2.yaml +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2024 Universidad Carlos III de Madrid -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: veth2 - labels: - app: l2sm -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "bridge", - "bridge": "br2", - "mtu": 1400, - "device": "veth2", - "ipam": { - "type":"static" - } - }' diff --git a/config/tmp/vhost4.yaml b/config/tmp/vhost4.yaml deleted file mode 100644 index 8738478693fb2a9429be0f5840e08f7ee589ce59..0000000000000000000000000000000000000000 --- a/config/tmp/vhost4.yaml +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2024 Universidad Carlos III de Madrid -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: veth4 - labels: - app: l2sm -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "bridge", - "bridge": "br4", - "mtu": 1400, - "device": "veth4", - "ipam": { - "type":"static" - } - }' diff --git a/config/tmp/vhost5.yaml b/config/tmp/vhost5.yaml deleted file mode 100644 index 44c449efb3520a3ffc668f9eca6dd75dd2332ae3..0000000000000000000000000000000000000000 --- a/config/tmp/vhost5.yaml +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2024 Universidad Carlos III de Madrid -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: veth5 - labels: - app: l2sm -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "bridge", - "bridge": "br5", - "mtu": 1400, - "device": "veth5", - "ipam": { - "type":"static" - } - }' diff --git a/config/tmp/vhost6.yaml b/config/tmp/vhost6.yaml deleted file mode 100644 index 4deed49f2cd1c69b82c10bb196a7531e120cee7f..0000000000000000000000000000000000000000 --- a/config/tmp/vhost6.yaml +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2024 Universidad Carlos III de Madrid -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: veth6 - labels: - app: l2sm -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "bridge", - "bridge": "br6", - "mtu": 1400, - "device": "veth6", - "ipam": { - "type":"static" - } - }' diff --git a/config/tmp/vhost7.yaml b/config/tmp/vhost7.yaml deleted file mode 100644 index b5e2022e5fa06a64b6b668d48490ced53554bdc2..0000000000000000000000000000000000000000 --- a/config/tmp/vhost7.yaml +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2024 Universidad Carlos III de Madrid -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: veth7 - labels: - app: l2sm -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "bridge", - "bridge": "br7", - "mtu": 1400, - "device": "veth7", - "ipam": { - "type":"static" - } - }' diff --git a/config/tmp/vhost8.yaml b/config/tmp/vhost8.yaml deleted file mode 100644 index b05b60f32c13c32b2e1f478d58e9730e8ea58e29..0000000000000000000000000000000000000000 --- a/config/tmp/vhost8.yaml +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2024 Universidad Carlos III de Madrid -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: veth8 - labels: - app: l2sm -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "bridge", - "bridge": "br8", - "mtu": 1400, - "device": "veth8", - "ipam": { - "type":"static" - } - }' diff --git a/config/tmp/vhost9.yaml b/config/tmp/vhost9.yaml deleted file mode 100644 index 6e9f2777d6d93ebcc6ab282e67ae4f9b61f8c962..0000000000000000000000000000000000000000 --- a/config/tmp/vhost9.yaml +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2024 Universidad Carlos III de Madrid -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: veth9 - labels: - app: l2sm -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "bridge", - "bridge": "br9", - "mtu": 1400, - "device": "veth9", - "ipam": { - "type":"static" - } - }' diff --git a/config/webhook/service.yaml b/config/webhook/service.yaml index 4f4940d147a976c8dee2a666d64ab373934a6887..cf5fb83dae5375c9f1d73217a399069e6bec1f3b 100644 --- a/config/webhook/service.yaml +++ b/config/webhook/service.yaml @@ -23,7 +23,6 @@ metadata: app.kubernetes.io/part-of: controllermanager app.kubernetes.io/managed-by: kustomize name: webhook-service - namespace: l2sm-system spec: ports: - port: 443 diff --git a/deployments/l2sm-deployment.yaml b/deployments/l2sm-deployment.yaml index 7832d21820fff601bcf12af403cb1ad4094b388e..3600304b2e7648c0f79cd2bdb0e23b75f8584c54 100644 --- a/deployments/l2sm-deployment.yaml +++ b/deployments/l2sm-deployment.yaml @@ -1,3 +1,17 @@ +# Copyright 2024 Universidad Carlos III de Madrid +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + --- apiVersion: v1 @@ -4766,26 +4780,11 @@ spec: spec: description: OverlaySpec defines the desired state of Overlay properties: - neighbors: - description: Field exclusive to the multi-domain overlay type. If - specified in other types of overlays, the reosurce will launch - an error and won't be created. - items: - properties: - domain: - description: |- - Domain where the neighbor's NED switch can be reached at. Must be a valid IP Address or Domain name, reachable from the node the NED - is going to be deployed at. - type: string - node: - description: Name of the cluster the link is going to be made - upon. - type: string - required: - - domain - - node - type: object - type: array + interfaceNumber: + default: 10 + description: Interface number specifies how many interfaces the switch + should have predefined (if used with multus) + type: integer networkController: description: The SDN Controller that manages the overlay network. Must specify a domain and a name. @@ -9390,6 +9389,18 @@ rules: - patch - update - watch +- apiGroups: + - "" + resources: + - configmaps + verbs: + - create + - delete + - get + - list + - patch + - update + - watch - apiGroups: - "" resources: @@ -9416,6 +9427,30 @@ rules: - get - patch - update +- apiGroups: + - "" + resources: + - services + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - k8s.cni.cncf.io + resources: + - network-attachment-definitions + verbs: + - create + - delete + - get + - list + - patch + - update + - watch - apiGroups: - l2sm.l2sm.k8s.local resources: @@ -9736,9 +9771,7 @@ spec: value: l2sm-controller-service.l2sm-system.svc.cluster.local - name: CONTROLLER_PORT value: "8181" - - name: SWITCHES_NAMESPACE - value: l2sm-system - image: alexdecb/l2sm-controller-manager:2.7.1 + image: alexdecb/l2sm-controller-manager:2.7.2 livenessProbe: httpGet: path: /healthz @@ -9879,113 +9912,3 @@ webhooks: resources: - pods sideEffects: None ---- -apiVersion: k8s.cni.cncf.io/v1 -kind: NetworkAttachmentDefinition -metadata: - labels: - app: l2sm - name: veth1 - namespace: l2sm-system -spec: - config: '{ "cniVersion": "0.3.0", "type": "bridge", "bridge": "br1", "mtu": 1400, - "device": "veth1", "ipam": { "type":"static" } }' ---- -apiVersion: k8s.cni.cncf.io/v1 -kind: NetworkAttachmentDefinition -metadata: - labels: - app: l2sm - name: veth10 - namespace: l2sm-system -spec: - config: '{ "cniVersion": "0.3.0", "type": "bridge", "bridge": "br10", "mtu": 1400, - "device": "veth10", "ipam": { "type":"static" } }' ---- -apiVersion: k8s.cni.cncf.io/v1 -kind: NetworkAttachmentDefinition -metadata: - labels: - app: l2sm - name: veth2 - namespace: l2sm-system -spec: - config: '{ "cniVersion": "0.3.0", "type": "bridge", "bridge": "br2", "mtu": 1400, - "device": "veth2", "ipam": { "type":"static" } }' ---- -apiVersion: k8s.cni.cncf.io/v1 -kind: NetworkAttachmentDefinition -metadata: - labels: - app: l2sm - name: veth3 - namespace: l2sm-system -spec: - config: '{ "cniVersion": "0.3.0", "type": "bridge", "bridge": "br3", "mtu": 1400, - "device": "veth3", "ipam": { "type":"static" } }' ---- -apiVersion: k8s.cni.cncf.io/v1 -kind: NetworkAttachmentDefinition -metadata: - labels: - app: l2sm - name: veth4 - namespace: l2sm-system -spec: - config: '{ "cniVersion": "0.3.0", "type": "bridge", "bridge": "br4", "mtu": 1400, - "device": "veth4", "ipam": { "type":"static" } }' ---- -apiVersion: k8s.cni.cncf.io/v1 -kind: NetworkAttachmentDefinition -metadata: - labels: - app: l2sm - name: veth5 - namespace: l2sm-system -spec: - config: '{ "cniVersion": "0.3.0", "type": "bridge", "bridge": "br5", "mtu": 1400, - "device": "veth5", "ipam": { "type":"static" } }' ---- -apiVersion: k8s.cni.cncf.io/v1 -kind: NetworkAttachmentDefinition -metadata: - labels: - app: l2sm - name: veth6 - namespace: l2sm-system -spec: - config: '{ "cniVersion": "0.3.0", "type": "bridge", "bridge": "br6", "mtu": 1400, - "device": "veth6", "ipam": { "type":"static" } }' ---- -apiVersion: k8s.cni.cncf.io/v1 -kind: NetworkAttachmentDefinition -metadata: - labels: - app: l2sm - name: veth7 - namespace: l2sm-system -spec: - config: '{ "cniVersion": "0.3.0", "type": "bridge", "bridge": "br7", "mtu": 1400, - "device": "veth7", "ipam": { "type":"static" } }' ---- -apiVersion: k8s.cni.cncf.io/v1 -kind: NetworkAttachmentDefinition -metadata: - labels: - app: l2sm - name: veth8 - namespace: l2sm-system -spec: - config: '{ "cniVersion": "0.3.0", "type": "bridge", "bridge": "br8", "mtu": 1400, - "device": "veth8", "ipam": { "type":"static" } }' ---- -apiVersion: k8s.cni.cncf.io/v1 -kind: NetworkAttachmentDefinition -metadata: - labels: - app: l2sm - name: veth9 - namespace: l2sm-system -spec: - config: '{ "cniVersion": "0.3.0", "type": "bridge", "bridge": "br9", "mtu": 1400, - "device": "veth9", "ipam": { "type":"static" } }' diff --git a/examples/overlay-setup/overlay-sample.yaml b/examples/overlay-setup/overlay-sample.yaml index 75e6a72a22ec68858e997214b54090b085236728..13b2fdeb5f52b30c69be2471f41b277ee2c3beb9 100644 --- a/examples/overlay-setup/overlay-sample.yaml +++ b/examples/overlay-setup/overlay-sample.yaml @@ -17,33 +17,32 @@ kind: Overlay metadata: name: overlay-sample spec: + networkController: + name: l2sm-test-sdn + domain: "l2sm-controller-service.l2sm-system.svc" topology: nodes: - - l2sm1 - - l2sm2 + - l2sm-test-control-plane + - l2sm-test-worker + - l2sm-test-worker2 links: - - endpointA: l2sm1 - endpointB: l2sm2 + - endpointA: l2sm-test-worker + endpointB: l2sm-test-worker2 + - endpointA: l2sm-test-worker + endpointB: l2sm-test-control-plane + - endpointA: l2sm-test-control-plane + endpointB: l2sm-test-worker2 switchTemplate: spec: containers: - name: l2sm-switch - image: alexdecb/l2sm-switch:2.7 + image: alexdecb/l2sm-switch:1.0.2 resources: {} env: - name: NODENAME valueFrom: fieldRef: fieldPath: spec.nodeName - - name: NVETHS - value: "10" - - name: CONTROLLERIP - value: "l2sm-controller-service" - - name: PODNAME - valueFrom: - fieldRef: - fieldPath: metadata.name - imagePullPolicy: Always securityContext: capabilities: add: ["NET_ADMIN"] diff --git a/config/tmp/vhost3.yaml b/examples/quickstart/kind-cluster.yaml similarity index 55% rename from config/tmp/vhost3.yaml rename to examples/quickstart/kind-cluster.yaml index 32231b49fd7f0daf55ba8e56a8910f6d28f2a7ab..45890bcd5f55d70c3feda712024d2fe668838179 100644 --- a/config/tmp/vhost3.yaml +++ b/examples/quickstart/kind-cluster.yaml @@ -12,21 +12,21 @@ # See the License for the specific language governing permissions and # limitations under the License. +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +name: l2sm-test +networking: + disableDefaultCNI: true # Disable Kindnet, we will use Flannel as the primary CNI plugin + podSubnet: "10.244.0.0/16" # Flannel requires this CIDR +nodes: +- role: control-plane + image: kindest/node:v1.26.6 + extraPortMappings: + - containerPort: 30000 + hostPort: 30000 + protocol: TCP +- role: worker + image: kindest/node:v1.26.6 +- role: worker + image: kindest/node:v1.26.6 -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: veth3 - labels: - app: l2sm -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "bridge", - "bridge": "br3", - "mtu": 1400, - "device": "veth3", - "ipam": { - "type":"static" - } - }' diff --git a/go.mod b/go.mod index f2b49960b6d990030acd7671fcf8b8ac0616c0da..25ca1e4feba9bc12f19662405aafa73290b9f95a 100644 --- a/go.mod +++ b/go.mod @@ -5,19 +5,33 @@ go 1.21.7 toolchain go1.22.5 require ( + github.com/Networks-it-uc3m/l2sm-switch v1.0.2 github.com/go-logr/logr v1.4.1 github.com/onsi/ginkgo/v2 v2.14.0 github.com/onsi/gomega v1.30.0 + github.com/stretchr/testify v1.9.0 google.golang.org/grpc v1.67.0 k8s.io/api v0.29.0 k8s.io/apimachinery v0.29.0 k8s.io/client-go v0.29.0 - github.com/Networks-it-uc3m/l2sm-switch v1.0.0 sigs.k8s.io/controller-runtime v0.17.0 ) -require google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect +require ( + github.com/BurntSushi/toml v1.2.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/exp/typeparams v0.0.0-20221212164502-fae10dda9338 // indirect + golang.org/x/mod v0.20.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/telemetry v0.0.0-20240829154258-f29ab539cc98 // indirect + golang.org/x/tools/gopls v0.16.2 // indirect + golang.org/x/vuln v1.0.4 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect + honnef.co/go/tools v0.4.7 // indirect + mvdan.cc/gofumpt v0.6.0 // indirect + mvdan.cc/xurls/v2 v2.5.0 // indirect +) // replace github.com/Networks-it-uc3m/l2sm-switch => ../switch @@ -65,7 +79,7 @@ require ( golang.org/x/term v0.23.0 // indirect golang.org/x/text v0.17.0 // indirect golang.org/x/time v0.3.0 // indirect - golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect + golang.org/x/tools v0.22.1-0.20240829175637-39126e24d653 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/inf.v0 v0.9.1 // indirect diff --git a/go.sum b/go.sum index 3032b5cc403587524030d7eef7cce4d6b7015246..85b36e58ab800a549844233091c93b9fa0ff26ba 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ -github.com/Networks-it-uc3m/l2sm-switch v1.0.0 h1:SQ2hFmObffhNV2jVSeSpqVGCm2/d6HZuQ02YzeCI+x0= -github.com/Networks-it-uc3m/l2sm-switch v1.0.0/go.mod h1:zcfUyOLAiCEQza5QRTJoQsrOYdu+WQf/6rQNmhGb4WQ= +github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= +github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/Networks-it-uc3m/l2sm-switch v1.0.2 h1:P4gVqfcO6LgKVxWI4aDfQnbYnRi+8+nc5+K1wq9sIEU= +github.com/Networks-it-uc3m/l2sm-switch v1.0.2/go.mod h1:zcfUyOLAiCEQza5QRTJoQsrOYdu+WQf/6rQNmhGb4WQ= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -124,8 +126,12 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA= golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA= +golang.org/x/exp/typeparams v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y= +golang.org/x/exp/typeparams v0.0.0-20221212164502-fae10dda9338/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= +golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -137,12 +143,16 @@ golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbht golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/telemetry v0.0.0-20240829154258-f29ab539cc98 h1:Wm3cG5X6sZ0RSVRc/H1/sciC4AT6HAKgLCSH2lbpR/c= +golang.org/x/telemetry v0.0.0-20240829154258-f29ab539cc98/go.mod h1:m7R/r+o5h7UvF2JD9n2iLSGY4v8v+zNSyTJ6xynLrqs= golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -157,6 +167,12 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= +golang.org/x/tools v0.22.1-0.20240829175637-39126e24d653 h1:6bJEg2w2kUHWlfdJaESYsmNfI1LKAZQi6zCa7LUn7eI= +golang.org/x/tools v0.22.1-0.20240829175637-39126e24d653/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= +golang.org/x/tools/gopls v0.16.2 h1:K1z03MlikHfaMTtG01cUeL5FAOTJnITuNe0TWOcg8tM= +golang.org/x/tools/gopls v0.16.2/go.mod h1:Hj8YxzfHfFyRK5muTZy5oO6/0nL7CZWu28ZNac7tXF0= +golang.org/x/vuln v1.0.4 h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I= +golang.org/x/vuln v1.0.4/go.mod h1:NbJdUQhX8jY++FtuhrXs2Eyx0yePo9pF7nPlIjo9aaQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -182,6 +198,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs= +honnef.co/go/tools v0.4.7/go.mod h1:+rnGS1THNh8zMwnd2oVOTL9QF6vmfyG6ZXBULae2uc0= k8s.io/api v0.29.0 h1:NiCdQMY1QOp1H8lfRyeEf8eOwV6+0xA6XEE44ohDX2A= k8s.io/api v0.29.0/go.mod h1:sdVmXoz2Bo/cb77Pxi71IPTSErEW32xa4aXwKH7gfBA= k8s.io/apiextensions-apiserver v0.29.0 h1:0VuspFG7Hj+SxyF/Z/2T0uFbI5gb5LRgEyUVE3Q4lV0= @@ -198,6 +216,10 @@ k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/A k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA= k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI= k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +mvdan.cc/gofumpt v0.6.0 h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo= +mvdan.cc/gofumpt v0.6.0/go.mod h1:4L0wf+kgIPZtcCWXynNS2e6bhmj73umwnuXSZarixzA= +mvdan.cc/xurls/v2 v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8= +mvdan.cc/xurls/v2 v2.5.0/go.mod h1:yQgaGQ1rFtJUzkmKiHYSSfuQxqfYmd//X6PxvholpeE= sigs.k8s.io/controller-runtime v0.17.0 h1:fjJQf8Ukya+VjogLO6/bNX9HE6Y2xpsO5+fyS26ur/s= sigs.k8s.io/controller-runtime v0.17.0/go.mod h1:+MngTvIQQQhfXtwfdGw/UOQ/aIaqsYywfCINOtwMO/s= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= diff --git a/hack/install_dependencies.sh b/hack/install_dependencies.sh new file mode 100755 index 0000000000000000000000000000000000000000..dd733ea3f2e06c5a764f81f1f613113b33bd1d9f --- /dev/null +++ b/hack/install_dependencies.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +git clone https://github.com/containernetworking/plugins.git +sed -i "s/go 1.23/go 1.23.0/g" ./plugins/go.mod # to avoid error after recent update +./plugins/build_linux.sh + +# copy necessary plugins into all nodes +docker cp ./plugins/bin/. l2sm-test-control-plane:/opt/cni/bin +docker cp ./plugins/bin/. l2sm-test-worker:/opt/cni/bin +docker cp ./plugins/bin/. l2sm-test-worker2:/opt/cni/bin +docker exec -it l2sm-test-control-plane modprobe br_netfilter +docker exec -it l2sm-test-worker modprobe br_netfilter +docker exec -it l2sm-test-worker2 modprobe br_netfilter + +docker exec -it l2sm-test-control-plane sysctl -p /etc/sysctl.conf +docker exec -it l2sm-test-worker sysctl -p /etc/sysctl.conf +docker exec -it l2sm-test-worker2 sysctl -p /etc/sysctl.conf + + +kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml +kubectl wait --for=condition=Ready pods -n kube-flannel -l app=flannel --timeout=300s + +kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.16.1/cert-manager.yaml +kubectl apply -f https://raw.githubusercontent.com/k8snetworkplumbingwg/multus-cni/master/deployments/multus-daemonset-thick.yml +kubectl wait --for=condition=Ready pods --all -A --timeout=300s diff --git a/internal/controller/networkedgedevice_controller.go b/internal/controller/networkedgedevice_controller.go index ab2aaf2596978e7b49900d7277357411e675f8f1..a6023439e1fa125ffae5c163c2652da900d11b5b 100644 --- a/internal/controller/networkedgedevice_controller.go +++ b/internal/controller/networkedgedevice_controller.go @@ -22,6 +22,7 @@ import ( l2smv1 "github.com/Networks-it-uc3m/L2S-M/api/v1" "github.com/Networks-it-uc3m/L2S-M/internal/utils" + switchv1 "github.com/Networks-it-uc3m/l2sm-switch/api/v1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -30,8 +31,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/log" - - nedv1 "github.com/Networks-it-uc3m/l2sm-switch/api/v1" ) // NetworkEdgeDeviceReconciler reconciles a NetworkEdgeDevice object @@ -168,13 +167,13 @@ func (r *NetworkEdgeDeviceReconciler) createExternalResources(ctx context.Contex for i, neighbor := range netEdgeDevice.Spec.Neighbors { neighbors[i] = neighbor.Domain } - nedNeighbors, err := json.Marshal(nedv1.Node{Name: netEdgeDevice.Spec.NodeConfig.NodeName, NodeIP: netEdgeDevice.Spec.NodeConfig.IPAddress, NeighborNodes: neighbors}) + nedNeighbors, err := json.Marshal(switchv1.Node{Name: netEdgeDevice.Spec.NodeConfig.NodeName, NodeIP: netEdgeDevice.Spec.NodeConfig.IPAddress, NeighborNodes: neighbors}) if err != nil { return err } nedName := utils.GetBridgeName(utils.BridgeParams{NodeName: netEdgeDevice.Spec.NodeConfig.NodeName, ProviderName: netEdgeDevice.Spec.NetworkController.Name}) - nedConfig, err := json.Marshal(nedv1.NedSettings{ControllerIP: netEdgeDevice.Spec.NetworkController.Domain, NodeName: netEdgeDevice.Spec.NodeConfig.NodeName, NedName: nedName}) + nedConfig, err := json.Marshal(switchv1.NedSettings{ControllerIP: netEdgeDevice.Spec.NetworkController.Domain, NodeName: netEdgeDevice.Spec.NodeConfig.NodeName, NedName: nedName}) if err != nil { return err } diff --git a/internal/controller/overlay_controller.go b/internal/controller/overlay_controller.go index 8ff853f12044a5dd9ad271be4b1a924172108258..638e01539b01f68c53a4afdac2bafe0552df89fe 100644 --- a/internal/controller/overlay_controller.go +++ b/internal/controller/overlay_controller.go @@ -22,6 +22,7 @@ import ( l2smv1 "github.com/Networks-it-uc3m/L2S-M/api/v1" "github.com/Networks-it-uc3m/L2S-M/internal/utils" + nettypes "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -30,6 +31,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/log" + + switchv1 "github.com/Networks-it-uc3m/l2sm-switch/api/v1" ) // OverlayReconciler reconciles a Overlay object @@ -40,11 +43,13 @@ type OverlayReconciler struct { var replicaSetOwnerKeyOverlay = ".metadata.controller.overlay" -// +kubebuilder:rbac:groups=l2sm.l2sm.k8s.local,resources=replicasets,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=apps,resources=replicasets,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=l2sm.l2sm.k8s.local,resources=overlays,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=l2sm.l2sm.k8s.local,resources=overlays/status,verbs=get;update;patch //+kubebuilder:rbac:groups=l2sm.l2sm.k8s.local,resources=overlays/finalizers,verbs=update +// +kubebuilder:rbac:groups=k8s.cni.cncf.io,resources=network-attachment-definitions,verbs=get;list;watch;create;update;patch;delete // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. @@ -87,11 +92,11 @@ func (r *OverlayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct // The object is being deleted if controllerutil.ContainsFinalizer(overlay, l2smFinalizer) { // our finalizer is present, so lets handle any external dependency - // if err := r.deleteExternalResources(ctx, overlay); err != nil { - // // if fail to delete the external dependency here, return with error - // // so that it can be retried. - // return ctrl.Result{}, err - // } + if err := r.deleteExternalResources(ctx, overlay); err != nil { + // if fail to delete the external dependency here, return with error + // so that it can be retried. + return ctrl.Result{}, err + } // remove our finalizer from the list and update it. controllerutil.RemoveFinalizer(overlay, l2smFinalizer) @@ -153,10 +158,18 @@ func (r *OverlayReconciler) SetupWithManager(mgr ctrl.Manager) error { Complete(r) } -// func (r *OverlayReconciler) deleteExternalResources(ctx context.Context, overlay *l2smv1.Overlay) error { +func (r *OverlayReconciler) deleteExternalResources(ctx context.Context, overlay *l2smv1.Overlay) error { + opts := []client.DeleteAllOfOption{ + client.InNamespace(overlay.Namespace), + client.MatchingLabels{"overlay": overlay.Name}, + } + r.Client.DeleteAllOf(ctx, &nettypes.NetworkAttachmentDefinition{}, opts...) + return nil +} -// return nil -// } +type OverlayConfigJson struct { + ControllerIp string `json:"ControllerIp"` +} type TopologySwitchJson struct { Nodes []NodeJson `json:"Nodes"` @@ -174,21 +187,31 @@ func (r *OverlayReconciler) createExternalResources(ctx context.Context, overlay constructConfigMapForOverlay := func(overlay *l2smv1.Overlay) (*corev1.ConfigMap, error) { // Construct the TopologySwitchJson - topologySwitch := TopologySwitchJson{} + topologySwitch := switchv1.Topology{} + + overlayConfig := switchv1.OverlaySettings{ControllerIp: overlay.Spec.NetworkController.Domain, + InterfacesNumber: overlay.Spec.InterfaceNumber, + OverlayName: overlay.Name} overlayName := overlay.ObjectMeta.Name // Populate Nodes for _, nodeName := range overlay.Spec.Topology.Nodes { - node := NodeJson{ + node := switchv1.Node{ Name: nodeName, - NodeIP: fmt.Sprintf("l2sm-switch-%s-%s", overlayName, nodeName), + NodeIP: utils.GenerateServiceName(overlayName, nodeName), } topologySwitch.Nodes = append(topologySwitch.Nodes, node) } // Populate Links - topologySwitch.Links = append(topologySwitch.Links, overlay.Spec.Topology.Links...) + for _, overlayLink := range overlay.Spec.Topology.Links { + link := switchv1.Link{ + EndpointNodeA: overlayLink.EndpointA, + EndpointNodeB: overlayLink.EndpointB, + } + topologySwitch.Links = append(topologySwitch.Links, link) + } // Convert TopologySwitchJson to JSON topologyJSON, err := json.Marshal(topologySwitch) @@ -196,6 +219,10 @@ func (r *OverlayReconciler) createExternalResources(ctx context.Context, overlay return nil, err } + configJSON, err := json.Marshal(overlayConfig) + if err != nil { + return nil, err + } configMap := &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("%s-topology", overlay.Name), @@ -203,6 +230,7 @@ func (r *OverlayReconciler) createExternalResources(ctx context.Context, overlay }, Data: map[string]string{ "topology.json": string(topologyJSON), + "config.json": string(configJSON), }, } if err := controllerutil.SetControllerReference(overlay, configMap, r.Scheme); err != nil { @@ -218,12 +246,12 @@ func (r *OverlayReconciler) createExternalResources(ctx context.Context, overlay return err } - constructNodeResourcesForOverlay := func(overlay *l2smv1.Overlay) ([]*appsv1.ReplicaSet, []*corev1.Service, error) { + constructNodeResourcesForOverlay := func(overlay *l2smv1.Overlay) ([]*appsv1.ReplicaSet, []*corev1.Service, []*nettypes.NetworkAttachmentDefinition, error) { // Define volume mounts to be added to each container volumeMounts := []corev1.VolumeMount{ { - Name: "topology", + Name: "config", MountPath: "/etc/l2sm/", ReadOnly: true, }, @@ -239,7 +267,7 @@ func (r *OverlayReconciler) createExternalResources(ctx context.Context, overlay // Define the volume using the created ConfigMap volumes := []corev1.Volume{ { - Name: "topology", + Name: "config", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ LocalObjectReference: corev1.LocalObjectReference{ @@ -250,15 +278,46 @@ func (r *OverlayReconciler) createExternalResources(ctx context.Context, overlay Key: "topology.json", Path: "topology.json", }, + { + Key: "config.json", + Path: "config.json", + }, }, }, }, }, } + switchInterfacesAnnotations := GenerateAnnotations(overlay.Name, overlay.Spec.InterfaceNumber) + + var networkAttachmentDefinitions []*nettypes.NetworkAttachmentDefinition + var auxNetAttachDef *nettypes.NetworkAttachmentDefinition + + for i := 1; i <= overlay.Spec.InterfaceNumber; i++ { + auxNetAttachDef = &nettypes.NetworkAttachmentDefinition{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("%s-veth%d", overlay.Name, i), + Namespace: overlay.Namespace, + Labels: map[string]string{"app": "l2sm", "overlay": overlay.Name}, + }, + Spec: nettypes.NetworkAttachmentDefinitionSpec{ + Config: fmt.Sprintf(`{ + "cniVersion": "0.3.0", + "type": "bridge", + "bridge": "%s-br%d", + "mtu": 1400, + "device": "%s-veth%d", + "ipam": { + "type":"static" + } + }`, "", i, overlay.Name, i), + }, + } + networkAttachmentDefinitions = append(networkAttachmentDefinitions, auxNetAttachDef) + } + var replicaSets []*appsv1.ReplicaSet var services []*corev1.Service - for _, node := range overlay.Spec.Topology.Nodes { name := fmt.Sprintf("%s-%s-%s", "l2sm-switch", node, utils.GenerateHash(overlay)) @@ -283,27 +342,7 @@ func (r *OverlayReconciler) createExternalResources(ctx context.Context, overlay "app": name, }, Annotations: map[string]string{ - "k8s.v1.cni.cncf.io/networks": `[{ - "name": "veth1", "ips": ["fe80::58d0:b8ff:fe42:debf/64"] - }, { - "name": "veth2", "ips": ["fe80::58d0:b8ff:fe42:debe/64"] - }, { - "name": "veth3", "ips": ["fe80::58d0:b8ff:fe42:debd/64"] - }, { - "name": "veth4", "ips": ["fe80::58d0:b8ff:fe42:debc/64"] - }, { - "name": "veth5", "ips": ["fe80::58d0:b8ff:fe42:debb/64"] - }, { - "name": "veth6", "ips": ["fe80::58d0:b8ff:fe42:deba/64"] - }, { - "name": "veth7", "ips": ["fe80::58d0:b8ff:fe42:deb9/64"] - }, { - "name": "veth8", "ips": ["fe80::58d0:b8ff:fe42:deb8/64"] - }, { - "name": "veth9", "ips": ["fe80::58d0:b8ff:fe42:deb7/64"] - }, { - "name": "veth10", "ips": ["fe80::58d0:b8ff:fe42:deb6/64"] - }]`, + MULTUS_ANNOTATION_KEY: switchInterfacesAnnotations, }, }, Spec: corev1.PodSpec{ @@ -324,7 +363,7 @@ func (r *OverlayReconciler) createExternalResources(ctx context.Context, overlay replicaSet.Labels[k] = v } if err := controllerutil.SetControllerReference(overlay, replicaSet, r.Scheme); err != nil { - return nil, nil, err + return nil, nil, nil, err } replicaSets = append(replicaSets, replicaSet) @@ -332,7 +371,7 @@ func (r *OverlayReconciler) createExternalResources(ctx context.Context, overlay // Create a headless service for the ReplicaSet service := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("l2sm-switch-%s-%s", overlay.Name, node), + Name: utils.GenerateServiceName(overlay.Name, node), Namespace: overlay.Namespace, Labels: map[string]string{"app": name}, }, @@ -349,20 +388,24 @@ func (r *OverlayReconciler) createExternalResources(ctx context.Context, overlay } if err := controllerutil.SetControllerReference(overlay, service, r.Scheme); err != nil { - return nil, nil, err + return nil, nil, nil, err } services = append(services, service) } - return replicaSets, services, nil + return replicaSets, services, networkAttachmentDefinitions, nil } - replicaSets, services, err := constructNodeResourcesForOverlay(overlay) + replicaSets, services, netAttachDefs, err := constructNodeResourcesForOverlay(overlay) if err != nil { return err } - + for _, netAttachDef := range netAttachDefs { + if err = r.Client.Create(ctx, netAttachDef); err != nil { + return err + } + } for _, replicaSet := range replicaSets { if err = r.Client.Create(ctx, replicaSet); err != nil { return err diff --git a/internal/controller/pod_controller.go b/internal/controller/pod_controller.go index 93ef743d9d544f10bc09a9ba54630dd3ae5ff071..d9661c9f8500d5f9e0c04d65d4cbadd670669351 100644 --- a/internal/controller/pod_controller.go +++ b/internal/controller/pod_controller.go @@ -150,9 +150,14 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R // Add the pod interfaces to the sdn controller multusAnnotations, ok := pod.Annotations[MULTUS_ANNOTATION_KEY] + // if ok { + + // logger.Info(multusAnnotations) + // return ctrl.Result{Requeue: true}, fmt.Errorf("back") + // } if !ok { - logger.Error(nil, "Error detaching the pod from the network attachment definitions") + logger.Error(nil, "Error getting the pod network attachment definitions annotations") return ctrl.Result{}, nil } diff --git a/internal/controller/pod_utils.go b/internal/controller/pod_utils.go index 3b0d20f13009353dbb0c1aca2db3422ef25d0204..cd3f13d1a07b3f651a18f30d71b1cf2f7eb87016 100644 --- a/internal/controller/pod_utils.go +++ b/internal/controller/pod_utils.go @@ -154,3 +154,26 @@ func (r *PodReconciler) DetachNetAttachDef(ctx context.Context, multusNetAttachD return err } + +func GenerateAnnotations(overlayName string, ammount int) string { + annotationsString := []string{} + var newAnnotation string + for i := 1; i <= ammount; i++ { + newAnnotation = fmt.Sprintf(`{"name": "%s-veth%d", "ips": ["fe80::58d0:b8ff:fe%s:%s/64"]}`, overlayName, i, fmt.Sprintf("%02d", i), Generate4byteChunk()) + annotationsString = append(annotationsString, newAnnotation) + } + + return "[" + strings.Join(annotationsString, ",") + "]" +} + +func Generate4byteChunk() string { + + // Generating the interface ID (64 bits) + interfaceID := rand.Uint64() & 0xffff + + // Formatting to a 4 character hexadecimal string + interfaceIDHex := fmt.Sprintf("%04x", interfaceID) + + return interfaceIDHex + +} diff --git a/internal/controller/pod_utils_test.go b/internal/controller/pod_utils_test.go new file mode 100644 index 0000000000000000000000000000000000000000..82251f65be4e333ccf764154153a8c60ab89b498 --- /dev/null +++ b/internal/controller/pod_utils_test.go @@ -0,0 +1,37 @@ +// Copyright 2024 Universidad Carlos III de Madrid +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// generate_test.go +package controller + +import ( + "regexp" + "testing" +) + +// TestGenerate4byteChunk verifies that Generate4byteChunk produces a 4-character hexadecimal string. +func TestGenerate4byteChunk(t *testing.T) { + // Regular expression to match exactly 4 hexadecimal characters + re := regexp.MustCompile(`^[0-9a-fA-F]{4}$`) + + // Call Generate4byteChunk multiple times to check if output is always 4 characters + for i := 0; i < 100; i++ { + output := Generate4byteChunk() + + // Check if the output matches the 4-character hex pattern + if !re.MatchString(output) { + t.Errorf("Expected a 4-character hexadecimal string, but got: %s", output) + } + } +} diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 943540c09003422123f3df4b119a79e06aa9e4f9..99a4e710513b25bf42681d56aa5f84768771235b 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -20,6 +20,7 @@ import ( "crypto/sha256" "encoding/hex" "fmt" + "hash/fnv" "strings" "k8s.io/apimachinery/pkg/runtime" @@ -133,3 +134,11 @@ func GetBridgeName(params BridgeParams) string { dpid := hex.EncodeToString(dpidBytes) return fmt.Sprintf("br-%s", dpid) } + +func GenerateServiceName(overlayName, nodeName string) string { + hash := fnv.New32() // Using FNV hash for a compact hash, but still 32 bits + hash.Write([]byte(fmt.Sprintf("%s%s", overlayName, nodeName))) + sum := hash.Sum32() + // Encode the hash as a base32 string and take the first 4 characters + return fmt.Sprintf("l2sm-switch-%04x", sum) // H +}