diff --git a/old_versions/cli/delete/kubectl_delete.py b/old_versions/cli/delete/kubectl_delete.py deleted file mode 100644 index a8afd9b47174c944297dd9da556b6c6c429b5485..0000000000000000000000000000000000000000 --- a/old_versions/cli/delete/kubectl_delete.py +++ /dev/null @@ -1,77 +0,0 @@ -import subprocess -from subprocess import CalledProcessError -import sys -import json -import os -from kubernetes import client, config - -import pymysql - -#CONNECT TO THE DATABASE -db = pymysql.connect(host="localhost",user="l2sm",password="l2sm;",db="L2SM") - -cur = db.cursor() - -def main(argv): - - #CHECK IF KUBECONFIG IS PRESENT - if len(sys.argv) > 2: - pod = argv[1] - kubeConfig = argv[2] - - else: - pod = argv[1] - kubeConfig = '' - - try: - delete_pod(pod, kubeConfig) - except CalledProcessError: - db.close() - except Exception as e: - print(e) - - -def delete_pod(pod, kubeConfig): - - #QUERY TO SEARCH FOR THEN POD TO BE DELETED - sql = "SELECT pod FROM interfaces WHERE pod = '%s'" % (pod) - cur.execute(sql) - data = cur.fetchone() - - if not data: - raise NameError("l2sm could not remove the pod: Pod " + pod.strip() + " does not exist") - - else: - if kubeConfig == '': - #USE K8S API TO RETRIEVE THE NODE WHERE THE POD HAS BEEN DEPLOYED - config.load_kube_config() - v1 = client.CoreV1Api() - ret = v1.list_pod_for_all_namespaces(watch=False) - for i in ret.items: - if i.metadata.name == pod: - node = i.spec.node_name - - subprocess.run(["kubectl", "delete", "pods/" + pod], stdout=subprocess.DEVNULL).check_returncode() - - else: - config.load_kube_config(kubeConfig) - v1 = client.CoreV1Api() - ret = v1.list_pod_for_all_namespaces(watch=False) - for i in ret.items: - if i.metadata.name == pod: - node = i.spec.node_name - - #DELETE THE POD USING THE KUBECTL TOOL - subprocess.run(["kubectl", "--kubeconfig", kubeConfig, "delete", "pods/" + pod], stdout=subprocess.DEVNULL).check_returncode() - - #UPDATE THE DATABASE TO REMOVE THE POD - dsql = "UPDATE interfaces SET network = '-1', pod = '' WHERE pod = '%s'" % (pod) - cur.execute(dsql) - db.commit() - print("Pod " + pod.strip() + " has been deleted") - - -if __name__== "__main__": - main(sys.argv) - db.close() - diff --git a/old_versions/cli/deploy/kubectl_create.py b/old_versions/cli/deploy/kubectl_create.py deleted file mode 100644 index 0f719aaf6777537951708d3b51ee364686555953..0000000000000000000000000000000000000000 --- a/old_versions/cli/deploy/kubectl_create.py +++ /dev/null @@ -1,196 +0,0 @@ -import subprocess -from subprocess import CalledProcessError -import sys -import json -import os - -import pymysql - -db = pymysql.connect(host="localhost",user="l2sm",password="l2sm;",db="L2SM") - -cur = db.cursor() - -def main(argv): - - #USE TEMPORARY FILE AS DESCRIPTOR TO BE USED - newDescriptor = 'tmp-descriptor.yaml' - - #USE KUBECONFIG IF PRESENT - if len(sys.argv) > 1: - nativeDescriptor = argv[1] - kubeConfig = argv[2] - else: - nativeDescriptor = argv - kubeConfig = '' - - #CONTINUE IF VALID .YAML FORMAT - if os.path.isfile(nativeDescriptor): - if os.path.splitext(nativeDescriptor)[-1].lower() == '.yaml': - - #CHECK IF THE NODE WHERE THE POD WILL BE DEPLOYED IS VALID AND GET THE NAME - try: - node = get_node(nativeDescriptor) - - except Exception as e: - print(e) - db.close() - quit() - - #CHECK IF THE NODE HAS FREE INTERFACES LEFT TO USE IN THE DATABASE - nsql = "SELECT * FROM interfaces WHERE node = '%s' AND network = '-1'" % (node.strip()) - cur.execute(nsql) - data = cur.fetchone() - - #TO DO: instanciar un nuevo NED -> mejor hacerlo al final si no quedan interfaces o ahora? - if not data: - print("l2sm could not deploy the pod: Node " + node.strip() + "has no free interfaces left") - db.close() - quit() - - interface_to_attach = data[0] - - try: - #PROCCESS THE DESCRIPTOR TO SEE INCOMPATIBILITIES OR NULL VALUES - newDescriptor = prepare_yaml(nativeDescriptor) - #CREATE NEW DESCRIPTOR - id, pod = process_file(newDescriptor, interface_to_attach) - if kubeConfig == '': - #subprocess.run(["kubectl", "get", "vn/" + network.strip()], stdout=subprocess.DEVNULL).check_returncode() - subprocess.run(["kubectl", "create", "-f", newDescriptor], stdout=subprocess.DEVNULL).check_returncode() - else: - #subprocess.run(["kubectl", "--kubeconfig", kubeConfig, "get", "vn/" + network.strip()], stdout=subprocess.DEVNULL).check_returncode() - subprocess.run(["kubectl", "--kubeconfig", kubeConfig, "create", "-f", newDescriptor], stdout=subprocess.DEVNULL).check_returncode() - - print('Scheduling pod ' + pod.strip() + ' at node ' + node.strip()) - - except CalledProcessError: - db.close() - subprocess.run(["rm", newDescriptor], stdout=subprocess.DEVNULL) - quit() - except Exception as e: - print(e) - db.close() - subprocess.run(["rm", newDescriptor], stdout=subprocess.DEVNULL) - quit() - - #UPDATE DB VALUES - try: - sql = "UPDATE interfaces SET network = '%s', pod = '%s' WHERE interface = '%s' AND node = '%s'" % (id.strip(), pod.strip(), data[0], node.strip()) - cur.execute(sql) - #If más de 2 interfaces, haz magia de Borhacker - db.commit() - subprocess.run(["rm", newDescriptor], stdout=subprocess.DEVNULL) - except: - print("Could not perform db update") - subprocess.run(["rm", newDescriptor], stdout=subprocess.DEVNULL) - db.rollback() - - else: - print("Wrong file format: Currently l2sm only supports yaml files") - - else: - print("Descriptor is not a file: Please introduce a valid descriptor") - -#FUNCTION FOR RETRIEVING THE NODE NAME -def get_node(descriptor): - with open(descriptor, 'r') as nodefile: - if 'nodeName' not in nodefile.read(): - raise NameError("l2sm could not deploy the pod: The field nodeName is not present in the descriptor") - nodefile.seek(0) - for line in nodefile: - if 'nodeName' in line: - node = line.split(":", 1)[1] - if node.strip() == '': - raise Exception('l2sm could not deploy the pod: Field nodeName cannot be an empty value') - nodefile.close() - return node - -#PROCCESS THE DESCRIPTOR TO SEE INCOMPATIBILITIES OR NULL VALUES -def prepare_yaml(fname): - newDescriptor = 'tmp-descriptor.yaml' - with open(fname, 'r') as infile: - with open(newDescriptor, 'w') as outfile: - for line in infile: - analyseLine = line.strip() - #LOOK FOR COMMENTS AND REMOVE THEM -> ONLY IF SYMBOL IS THE FIRST ONE OF THE NEW LINE - if '#' in analyseLine: - if analyseLine.find('#') == 0: - pass - else: - outfile.write(line) - else: - outfile.write(line) - - #IF THE KUBERNETES ANNOTATION IS NOT PRESENT, STOP - with open(newDescriptor, 'r') as prepfile: - if 'l2sm.k8s.conf.io/virtual-networks:' not in prepfile.read(): - raise NameError("l2sm could not deploy the pod: no virtual network was defined in the descriptor (to deploy pods not attached to l2sm, use exec options instead)") - prepfile.close() - - #IF NODENAME IS EMPTY, STOP - with open(newDescriptor, 'r') as prepfile: - if 'nodeName' not in prepfile.read(): - raise NameError("l2sm could not deploy the pod: The field nodeName is not present in the descriptor") - prepfile.close() - - return newDescriptor - -#GENERATE THE DESCRIPTOR TO BE USED IN THE KUBECTL -def process_file(onefile, interface_to_attach): - # CHANGE VIRTUAL NETWORK VALUE FOR INTERFACE - lines = [] - network = '' - pod = '' - id = '-1' - - with open(onefile, 'r') as file: - for line in file: - if 'l2sm.k8s.conf.io/virtual-networks' in line: - network = line.split(":", 1)[1] - #CHECK IF NETWORK IN THE DESCRIPTOR EXISTS - sql = "SELECT id FROM networks WHERE network = '%s'" % (network.strip()) - cur.execute(sql) - data = cur.fetchone() - if not data: - raise Exception("l2sm could not deploy the pod: Virtual network " + network.strip() + " does not exist in the cluster") - newDescriptor.close() - return id, pod - #REPLACE THE VIRTUAL NETWORK ANNOTATION WITH THE MULTUS ONE - id = data[0] - #print(id) - interface_in_file = ' ' + interface_to_attach + '\n' - line = line.replace('l2sm.k8s.conf.io/virtual-networks:' + network, 'k8s.v1.cni.cncf.io/networks:' + interface_in_file) - lines.append(line) - - # GET POD NAME VALUE - if 'metadata:' in line: - try: - search = 1 - while search: - newline = next(file) - lines.append(newline) - if 'name:' in newline: - pod = newline.split(":", 1)[1] - search = 0 - except: - raise Exception('l2sm could not deploy the pod: Pod name is not present in the descriptor metadata') - onefile.close() - return id, pod - - if pod.strip() == '': - raise Exception('l2sm could not deploy the pod: Pod name cannot be an empty value') - onefile.close() - return id, pod - - # WRITE TMP FILE - with open(onefile, 'w') as out: - for line in lines: - out.write(line) - - return id, pod - - -if __name__== "__main__": - main(sys.argv) - db.close() - diff --git a/old_versions/cli/installation/create-db.bash b/old_versions/cli/installation/create-db.bash deleted file mode 100755 index 70828109eb9a705af899dca01090682b26446f8a..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/create-db.bash +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -echo MySQL user: -read user -echo MySQL pass: -read -s pass - -mysql --user="$user" --password="$pass" --execute="CREATE DATABASE L2SM;" &> /dev/null -mysql --user="$user" --password="$pass" --database="L2SM" --execute="CREATE TABLE networks (network TEXT NOT NULL, id INT, metadata TEXT NOT NULL);" &> /dev/null -mysql --user="$user" --password="$pass" --database="L2SM" --execute="CREATE TABLE interfaces (interface TEXT NOT NULL, node TEXT NOT NULL, network INT, pod TEXT);" &> /dev/null - -echo 'Introduce the node names of the cluster separated with ;' - -read IN - -IFS=';' read -ra NODES <<< "$IN" - - -for i in "${NODES[@]}"; do -for j in {1..10}; do - mysql --user="$user" --password="$pass" --database="L2SM" --execute="INSERT INTO interfaces VALUES ('"vpod$j"', '"$i"', '-1', '');" &> /dev/null -done -done - - diff --git a/old_versions/cli/installation/wrapper-config/L2Switches/L2-pyra.yaml b/old_versions/cli/installation/wrapper-config/L2Switches/L2-pyra.yaml deleted file mode 100644 index a469b188d6edb7b09f4fcf0da80cbfa94c7b1fb3..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/L2Switches/L2-pyra.yaml +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: l2-pyra - annotations: - k8s.v1.cni.cncf.io/networks: vhost1@vhost1, vhost2@vhost2, vhost3@vhost3, vhost4@vhost4, vxlan1@vxlan1 -spec: - containers: - - name: l2-pyra - image: lewisfelix24/ovs-pod-ml2s:rpi - command: ["/bin/sh", "-c"] - args: ["ovsdb-server --remote=punix:/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,Open_vSwitch,manager_options --pidfile=/var/run/openvswitch/ovsdb-server.pid - --detach && ovs-vsctl --db=unix:/var/run/openvswitch/db.sock --no-wait init && ovs-vswitchd --pidfile=/var/run/openvswitch/ovs-vswitchd.pid --detach && - ip link set vhost1 up && ip link set vhost2 up && ip link set vhost3 up && ip link set vhost4 up && ip link set vxlan1 up && - ovs-vsctl add-br brtun && ip link set brtun up && - ovs-vsctl add-port brtun vhost1 && ovs-vsctl add-port brtun vhost2 && ovs-vsctl add-port brtun vhost3 && ovs-vsctl add-port brtun vhost4 && ovs-vsctl add-port brtun vxlan1 && - /bin/sleep 3650d"] - imagePullPolicy: IfNotPresent - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeName: pyra diff --git a/old_versions/cli/installation/wrapper-config/L2Switches/L2-rex.yaml b/old_versions/cli/installation/wrapper-config/L2Switches/L2-rex.yaml deleted file mode 100644 index b246b02853432074348403ea3040133bfbb08727..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/L2Switches/L2-rex.yaml +++ /dev/null @@ -1,23 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: l2-rex - annotations: - k8s.v1.cni.cncf.io/networks: vhost1@vhost1, vhost2@vhost2, vhost3@vhost3, vhost4@vhost4, vxlan1@vxlan1 -spec: - containers: - - name: l2-rex - image: lewisfelix24/ovs-pod-ml2s:amd64 - command: ["/bin/sh", "-c"] - args: ["ovsdb-server --remote=punix:/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,Open_vSwitch,manager_options --pidfile=/var/run/openvswitch/ovsdb-server.pid - --detach && ovs-vsctl --db=unix:/var/run/openvswitch/db.sock --no-wait init && ovs-vswitchd --pidfile=/var/run/openvswitch/ovs-vswitchd.pid --detach && - ip link set vhost1 up && ip link set vhost2 up && ip link set vhost3 up && ip link set vhost4 up && ip link set vxlan1 up && - ovs-vsctl add-br brtun && ip link set brtun up && - ovs-vsctl add-port brtun vhost1 && ovs-vsctl add-port brtun vhost2 && ovs-vsctl add-port brtun vhost3 && ovs-vsctl add-port brtun vhost4 && - ovs-vsctl add-port brtun vxlan1 && - /bin/sleep 3650d"] - imagePullPolicy: IfNotPresent - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeName: rex diff --git a/old_versions/cli/installation/wrapper-config/demo/configure-l2sm-demo.bash b/old_versions/cli/installation/wrapper-config/demo/configure-l2sm-demo.bash deleted file mode 100755 index ec5d4790de5b10150d3b7b43c85df5e50b098193..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/demo/configure-l2sm-demo.bash +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -ip link add vxlan1 type vxlan id 1969 dev enp1s0 dstport 4789 -ip link set vxlan1 up -#bridge fdb append to 00:00:00:00:00:00 dst 163.117.140.237 dev vxlan1 -ip link add dev vpod1 mtu 1450 type veth peer name vhost1 mtu 1450 -ip link add dev vpod2 mtu 1450 type veth peer name vhost2 mtu 1450 -ip link add dev vpod3 mtu 1450 type veth peer name vhost3 mtu 1450 -ip link add dev vpod4 mtu 1450 type veth peer name vhost4 mtu 1450 diff --git a/old_versions/cli/installation/wrapper-config/demo/l2switch/L2-pyra.yaml b/old_versions/cli/installation/wrapper-config/demo/l2switch/L2-pyra.yaml deleted file mode 100644 index 00872dcd477ec6b3fa38c5a1e5622fda4e9ff8f6..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/demo/l2switch/L2-pyra.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: l2-pyra - annotations: - k8s.v1.cni.cncf.io/networks: vhost1@vhost1, vhost2@vhost2, vhost3@vhost3, vhost4@vhost4, vxlan1@vxlan1 -spec: - containers: - - name: l2-pyra - image: lewisfelix24/ovs-pod-ml2s:rpi - command: ["/bin/sh", "-c"] - args: ["ovsdb-server --remote=punix:/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,Open_vSwitch,manager_options --pidfile=/var/run/openvswitch/ovsdb-server.pid - --detach && ovs-vsctl --db=unix:/var/run/openvswitch/db.sock --no-wait init && ovs-vswitchd --pidfile=/var/run/openvswitch/ovs-vswitchd.pid --detach && - ip link set vhost1 up && ip link set vhost2 up && ip link set vhost3 up && ip link set vhost4 up && ip link set vxlan1 up && - ovs-vsctl add-br brtun && ip link set brtun up && - /bin/sleep 3650d"] - imagePullPolicy: IfNotPresent - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeName: pyra diff --git a/old_versions/cli/installation/wrapper-config/demo/l2switch/L2-rex.yaml b/old_versions/cli/installation/wrapper-config/demo/l2switch/L2-rex.yaml deleted file mode 100644 index 1e945bb462fa36aa56792b6ede22990c0bc0710f..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/demo/l2switch/L2-rex.yaml +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: l2-rex - annotations: - k8s.v1.cni.cncf.io/networks: vhost1@vhost1, vhost2@vhost2, vhost3@vhost3, vhost4@vhost4, vxlan1@vxlan1 -spec: - containers: - - name: l2-rex - image: lewisfelix24/ovs-pod-ml2s:amd64 - command: ["/bin/sh", "-c"] - args: ["ovsdb-server --remote=punix:/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,Open_vSwitch,manager_options --pidfile=/var/run/openvswitch/ovsdb-server.pid - --detach && ovs-vsctl --db=unix:/var/run/openvswitch/db.sock --no-wait init && ovs-vswitchd --pidfile=/var/run/openvswitch/ovs-vswitchd.pid --detach && - ip link set vhost1 up && ip link set vhost2 up && ip link set vhost3 up && ip link set vhost4 up && ip link set vxlan1 up && - ovs-vsctl add-br brtun && ip link set brtun up && - ovs-vsctl add-port brtun vxlan1 && - /bin/sleep 3650d"] - imagePullPolicy: IfNotPresent - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeName: rex diff --git a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vhost1.yaml b/old_versions/cli/installation/wrapper-config/interfaces_definitions/vhost1.yaml deleted file mode 100644 index 22675e54fafbe46d4e16be4b2ed28ceec9001d39..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vhost1.yaml +++ /dev/null @@ -1,11 +0,0 @@ - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: vhost1 -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "host-device", - "device": "vhost1" - }' diff --git a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vhost2.yaml b/old_versions/cli/installation/wrapper-config/interfaces_definitions/vhost2.yaml deleted file mode 100644 index b155818d1a53c65ec41973b1264f49055e3e68e5..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vhost2.yaml +++ /dev/null @@ -1,11 +0,0 @@ - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: vhost2 -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "host-device", - "device": "vhost2" - }' diff --git a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vhost3.yaml b/old_versions/cli/installation/wrapper-config/interfaces_definitions/vhost3.yaml deleted file mode 100644 index 64e3fad24e78ee58cb6aa00c8a6c7d2203979126..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vhost3.yaml +++ /dev/null @@ -1,11 +0,0 @@ - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: vhost3 -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "host-device", - "device": "vhost3" - }' diff --git a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vhost4.yaml b/old_versions/cli/installation/wrapper-config/interfaces_definitions/vhost4.yaml deleted file mode 100644 index 618369f46aecfacd7e10735a145cf48ff2b35738..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vhost4.yaml +++ /dev/null @@ -1,11 +0,0 @@ - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: vhost4 -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "host-device", - "device": "vhost4" - }' diff --git a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vpod1.yaml b/old_versions/cli/installation/wrapper-config/interfaces_definitions/vpod1.yaml deleted file mode 100644 index af8a907392691a157e6df25e4413e5d34a9a722c..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vpod1.yaml +++ /dev/null @@ -1,11 +0,0 @@ - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: vpod1 -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "host-device", - "device": "vpod1" - }' diff --git a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vpod2.yaml b/old_versions/cli/installation/wrapper-config/interfaces_definitions/vpod2.yaml deleted file mode 100644 index 1aee3a4a7c545aef95d7543a6cf2f27e7ab314a3..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vpod2.yaml +++ /dev/null @@ -1,11 +0,0 @@ - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: vpod2 -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "host-device", - "device": "vpod2" - }' diff --git a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vpod3.yaml b/old_versions/cli/installation/wrapper-config/interfaces_definitions/vpod3.yaml deleted file mode 100644 index af8246bcf0ab6b4443bedaec8999cfa9a481fb2b..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vpod3.yaml +++ /dev/null @@ -1,11 +0,0 @@ - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: vpod3 -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "host-device", - "device": "vpod3" - }' diff --git a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vpod4.yaml b/old_versions/cli/installation/wrapper-config/interfaces_definitions/vpod4.yaml deleted file mode 100644 index 2fe22d6e2a7094c517ee43c12934e32969333954..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vpod4.yaml +++ /dev/null @@ -1,11 +0,0 @@ - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: vpod4 -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "host-device", - "device": "vpod4" - }' diff --git a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vxlan1.yaml b/old_versions/cli/installation/wrapper-config/interfaces_definitions/vxlan1.yaml deleted file mode 100644 index f35f082a3719ee1879cd4031285694a4314ab1ad..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/interfaces_definitions/vxlan1.yaml +++ /dev/null @@ -1,11 +0,0 @@ - -apiVersion: "k8s.cni.cncf.io/v1" -kind: NetworkAttachmentDefinition -metadata: - name: vxlan1 -spec: - config: '{ - "cniVersion": "0.3.0", - "type": "host-device", - "device": "vxlan1" - }' diff --git a/old_versions/cli/installation/wrapper-config/k8s/network1.yaml b/old_versions/cli/installation/wrapper-config/k8s/network1.yaml deleted file mode 100644 index 62e8e1fd5de573a34af3354c84d074145e2a15c1..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/k8s/network1.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: l2sm.k8s.conf.io/v1 -kind: VirtualNetwork -metadata: - name: my-first-network-2 -spec: - name: hello-world - id: 345678 diff --git a/old_versions/cli/installation/wrapper-config/k8s/networkCRD.yaml b/old_versions/cli/installation/wrapper-config/k8s/networkCRD.yaml deleted file mode 100644 index 309058f6d34e4c005b7a65ba870e9be26c2946c2..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/k8s/networkCRD.yaml +++ /dev/null @@ -1,43 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: virtual-networks.l2sm.k8s.conf.io -spec: - group: l2sm.k8s.conf.io - scope: Namespaced - names: - plural: virtual-networks - singular: virtual-network - kind: VirtualNetwork - shortNames: - - virt-net - - vn - versions: - - name: v1 - served: true - storage: true - schema: - openAPIV3Schema: - type: object - required: - - kind - - spec - properties: - apiVersion: - type: string - kind: - type: string - metadata: - type: object - spec: - type: object - required: - - name - - id - properties: - name: - type: string - id: - type: string - config: - type: string diff --git a/old_versions/cli/installation/wrapper-config/pod-pyra-sin-multus.yaml b/old_versions/cli/installation/wrapper-config/pod-pyra-sin-multus.yaml deleted file mode 100644 index b52b6d4dbd5bed3555c67b43e41938376eb4afcc..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/pod-pyra-sin-multus.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: pod-pyra-2 -# annotations: -# k8s.v1.cni.cncf.io/networks: vpod1@vpod1 -spec: - containers: - - name: pod-pyra-2 - command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"] - image: lewisfelix24/testing-pod:rpi - imagePullPolicy: IfNotPresent - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeName: pyra diff --git a/old_versions/cli/installation/wrapper-config/pod-pyra.yaml b/old_versions/cli/installation/wrapper-config/pod-pyra.yaml deleted file mode 100644 index cc8393627ebf8f0ad4a86fb92246b594ba865c45..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/pod-pyra.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: pod-pyra - annotations: - k8s.v1.cni.cncf.io/networks: vpod1@vpod1 -spec: - containers: - - name: pod-pyra-test - command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"] - image: lewisfelix24/testing-pod:rpi - imagePullPolicy: IfNotPresent - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeName: pyra diff --git a/old_versions/cli/installation/wrapper-config/pod-rex.yaml b/old_versions/cli/installation/wrapper-config/pod-rex.yaml deleted file mode 100644 index 838f112bebb4dfab99934852e7709d8fd15f7a04..0000000000000000000000000000000000000000 --- a/old_versions/cli/installation/wrapper-config/pod-rex.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: pod-rex - annotations: - k8s.v1.cni.cncf.io/networks: vpod1@vpod1 -spec: - containers: - - name: pod-rex - command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"] - image: alpine:latest - imagePullPolicy: IfNotPresent - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeName: rex diff --git a/old_versions/cli/l2sm.py b/old_versions/cli/l2sm.py deleted file mode 100644 index 9590d41948ae2901107f82aadcd5f4ca6093f003..0000000000000000000000000000000000000000 --- a/old_versions/cli/l2sm.py +++ /dev/null @@ -1,108 +0,0 @@ -import os -import sys -import json -import subprocess -from subprocess import CalledProcessError -from random import randrange -from prettytable import from_db_cursor - -import argparse -import pymysql - - -#network function -def network_man(args): - arguments = ["python3", "./network/l2sm_networks.py"] - arguments.append(args.action) - arguments.append(args.argument) - if args.kubeconfig != '': - arguments.append(args.kubeconfig) -# print(arguments) - subprocess.run(arguments) - -#deploy function -def deploy_man(args): - arguments = ["python3", "./deploy/kubectl_create.py"] - arguments.append(args.file) - if args.kubeconfig != '': - arguments.append(args.kubeconfig) -# print(arguments) - subprocess.run(arguments) - -#delete function -def delete_man(args): - arguments = ["python3", "./delete/kubectl_delete.py"] - arguments.append(args.pod) - if args.kubeconfig != '': - arguments.append(args.kubeconfig) -# print(arguments) - subprocess.run(arguments) - -#execute kubectl function NOTE: always use '' before the options or other functions may not work -def exec_man(args): - arguments = ["kubectl"] - # Variable to introduce the new arguments - var = list() - # Steparate the string into a new list - for line in args.options: - line = line.strip() - var.extend(line.split()) - # These operations should only be performed using L2S-M - if "create" in var or "apply" in var or "delete" in var: - print("Operation not permitted: Creating and deleting resources are limited to l2sm operations") - return - arguments.extend(var) - if args.kubeconfig != '': - arguments.append("--kubeconfig") - arguments.append(args.kubeconfig) - subprocess.run(arguments) - - - - -def main(argv): - #Create Parser - parser = argparse.ArgumentParser() -# parser.add_argument("option", help= "Option to be used by l2sm", choices=['deploy', 'delete', 'exec']) - subparsers = parser.add_subparsers(help="Special options for l2sm") - - #Add network parser - parser_networks = subparsers.add_parser('network', help='Operate with network options') - parser_networks.add_argument("action", choices=['create', 'show', 'delete'], help = "Network management action") - parser_networks.add_argument("argument", help = "File or network to operate with") - parser_networks.add_argument("--kubeconfig", help="If needed, use kubeConfig file to contact the Kubernetes cluster", action="store", default='') - # define the function to use with network - parser_networks.set_defaults(func=network_man) - - #Add deploy parser - parser_networks = subparsers.add_parser('deploy', help='Deploy a pod to be connected to l2sm networks') - parser_networks.add_argument("file", help = "File to be deployed") - parser_networks.add_argument("--kubeconfig", help="If needed, use kubeConfig file to contact the Kubernetes cluster", action="store", default='') - # define the function to use with network - parser_networks.set_defaults(func=deploy_man) - - #Add delete parser - parser_networks = subparsers.add_parser('delete', help='Delete a pod connected to l2sm networks') - parser_networks.add_argument("pod", help = "Pod to be deleted") - parser_networks.add_argument("--kubeconfig", help="If needed, use kubeConfig file to contact the Kubernetes cluster", action="store", default='') - # define the function to use with network - parser_networks.set_defaults(func=delete_man) - - #Add exec parser - parser_exec = subparsers.add_parser('exec', help='Operate with kubectl') - parser_exec.add_argument("options", help = "Use the same notation as it would be used in kubectl", nargs='*') - parser_exec.add_argument("--kubeconfig", help="If needed, use kubeConfig file to contact the Kubernetes cluster", action="store", default='') - # define the function to use with exec - parser_exec.set_defaults(func=exec_man) - - - # Get arguments - args = parser.parse_args() - # print(args) - - args.func(args) - - -if __name__== "__main__": - main(sys.argv) - diff --git a/old_versions/cli/network/l2sm_networks.py b/old_versions/cli/network/l2sm_networks.py deleted file mode 100644 index 9cd7e27d6a8a998480865732273a876a1040dfd0..0000000000000000000000000000000000000000 --- a/old_versions/cli/network/l2sm_networks.py +++ /dev/null @@ -1,200 +0,0 @@ -import os -import sys -import json -import subprocess -import secrets -from subprocess import CalledProcessError -from random import randrange -from prettytable import from_db_cursor, PrettyTable -from kubernetes import client, config - -import pymysql - -db = pymysql.connect(host="localhost",user="l2sm",password="l2sm;",db="L2SM") - -cur = db.cursor() - -def main(argv): - #CREATE OPTION - if argv[1] == 'create': - if os.path.isfile(argv[2]): - if os.path.splitext(argv[2])[-1].lower() == '.yaml': - try: - #WITHOUT KUBECONFIG - if len(argv) == 3: - create_network(argv[2], '') - #WITH KUBECONFIG - elif len(argv) == 4: - create_network(argv[2], argv[3]) - else: - print("Something went wrong: introduce the proper arguments") - except CalledProcessError: - db.close() - subprocess.run(["rm", "tmp.yaml"], stdout=subprocess.DEVNULL) - except Exception as e: - print(e) - subprocess.run(["rm", "tmp.yaml"], stdout=subprocess.DEVNULL) - - else: - print("Wrong file format: Currently l2sm only supports yaml files") - else: - print("Descriptor is not a file: Please introduce a valid descriptor") - - #SHOW OPTION - elif argv[1] == 'show': -# show_networks(argv[2]) - if len(argv) == 3: - show_networks(argv[2], '') - elif len(argv) == 4: - show_networks(argv[2], argv[3]) - - elif argv[1] == 'delete': - try: - #DELETE OPTION - if len(argv) == 3: - delete_network(argv[2], '') - elif len(argv) == 4: - delete_network(argv[2], argv[3]) - else: - print("Something went wrong: introduce the proper arguments") - except CalledProcessError: - db.close() - except Exception as e: - print(e) - - -#BUILD A NETWORK FROM A K8S DESCRIPTOR -def create_network(onefile, kubeConfig): - #GET NETWORK NAME - with open(onefile, 'r') as file: - with open('tmp.yaml', 'w') as newFile: - for line in file: - newFile.write(line) - # GET THE NETWORK NAME - if 'spec:' in line: - search = 1 - while search: - newline = next(file) - newFile.write(newline) - if 'name:' in newline: - network = newline.split(":", 1)[1] - search = 0 - # GET KUBERNETTES VN RESOURCE NAME - if 'metadata:' in line: - search = 1 - while search: - newline = next(file) - newFile.write(newline) - if 'name:' in newline: - metadata = newline.split(":", 1)[1] - search = 0 - - # GENERATE RANDOM ID NUMBER - #id = randrange(999999999) - id = secrets.token_hex(32) - newFile.write('\n id: ' + id) - - #CHECK IF NETWORK EXISTS IN DATABASE - nsql = "SELECT * FROM networks WHERE network = '%s'" % (network.strip()) - cur.execute(nsql) - data=cur.fetchall() - if data: - print("Network " + network.strip() + " exists") - subprocess.run(["rm", "tmp.yaml"], stdout=subprocess.DEVNULL) - return - - #CREATE NETWORK IN MASTER (IF REQUIRED, USE KUBECONFIG FILE) - if kubeConfig == '': - subprocess.run(["kubectl", "create", "-f" + "tmp.yaml"], stdout=subprocess.DEVNULL).check_returncode() - else: - subprocess.run(["kubectl", "create", "--kubeconfig", kubeConfig, "-f" + "tmp.yaml"], stdout=subprocess.DEVNULL).check_returncode() - - subprocess.run(["rm", "tmp.yaml"], stdout=subprocess.DEVNULL) - - #CREATE IN THE DATABASE THE NEW VALUES - sql = "INSERT INTO networks (network, id, metadata) VALUES ('%s', '%s', '%s')" % (network.strip(), id.strip(), metadata.strip()) - cur.execute(sql) - db.commit() - db.close() - print("Network " + network.strip() + " has been created") - -def show_networks(network, kubeConfig): - table = '' - output = '' - #SHOW ALL NETWORKS - if network == 'all': - sql = "SELECT id FROM networks" - #SHOW ONLY THE SELECTED NETWORK - else: - sql = "SELECT id FROM networks WHERE network = '%s'" % (network) - cur.execute(sql) - data = cur.fetchall() - - if not data: - if network == 'all': - print("No networks have been defined in the cluster") - else: - print("Network " + network + " has not been created in the cluster") - return - - #PRINT THE NETWORK (TO DO: SHOW POD ID'S) - for id in data: - sqln = "SELECT * FROM networks WHERE id = '%s'" % (id[0]) - cur.execute(sqln) - output = from_db_cursor(cur).get_string(fields=['network', 'id']) - print(output) - sql2 = "SELECT * FROM interfaces WHERE network = '%s'" % (id[0]) - cur.execute(sql2) - table_data = cur.fetchall() - output = PrettyTable() - output.field_names = ["network", "pod", "pod id"] - if kubeConfig == '': - config.load_kube_config() - else: - config.load_kube_config(kubeConfig) - v1 = client.CoreV1Api() - ret = v1.list_pod_for_all_namespaces(watch=False) - - for entry in table_data: - for i in ret.items: - if i.metadata.name == entry[3]: - id = i.metadata.uid - output.add_row([entry[2], entry[3], id]) - print(output) - -def delete_network(network, kubeConfig): - #CHECK IF NETWORK TO BE DELETED IS PRESENT - sql = "SELECT id FROM networks WHERE network = '%s'" % (network) - cur.execute(sql) - data = cur.fetchall() - if not data: - print("Network " + network + " has not been created") - return - #RETRIEVE THE METADATA NAME OF THE NETWORK TO BE DELETED (SO IT CAN BE REMOVED FROM K8S) - for id in data: - sqln = "SELECT * FROM interfaces WHERE network = '%s'" % (id[0]) - cur.execute(sqln) - pods = cur.fetchall() - mqln = "SELECT metadata FROM networks WHERE id = '%s'" % (id[0]) - cur.execute(mqln) - metadata = cur.fetchone() - #DELETE THE VN RESOURCE FROM K8S - if not pods: - if kubeConfig == '': - subprocess.run(["kubectl", "delete", " vn/ " + metadata[0]], stdout=subprocess.DEVNULL).check_returncode() - else: - subprocess.run(["kubectl", "delete", "--kubeconfig", kubeConfig, "vn/" + metadata[0]], stdout=subprocess.DEVNULL).check_returncode() - #REMOVE ENTRY FROM THE DATABASE - delsql = "DELETE FROM networks WHERE id = '%s'" % (id[0]) - cur.execute(delsql) - db.commit() - db.close() - print("Network " + network.strip() + " has been deleted") - - else: - print("Network " + network.strip() + " could not be removed, since there are pods still attached") - return - - -if __name__== "__main__": - main(sys.argv) diff --git a/old_versions/operator_custom_CRD/Dockerfile b/old_versions/operator_custom_CRD/Dockerfile deleted file mode 100644 index bde2d1d115347a0e2d1e84baaa3d5ddb37cbc373..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM python:3.7 -RUN pip install kopf kubernetes PyMySQL cryptography -COPY l2sm-operator.py /l2sm-operator.py -CMD kopf run --standalone --all-namespaces /l2sm-operator.py diff --git a/old_versions/operator_custom_CRD/daemonset/l2-ps-amd64.yaml b/old_versions/operator_custom_CRD/daemonset/l2-ps-amd64.yaml deleted file mode 100644 index ed30263fedc5d69e04ae1712989f97192fe1a480..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/daemonset/l2-ps-amd64.yaml +++ /dev/null @@ -1,40 +0,0 @@ -apiVersion: apps/v1 -kind: DaemonSet -metadata: - name: l2-ps - #namespace: kube-system - labels: - l2sm-component: l2-ps -spec: - selector: - matchLabels: - l2sm-component: l2-ps - template: - metadata: - labels: - l2sm-component: l2-ps - annotations: - k8s.v1.cni.cncf.io/networks: vhost1@vhost1, vhost2@vhost2, vhost3@vhost3, vhost4@vhost4, vxlan1@vxlan1 - spec: - tolerations: - # this toleration is to have the daemonset runnable on master nodes - # remove it if your masters can't run pods - - key: node-role.kubernetes.io/master - operator: Exists - effect: NoSchedule - containers: - - name: l2-ps - image: lewisfelix24/ovs-pod-ml2s:amd64 - command: ["/bin/sh", "-c"] - args: ["ovsdb-server --remote=punix:/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,Open_vSwitch,manager_options --pidfile=/var/run/openvswitch/ovsdb-server.pid - --detach && ovs-vsctl --db=unix:/var/run/openvswitch/db.sock --no-wait init && ovs-vswitchd --pidfile=/var/run/openvswitch/ovs-vswitchd.pid --detach && - ip link set vhost1 up && ip link set vhost2 up && ip link set vhost3 up && ip link set vhost4 up && ip link set vxlan1 up && - ovs-vsctl add-br brtun && ip link set brtun up && - ovs-vsctl add-port brtun vhost1 && ovs-vsctl add-port brtun vhost2 && ovs-vsctl add-port brtun vhost3 && ovs-vsctl add-port brtun vhost4 && ovs-vsctl add-port brtun vxlan1 && - /bin/sleep 3650d"] - imagePullPolicy: IfNotPresent - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeSelector: - kubernetes.io/arch: amd64 diff --git a/old_versions/operator_custom_CRD/daemonset/l2-ps-arm64.yaml b/old_versions/operator_custom_CRD/daemonset/l2-ps-arm64.yaml deleted file mode 100644 index bbf10d84eebabb8ea8da8161c937c697481e4eba..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/daemonset/l2-ps-arm64.yaml +++ /dev/null @@ -1,40 +0,0 @@ -apiVersion: apps/v1 -kind: DaemonSet -metadata: - name: l2-ps-arm64 - #namespace: kube-system - labels: - l2sm-component: l2-ps -spec: - selector: - matchLabels: - l2sm-component: l2-ps - template: - metadata: - labels: - l2sm-component: l2-ps - annotations: - k8s.v1.cni.cncf.io/networks: vhost1@vhost1, vhost2@vhost2, vhost3@vhost3, vhost4@vhost4, vxlan1@vxlan1 - spec: - tolerations: - # this toleration is to have the daemonset runnable on master nodes - # remove it if your masters can't run pods - - key: node-role.kubernetes.io/master - operator: Exists - effect: NoSchedule - containers: - - name: l2-ps - image: lewisfelix24/ovs-pod-ml2s:rpi - command: ["/bin/sh", "-c"] - args: ["ovsdb-server --remote=punix:/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,Open_vSwitch,manager_options --pidfile=/var/run/openvswitch/ovsdb-server.pid - --detach && ovs-vsctl --db=unix:/var/run/openvswitch/db.sock --no-wait init && ovs-vswitchd --pidfile=/var/run/openvswitch/ovs-vswitchd.pid --detach && - ip link set vhost1 up && ip link set vhost2 up && ip link set vhost3 up && ip link set vhost4 up && ip link set vxlan1 up && - ovs-vsctl add-br brtun && ip link set brtun up && - ovs-vsctl add-port brtun vhost1 && ovs-vsctl add-port brtun vhost2 && ovs-vsctl add-port brtun vhost3 && ovs-vsctl add-port brtun vhost4 && ovs-vsctl add-port brtun vxlan1 && - /bin/sleep 3650d"] - imagePullPolicy: IfNotPresent - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeSelector: - kubernetes.io/arch: arm64 diff --git a/old_versions/operator_custom_CRD/deploy/config/account.yaml b/old_versions/operator_custom_CRD/deploy/config/account.yaml deleted file mode 100644 index 2af8ec50ab827474b33951a784a9e36a5cb41373..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/deploy/config/account.yaml +++ /dev/null @@ -1,4 +0,0 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - name: l2sm-operator diff --git a/old_versions/operator_custom_CRD/deploy/config/binding.yaml b/old_versions/operator_custom_CRD/deploy/config/binding.yaml deleted file mode 100644 index 01997ea9bbe7d51f0a16c125ad53d6e5b9ec2a93..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/deploy/config/binding.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: l2sm-operator -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: cluster-admin -subjects: - - kind: ServiceAccount - name: l2sm-operator - namespace: default diff --git a/old_versions/operator_custom_CRD/deploy/deployOperator.yaml b/old_versions/operator_custom_CRD/deploy/deployOperator.yaml deleted file mode 100644 index a6359de7e7ac7fc69146644b340643dfd29a6a9d..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/deploy/deployOperator.yaml +++ /dev/null @@ -1,37 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: l2sm-operator-deployment -spec: - replicas: 1 - strategy: - type: Recreate - selector: - matchLabels: - l2sm-component: l2sm-opt - template: - metadata: - labels: - l2sm-component: l2sm-opt - spec: - serviceAccountName: l2sm-operator - containers: - - image: lewisfelix24/l2sm-operator:latest - name: l2sm-opt-pod - - image: mysql:latest - name: mysql - env: - - name: MYSQL_ROOT_PASSWORD - value: password - ports: - - containerPort: 3306 - name: mysql - volumeMounts: - - name: mysql-persistent-storage - mountPath: /var/lib/mysql - volumes: - - name: mysql-persistent-storage - persistentVolumeClaim: - claimName: mysql-pv-claim - nodeSelector: - node-role.kubernetes.io/master: "" diff --git a/old_versions/operator_custom_CRD/deploy/mysql/mysql-pv.yaml b/old_versions/operator_custom_CRD/deploy/mysql/mysql-pv.yaml deleted file mode 100644 index 8eef7d15802a05f302ad37446d59065cea7438e1..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/deploy/mysql/mysql-pv.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: v1 -kind: PersistentVolume -metadata: - name: mysql-pv - labels: - type: local -spec: - storageClassName: manual - capacity: - storage: 2Gi - accessModes: - - ReadWriteOnce - hostPath: - path: "/mnt/data" diff --git a/old_versions/operator_custom_CRD/deploy/mysql/mysql-pvc.yaml b/old_versions/operator_custom_CRD/deploy/mysql/mysql-pvc.yaml deleted file mode 100644 index 889f6d5e7826aa40756b7065b3457313dac5edeb..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/deploy/mysql/mysql-pvc.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: mysql-pv-claim -spec: - storageClassName: manual - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 2Gi diff --git a/old_versions/operator_custom_CRD/descriptors/deployments/deployment.yaml b/old_versions/operator_custom_CRD/descriptors/deployments/deployment.yaml deleted file mode 100644 index d95b548f7ec0a93fd9b2ff6c0275138aad00ffdc..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/descriptors/deployments/deployment.yaml +++ /dev/null @@ -1,52 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: ping-l2sm-amd -spec: - replicas: 1 - selector: - matchLabels: - test: rex - template: - metadata: - labels: - test: rex - annotations: - l2sm.k8s.conf.io/virtual-networks: my-first-network - spec: - containers: - - name: ping-amd - command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"] - image: alpine:latest - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeSelector: - kubernetes.io/arch: amd64 - ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: ping-l2sm-arm -spec: - replicas: 1 - selector: - matchLabels: - test: pyra - template: - metadata: - labels: - test: pyra - annotations: - l2sm.k8s.conf.io/virtual-networks: my-first-network - spec: - containers: - - name: ping-arm - command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"] - image: lewisfelix24/testing-pod:rpi - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeSelector: - kubernetes.io/arch: arm64 diff --git a/old_versions/operator_custom_CRD/descriptors/deployments/deployment_2_networks.yaml b/old_versions/operator_custom_CRD/descriptors/deployments/deployment_2_networks.yaml deleted file mode 100644 index 3329803a8a939ff492ea645963a000346ff2a907..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/descriptors/deployments/deployment_2_networks.yaml +++ /dev/null @@ -1,53 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: ping-l2sm-net1 -spec: - replicas: 1 - selector: - matchLabels: - test: rex - template: - metadata: - labels: - test: rex - annotations: - l2sm.k8s.conf.io/virtual-networks: my-first-network - spec: - containers: - - name: ping-amd - command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"] - image: alpine:latest - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeSelector: - kubernetes.io/arch: amd64 - ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: ping-l2sm-net2 -spec: - replicas: 1 - selector: - matchLabels: - test: pyra - template: - metadata: - labels: - test: pyra - annotations: - l2sm.k8s.conf.io/virtual-networks: my-second-network - spec: - containers: - - name: ping-arm - command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"] - image: lewisfelix24/testing-pod:rpi - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeSelector: - kubernetes.io/arch: arm64 - diff --git a/old_versions/operator_custom_CRD/descriptors/deployments/deployment_pyra.yaml b/old_versions/operator_custom_CRD/descriptors/deployments/deployment_pyra.yaml deleted file mode 100644 index 4d9abc0c21185208ab6c792fc042440095325911..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/descriptors/deployments/deployment_pyra.yaml +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: ping-l2sm-arm -spec: - replicas: 2 - selector: - matchLabels: - test: pyra - template: - metadata: - labels: - test: pyra - annotations: - l2sm.k8s.conf.io/virtual-networks: my-first-network, my-second-network - spec: - containers: - - name: ping-arm - command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"] - image: alpine:latest - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeName: pyra diff --git a/old_versions/operator_custom_CRD/descriptors/deployments/deployment_rex.yaml b/old_versions/operator_custom_CRD/descriptors/deployments/deployment_rex.yaml deleted file mode 100644 index 68f922f4f9a28dcbad44f8d8678cfd632bcf3e4c..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/descriptors/deployments/deployment_rex.yaml +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: ping-l2sm-amd -spec: - replicas: 4 - selector: - matchLabels: - test: rex - template: - metadata: - labels: - test: rex - annotations: - l2sm.k8s.conf.io/virtual-networks: my-first-network - spec: - containers: - - name: ping-amd - command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"] - image: alpine:latest - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeName: rex diff --git a/old_versions/operator_custom_CRD/descriptors/networks/test_network.yaml b/old_versions/operator_custom_CRD/descriptors/networks/test_network.yaml deleted file mode 100644 index 6faecd0fe9d8ac8fb04d54f1766f1a5196033797..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/descriptors/networks/test_network.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: l2sm.k8s.conf.io/v1 -kind: VirtualNetwork -metadata: - name: my-first-network -spec: - name: my-first-network diff --git a/old_versions/operator_custom_CRD/descriptors/networks/test_network_2.yaml b/old_versions/operator_custom_CRD/descriptors/networks/test_network_2.yaml deleted file mode 100644 index 41265e3bf3c3699ad3fed0ee17fc65284cfadba2..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/descriptors/networks/test_network_2.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: l2sm.k8s.conf.io/v1 -kind: VirtualNetwork -metadata: - name: my-second-network -spec: - name: my-second-network diff --git a/old_versions/operator_custom_CRD/descriptors/networks/test_network_3.yaml b/old_versions/operator_custom_CRD/descriptors/networks/test_network_3.yaml deleted file mode 100644 index c5aff09f31230d5551d448df996a18aaf92ab5eb..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/descriptors/networks/test_network_3.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: l2sm.k8s.conf.io/v1 -kind: VirtualNetwork -metadata: - name: my-third-network -spec: - name: my-third-network diff --git a/old_versions/operator_custom_CRD/descriptors/pods/pod-pyra-net2.yaml b/old_versions/operator_custom_CRD/descriptors/pods/pod-pyra-net2.yaml deleted file mode 100644 index 60ad37c331ff39d9e326584389544b3b054c646a..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/descriptors/pods/pod-pyra-net2.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: pod-pyra-2 - annotations: - l2sm.k8s.conf.io/virtual-networks: my-first-network -spec: - containers: - - name: pod-pyra-2 - command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"] - image: lewisfelix24/testing-pod:rpi - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeName: pyra diff --git a/old_versions/operator_custom_CRD/descriptors/pods/pod-pyra.yaml b/old_versions/operator_custom_CRD/descriptors/pods/pod-pyra.yaml deleted file mode 100644 index 0f11c84f341884c5cf045cacbab4dfd72070ff0a..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/descriptors/pods/pod-pyra.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: pod-pyra - annotations: - l2sm.k8s.conf.io/virtual-networks: my-first-network -spec: - containers: - - name: pod-pyra - command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"] - image: lewisfelix24/testing-pod:rpi - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeName: pyra diff --git a/old_versions/operator_custom_CRD/descriptors/pods/pod-rex-1-net.yaml b/old_versions/operator_custom_CRD/descriptors/pods/pod-rex-1-net.yaml deleted file mode 100644 index 039bd49a3911f4837cc75fbd96b64c28c1d69b7b..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/descriptors/pods/pod-rex-1-net.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: pod-rex-1-net - annotations: - l2sm.k8s.conf.io/virtual-networks: my-first-network -spec: - containers: - - name: pod-rex-1-net - command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"] - image: alpine:latest - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeName: rex diff --git a/old_versions/operator_custom_CRD/descriptors/pods/pod-rex.yaml b/old_versions/operator_custom_CRD/descriptors/pods/pod-rex.yaml deleted file mode 100644 index 6d6638a4d18cfcb6a503ef361753c18417d08be8..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/descriptors/pods/pod-rex.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: pod-rex - annotations: - l2sm.k8s.conf.io/virtual-networks: my-first-network, my-second-network, my-third-network -spec: - containers: - - name: pod-rex - command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"] - image: alpine:latest - securityContext: - capabilities: - add: ["NET_ADMIN"] - nodeName: rex diff --git a/old_versions/operator_custom_CRD/l2sm-operator.py b/old_versions/operator_custom_CRD/l2sm-operator.py deleted file mode 100644 index 40e0bfdc4c879419e0f90f3eeb9d3d97636bf74e..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/l2sm-operator.py +++ /dev/null @@ -1,149 +0,0 @@ -import kopf -import os -import sys -import json -import subprocess -import secrets -import kubernetes -from subprocess import CalledProcessError -from random import randrange -from kubernetes import client, config -import pymysql -import random -import time - -ip = "127.0.0.1" - -#POPULATE DATABASE ENTRIES WHEN A NEW L2SM POD IS CREATED (A NEW NODE APPEARS) -@kopf.on.create('pods.v1', labels={'l2sm-component': 'l2-ps'}) -def build_db(body, logger, annotations, **kwargs): - db = pymysql.connect(host=ip,user="l2sm",password="l2sm;",db="L2SM") - cur = db.cursor() - #CREATE TABLES IF THEY DO NOT EXIST - table1 = "CREATE TABLE IF NOT EXISTS networks (network TEXT NOT NULL, id TEXT NOT NULL);" - table2 = "CREATE TABLE IF NOT EXISTS interfaces (interface TEXT NOT NULL, node TEXT NOT NULL, network TEXT, pod TEXT);" - cur.execute(table1) - cur.execute(table2) - db.commit() - values = [] - #MODIFY THE END VALUE TO ADD MORE INTERFACES - for i in range(1,5): - values.append(['vpod'+str(i), body['spec']['nodeName'], '-1', '']) - sql = "INSERT INTO interfaces (interface, node, network, pod) VALUES (%s, %s, %s, %s)" - cur.executemany(sql, values) - db.commit() - db.close() - logger.info(f"Node {body['spec']['nodeName']} has been registered in the operator") - -#UPDATE DATABASE WHEN NETWORK IS CREATED -@kopf.on.create('virtual-networks') -def create_vn(spec, name, namespace, logger, **kwargs): - db = pymysql.connect(host=ip,user="l2sm",password="l2sm;",db="L2SM") - cur = db.cursor() - id = secrets.token_hex(32) - sql = "INSERT INTO networks (network, id) VALUES ('%s', '%s')" % (name.strip(), id.strip()) - cur.execute(sql) - db.commit() - db.close() - logger.info(f"Network has been created") - - -#ASSIGN POD TO NETWORK (TRIGGERS ONLY IF ANNOTATION IS PRESENT) -@kopf.on.create('pods.v1', annotations={'l2sm.k8s.conf.io/virtual-networks': kopf.PRESENT}) -def pod_vn(body, name, namespace, logger, annotations, **kwargs): - #GET NETWORK IN THE DESCRIPTOR - #IN QUARANTINE: SLOWER THAN MULTUS!!!!! - time.sleep(random.uniform(0,0.8)) #Make sure the database is not consulted at the same time to avoid overlaping - - network = annotations.get('l2sm.k8s.conf.io/virtual-networks').split(",") - #VERIFY IF NETWORK IS PRESENT IN THE CLUSTER - api = client.CustomObjectsApi() - items = api.list_namespaced_custom_object('l2sm.k8s.conf.io', 'v1', namespace, 'virtual-networks').get('items') - resources = [] - for i in items: - resources.append(i['metadata']['name']) - - for k in range(len(network)): - network[k] = network[k].strip() - if network[k] not in resources: - raise kopf.PermanentError("The pod could not be attached the network since network " + network[k] + " was not defined in the cluster") - - - #CHECK IF NODE HAS FREE VIRTUAL INTERFACES LEFT - v1 = client.CoreV1Api() - ret = v1.read_namespaced_pod(name, namespace) - node = body['spec']['nodeName'] - - db = pymysql.connect(host=ip,user="l2sm",password="l2sm;",db="L2SM") - nsql = "SELECT * FROM interfaces WHERE node = '%s' AND network = '-1'" % (node.strip()) - cur = db.cursor() - cur.execute(nsql) - data = cur.fetchall() - if not data or len(data)<len(network): - db.close() - raise kopf.PermanentError("l2sm could not deploy the pod: Node " + node.strip() + "has no free interfaces left") - - #IF THERE IS ALREADY A MULTUS ANNOTATION, APPEND IT TO THE END. - interface_to_attach = [] - for interface in data[0:len(network)]: - interface_to_attach.append(interface[0].strip()) - if 'k8s.v1.cni.cncf.io/networks' not in ret.metadata.annotations: - ret.metadata.annotations['k8s.v1.cni.cncf.io/networks'] = interface[0].strip() - else: - ret.metadata.annotations['k8s.v1.cni.cncf.io/networks'] = ret.metadata.annotations['k8s.v1.cni.cncf.io/networks'] + ", " + interface[0].strip() - - #PATCH NETWORK WITH ANNOTATION - v1.patch_namespaced_pod(name, namespace, ret) - - #GET NETWORK ID'S - #for j in items: - # if network in j['metadata']['name']: - # idsql = "SELECT id FROM networks WHERE network = '%s'" % (network.strip()) - # cur.execute(idsql) - # retrieve = cur.fetchone() - # networkN = retrieve[0].strip() - # break - - for m in range(len(network)): - sql = "UPDATE interfaces SET network = '%s', pod = '%s' WHERE interface = '%s' AND node = '%s'" % (network[m], name, interface_to_attach[m], node) - cur.execute(sql) - - db.commit() - db.close() - #HERE GOES SDN, THIS IS WHERE THE FUN BEGINS - logger.info(f"Pod {name} attached to network {network}") - - -#UPDATE DATABASE WHEN POD IS DELETED -@kopf.on.delete('pods.v1', annotations={'l2sm.k8s.conf.io/virtual-networks': kopf.PRESENT}) -def dpod_vn(name, logger, **kwargs): - db = pymysql.connect(host=ip,user="l2sm",password="l2sm;",db="L2SM") - cur = db.cursor() - sql = "UPDATE interfaces SET network = '-1', pod = '' WHERE pod = '%s'" % (name) - cur.execute(sql) - db.commit() - db.close() - logger.info(f"Pod {name} removed") - -#UPDATE DATABASE WHEN NETWORK IS DELETED -@kopf.on.delete('virtual-networks') -def delete_vn(spec, name, logger, **kwargs): - db = pymysql.connect(host=ip,user="l2sm",password="l2sm;",db="L2SM") - cur = db.cursor() - sql = "DELETE FROM networks WHERE network = '%s'" % (name) - cur.execute(sql) - db.commit() - db.close() - logger.info(f"Network has been deleted") - -#DELETE DATABASE ENTRIES WHEN A NEW L2SM POD IS DELETED (A NEW NODE GETS OUT OF THE CLUSTER) -@kopf.on.delete('pods.v1', labels={'l2sm-component': 'l2-ps'}) -def remove_node(body, logger, annotations, **kwargs): - db = pymysql.connect(host=ip,user="l2sm",password="l2sm;",db="L2SM") - cur = db.cursor() - sql = "DELETE FROM interfaces WHERE node = '%s'" % (body['spec']['nodeName']) - cur.execute(sql) - db.commit() - db.close() - logger.info(f"Node {body['spec']['nodeName']} has been deleted from the cluster") - diff --git a/old_versions/operator_custom_CRD/sidecar/mysql-deployment.yaml b/old_versions/operator_custom_CRD/sidecar/mysql-deployment.yaml deleted file mode 100644 index 4b14f1584169ef07c88462ea99af008c76aacd7d..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/sidecar/mysql-deployment.yaml +++ /dev/null @@ -1,38 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: mysql -spec: - selector: - matchLabels: - app: mysql - strategy: - type: Recreate - template: - metadata: - labels: - app: mysql - spec: - containers: - - image: mysql:latest - name: mysql - env: - - name: MYSQL_ROOT_PASSWORD - value: password - - name: MYSQL_DATABASE - value: L2SM - - name: MYSQL_USER - value: l2sm - - name: MYSQL_PASSWORD - value: l2sm; - ports: - - containerPort: 3306 - name: mysql - volumeMounts: - - name: mysql-persistent-storage - mountPath: /var/lib/mysql - volumes: - - name: mysql-persistent-storage - persistentVolumeClaim: - claimName: mysql-pv-claim - nodeName: rex diff --git a/old_versions/operator_custom_CRD/sidecar/mysql-pv.yaml b/old_versions/operator_custom_CRD/sidecar/mysql-pv.yaml deleted file mode 100644 index 8eef7d15802a05f302ad37446d59065cea7438e1..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/sidecar/mysql-pv.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: v1 -kind: PersistentVolume -metadata: - name: mysql-pv - labels: - type: local -spec: - storageClassName: manual - capacity: - storage: 2Gi - accessModes: - - ReadWriteOnce - hostPath: - path: "/mnt/data" diff --git a/old_versions/operator_custom_CRD/sidecar/mysql-pvc.yaml b/old_versions/operator_custom_CRD/sidecar/mysql-pvc.yaml deleted file mode 100644 index 889f6d5e7826aa40756b7065b3457313dac5edeb..0000000000000000000000000000000000000000 --- a/old_versions/operator_custom_CRD/sidecar/mysql-pvc.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: mysql-pv-claim -spec: - storageClassName: manual - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 2Gi