diff --git a/src/kubernetes-api/Makefile b/src/kubernetes-api/Makefile index 1b1fd623b9524bf42e872c25e57ed9a41a754330..0dc8eec14449ce877d4de37d8b1cc09bc140427d 100644 --- a/src/kubernetes-api/Makefile +++ b/src/kubernetes-api/Makefile @@ -120,9 +120,7 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform .PHONY: build-installer build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment. mkdir -p dist - @if [ -d "config/crd" ]; then \ - $(KUSTOMIZE) build config/crd > dist/install.yaml; \ - fi + echo "" > dist/install.yaml echo "---" >> dist/install.yaml # Add a document separator before appending cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} $(KUSTOMIZE) build config/default >> dist/install.yaml diff --git a/src/kubernetes-api/config/default/webhookcainjection_patch.yaml b/src/kubernetes-api/config/default/webhookcainjection_patch.yaml index 0f81bee13c28119be5d57a1db6efc2b02a00166f..430e24a352c8c8d72a5ea3d053ee80d516533633 100644 --- a/src/kubernetes-api/config/default/webhookcainjection_patch.yaml +++ b/src/kubernetes-api/config/default/webhookcainjection_patch.yaml @@ -28,4 +28,7 @@ webhooks: resources: ["pods"] failurePolicy: Ignore sideEffects: None - admissionReviewVersions: ["v1"] \ No newline at end of file + admissionReviewVersions: ["v1"] + objectSelector: + matchLabels: + l2sm: "true" \ No newline at end of file diff --git a/src/kubernetes-api/config/dev/kustomization.yaml b/src/kubernetes-api/config/dev/kustomization.yaml index 85ed9757dd655193d4f6fd119a34543bb84c4c71..4161faf673b3b5e3bf54ca45805e9f6fe3b317fc 100644 --- a/src/kubernetes-api/config/dev/kustomization.yaml +++ b/src/kubernetes-api/config/dev/kustomization.yaml @@ -1,4 +1,12 @@ +# # Adds namespace to all resources. +# namespace: l2sm-system +# # Value of this field is prepended to the +# # names of all resources, e.g. a deployment named +# # "wordpress" becomes "alices-wordpress". +# # Note that it should also match with the prefix (text before '-') of the namespace +# # field above. +# namePrefix: l2sm- resources: # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in diff --git a/src/kubernetes-api/config/manager/manager.yaml b/src/kubernetes-api/config/manager/manager.yaml index b7d1c837ad60fe1561c9afec7923decaa7763b34..c8103e3bb1eac54d3c197c636a2bdd80cdadd420 100644 --- a/src/kubernetes-api/config/manager/manager.yaml +++ b/src/kubernetes-api/config/manager/manager.yaml @@ -72,7 +72,11 @@ spec: - --leader-elect env: - name: CONTROLLER_IP - value: l2sm-controller-service.default.svc.cluster.local + value: l2sm-controller-service.l2sm-system.svc.cluster.local + - name: CONTROLLER_PORT + value: "8181" + - name: SWITCHES_NAMESPACE + value: "he-codeco-netma" image: controller:latest name: manager securityContext: diff --git a/src/operator/l2sm-operator.py b/src/operator/l2sm-operator.py index fd56a905e879e104f8e5432a7dc740e7d7a2373b..30e0030f6a2a53a898c6f39c997dcde85d062f5a 100644 --- a/src/operator/l2sm-operator.py +++ b/src/operator/l2sm-operator.py @@ -185,6 +185,11 @@ def pod_vn(body, name, namespace, logger, annotations, **kwargs): #time.sleep(random.uniform(0,0.8)) # Avoid database overlap by introducing a random sleep time l2networks = extract_l2networks(annotations) + logger.info("These l2networks extracted") + logger.info(l2networks) + + + if not l2networks: logger.info("No Multus networks specified. Exiting.") return @@ -199,6 +204,9 @@ def pod_vn(body, name, namespace, logger, annotations, **kwargs): # Update `target_networks` to include IP information if available target_networks = [net for net in l2networks if net['name'] in target_networks_info] + logger.info("These are the target networks") + logger.info(target_networks) + api = CustomObjectsApi() # Assign pods to each of the target networks, this part remains unchanged for network in target_networks: @@ -207,9 +215,13 @@ def pod_vn(body, name, namespace, logger, annotations, **kwargs): if 'spec' in body and 'nodeName' in body['spec']: node_name = body['spec']['nodeName'] # free_interfaces = get_free_interfaces(node_name) + v1 = client.CoreV1Api() + pod = v1.read_namespaced_pod(name, namespace) multus_annotations = pod.metadata.annotations if pod.metadata.annotations else {} free_interfaces = extract_multus_networks(multus_annotations) + logger.info("These are the target used interfaces") + logger.info(free_interfaces) if len(free_interfaces) != len(target_networks): raise kopf.PermanentError(f"Node {node_name} has no free interfaces left") @@ -357,12 +369,14 @@ def update_network_assignments(pod_name, namespace, node_name, free_interfaces, assigned_interfaces = [] with connection.cursor() as cursor: for i, interface in enumerate(free_interfaces[:len(target_networks)]): + logger.info("interface: ") + logger.info(interface) if openflow_id: port_number = extract_port_number(interface['name']) - post_network_assignment(openflow_id, port_number, target_networks[i]['name']) - - # update_pod_annotation(pod_name, namespace, assigned_interfaces) + logger.info("port number: ") + logger.info(port_number) + post_network_assignment(openflow_id, port_number, target_networks[i]['name']) connection.commit() finally: connection.close() @@ -491,21 +505,3 @@ def remove_node(body, logger, annotations, **kwargs): connection.close() logger.info(f"Node {body['spec']['nodeName']} has been deleted from the cluster") - -def generate_random_ipv6_fe80(): - # IPv6 FE80::/64 starts with '1111 1110 10' and 54 bits of 0s - # So we can fix the first 10 bits as '1111 1110 10' - # Then we generate the last 64 bits randomly for the interface ID - # Since IPv6 addresses are represented in hexadecimal, we convert the binary values to hexadecimal - - - # Generating the interface ID (64 bits) - interface_id = random.getrandbits(64) - # Formatting to a 16 character hexadecimal string - interface_id_hex = format(interface_id, '016x') - - # Constructing the full IPv6 address in the fe80::/64 range - ipv6_address = f"fe80::{interface_id_hex[:4]}:{interface_id_hex[4:8]}:{interface_id_hex[8:12]}:{interface_id_hex[12:]}/64" - - return ipv6_address -