From afc6a379f191403d17c5e3575cb0fe192e39b2b5 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 6 Sep 2022 14:40:25 +0800 Subject: [PATCH 01/31] imeplement test and add into pipeline --- azure-pipelines/azure-pipelines.yml | 34 ++++++++++-- .../edgedevice-mqtt/checkoutput.sh | 11 ++++ .../edgedevice-mqtt/mosquitto.yaml | 53 +++++++++++++++++++ .../mqtt_deviceshifu_configmap.yaml | 16 ++++++ .../mqtt_deviceshifu_deployment.yaml | 36 +++++++++++++ .../mqtt_deviceshifu_service.yaml | 15 ++++++ .../edgedevice-mqtt/mqtt_edgedevice.yaml | 13 +++++ .../demo_device/edgedevice-opcua/dockerfile | 10 ++++ .../edgedevice-opcua/opcua-deployment.yaml | 23 ++++++++ .../edgedevice-opcua/opcua-service.yaml | 11 ++++ .../opcua_deviceshifu_configmap.yaml | 30 +++++++++++ .../opcua_deviceshifu_deployment.yaml | 43 +++++++++++++++ .../opcua_deviceshifu_service.yaml | 16 ++++++ .../edgedevice-opcua/opcua_edgedevice.yaml | 15 ++++++ .../edgedevice-opcua/requirements.txt | 2 + .../demo_device/edgedevice-opcua/server.py | 34 ++++++++++++ .../demo_device/edgedevice-socket/dockerfile | 7 +++ .../edgedevice-socket/echo_server.py | 15 ++++++ .../edgedevice-socket/socket-deployment.yaml | 23 ++++++++ .../edgedevice-socket/socket-service.yaml | 13 +++++ .../socket_deviceshifu_configmap.yaml | 15 ++++++ .../socket_deviceshifu_deployment.yaml | 36 +++++++++++++ .../socket_deviceshifu_service.yaml | 16 ++++++ .../edgedevice-socket/socket_edgedevice.yaml | 14 +++++ .../socket_deviceshifu_configmap.yaml | 3 +- go.mod | 2 + go.sum | 4 ++ 27 files changed, 506 insertions(+), 4 deletions(-) create mode 100755 examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh create mode 100644 examples/deviceshifu/demo_device/edgedevice-mqtt/mosquitto.yaml create mode 100644 examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_configmap.yaml create mode 100644 examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_deployment.yaml create mode 100644 examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_service.yaml create mode 100644 examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_edgedevice.yaml create mode 100644 examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile create mode 100644 examples/deviceshifu/demo_device/edgedevice-opcua/opcua-deployment.yaml create mode 100644 examples/deviceshifu/demo_device/edgedevice-opcua/opcua-service.yaml create mode 100644 examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_configmap.yaml create mode 100644 examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_deployment.yaml create mode 100644 examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_service.yaml create mode 100644 examples/deviceshifu/demo_device/edgedevice-opcua/opcua_edgedevice.yaml create mode 100644 examples/deviceshifu/demo_device/edgedevice-opcua/requirements.txt create mode 100644 examples/deviceshifu/demo_device/edgedevice-opcua/server.py create mode 100644 examples/deviceshifu/demo_device/edgedevice-socket/dockerfile create mode 100644 examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py create mode 100644 examples/deviceshifu/demo_device/edgedevice-socket/socket-deployment.yaml create mode 100644 examples/deviceshifu/demo_device/edgedevice-socket/socket-service.yaml create mode 100644 examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_configmap.yaml create mode 100644 examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml create mode 100644 examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_service.yaml create mode 100644 examples/deviceshifu/demo_device/edgedevice-socket/socket_edgedevice.yaml diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index 5525bfe65..40da647c8 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -126,7 +126,12 @@ stages: inputs: command: 'get' arguments: 'sigs.k8s.io/kind@v0.14.0' - + - task: CmdLine@2 + displayName: "mosquitto Installer" + inputs: + script: | + apt-add-repository ppa:mosquitto-dev/mosquitto-ppa + apt-get install mosquitto mosquitto-clients - script: | echo $tag docker buildx build --platform=linux/amd64 \ @@ -241,8 +246,31 @@ stages: kubectl wait --for=condition=Available deploy/thermometer -n devices --timeout=150s sleep 5 kubectl exec -it -n deviceshifu nginx -- curl http://deviceshifu-thermometer/read_value - kind delete cluster - displayName: "Shifu demo device E2E test" + displayName: "Shifu demo device HTTP E2E test" + - script: | + set -e + kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua + kubectl wait --for=condition=Available deploy/deviceshifu-opcua-deployment -n deviceshifu --timeout=150s + kubectl wait --for=condition=Available deploy/opcua-device -n devices --timeout=150s + sleep 5 + kubectl exec -it -n deviceshifu nginx -- curl http://deviceshifu-opcua/get_time + displayName: "Shifu demo device OPCUA E2E test" + - script: | + set -e + kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt + kubectl wait --for=condition=Available deploy/deviceshifu-mqtt-deployment -n deviceshifu --timeout=150s + kubectl wait --for=condition=Available deploy/mosquitto -n devices --timeout=150s + sleep 5 + bash checkoutput.sh + displayName: "Shifu demo device MQTT E2E test" + - script: | + set -e + kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket + kubectl wait --for=condition=Available deploy/deviceshifu-socket-deployment -n deviceshifu --timeout=150s + kubectl wait --for=condition=Available deploy/socket-mock-device -n devices --timeout=150s + sleep 5 + kubectl exec -it -n deviceshifu nginx -- curl -XPOST -H "Content-Type:application/json" deviceshifu-socket.deviceshifu.svc.cluster.local/cmd -d '{"command":"123"}' + displayName: "Shifu demo device Socket E2E test" - stage: docker_build_muiltiarch_and_push condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) diff --git a/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh b/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh new file mode 100755 index 000000000..2511486b8 --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh @@ -0,0 +1,11 @@ +#!bin/bash + +default='{"mqtt_message":"","mqtt_receive_timestamp":"0001-01-01 00:00:00 +0000 UTC"}' + +mosquitto_pub -h localhost -d -p 18830 -t /test/test -m "test2333" +kubectl exec -it -n deviceshifu nginx -- curl deviceshifu-mqtt/mqtt_data + +if [[ $1 == $default ]]; then + echo "not equal" + exit 1 +fi \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-mqtt/mosquitto.yaml b/examples/deviceshifu/demo_device/edgedevice-mqtt/mosquitto.yaml new file mode 100644 index 000000000..8c78812da --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-mqtt/mosquitto.yaml @@ -0,0 +1,53 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mosquitto + namespace: devices +spec: + replicas: 1 + selector: + matchLabels: + name: mosquitto + template: + metadata: + labels: + name: mosquitto + spec: + containers: + - name: mosquitto + image: eclipse-mosquitto:2.0.14 + ports: + - containerPort: 1883 + volumeMounts: + - name: mosquitto-config + mountPath: /mosquitto/config/mosquitto.conf + subPath: mosquitto.conf + volumes: + - name: mosquitto-config + configMap: + name: mosquitto-configmap +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: mosquitto-configmap + namespace: devices +data: + mosquitto.conf: |- + listener 1883 + allow_anonymous true +--- +apiVersion: v1 +kind: Service +metadata: + name: mosquitto-service + namespace: devices +spec: + type: LoadBalancer + selector: + name: mosquitto + ports: + - name: mosquitto + protocol: TCP + port: 18830 + targetPort: 1883 \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_configmap.yaml b/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_configmap.yaml new file mode 100644 index 000000000..6ebf8d327 --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_configmap.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: mqtt-configmap-0.0.1 + namespace: deviceshifu +data: + driverProperties: | + driverSku: testMQTT + driverImage: + instructions: | + + telemetries: | + telemetries: + device_health: + properties: + diff --git a/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_deployment.yaml new file mode 100644 index 000000000..2e29b1ce7 --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_deployment.yaml @@ -0,0 +1,36 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: deviceshifu-mqtt-deployment + name: deviceshifu-mqtt-deployment + namespace: deviceshifu +spec: + replicas: 1 + selector: + matchLabels: + app: deviceshifu-mqtt-deployment + template: + metadata: + labels: + app: deviceshifu-mqtt-deployment + spec: + containers: + - image: edgehub/deviceshifu-http-mqtt:v0.1.0 + name: deviceshifu-http + ports: + - containerPort: 8080 + volumeMounts: + - name: deviceshifu-config + mountPath: "/etc/edgedevice/config" + readOnly: true + env: + - name: EDGEDEVICE_NAME + value: "edgedevice-mqtt" + - name: EDGEDEVICE_NAMESPACE + value: "devices" + volumes: + - name: deviceshifu-config + configMap: + name: mqtt-configmap-0.0.1 + serviceAccountName: edgedevice-sa diff --git a/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_service.yaml b/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_service.yaml new file mode 100644 index 000000000..7461dfd1b --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: deviceshifu-mqtt-deployment + name: deviceshifu-mqtt + namespace: deviceshifu +spec: + ports: + - port: 80 + protocol: TCP + targetPort: 8080 + selector: + app: deviceshifu-mqtt-deployment + type: LoadBalancer diff --git a/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_edgedevice.yaml b/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_edgedevice.yaml new file mode 100644 index 000000000..952f2fed0 --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_edgedevice.yaml @@ -0,0 +1,13 @@ +apiVersion: shifu.edgenesis.io/v1alpha1 +kind: EdgeDevice +metadata: + name: edgedevice-mqtt + namespace: devices +spec: + sku: "testMQTT" + connection: Ethernet + address: mosquitto-service.devices.svc.cluster.local:18830 # change this accordingly + protocol: MQTT + protocolSettings: + MQTTSetting: + MQTTTopic: /test/test diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile b/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile new file mode 100644 index 000000000..3c1a4633a --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile @@ -0,0 +1,10 @@ +FROM python:3.9-bullseye + +WORKDIR /worker + +COPY requirements.txt requirements.txt +COPY server.py server.py + +RUN pip3 install -r requirements.txt + +CMD [ "python3","server.py" ] \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-deployment.yaml new file mode 100644 index 000000000..e05201add --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-deployment.yaml @@ -0,0 +1,23 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: opcua-device + namespace: devices +spec: + selector: + matchLabels: + app: opcua-device + template: + metadata: + labels: + app: opcua-device + spec: + containers: + - name: opcua-device + image: opcua-mock-device:v0.0.1 + resources: + limits: + memory: "128Mi" + cpu: "500m" + ports: + - containerPort: 4840 diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-service.yaml b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-service.yaml new file mode 100644 index 000000000..b70724648 --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: opcua-device + namespace: devices +spec: + selector: + app: opcua-device + ports: + - port: 4840 + targetPort: 4840 diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_configmap.yaml b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_configmap.yaml new file mode 100644 index 000000000..eafa95604 --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_configmap.yaml @@ -0,0 +1,30 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: opcua-configmap-0.0.1 + namespace: deviceshifu +data: + driverProperties: | + driverSku: Test OPC UA Server + driverImage: + instructions: | + instructions: + get_value: + protocolPropertyList: + OPCUANodeID: "ns=2;i=2" + get_time: + protocolPropertyList: + OPCUANodeID: "i=2258" + get_server: + protocolPropertyList: + OPCUANodeID: "i=2261" + telemetries: | + telemetrySettings: + telemetryUpdateIntervalInMiliseconds: 1000 + telemetries: + device_health: + properties: + instruction: get_server + initialDelayMs: 1000 + intervalMs: 1000 + \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_deployment.yaml new file mode 100644 index 000000000..146556d82 --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_deployment.yaml @@ -0,0 +1,43 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: deviceshifu-opcua-deployment + name: deviceshifu-opcua-deployment + namespace: deviceshifu +spec: + replicas: 1 + selector: + matchLabels: + app: deviceshifu-opcua-deployment + template: + metadata: + labels: + app: deviceshifu-opcua-deployment + spec: + containers: + - image: edgehub/deviceshifu-http-opcua:v0.1.0 + name: deviceshifu-http + ports: + - containerPort: 8080 + volumeMounts: + - name: deviceshifu-config + mountPath: "/etc/edgedevice/config" + readOnly: true + - name: edgedevice-certificate + mountPath: "/etc/edgedevice/certificate" + readOnly: true + env: + - name: EDGEDEVICE_NAME + value: "edgedevice-opcua" + - name: EDGEDEVICE_NAMESPACE + value: "devices" + volumes: + - name: deviceshifu-config + configMap: + name: opcua-configmap-0.0.1 + - name: edgedevice-certificate + configMap: + name: edgedevice-opcua-certificate + optional: true + serviceAccountName: edgedevice-sa diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_service.yaml b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_service.yaml new file mode 100644 index 000000000..51d937f6b --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: deviceshifu-opcua-deployment + name: deviceshifu-opcua + namespace: deviceshifu +spec: + ports: + - port: 80 + protocol: TCP + targetPort: 8080 + selector: + app: deviceshifu-opcua-deployment + type: LoadBalancer + \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_edgedevice.yaml b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_edgedevice.yaml new file mode 100644 index 000000000..55ec92eb2 --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_edgedevice.yaml @@ -0,0 +1,15 @@ +apiVersion: shifu.edgenesis.io/v1alpha1 +kind: EdgeDevice +metadata: + name: edgedevice-opcua + namespace: devices +spec: + sku: "opcua-test" + connection: Ethernet + address: opc.tcp://opcua-device.devices.svc.cluster.local:4840/freeopcua/server #change this accordingly + protocol: OPCUA + protocolSettings: + OPCUASetting: + SecurityMode: None + ConnectionTimeoutInMilliseconds: 5000 + AuthenticationMode: Anonymous diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/requirements.txt b/examples/deviceshifu/demo_device/edgedevice-opcua/requirements.txt new file mode 100644 index 000000000..3f17f411a --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/requirements.txt @@ -0,0 +1,2 @@ +asyncua +opcua \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/server.py b/examples/deviceshifu/demo_device/edgedevice-opcua/server.py new file mode 100644 index 000000000..3718dc49f --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/server.py @@ -0,0 +1,34 @@ +import sys +sys.path.insert(0, "..") +import time +from opcua import ua, Server + +if __name__ == "__main__": + # setup our server + server = Server() + server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/") + + # setup our own namespace, not really necessary but should as spec + uri = "http://examples.freeopcua.github.io" + idx = server.register_namespace(uri) + + # get Objects node, this is where we should put our nodes + objects = server.get_objects_node() + + # populating our address space + myobj = objects.add_object(idx, "MyObject") + myvar = myobj.add_variable(idx, "MyVariable", 6.7) + myvar.set_writable() # Set MyVariable to be writable by clients + + # starting! + server.start() + + try: + count = 0 + while True: + time.sleep(1) + count += 0.1 + myvar.set_value(count) + finally: + #close connection, remove subcsriptions, etc + server.stop() diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile b/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile new file mode 100644 index 000000000..1803b5a60 --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile @@ -0,0 +1,7 @@ +FROM python:3.9-bullseye + +WORKDIR /worker + +COPY echo_server.py echo_server.py + +CMD [ "python3","echo_server.py" ] \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py b/examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py new file mode 100644 index 000000000..85561e9bc --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py @@ -0,0 +1,15 @@ +# Echo server program +import socket +HOST = '0.0.0.0' # Symbolic name meaning all available interfaces +PORT = 11122 # Arbitrary non-privileged port +while 1: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.bind((HOST, PORT)) + s.listen(1) + conn, addr = s.accept() + print('Connected by', addr) + while 1: + data = conn.recv(1024) + if not data: break + conn.sendall(data) + conn.close() \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/socket-deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/socket-deployment.yaml new file mode 100644 index 000000000..b41c39090 --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-socket/socket-deployment.yaml @@ -0,0 +1,23 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: socket-mock-device + namespace: devices +spec: + selector: + matchLabels: + app: socket-mock-device + template: + metadata: + labels: + app: socket-mock-device + spec: + containers: + - name: socket-mock-device + image: socket-mock-device:v0.0.1 + resources: + limits: + memory: "128Mi" + cpu: "500m" + ports: + - containerPort: 11122 diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/socket-service.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/socket-service.yaml new file mode 100644 index 000000000..5c5d0c4a9 --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-socket/socket-service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: socket-mock-device + namespace: devices +spec: + selector: + app: socket-mock-device + ports: + - port: 11122 + protocol: TCP + targetPort: 11122 + diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_configmap.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_configmap.yaml new file mode 100644 index 000000000..2954188d3 --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_configmap.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: socket-configmap-0.0.1 + namespace: deviceshifu +data: + driverProperties: | + driverSku: testSocket + driverImage: + instructions: | + instructions: + cmd: + telemetries: | + telemetrySettings: + telemetryUpdateIntervalInMiliseconds: 1000 diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml new file mode 100644 index 000000000..ff50ec770 --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml @@ -0,0 +1,36 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: deviceshifu-socket-deployment + name: deviceshifu-socket-deployment + namespace: deviceshifu +spec: + replicas: 1 + selector: + matchLabels: + app: deviceshifu-socket-deployment + template: + metadata: + labels: + app: deviceshifu-socket-deployment + spec: + containers: + - image: edgehub/deviceshifu-http-socket:v0.1.0 + name: deviceshifu-http + ports: + - containerPort: 8080 + volumeMounts: + - name: deviceshifu-config + mountPath: "/etc/edgedevice/config" + readOnly: true + env: + - name: EDGEDEVICE_NAME + value: "edgedevice-socket" + - name: EDGEDEVICE_NAMESPACE + value: "devices" + volumes: + - name: deviceshifu-config + configMap: + name: socket-configmap-0.0.1 + serviceAccountName: edgedevice-sa diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_service.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_service.yaml new file mode 100644 index 000000000..bbb5a0fb6 --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: deviceshifu-socket-deployment + name: deviceshifu-socket + namespace: deviceshifu +spec: + ports: + - port: 80 + protocol: TCP + targetPort: 8080 + selector: + app: deviceshifu-socket-deployment + type: LoadBalancer + \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/socket_edgedevice.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/socket_edgedevice.yaml new file mode 100644 index 000000000..5d55739c0 --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-socket/socket_edgedevice.yaml @@ -0,0 +1,14 @@ +apiVersion: shifu.edgenesis.io/v1alpha1 +kind: EdgeDevice +metadata: + name: edgedevice-socket + namespace: devices +spec: + sku: "testSocket" + connection: Ethernet + address: socket-mock-device.devices.svc.cluster.local:11122 #change this accordingly + protocol: Socket + protocolSettings: + SocketSetting: + encoding: utf-8 + networkType: tcp \ No newline at end of file diff --git a/examples/socketDeviceShifu/socket_deviceshifu_configmap.yaml b/examples/socketDeviceShifu/socket_deviceshifu_configmap.yaml index 413a0c9c3..2954188d3 100644 --- a/examples/socketDeviceShifu/socket_deviceshifu_configmap.yaml +++ b/examples/socketDeviceShifu/socket_deviceshifu_configmap.yaml @@ -8,7 +8,8 @@ data: driverSku: testSocket driverImage: instructions: | - cmd: + instructions: + cmd: telemetries: | telemetrySettings: telemetryUpdateIntervalInMiliseconds: 1000 diff --git a/go.mod b/go.mod index 102226f33..9f2c4edcd 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,9 @@ require ( github.com/google/gofuzz v1.2.0 // indirect github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.4.2 // indirect + github.com/huin/mqtt v0.0.0-20220729180547-9e81042af5f7 // indirect github.com/imdario/mergo v0.3.12 // indirect + github.com/jeffallen/mqtt v0.0.0-20180518073322-5387cfa89df0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/mailru/easyjson v0.7.7 // indirect diff --git a/go.sum b/go.sum index 6d84e89d6..58cf1d22e 100644 --- a/go.sum +++ b/go.sum @@ -357,6 +357,8 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/huin/mqtt v0.0.0-20220729180547-9e81042af5f7 h1:FbE0sTosmODWNX7oRNCd+xNK8HI1Ys2Je+612xmad38= +github.com/huin/mqtt v0.0.0-20220729180547-9e81042af5f7/go.mod h1:zbO4h3NDGxpAVWGYzQNle+BDfuwm8fWcgVxFuIHyuas= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= @@ -366,6 +368,8 @@ github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/influxdata/tdigest v0.0.0-20180711151920-a7d76c6f093a/go.mod h1:9GkyshztGufsdPQWjH+ifgnIr3xNUL5syI70g2dzU1o= github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9/go.mod h1:Js0mqiSBE6Ffsg94weZZ2c+v/ciT8QRHFOap7EKDrR0= +github.com/jeffallen/mqtt v0.0.0-20180518073322-5387cfa89df0 h1:ESdZtIOKF9F7Ah9lbdKyc0xiioZvnGe3XrvXzgEka0Y= +github.com/jeffallen/mqtt v0.0.0-20180518073322-5387cfa89df0/go.mod h1:5VmMaANxUXHvNfKSdcjuEYlAFnxsu6vVAr6kgQOoUG4= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= From e2b99933a60b64906e13599233ac25ae01b66d8e Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 6 Sep 2022 14:47:48 +0800 Subject: [PATCH 02/31] fix pipeline --- azure-pipelines/azure-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index 40da647c8..837ebbee7 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -130,8 +130,8 @@ stages: displayName: "mosquitto Installer" inputs: script: | - apt-add-repository ppa:mosquitto-dev/mosquitto-ppa - apt-get install mosquitto mosquitto-clients + sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa + sudo apt-get install mosquitto mosquitto-clients - script: | echo $tag docker buildx build --platform=linux/amd64 \ From 73a4920e420f605019012ac28f0fbe17e3b82d60 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 6 Sep 2022 15:10:40 +0800 Subject: [PATCH 03/31] add build dockerfile --- azure-pipelines/azure-pipelines.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index 837ebbee7..8b646980c 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -193,7 +193,16 @@ stages: --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ -t edgehub/mockdevice-plc:$(tag) --load displayName: build edgehub/mockdevice-plc - + - script: | + docker buildx build --platform=linux/amd64 \ + -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile \ + -t socket-mock-device:v0.0.1 --load + displayName: build socket-mock-device + - script: | + docker buildx build --platform=linux/amd64 \ + -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile \ + -t opcua-mock-device:v0.0.1 --load + - script: | set -e kind --version @@ -208,6 +217,9 @@ stages: kind load docker-image edgehub/deviceshifu-http-mqtt:$(tag) kind load docker-image edgehub/deviceshifu-http-opcua:$(tag) kind load docker-image edgehub/deviceshifu-http-socket:$(tag) + kind load docker-image opcua-mock-device:v0.0.1 + kind load docker-image socket-mock-device:v0.0.1 + kubectl version kubectl apply -f $(System.DefaultWorkingDirectory)/pkg/k8s/crd/install/shifu_install.yml kubectl wait --for=condition=Available deploy/shifu-crd-controller-manager -n shifu-crd-system --timeout=150s From db16072d7830d01e3f9b7e4574f8b93acef8e442 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 6 Sep 2022 15:36:04 +0800 Subject: [PATCH 04/31] fix pipeline --- azure-pipelines/azure-pipelines.yml | 13 ++++++++----- .../edgedevice-opcua/opcua-deployment.yaml | 2 +- .../edgedevice-socket/socket-deployment.yaml | 2 +- go.mod | 2 -- go.sum | 4 ---- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index 8b646980c..704e4e194 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -196,13 +196,15 @@ stages: - script: | docker buildx build --platform=linux/amd64 \ -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile \ - -t socket-mock-device:v0.0.1 --load + $(System.DefaultWorkingDirectory) \ + -t socket-mock-device:$(tag) --load displayName: build socket-mock-device - script: | docker buildx build --platform=linux/amd64 \ -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile \ - -t opcua-mock-device:v0.0.1 --load - + $(System.DefaultWorkingDirectory) \ + -t opcua-mock-device:$(tag) --load + displayName: build opcua-mock-device - script: | set -e kind --version @@ -217,8 +219,8 @@ stages: kind load docker-image edgehub/deviceshifu-http-mqtt:$(tag) kind load docker-image edgehub/deviceshifu-http-opcua:$(tag) kind load docker-image edgehub/deviceshifu-http-socket:$(tag) - kind load docker-image opcua-mock-device:v0.0.1 - kind load docker-image socket-mock-device:v0.0.1 + kind load docker-image opcua-mock-device:$(tag) + kind load docker-image socket-mock-device:$(tag) kubectl version kubectl apply -f $(System.DefaultWorkingDirectory)/pkg/k8s/crd/install/shifu_install.yml @@ -258,6 +260,7 @@ stages: kubectl wait --for=condition=Available deploy/thermometer -n devices --timeout=150s sleep 5 kubectl exec -it -n deviceshifu nginx -- curl http://deviceshifu-thermometer/read_value + kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-thermometer displayName: "Shifu demo device HTTP E2E test" - script: | set -e diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-deployment.yaml index e05201add..2028810b7 100644 --- a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-deployment.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: opcua-device - image: opcua-mock-device:v0.0.1 + image: opcua-mock-device:v0.1.0 resources: limits: memory: "128Mi" diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/socket-deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/socket-deployment.yaml index b41c39090..f818db5e9 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/socket-deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-socket/socket-deployment.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: socket-mock-device - image: socket-mock-device:v0.0.1 + image: socket-mock-device:v0.1.0 resources: limits: memory: "128Mi" diff --git a/go.mod b/go.mod index 9f2c4edcd..102226f33 100644 --- a/go.mod +++ b/go.mod @@ -48,9 +48,7 @@ require ( github.com/google/gofuzz v1.2.0 // indirect github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.4.2 // indirect - github.com/huin/mqtt v0.0.0-20220729180547-9e81042af5f7 // indirect github.com/imdario/mergo v0.3.12 // indirect - github.com/jeffallen/mqtt v0.0.0-20180518073322-5387cfa89df0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/mailru/easyjson v0.7.7 // indirect diff --git a/go.sum b/go.sum index 58cf1d22e..6d84e89d6 100644 --- a/go.sum +++ b/go.sum @@ -357,8 +357,6 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/huin/mqtt v0.0.0-20220729180547-9e81042af5f7 h1:FbE0sTosmODWNX7oRNCd+xNK8HI1Ys2Je+612xmad38= -github.com/huin/mqtt v0.0.0-20220729180547-9e81042af5f7/go.mod h1:zbO4h3NDGxpAVWGYzQNle+BDfuwm8fWcgVxFuIHyuas= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= @@ -368,8 +366,6 @@ github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/influxdata/tdigest v0.0.0-20180711151920-a7d76c6f093a/go.mod h1:9GkyshztGufsdPQWjH+ifgnIr3xNUL5syI70g2dzU1o= github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9/go.mod h1:Js0mqiSBE6Ffsg94weZZ2c+v/ciT8QRHFOap7EKDrR0= -github.com/jeffallen/mqtt v0.0.0-20180518073322-5387cfa89df0 h1:ESdZtIOKF9F7Ah9lbdKyc0xiioZvnGe3XrvXzgEka0Y= -github.com/jeffallen/mqtt v0.0.0-20180518073322-5387cfa89df0/go.mod h1:5VmMaANxUXHvNfKSdcjuEYlAFnxsu6vVAr6kgQOoUG4= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= From 5e90488bd3a2bb26fa69daff32357ff8fcd8da7d Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 6 Sep 2022 15:39:13 +0800 Subject: [PATCH 05/31] add port-forward --- examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh b/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh index 2511486b8..7d29d2af9 100755 --- a/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh +++ b/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh @@ -2,6 +2,8 @@ default='{"mqtt_message":"","mqtt_receive_timestamp":"0001-01-01 00:00:00 +0000 UTC"}' + +kubectl port-forward svc/mosquitto-service -n devices 18830:18830 & mosquitto_pub -h localhost -d -p 18830 -t /test/test -m "test2333" kubectl exec -it -n deviceshifu nginx -- curl deviceshifu-mqtt/mqtt_data From 31d0ce745d487a59fd17effd4a2c199a184ebbcd Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 6 Sep 2022 15:55:12 +0800 Subject: [PATCH 06/31] fix dockerfile --- examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile | 2 +- examples/deviceshifu/demo_device/edgedevice-socket/dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile b/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile index 3c1a4633a..345d6f2e1 100644 --- a/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile @@ -7,4 +7,4 @@ COPY server.py server.py RUN pip3 install -r requirements.txt -CMD [ "python3","server.py" ] \ No newline at end of file +CMD [ "python3","/worker/server.py" ] \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile b/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile index 1803b5a60..6792e47e4 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile +++ b/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile @@ -4,4 +4,4 @@ WORKDIR /worker COPY echo_server.py echo_server.py -CMD [ "python3","echo_server.py" ] \ No newline at end of file +CMD [ "python3","/worker/echo_server.py" ] \ No newline at end of file From 3cfe773caed39f9beb5730882e530f34e277b0af Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 6 Sep 2022 16:13:39 +0800 Subject: [PATCH 07/31] fix dockerfile path --- examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile | 4 ++-- examples/deviceshifu/demo_device/edgedevice-socket/dockerfile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile b/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile index 345d6f2e1..631ba93c2 100644 --- a/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile @@ -2,8 +2,8 @@ FROM python:3.9-bullseye WORKDIR /worker -COPY requirements.txt requirements.txt -COPY server.py server.py +COPY shifu/examples/deviceshifu/demo_device/edgedevice-opcua/requirements.txt requirements.txt +COPY shifu/examples/deviceshifu/demo_device/edgedevice-opcua/server.py server.py RUN pip3 install -r requirements.txt diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile b/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile index 6792e47e4..6825068f4 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile +++ b/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile @@ -2,6 +2,6 @@ FROM python:3.9-bullseye WORKDIR /worker -COPY echo_server.py echo_server.py +COPY shifu/examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py echo_server.py CMD [ "python3","/worker/echo_server.py" ] \ No newline at end of file From 44a00067ff712aca25b242298f81d2fe11c2b373 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 6 Sep 2022 16:28:31 +0800 Subject: [PATCH 08/31] fix docker path --- examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile | 4 ++-- examples/deviceshifu/demo_device/edgedevice-socket/dockerfile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile b/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile index 631ba93c2..3d164b7d4 100644 --- a/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile @@ -2,8 +2,8 @@ FROM python:3.9-bullseye WORKDIR /worker -COPY shifu/examples/deviceshifu/demo_device/edgedevice-opcua/requirements.txt requirements.txt -COPY shifu/examples/deviceshifu/demo_device/edgedevice-opcua/server.py server.py +COPY examples/deviceshifu/demo_device/edgedevice-opcua/requirements.txt requirements.txt +COPY examples/deviceshifu/demo_device/edgedevice-opcua/server.py server.py RUN pip3 install -r requirements.txt diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile b/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile index 6825068f4..b4d59d2e4 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile +++ b/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile @@ -2,6 +2,6 @@ FROM python:3.9-bullseye WORKDIR /worker -COPY shifu/examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py echo_server.py +COPY examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py echo_server.py CMD [ "python3","/worker/echo_server.py" ] \ No newline at end of file From 97a12afded22539e84e39666bb1fdb9af3d0dabe Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 6 Sep 2022 16:51:09 +0800 Subject: [PATCH 09/31] fix pipeline and docker image --- azure-pipelines/azure-pipelines.yml | 2 +- .../deviceshifu/demo_device/edgedevice-opcua/dockerfile | 6 +++--- .../deviceshifu/demo_device/edgedevice-socket/dockerfile | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index 704e4e194..e4fccfe55 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -276,7 +276,7 @@ stages: kubectl wait --for=condition=Available deploy/deviceshifu-mqtt-deployment -n deviceshifu --timeout=150s kubectl wait --for=condition=Available deploy/mosquitto -n devices --timeout=150s sleep 5 - bash checkoutput.sh + # bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh displayName: "Shifu demo device MQTT E2E test" - script: | set -e diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile b/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile index 3d164b7d4..605a3adf4 100644 --- a/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile @@ -1,9 +1,9 @@ -FROM python:3.9-bullseye +FROM python:3.9-slim WORKDIR /worker -COPY examples/deviceshifu/demo_device/edgedevice-opcua/requirements.txt requirements.txt -COPY examples/deviceshifu/demo_device/edgedevice-opcua/server.py server.py +COPY requirements.txt requirements.txt +COPY server.py server.py RUN pip3 install -r requirements.txt diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile b/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile index b4d59d2e4..b34276bda 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile +++ b/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile @@ -1,4 +1,4 @@ -FROM python:3.9-bullseye +FROM python:3.9-slim WORKDIR /worker From cfcce93774fb72a9737e637c6608c2f463f95d0a Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 6 Sep 2022 17:06:18 +0800 Subject: [PATCH 10/31] fix dockerfile path --- examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile b/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile index 605a3adf4..6fb049319 100644 --- a/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile @@ -2,8 +2,8 @@ FROM python:3.9-slim WORKDIR /worker -COPY requirements.txt requirements.txt -COPY server.py server.py +COPY examples/deviceshifu/demo_device/edgedevice-opcua/requirements.txt requirements.txt +COPY examples/deviceshifu/demo_device/edgedevice-opcua/server.py server.py RUN pip3 install -r requirements.txt From 70bd94e62baa633029029cd7b519659015f15e96 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 6 Sep 2022 17:34:42 +0800 Subject: [PATCH 11/31] fix pipeline --- azure-pipelines/azure-pipelines.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index e4fccfe55..37f2c9f7c 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -269,6 +269,7 @@ stages: kubectl wait --for=condition=Available deploy/opcua-device -n devices --timeout=150s sleep 5 kubectl exec -it -n deviceshifu nginx -- curl http://deviceshifu-opcua/get_time + kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua displayName: "Shifu demo device OPCUA E2E test" - script: | set -e @@ -276,16 +277,18 @@ stages: kubectl wait --for=condition=Available deploy/deviceshifu-mqtt-deployment -n deviceshifu --timeout=150s kubectl wait --for=condition=Available deploy/mosquitto -n devices --timeout=150s sleep 5 - # bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh + bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh + kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt displayName: "Shifu demo device MQTT E2E test" - script: | set -e kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket - kubectl wait --for=condition=Available deploy/deviceshifu-socket-deployment -n deviceshifu --timeout=150s kubectl wait --for=condition=Available deploy/socket-mock-device -n devices --timeout=150s + kubectl wait --for=condition=Available deploy/deviceshifu-socket-deployment -n deviceshifu --timeout=150s sleep 5 kubectl exec -it -n deviceshifu nginx -- curl -XPOST -H "Content-Type:application/json" deviceshifu-socket.deviceshifu.svc.cluster.local/cmd -d '{"command":"123"}' - displayName: "Shifu demo device Socket E2E test" + kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket + displayName: "Shifu demo device Socket E2E test" - stage: docker_build_muiltiarch_and_push condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) From 2ca7136f385102067f72bf507aa4fede8118760b Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 6 Sep 2022 17:52:40 +0800 Subject: [PATCH 12/31] fix pipeline --- azure-pipelines/azure-pipelines.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index 37f2c9f7c..a1a6ed1d9 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -265,8 +265,8 @@ stages: - script: | set -e kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua - kubectl wait --for=condition=Available deploy/deviceshifu-opcua-deployment -n deviceshifu --timeout=150s kubectl wait --for=condition=Available deploy/opcua-device -n devices --timeout=150s + kubectl wait --for=condition=Available deploy/deviceshifu-opcua-deployment -n deviceshifu --timeout=150s sleep 5 kubectl exec -it -n deviceshifu nginx -- curl http://deviceshifu-opcua/get_time kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua @@ -274,8 +274,8 @@ stages: - script: | set -e kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt - kubectl wait --for=condition=Available deploy/deviceshifu-mqtt-deployment -n deviceshifu --timeout=150s kubectl wait --for=condition=Available deploy/mosquitto -n devices --timeout=150s + kubectl wait --for=condition=Available deploy/deviceshifu-mqtt-deployment -n deviceshifu --timeout=150s sleep 5 bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt @@ -288,8 +288,7 @@ stages: sleep 5 kubectl exec -it -n deviceshifu nginx -- curl -XPOST -H "Content-Type:application/json" deviceshifu-socket.deviceshifu.svc.cluster.local/cmd -d '{"command":"123"}' kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket - displayName: "Shifu demo device Socket E2E test" - + displayName: "Shifu demo device Socket E2E test" - stage: docker_build_muiltiarch_and_push condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) variables: From 16efddc48523245c2db656f2085c20ae123ced06 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 6 Sep 2022 21:52:46 +0800 Subject: [PATCH 13/31] add probe --- azure-pipelines/azure-pipelines.yml | 11 +++++------ .../demo_device/edgedevice-mqtt/checkoutput.sh | 2 +- .../edgedevice-mqtt/mqtt_deviceshifu_deployment.yaml | 6 ++++++ .../edgedevice-opcua/opcua-deployment.yaml | 9 +++++---- .../opcua_deviceshifu_deployment.yaml | 6 ++++++ .../demo_device/edgedevice-socket/echo_server.py | 2 +- .../{ => mock-device}/socket-deployment.yaml | 5 +++++ .../{ => mock-device}/socket-service.yaml | 0 .../socket_deviceshifu_deployment.yaml | 10 ++++++++++ 9 files changed, 39 insertions(+), 12 deletions(-) rename examples/deviceshifu/demo_device/edgedevice-socket/{ => mock-device}/socket-deployment.yaml (78%) rename examples/deviceshifu/demo_device/edgedevice-socket/{ => mock-device}/socket-service.yaml (100%) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index a1a6ed1d9..0bb0788ab 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -267,8 +267,7 @@ stages: kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua kubectl wait --for=condition=Available deploy/opcua-device -n devices --timeout=150s kubectl wait --for=condition=Available deploy/deviceshifu-opcua-deployment -n deviceshifu --timeout=150s - sleep 5 - kubectl exec -it -n deviceshifu nginx -- curl http://deviceshifu-opcua/get_time + kubectl exec -it -n deviceshifu nginx -- curl http://deviceshifu-opcua/get_server kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua displayName: "Shifu demo device OPCUA E2E test" - script: | @@ -276,18 +275,18 @@ stages: kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt kubectl wait --for=condition=Available deploy/mosquitto -n devices --timeout=150s kubectl wait --for=condition=Available deploy/deviceshifu-mqtt-deployment -n deviceshifu --timeout=150s - sleep 5 bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt displayName: "Shifu demo device MQTT E2E test" - script: | set -e - kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket + kubectl apply -f examples/deviceshifu/demo_device/edgedevice-socket/mock-device kubectl wait --for=condition=Available deploy/socket-mock-device -n devices --timeout=150s + kubectl apply -f examples/deviceshifu/demo_device/edgedevice-socket kubectl wait --for=condition=Available deploy/deviceshifu-socket-deployment -n deviceshifu --timeout=150s - sleep 5 kubectl exec -it -n deviceshifu nginx -- curl -XPOST -H "Content-Type:application/json" deviceshifu-socket.deviceshifu.svc.cluster.local/cmd -d '{"command":"123"}' - kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket + kubectl delete -f examples/deviceshifu/demo_device/edgedevice-socket + kubectl delete -f examples/deviceshifu/demo_device/edgedevice-socket/mock-device displayName: "Shifu demo device Socket E2E test" - stage: docker_build_muiltiarch_and_push condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) diff --git a/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh b/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh index 7d29d2af9..8bb9a4b13 100755 --- a/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh +++ b/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh @@ -8,6 +8,6 @@ mosquitto_pub -h localhost -d -p 18830 -t /test/test -m "test2333" kubectl exec -it -n deviceshifu nginx -- curl deviceshifu-mqtt/mqtt_data if [[ $1 == $default ]]; then - echo "not equal" + echo "not equal" exit 1 fi \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_deployment.yaml index 2e29b1ce7..a2c7acbd6 100644 --- a/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_deployment.yaml @@ -29,6 +29,12 @@ spec: value: "edgedevice-mqtt" - name: EDGEDEVICE_NAMESPACE value: "devices" + readinessProbe: + httpGet: + path: /health + port: 8080 + initialDelaySeconds: 10 + periodSeconds: 10 volumes: - name: deviceshifu-config configMap: diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-deployment.yaml index 2028810b7..f316de88b 100644 --- a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-deployment.yaml @@ -15,9 +15,10 @@ spec: containers: - name: opcua-device image: opcua-mock-device:v0.1.0 - resources: - limits: - memory: "128Mi" - cpu: "500m" ports: - containerPort: 4840 + livenessProbe: + tcpSocket: + port: 4840 + initialDelaySeconds: 3 + periodSeconds: 3 \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_deployment.yaml index 146556d82..cb74aaf29 100644 --- a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_deployment.yaml @@ -32,6 +32,12 @@ spec: value: "edgedevice-opcua" - name: EDGEDEVICE_NAMESPACE value: "devices" + readinessProbe: + httpGet: + path: /health + port: 8080 + initialDelaySeconds: 10 + periodSeconds: 10 volumes: - name: deviceshifu-config configMap: diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py b/examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py index 85561e9bc..b56c328c1 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py +++ b/examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py @@ -5,7 +5,7 @@ while 1: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) - s.listen(1) + s.listen(5) conn, addr = s.accept() print('Connected by', addr) while 1: diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/socket-deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml similarity index 78% rename from examples/deviceshifu/demo_device/edgedevice-socket/socket-deployment.yaml rename to examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml index f818db5e9..a09b62b63 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/socket-deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml @@ -19,5 +19,10 @@ spec: limits: memory: "128Mi" cpu: "500m" + livenessProbe: + tcpSocket: + port: 11122 + initialDelaySeconds: 3 + periodSeconds: 3 ports: - containerPort: 11122 diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/socket-service.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-service.yaml similarity index 100% rename from examples/deviceshifu/demo_device/edgedevice-socket/socket-service.yaml rename to examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-service.yaml diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml index ff50ec770..936979b50 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml @@ -29,6 +29,16 @@ spec: value: "edgedevice-socket" - name: EDGEDEVICE_NAMESPACE value: "devices" + resources: + limits: + memory: "128Mi" + cpu: "500m" + readinessProbe: + httpGet: + path: /health + port: 8080 + initialDelaySeconds: 10 + periodSeconds: 10 volumes: - name: deviceshifu-config configMap: From 4fc9735f26cd0831a6abdc0a839282da029cdd48 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 6 Sep 2022 22:30:16 +0800 Subject: [PATCH 14/31] fix socket connect default --- .../edgedevice-socket/echo_server.py | 19 +++++++++---------- .../mock-device/socket-deployment.yaml | 5 ----- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py b/examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py index b56c328c1..484d21510 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py +++ b/examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py @@ -2,14 +2,13 @@ import socket HOST = '0.0.0.0' # Symbolic name meaning all available interfaces PORT = 11122 # Arbitrary non-privileged port +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +s.bind((HOST, PORT)) +s.listen(5) +conn, addr = s.accept() +print('Connected by', addr) while 1: - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.bind((HOST, PORT)) - s.listen(5) - conn, addr = s.accept() - print('Connected by', addr) - while 1: - data = conn.recv(1024) - if not data: break - conn.sendall(data) - conn.close() \ No newline at end of file + data = conn.recv(1024) + if not data: break + conn.sendall(data) +conn.close() \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml index a09b62b63..f818db5e9 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml @@ -19,10 +19,5 @@ spec: limits: memory: "128Mi" cpu: "500m" - livenessProbe: - tcpSocket: - port: 11122 - initialDelaySeconds: 3 - periodSeconds: 3 ports: - containerPort: 11122 From 2bcbd7b39be5d5be704076d7f871cd5b99f36945 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Wed, 7 Sep 2022 16:21:49 +0800 Subject: [PATCH 15/31] fix pipeline --- azure-pipelines/azure-pipelines.yml | 20 +++++++---- .../edgedevice-mqtt/checkoutput.sh | 11 +++--- .../demo_device/edgedevice-mqtt/dockerfile | 2 ++ .../{ => mock-device}/opcua-deployment.yaml | 2 +- .../{ => mock-device}/opcua-service.yaml | 0 .../demo_device/edgedevice-socket/dockerfile | 10 ++++-- .../edgedevice-socket/echo_server.py | 14 -------- .../mock-device/socket-deployment.yaml | 5 +++ .../demo_device/edgedevice-socket/server.go | 34 +++++++++++++++++++ .../socket_deviceshifu_deployment.yaml | 10 ++++-- .../socketDeviceShifu/socket_edgedevice.yaml | 2 +- .../deviceshifubase/deviceshifubase.go | 5 ++- 12 files changed, 78 insertions(+), 37 deletions(-) create mode 100644 examples/deviceshifu/demo_device/edgedevice-mqtt/dockerfile rename examples/deviceshifu/demo_device/edgedevice-opcua/{ => mock-device}/opcua-deployment.yaml (95%) rename examples/deviceshifu/demo_device/edgedevice-opcua/{ => mock-device}/opcua-service.yaml (100%) delete mode 100644 examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py create mode 100644 examples/deviceshifu/demo_device/edgedevice-socket/server.go diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index 0bb0788ab..b2a8bce96 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -264,29 +264,35 @@ stages: displayName: "Shifu demo device HTTP E2E test" - script: | set -e - kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua + kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device kubectl wait --for=condition=Available deploy/opcua-device -n devices --timeout=150s + kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua kubectl wait --for=condition=Available deploy/deviceshifu-opcua-deployment -n deviceshifu --timeout=150s - kubectl exec -it -n deviceshifu nginx -- curl http://deviceshifu-opcua/get_server + kubectl wait --for=jsonpath='{status.edgedevicephase}'=Running edgedevice/edgedevice-socket -n devices --timeout=150s + kubectl exec -it -n deviceshifu nginx -- curl http://deviceshifu-opcua/get_server;echo kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua + kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device displayName: "Shifu demo device OPCUA E2E test" - script: | set -e kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt kubectl wait --for=condition=Available deploy/mosquitto -n devices --timeout=150s kubectl wait --for=condition=Available deploy/deviceshifu-mqtt-deployment -n deviceshifu --timeout=150s + kubectl run mosquitto -n devices --image=eclipse-mosquitto:2.0.14 + kubectl exec -it mosquitto -n devices -- mosquitto_pub -h mosquitto-service -d -p 18830 -t /test/test -m "test2333" bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh - kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt + kubectl delete -f examples/deviceshifu/demo_device/edgedevice-mqtt + kubectl delete po mosquitto -n devices displayName: "Shifu demo device MQTT E2E test" - script: | set -e - kubectl apply -f examples/deviceshifu/demo_device/edgedevice-socket/mock-device + kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket/mock-device kubectl wait --for=condition=Available deploy/socket-mock-device -n devices --timeout=150s - kubectl apply -f examples/deviceshifu/demo_device/edgedevice-socket + kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket kubectl wait --for=condition=Available deploy/deviceshifu-socket-deployment -n deviceshifu --timeout=150s kubectl exec -it -n deviceshifu nginx -- curl -XPOST -H "Content-Type:application/json" deviceshifu-socket.deviceshifu.svc.cluster.local/cmd -d '{"command":"123"}' - kubectl delete -f examples/deviceshifu/demo_device/edgedevice-socket - kubectl delete -f examples/deviceshifu/demo_device/edgedevice-socket/mock-device + kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket + kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket/mock-device displayName: "Shifu demo device Socket E2E test" - stage: docker_build_muiltiarch_and_push condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) diff --git a/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh b/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh index 8bb9a4b13..bbc08fab7 100755 --- a/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh +++ b/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh @@ -3,11 +3,10 @@ default='{"mqtt_message":"","mqtt_receive_timestamp":"0001-01-01 00:00:00 +0000 UTC"}' -kubectl port-forward svc/mosquitto-service -n devices 18830:18830 & -mosquitto_pub -h localhost -d -p 18830 -t /test/test -m "test2333" -kubectl exec -it -n deviceshifu nginx -- curl deviceshifu-mqtt/mqtt_data +out=(kubectl exec -it -n deviceshifu nginx -- curl deviceshifu-mqtt/mqtt_data) -if [[ $1 == $default ]]; then - echo "not equal" +if [[ $out == $default ]]; then + echo "equal" exit 1 -fi \ No newline at end of file +fi +echo "not equal" \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-mqtt/dockerfile b/examples/deviceshifu/demo_device/edgedevice-mqtt/dockerfile new file mode 100644 index 000000000..74730573c --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-mqtt/dockerfile @@ -0,0 +1,2 @@ +FROM eclipse-mosquitto:latest + diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device/opcua-deployment.yaml similarity index 95% rename from examples/deviceshifu/demo_device/edgedevice-opcua/opcua-deployment.yaml rename to examples/deviceshifu/demo_device/edgedevice-opcua/mock-device/opcua-deployment.yaml index f316de88b..999c6f94a 100644 --- a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device/opcua-deployment.yaml @@ -17,7 +17,7 @@ spec: image: opcua-mock-device:v0.1.0 ports: - containerPort: 4840 - livenessProbe: + readinessProbe: tcpSocket: port: 4840 initialDelaySeconds: 3 diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua-service.yaml b/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device/opcua-service.yaml similarity index 100% rename from examples/deviceshifu/demo_device/edgedevice-opcua/opcua-service.yaml rename to examples/deviceshifu/demo_device/edgedevice-opcua/mock-device/opcua-service.yaml diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile b/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile index b34276bda..303267978 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile +++ b/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile @@ -1,7 +1,11 @@ -FROM python:3.9-slim +FROM golang:1.18-alpine WORKDIR /worker -COPY examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py echo_server.py +COPY examples/deviceshifu/demo_device/edgedevice-socket/server.go server.go -CMD [ "python3","/worker/echo_server.py" ] \ No newline at end of file +RUN go build -o /output/server server.go + +EXPOSE 11122:11122/tcp + +ENTRYPOINT [ "/output/server" ] \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py b/examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py deleted file mode 100644 index 484d21510..000000000 --- a/examples/deviceshifu/demo_device/edgedevice-socket/echo_server.py +++ /dev/null @@ -1,14 +0,0 @@ -# Echo server program -import socket -HOST = '0.0.0.0' # Symbolic name meaning all available interfaces -PORT = 11122 # Arbitrary non-privileged port -s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -s.bind((HOST, PORT)) -s.listen(5) -conn, addr = s.accept() -print('Connected by', addr) -while 1: - data = conn.recv(1024) - if not data: break - conn.sendall(data) -conn.close() \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml index f818db5e9..dca07255f 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml @@ -19,5 +19,10 @@ spec: limits: memory: "128Mi" cpu: "500m" + readinessProbe: + tcpSocket: + port: 11122 + initialDelaySeconds: 3 + periodSeconds: 3 ports: - containerPort: 11122 diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/server.go b/examples/deviceshifu/demo_device/edgedevice-socket/server.go new file mode 100644 index 000000000..5a1a54839 --- /dev/null +++ b/examples/deviceshifu/demo_device/edgedevice-socket/server.go @@ -0,0 +1,34 @@ +package main + +import ( + "log" + "net" +) + +func main() { + addr := "0.0.0.0:11122" + listener, err := net.Listen("tcp", addr) + if err != nil { + panic(err) + } + defer listener.Close() + log.Println("listening at ", addr) + for { + conn, err := listener.Accept() + log.Println(conn.RemoteAddr()) + if err != nil { + break + } + go handleReq(conn) // 启用一个协程处理请求 + } +} +func handleReq(conn net.Conn) { + data := make([]byte, 1024) + _, err := conn.Read(data) + log.Println(string(data), err) + if err != nil { + log.Println(err) + return + } + conn.Write(data) +} diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml index 936979b50..8ef85b61a 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml @@ -37,8 +37,14 @@ spec: httpGet: path: /health port: 8080 - initialDelaySeconds: 10 - periodSeconds: 10 + initialDelaySeconds: 3 + periodSeconds: 3 + livenessProbe: + httpGet: + path: /health + port: 8080 + initialDelaySeconds: 3 + periodSeconds: 3 volumes: - name: deviceshifu-config configMap: diff --git a/examples/socketDeviceShifu/socket_edgedevice.yaml b/examples/socketDeviceShifu/socket_edgedevice.yaml index 5f24f9d26..0ddec47ae 100644 --- a/examples/socketDeviceShifu/socket_edgedevice.yaml +++ b/examples/socketDeviceShifu/socket_edgedevice.yaml @@ -6,7 +6,7 @@ metadata: spec: sku: "testSocket" connection: Ethernet - address: 192.168.15.248:11122 #change this accordingly + address: 192.168.14.163:11122 #change this accordingly protocol: Socket protocolSettings: SocketSetting: diff --git a/pkg/deviceshifu/deviceshifubase/deviceshifubase.go b/pkg/deviceshifu/deviceshifubase/deviceshifubase.go index 3aef7b104..f1dfbd08c 100644 --- a/pkg/deviceshifu/deviceshifubase/deviceshifubase.go +++ b/pkg/deviceshifu/deviceshifubase/deviceshifubase.go @@ -4,11 +4,12 @@ import ( "context" "errors" "fmt" - "github.com/edgenesis/shifu/pkg/k8s/api/v1alpha1" "log" "net/http" "time" + "github.com/edgenesis/shifu/pkg/k8s/api/v1alpha1" + "k8s.io/client-go/rest" ) @@ -76,8 +77,6 @@ func New(deviceShifuMetadata *DeviceShifuMetaData) (*DeviceShifuBase, *http.Serv } mux := http.NewServeMux() - mux.HandleFunc("/health", deviceHealthHandler) - mux.HandleFunc("/", instructionNotFoundHandler) edgeDevice := &v1alpha1.EdgeDevice{} client := &rest.RESTClient{} From f14592f844db88b555f08ed1d39e10f73bf34f41 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Wed, 7 Sep 2022 16:42:49 +0800 Subject: [PATCH 16/31] revert mux --- pkg/deviceshifu/deviceshifubase/deviceshifubase.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/deviceshifu/deviceshifubase/deviceshifubase.go b/pkg/deviceshifu/deviceshifubase/deviceshifubase.go index f1dfbd08c..59222a364 100644 --- a/pkg/deviceshifu/deviceshifubase/deviceshifubase.go +++ b/pkg/deviceshifu/deviceshifubase/deviceshifubase.go @@ -77,6 +77,8 @@ func New(deviceShifuMetadata *DeviceShifuMetaData) (*DeviceShifuBase, *http.Serv } mux := http.NewServeMux() + mux.HandleFunc("/health", deviceHealthHandler) + mux.HandleFunc("/", instructionNotFoundHandler) edgeDevice := &v1alpha1.EdgeDevice{} client := &rest.RESTClient{} From 21a7d8cd2be3216a00ef58c7d07a975287377016 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Wed, 7 Sep 2022 17:02:10 +0800 Subject: [PATCH 17/31] fix pipeline --- azure-pipelines/azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index b2a8bce96..da12eb3db 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -268,7 +268,7 @@ stages: kubectl wait --for=condition=Available deploy/opcua-device -n devices --timeout=150s kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua kubectl wait --for=condition=Available deploy/deviceshifu-opcua-deployment -n deviceshifu --timeout=150s - kubectl wait --for=jsonpath='{status.edgedevicephase}'=Running edgedevice/edgedevice-socket -n devices --timeout=150s + kubectl wait --for=jsonpath='{status.edgedevicephase}'=Running edgedevice/edgedevice-opcua -n devices --timeout=150s kubectl exec -it -n deviceshifu nginx -- curl http://deviceshifu-opcua/get_server;echo kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device From 1a1577fc2d78f87643aca3309247545f95f598b0 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Wed, 7 Sep 2022 17:34:08 +0800 Subject: [PATCH 18/31] fix pipeline --- azure-pipelines/azure-pipelines.yml | 1 + examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index da12eb3db..828b891b1 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -279,6 +279,7 @@ stages: kubectl wait --for=condition=Available deploy/mosquitto -n devices --timeout=150s kubectl wait --for=condition=Available deploy/deviceshifu-mqtt-deployment -n deviceshifu --timeout=150s kubectl run mosquitto -n devices --image=eclipse-mosquitto:2.0.14 + kubectl wait --for=condition=Ready pod/mosquitto -n devices --timeout=150s kubectl exec -it mosquitto -n devices -- mosquitto_pub -h mosquitto-service -d -p 18830 -t /test/test -m "test2333" bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh kubectl delete -f examples/deviceshifu/demo_device/edgedevice-mqtt diff --git a/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh b/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh index bbc08fab7..ef9feace3 100755 --- a/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh +++ b/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh @@ -3,7 +3,7 @@ default='{"mqtt_message":"","mqtt_receive_timestamp":"0001-01-01 00:00:00 +0000 UTC"}' -out=(kubectl exec -it -n deviceshifu nginx -- curl deviceshifu-mqtt/mqtt_data) +out=shell kubectl exec -it -n deviceshifu nginx -- curl deviceshifu-mqtt/mqtt_data if [[ $out == $default ]]; then echo "equal" From ad4668bf6dcc58e1de5db33cd6854a4ac6dbb31f Mon Sep 17 00:00:00 2001 From: liyuqi Date: Wed, 7 Sep 2022 18:01:54 +0800 Subject: [PATCH 19/31] fix pipeline ? --- .../edgedevice-socket/socket_deviceshifu_deployment.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml index 8ef85b61a..56764c740 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml @@ -43,8 +43,8 @@ spec: httpGet: path: /health port: 8080 - initialDelaySeconds: 3 - periodSeconds: 3 + initialDelaySeconds: 10 + periodSeconds: 5 volumes: - name: deviceshifu-config configMap: From 3a47f8600ef44052fc35c047da9f82d2c3ca57c4 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Wed, 7 Sep 2022 19:08:39 +0800 Subject: [PATCH 20/31] fix pipeline --- azure-pipelines/azure-pipelines.yml | 1 + .../edgedevice-socket/mock-device/socket-deployment.yaml | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index 828b891b1..179df5ab1 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -291,6 +291,7 @@ stages: kubectl wait --for=condition=Available deploy/socket-mock-device -n devices --timeout=150s kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket kubectl wait --for=condition=Available deploy/deviceshifu-socket-deployment -n deviceshifu --timeout=150s + kubectl wait --for=jsonpath='{status.edgedevicephase}'=Running edgedevice/edgedevice-socket -n devices --timeout=150s kubectl exec -it -n deviceshifu nginx -- curl -XPOST -H "Content-Type:application/json" deviceshifu-socket.deviceshifu.svc.cluster.local/cmd -d '{"command":"123"}' kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket/mock-device diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml index dca07255f..f818db5e9 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml @@ -19,10 +19,5 @@ spec: limits: memory: "128Mi" cpu: "500m" - readinessProbe: - tcpSocket: - port: 11122 - initialDelaySeconds: 3 - periodSeconds: 3 ports: - containerPort: 11122 From f215817c74d98f95b7bd26493140d9c8e0f4d06f Mon Sep 17 00:00:00 2001 From: liyuqi Date: Wed, 7 Sep 2022 20:57:12 +0800 Subject: [PATCH 21/31] remove resource --- .../edgedevice-socket/mock-device/socket-deployment.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml index f818db5e9..8f42ac024 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml @@ -16,8 +16,5 @@ spec: - name: socket-mock-device image: socket-mock-device:v0.1.0 resources: - limits: - memory: "128Mi" - cpu: "500m" ports: - containerPort: 11122 From 996592450691157233319713d512ee96a5c853d1 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Wed, 7 Sep 2022 21:33:35 +0800 Subject: [PATCH 22/31] refactor pipeline --- azure-pipelines/azure-pipelines.yml | 227 ++++++++++++++++++++-------- 1 file changed, 162 insertions(+), 65 deletions(-) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index 179df5ab1..58a18bbe1 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -38,7 +38,8 @@ pool: vmImage: 'ubuntu-latest' stages: -- stage: go_test_and_build +- stage: go_test_and_kind_e2e_test + condition: succeeded() jobs: - job: go_setup steps: @@ -104,11 +105,8 @@ stages: inputs: command: 'build' workingDirectory: '$(System.DefaultWorkingDirectory)/pkg/driver_util' - -- stage: docker_build_and_kind_e2e_test - condition: succeeded() - jobs: - - job: setup_docker_kubectl_kind + + - job: kind_e2e_test_http steps: - script: | tag=`cat version.txt` && echo "##vso[task.setvariable variable=tag]$tag" @@ -126,12 +124,12 @@ stages: inputs: command: 'get' arguments: 'sigs.k8s.io/kind@v0.14.0' - - task: CmdLine@2 - displayName: "mosquitto Installer" - inputs: - script: | - sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa - sudo apt-get install mosquitto mosquitto-clients + - script: | + docker buildx build --platform=linux/amd64 \ + -f $(System.DefaultWorkingDirectory)/pkg/k8s/crd/Dockerfile \ + --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ + -t edgehub/shifu-controller:$(tag) --load + displayName: build edgehub/shifu-controller - script: | echo $tag docker buildx build --platform=linux/amd64 \ @@ -139,30 +137,6 @@ stages: --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ -t edgehub/deviceshifu-http-http:$(tag) --load displayName: build edgehub/deviceshifu-http-http - - script: | - docker buildx build --platform=linux/amd64 \ - -f $(System.DefaultWorkingDirectory)/dockerfiles/Dockerfile.deviceshifuSocket \ - --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ - -t edgehub/deviceshifu-http-socket:$(tag) --load - displayName: build edgehub/deviceshifu-http-socket - - script: | - docker buildx build --platform=linux/amd64 \ - -f $(System.DefaultWorkingDirectory)/dockerfiles/Dockerfile.deviceshifuMQTT \ - --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ - -t edgehub/deviceshifu-http-mqtt:$(tag) --load - displayName: build edgehub/deviceshifu-http-mqtt - - script: | - docker buildx build --platform=linux/amd64 \ - -f $(System.DefaultWorkingDirectory)/dockerfiles/Dockerfile.deviceshifuOPCUA \ - --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ - -t edgehub/deviceshifu-http-opcua:$(tag) --load - displayName: build deviceshifu-http-opcua - - script: | - docker buildx build --platform=linux/amd64 \ - -f $(System.DefaultWorkingDirectory)/pkg/k8s/crd/Dockerfile \ - --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ - -t edgehub/shifu-controller:$(tag) --load - displayName: build edgehub/shifu-controller - script: | docker buildx build --platform=linux/amd64 \ -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/mockdevice/thermometer/Dockerfile.mockdevice-thermometer \ @@ -193,18 +167,6 @@ stages: --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ -t edgehub/mockdevice-plc:$(tag) --load displayName: build edgehub/mockdevice-plc - - script: | - docker buildx build --platform=linux/amd64 \ - -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile \ - $(System.DefaultWorkingDirectory) \ - -t socket-mock-device:$(tag) --load - displayName: build socket-mock-device - - script: | - docker buildx build --platform=linux/amd64 \ - -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile \ - $(System.DefaultWorkingDirectory) \ - -t opcua-mock-device:$(tag) --load - displayName: build opcua-mock-device - script: | set -e kind --version @@ -216,17 +178,11 @@ stages: kind load docker-image edgehub/mockdevice-agv:$(tag) kind load docker-image edgehub/mockdevice-plc:$(tag) kind load docker-image edgehub/deviceshifu-http-http:$(tag) - kind load docker-image edgehub/deviceshifu-http-mqtt:$(tag) - kind load docker-image edgehub/deviceshifu-http-opcua:$(tag) - kind load docker-image edgehub/deviceshifu-http-socket:$(tag) - kind load docker-image opcua-mock-device:$(tag) - kind load docker-image socket-mock-device:$(tag) kubectl version kubectl apply -f $(System.DefaultWorkingDirectory)/pkg/k8s/crd/install/shifu_install.yml kubectl wait --for=condition=Available deploy/shifu-crd-controller-manager -n shifu-crd-system --timeout=150s displayName: "setup Kind cluster and install Shifu" - - script: | set -e kubectl run nginx --image=nginx -n deviceshifu @@ -262,6 +218,55 @@ stages: kubectl exec -it -n deviceshifu nginx -- curl http://deviceshifu-thermometer/read_value kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-thermometer displayName: "Shifu demo device HTTP E2E test" + + - job: kind_e2e_test_opcua + steps: + - script: | + tag=`cat version.txt` && echo "##vso[task.setvariable variable=tag]$tag" + displayName: Set the tag name as an environment variable + - task: DockerInstaller@0 + displayName: "Docker Installer" + inputs: + dockerVersion: 20.10.9 + releaseType: stable + - task: KubectlInstaller@0 + inputs: + kubectlVersion: latest + - task: Go@0 + displayName: "Kind Installer" + inputs: + command: 'get' + arguments: 'sigs.k8s.io/kind@v0.14.0' + - script: | + docker buildx build --platform=linux/amd64 \ + -f $(System.DefaultWorkingDirectory)/pkg/k8s/crd/Dockerfile \ + --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ + -t edgehub/shifu-controller:$(tag) --load + displayName: build edgehub/shifu-controller + - script: | + docker buildx build --platform=linux/amd64 \ + -f $(System.DefaultWorkingDirectory)/dockerfiles/Dockerfile.deviceshifuOPCUA \ + --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ + -t edgehub/deviceshifu-http-opcua:$(tag) --load + displayName: build deviceshifu-http-opcua + - script: | + docker buildx build --platform=linux/amd64 \ + -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile \ + $(System.DefaultWorkingDirectory) \ + -t opcua-mock-device:$(tag) --load + displayName: build opcua-mock-device + - script: | + set -e + kind --version + kind delete cluster && kind create cluster + kind load docker-image edgehub/shifu-controller:$(tag) + kind load docker-image edgehub/deviceshifu-http-opcua:$(tag) + kind load docker-image opcua-mock-device:$(tag) + + kubectl version + kubectl apply -f $(System.DefaultWorkingDirectory)/pkg/k8s/crd/install/shifu_install.yml + kubectl wait --for=condition=Available deploy/shifu-crd-controller-manager -n shifu-crd-system --timeout=150s + displayName: "setup Kind cluster and install Shifu" - script: | set -e kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device @@ -273,18 +278,55 @@ stages: kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device displayName: "Shifu demo device OPCUA E2E test" + + - job: kind_e2e_test_socket + steps: - script: | - set -e - kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt - kubectl wait --for=condition=Available deploy/mosquitto -n devices --timeout=150s - kubectl wait --for=condition=Available deploy/deviceshifu-mqtt-deployment -n deviceshifu --timeout=150s - kubectl run mosquitto -n devices --image=eclipse-mosquitto:2.0.14 - kubectl wait --for=condition=Ready pod/mosquitto -n devices --timeout=150s - kubectl exec -it mosquitto -n devices -- mosquitto_pub -h mosquitto-service -d -p 18830 -t /test/test -m "test2333" - bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh - kubectl delete -f examples/deviceshifu/demo_device/edgedevice-mqtt - kubectl delete po mosquitto -n devices - displayName: "Shifu demo device MQTT E2E test" + tag=`cat version.txt` && echo "##vso[task.setvariable variable=tag]$tag" + displayName: Set the tag name as an environment variable + - task: DockerInstaller@0 + displayName: "Docker Installer" + inputs: + dockerVersion: 20.10.9 + releaseType: stable + - task: KubectlInstaller@0 + inputs: + kubectlVersion: latest + - task: Go@0 + displayName: "Kind Installer" + inputs: + command: 'get' + arguments: 'sigs.k8s.io/kind@v0.14.0' + - script: | + docker buildx build --platform=linux/amd64 \ + -f $(System.DefaultWorkingDirectory)/pkg/k8s/crd/Dockerfile \ + --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ + -t edgehub/shifu-controller:$(tag) --load + displayName: build edgehub/shifu-controller + - script: | + docker buildx build --platform=linux/amd64 \ + -f $(System.DefaultWorkingDirectory)/dockerfiles/Dockerfile.deviceshifuSocket \ + --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ + -t edgehub/deviceshifu-http-socket:$(tag) --load + displayName: build edgehub/deviceshifu-http-socket + - script: | + docker buildx build --platform=linux/amd64 \ + -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile \ + $(System.DefaultWorkingDirectory) \ + -t socket-mock-device:$(tag) --load + displayName: build socket-mock-device + - script: | + set -e + kind --version + kind delete cluster && kind create cluster + kind load docker-image edgehub/shifu-controller:$(tag) + kind load docker-image edgehub/deviceshifu-http-socket:$(tag) + kind load docker-image socket-mock-device:$(tag) + + kubectl version + kubectl apply -f $(System.DefaultWorkingDirectory)/pkg/k8s/crd/install/shifu_install.yml + kubectl wait --for=condition=Available deploy/shifu-crd-controller-manager -n shifu-crd-system --timeout=150s + displayName: "setup Kind cluster and install Shifu" - script: | set -e kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket/mock-device @@ -296,6 +338,61 @@ stages: kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket/mock-device displayName: "Shifu demo device Socket E2E test" + + - job: kind_e2e_test_mqtt + steps: + - script: | + tag=`cat version.txt` && echo "##vso[task.setvariable variable=tag]$tag" + displayName: Set the tag name as an environment variable + - task: DockerInstaller@0 + displayName: "Docker Installer" + inputs: + dockerVersion: 20.10.9 + releaseType: stable + - task: KubectlInstaller@0 + inputs: + kubectlVersion: latest + - task: Go@0 + displayName: "Kind Installer" + inputs: + command: 'get' + arguments: 'sigs.k8s.io/kind@v0.14.0' + - script: | + docker buildx build --platform=linux/amd64 \ + -f $(System.DefaultWorkingDirectory)/pkg/k8s/crd/Dockerfile \ + --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ + -t edgehub/shifu-controller:$(tag) --load + displayName: build edgehub/shifu-controller + - script: | + docker buildx build --platform=linux/amd64 \ + -f $(System.DefaultWorkingDirectory)/dockerfiles/Dockerfile.deviceshifuMQTT \ + --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ + -t edgehub/deviceshifu-http-mqtt:$(tag) --load + displayName: build edgehub/deviceshifu-http-mqtt + + - script: | + set -e + kind --version + kind delete cluster && kind create cluster + kind load docker-image edgehub/shifu-controller:$(tag) + + kubectl version + kubectl apply -f $(System.DefaultWorkingDirectory)/pkg/k8s/crd/install/shifu_install.yml + kubectl wait --for=condition=Available deploy/shifu-crd-controller-manager -n shifu-crd-system --timeout=150s + displayName: "setup Kind cluster and install Shifu" + - script: | + set -e + kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt + kubectl wait --for=condition=Available deploy/mosquitto -n devices --timeout=150s + kubectl wait --for=condition=Available deploy/deviceshifu-mqtt-deployment -n deviceshifu --timeout=150s + kubectl run mosquitto -n devices --image=eclipse-mosquitto:2.0.14 + kubectl wait --for=condition=Ready pod/mosquitto -n devices --timeout=150s + kubectl exec -it mosquitto -n devices -- mosquitto_pub -h mosquitto-service -d -p 18830 -t /test/test -m "test2333" + bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh + kubectl delete -f examples/deviceshifu/demo_device/edgedevice-mqtt + kubectl delete po mosquitto -n devices + displayName: "Shifu demo device MQTT E2E test" + - stage: docker_build_muiltiarch_and_push condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) variables: From 51e75f941e44ccdb8db78925da9d8da9b17fa046 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Wed, 7 Sep 2022 21:45:00 +0800 Subject: [PATCH 23/31] delete nginx --- azure-pipelines/azure-pipelines.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index 58a18bbe1..bc24307c1 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -269,6 +269,7 @@ stages: displayName: "setup Kind cluster and install Shifu" - script: | set -e + kubectl run nginx --image=nginx -n deviceshifu kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device kubectl wait --for=condition=Available deploy/opcua-device -n devices --timeout=150s kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua @@ -329,6 +330,7 @@ stages: displayName: "setup Kind cluster and install Shifu" - script: | set -e + kubectl run nginx --image=nginx -n deviceshifu kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket/mock-device kubectl wait --for=condition=Available deploy/socket-mock-device -n devices --timeout=150s kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket @@ -338,7 +340,7 @@ stages: kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket/mock-device displayName: "Shifu demo device Socket E2E test" - + - job: kind_e2e_test_mqtt steps: - script: | From 5a3bd493836b97d54f3f6c4008c720d6b534b164 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Wed, 7 Sep 2022 21:48:05 +0800 Subject: [PATCH 24/31] fix_mqtt pipeline --- azure-pipelines/azure-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index bc24307c1..d059c1481 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -384,6 +384,7 @@ stages: displayName: "setup Kind cluster and install Shifu" - script: | set -e + kubectl run nginx --image=nginx -n deviceshifu kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt kubectl wait --for=condition=Available deploy/mosquitto -n devices --timeout=150s kubectl wait --for=condition=Available deploy/deviceshifu-mqtt-deployment -n deviceshifu --timeout=150s From 0216aa69f8609464baccc8a5643c95b8aa849113 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Wed, 7 Sep 2022 22:06:14 +0800 Subject: [PATCH 25/31] fix pipeline --- azure-pipelines/azure-pipelines.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index d059c1481..595842957 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -186,11 +186,11 @@ stages: - script: | set -e kubectl run nginx --image=nginx -n deviceshifu - kubectl wait --for condition=Ready pod/nginx -n deviceshifu --timeout=600s kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-plc kubectl wait --for=condition=Available deploy/plc -n devices --timeout=150s kubectl wait --for=condition=Available deploy/deviceshifu-plc-deployment -n deviceshifu --timeout=150s sleep 5 + kubectl wait --for condition=Ready pod/nginx -n deviceshifu --timeout=150s kubectl exec -it -n deviceshifu nginx -- curl deviceshifu-plc/getcontent?rootsssaddress=Q;echo kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-plc kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-agv @@ -275,6 +275,7 @@ stages: kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua kubectl wait --for=condition=Available deploy/deviceshifu-opcua-deployment -n deviceshifu --timeout=150s kubectl wait --for=jsonpath='{status.edgedevicephase}'=Running edgedevice/edgedevice-opcua -n devices --timeout=150s + kubectl wait --for=condition=Ready pod/nginx -n deviceshifu --timeout=150s kubectl exec -it -n deviceshifu nginx -- curl http://deviceshifu-opcua/get_server;echo kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device @@ -336,6 +337,7 @@ stages: kubectl apply -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket kubectl wait --for=condition=Available deploy/deviceshifu-socket-deployment -n deviceshifu --timeout=150s kubectl wait --for=jsonpath='{status.edgedevicephase}'=Running edgedevice/edgedevice-socket -n devices --timeout=150s + kubectl wait --for=condition=Ready pod/nginx -n deviceshifu --timeout=150s kubectl exec -it -n deviceshifu nginx -- curl -XPOST -H "Content-Type:application/json" deviceshifu-socket.deviceshifu.svc.cluster.local/cmd -d '{"command":"123"}' kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket/mock-device @@ -391,6 +393,7 @@ stages: kubectl run mosquitto -n devices --image=eclipse-mosquitto:2.0.14 kubectl wait --for=condition=Ready pod/mosquitto -n devices --timeout=150s kubectl exec -it mosquitto -n devices -- mosquitto_pub -h mosquitto-service -d -p 18830 -t /test/test -m "test2333" + kubectl wait --for=condition=Ready pod/nginx -n deviceshifu --timeout=150s bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh kubectl delete -f examples/deviceshifu/demo_device/edgedevice-mqtt kubectl delete po mosquitto -n devices From b905ad4107db8e31d40cc046d67b3d88332222f2 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Thu, 8 Sep 2022 10:55:21 +0800 Subject: [PATCH 26/31] fix pipeline --- azure-pipelines/azure-pipelines.yml | 31 +++++++++++++------ .../edgedevice-mqtt/checkoutput.sh | 12 ------- .../demo_device/edgedevice-mqtt/dockerfile | 2 -- .../mock-device/opcua-deployment.yaml | 2 +- .../mockdevice/mqtt/checkoutput.sh | 20 ++++++++++++ .../opcua/Dockerfile.mockdevice-opcua} | 0 .../deviceshifu/mockdevice/opcua/checkout.sh | 20 ++++++++++++ .../socket/Dockerfile.mockdevice-socket} | 2 +- .../deviceshifu/mockdevice/socket/checkout.sh | 20 ++++++++++++ .../server}/server.go | 0 10 files changed, 83 insertions(+), 26 deletions(-) delete mode 100755 examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh delete mode 100644 examples/deviceshifu/demo_device/edgedevice-mqtt/dockerfile create mode 100755 examples/deviceshifu/mockdevice/mqtt/checkoutput.sh rename examples/deviceshifu/{demo_device/edgedevice-opcua/dockerfile => mockdevice/opcua/Dockerfile.mockdevice-opcua} (100%) create mode 100644 examples/deviceshifu/mockdevice/opcua/checkout.sh rename examples/deviceshifu/{demo_device/edgedevice-socket/dockerfile => mockdevice/socket/Dockerfile.mockdevice-socket} (64%) create mode 100644 examples/deviceshifu/mockdevice/socket/checkout.sh rename examples/{deviceshifu/demo_device/edgedevice-socket => socketDeviceShifu/server}/server.go (100%) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index 595842957..01fcdebae 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -251,9 +251,9 @@ stages: displayName: build deviceshifu-http-opcua - script: | docker buildx build --platform=linux/amd64 \ - -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile \ + -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/mockdevice/opcua/Dockerfile.mockdevice-opcua \ $(System.DefaultWorkingDirectory) \ - -t opcua-mock-device:$(tag) --load + -t edgehub/opcua-mock-device:$(tag) --load displayName: build opcua-mock-device - script: | set -e @@ -261,7 +261,7 @@ stages: kind delete cluster && kind create cluster kind load docker-image edgehub/shifu-controller:$(tag) kind load docker-image edgehub/deviceshifu-http-opcua:$(tag) - kind load docker-image opcua-mock-device:$(tag) + kind load docker-image edgehub/opcua-mock-device:$(tag) kubectl version kubectl apply -f $(System.DefaultWorkingDirectory)/pkg/k8s/crd/install/shifu_install.yml @@ -276,7 +276,7 @@ stages: kubectl wait --for=condition=Available deploy/deviceshifu-opcua-deployment -n deviceshifu --timeout=150s kubectl wait --for=jsonpath='{status.edgedevicephase}'=Running edgedevice/edgedevice-opcua -n devices --timeout=150s kubectl wait --for=condition=Ready pod/nginx -n deviceshifu --timeout=150s - kubectl exec -it -n deviceshifu nginx -- curl http://deviceshifu-opcua/get_server;echo + bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/mockdevice/opcua/checkoutput.sh kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device displayName: "Shifu demo device OPCUA E2E test" @@ -313,9 +313,9 @@ stages: displayName: build edgehub/deviceshifu-http-socket - script: | docker buildx build --platform=linux/amd64 \ - -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile \ + -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/mockdevice/socket/Dockerfile.mockdevice-socket \ $(System.DefaultWorkingDirectory) \ - -t socket-mock-device:$(tag) --load + -t edgehub/socket-mock-device:$(tag) --load displayName: build socket-mock-device - script: | set -e @@ -323,7 +323,7 @@ stages: kind delete cluster && kind create cluster kind load docker-image edgehub/shifu-controller:$(tag) kind load docker-image edgehub/deviceshifu-http-socket:$(tag) - kind load docker-image socket-mock-device:$(tag) + kind load docker-image edgehub/socket-mock-device:$(tag) kubectl version kubectl apply -f $(System.DefaultWorkingDirectory)/pkg/k8s/crd/install/shifu_install.yml @@ -338,7 +338,7 @@ stages: kubectl wait --for=condition=Available deploy/deviceshifu-socket-deployment -n deviceshifu --timeout=150s kubectl wait --for=jsonpath='{status.edgedevicephase}'=Running edgedevice/edgedevice-socket -n devices --timeout=150s kubectl wait --for=condition=Ready pod/nginx -n deviceshifu --timeout=150s - kubectl exec -it -n deviceshifu nginx -- curl -XPOST -H "Content-Type:application/json" deviceshifu-socket.deviceshifu.svc.cluster.local/cmd -d '{"command":"123"}' + bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/mockdevice/socket/checkoutput.sh kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket/mock-device displayName: "Shifu demo device Socket E2E test" @@ -394,7 +394,7 @@ stages: kubectl wait --for=condition=Ready pod/mosquitto -n devices --timeout=150s kubectl exec -it mosquitto -n devices -- mosquitto_pub -h mosquitto-service -d -p 18830 -t /test/test -m "test2333" kubectl wait --for=condition=Ready pod/nginx -n deviceshifu --timeout=150s - bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh + bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/mockdevice/mqtt/checkoutput.sh kubectl delete -f examples/deviceshifu/demo_device/edgedevice-mqtt kubectl delete po mosquitto -n devices displayName: "Shifu demo device MQTT E2E test" @@ -419,7 +419,6 @@ stages: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes docker buildx create --use displayName: configure multi-arch and buildx - - script: | docker buildx build --platform=linux/amd64,linux/arm64,linux/arm \ -f $(System.DefaultWorkingDirectory)/dockerfiles/Dockerfile.deviceshifuHTTP \ @@ -483,3 +482,15 @@ stages: --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ -t edgehub/mockdevice-plc:$(release_tag) --push displayName: build edgehub/mockdevice-plc + - script: | + docker buildx build --platform=linux/amd64,linux/arm64,linux/arm \ + -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/mockdevice/socket/Dockerfile.mockdevice-socket \ + --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ + -t edgehub/mockdevice-socket:$(release_tag) --push + displayName: build edgehub/mockdevice-socket + - script: | + docker buildx build --platform=linux/amd64,linux/arm64,linux/arm \ + -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/mockdevice/opcua/Dockerfile.mockdevice-opcua \ + --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ + -t edgehub/mockdevice-opcua:$(release_tag) --push + displayName: build edgehub/mockdevice-opcua \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh b/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh deleted file mode 100755 index ef9feace3..000000000 --- a/examples/deviceshifu/demo_device/edgedevice-mqtt/checkoutput.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!bin/bash - -default='{"mqtt_message":"","mqtt_receive_timestamp":"0001-01-01 00:00:00 +0000 UTC"}' - - -out=shell kubectl exec -it -n deviceshifu nginx -- curl deviceshifu-mqtt/mqtt_data - -if [[ $out == $default ]]; then - echo "equal" - exit 1 -fi -echo "not equal" \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-mqtt/dockerfile b/examples/deviceshifu/demo_device/edgedevice-mqtt/dockerfile deleted file mode 100644 index 74730573c..000000000 --- a/examples/deviceshifu/demo_device/edgedevice-mqtt/dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM eclipse-mosquitto:latest - diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device/opcua-deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device/opcua-deployment.yaml index 999c6f94a..61126597e 100644 --- a/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device/opcua-deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device/opcua-deployment.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: opcua-device - image: opcua-mock-device:v0.1.0 + image: edgehub/opcua-mock-device:v0.1.0 ports: - containerPort: 4840 readinessProbe: diff --git a/examples/deviceshifu/mockdevice/mqtt/checkoutput.sh b/examples/deviceshifu/mockdevice/mqtt/checkoutput.sh new file mode 100755 index 000000000..e925680da --- /dev/null +++ b/examples/deviceshifu/mockdevice/mqtt/checkoutput.sh @@ -0,0 +1,20 @@ +#!bin/bash + +default='{"mqtt_message":"","mqtt_receive_timestamp":"0001-01-01 00:00:00 +0000 UTC"}' + +for i in {1..5} +do + out=(shell kubectl exec -it -n deviceshifu nginx -- curl deviceshifu-mqtt/mqtt_data --connect-timeout 5) + + if [[ $out == "" ]] + then + echo "empty reply" + elif [[ $out != $default ]] + then + echo "not euqal" + exit 0 + else + exit 1 + fi +done +exit 1 \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile b/examples/deviceshifu/mockdevice/opcua/Dockerfile.mockdevice-opcua similarity index 100% rename from examples/deviceshifu/demo_device/edgedevice-opcua/dockerfile rename to examples/deviceshifu/mockdevice/opcua/Dockerfile.mockdevice-opcua diff --git a/examples/deviceshifu/mockdevice/opcua/checkout.sh b/examples/deviceshifu/mockdevice/opcua/checkout.sh new file mode 100644 index 000000000..30804602c --- /dev/null +++ b/examples/deviceshifu/mockdevice/opcua/checkout.sh @@ -0,0 +1,20 @@ +#!bin/bash + +default='FreeOpcUa Python Server' + +for i in {1..5} +do + out=(shell kubectl exec -it -n deviceshifu nginx -- curl deviceshifu-opcua/get_server --connect-timeout 5) + + if [[ $out == "" ]] + then + echo "empty reply" + elif [[ $out != $default ]] + then + echo "not euqal" + exit 0 + else + exit 1 + fi +done +exit 1 \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile b/examples/deviceshifu/mockdevice/socket/Dockerfile.mockdevice-socket similarity index 64% rename from examples/deviceshifu/demo_device/edgedevice-socket/dockerfile rename to examples/deviceshifu/mockdevice/socket/Dockerfile.mockdevice-socket index 303267978..3fb9c41a5 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/dockerfile +++ b/examples/deviceshifu/mockdevice/socket/Dockerfile.mockdevice-socket @@ -2,7 +2,7 @@ FROM golang:1.18-alpine WORKDIR /worker -COPY examples/deviceshifu/demo_device/edgedevice-socket/server.go server.go +COPY examples/socketDeviceshifu/server/server.go server.go RUN go build -o /output/server server.go diff --git a/examples/deviceshifu/mockdevice/socket/checkout.sh b/examples/deviceshifu/mockdevice/socket/checkout.sh new file mode 100644 index 000000000..49de4123f --- /dev/null +++ b/examples/deviceshifu/mockdevice/socket/checkout.sh @@ -0,0 +1,20 @@ +#!bin/bash + +default='{"message":"123\n","status":200}' + +for i in {1..5} +do + out=(kubectl exec -it -n deviceshifu nginx -- curl -XPOST -H "Content-Type:application/json" deviceshifu-socket.deviceshifu.svc.cluster.local/cmd -d '{"command":"123"}' --connect-timeout 5) + + if [[ $out == "" ]] + then + echo "empty reply" + elif [[ $out != $default ]] + then + echo "not euqal" + exit 0 + else + exit 1 + fi +done +exit 1 \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/server.go b/examples/socketDeviceShifu/server/server.go similarity index 100% rename from examples/deviceshifu/demo_device/edgedevice-socket/server.go rename to examples/socketDeviceShifu/server/server.go From 34a38f09880cbde8cd75d847e3e5d8da60af4d7a Mon Sep 17 00:00:00 2001 From: liyuqi Date: Thu, 8 Sep 2022 11:05:28 +0800 Subject: [PATCH 27/31] fix pipeline --- azure-pipelines/azure-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index 01fcdebae..0a08ea31c 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -276,7 +276,7 @@ stages: kubectl wait --for=condition=Available deploy/deviceshifu-opcua-deployment -n deviceshifu --timeout=150s kubectl wait --for=jsonpath='{status.edgedevicephase}'=Running edgedevice/edgedevice-opcua -n devices --timeout=150s kubectl wait --for=condition=Ready pod/nginx -n deviceshifu --timeout=150s - bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/mockdevice/opcua/checkoutput.sh + bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/mockdevice/opcua/checkout.sh kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device displayName: "Shifu demo device OPCUA E2E test" @@ -338,7 +338,7 @@ stages: kubectl wait --for=condition=Available deploy/deviceshifu-socket-deployment -n deviceshifu --timeout=150s kubectl wait --for=jsonpath='{status.edgedevicephase}'=Running edgedevice/edgedevice-socket -n devices --timeout=150s kubectl wait --for=condition=Ready pod/nginx -n deviceshifu --timeout=150s - bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/mockdevice/socket/checkoutput.sh + bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/mockdevice/socket/checkout.sh kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-socket/mock-device displayName: "Shifu demo device Socket E2E test" From af3c6b0cebe042d471655abe5c27de61bae4d3cf Mon Sep 17 00:00:00 2001 From: liyuqi Date: Thu, 8 Sep 2022 11:40:25 +0800 Subject: [PATCH 28/31] fix dockerfile --- .../deviceshifu/mockdevice/socket/Dockerfile.mockdevice-socket | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/deviceshifu/mockdevice/socket/Dockerfile.mockdevice-socket b/examples/deviceshifu/mockdevice/socket/Dockerfile.mockdevice-socket index 3fb9c41a5..f7f54ea4b 100644 --- a/examples/deviceshifu/mockdevice/socket/Dockerfile.mockdevice-socket +++ b/examples/deviceshifu/mockdevice/socket/Dockerfile.mockdevice-socket @@ -2,7 +2,7 @@ FROM golang:1.18-alpine WORKDIR /worker -COPY examples/socketDeviceshifu/server/server.go server.go +COPY examples/socketDeviceShifu/server/server.go server.go RUN go build -o /output/server server.go From 2bf08dd2f0b1f89d949bcf1bf2497b22b2ef71bd Mon Sep 17 00:00:00 2001 From: liyuqi Date: Thu, 8 Sep 2022 12:09:30 +0800 Subject: [PATCH 29/31] fix deployment --- .../edgedevice-socket/mock-device/socket-deployment.yaml | 1 - .../edgedevice-socket/socket_deviceshifu_deployment.yaml | 4 ---- 2 files changed, 5 deletions(-) diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml index 8f42ac024..7614c4264 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml @@ -15,6 +15,5 @@ spec: containers: - name: socket-mock-device image: socket-mock-device:v0.1.0 - resources: ports: - containerPort: 11122 diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml index 56764c740..ad188eb53 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-socket/socket_deviceshifu_deployment.yaml @@ -29,10 +29,6 @@ spec: value: "edgedevice-socket" - name: EDGEDEVICE_NAMESPACE value: "devices" - resources: - limits: - memory: "128Mi" - cpu: "500m" readinessProbe: httpGet: path: /health From dbdbe57625436f3468e849d619ebaa73e7601d24 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Thu, 8 Sep 2022 12:21:04 +0800 Subject: [PATCH 30/31] fix image name --- .../edgedevice-socket/mock-device/socket-deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml index 7614c4264..21155c74b 100644 --- a/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-socket/mock-device/socket-deployment.yaml @@ -14,6 +14,6 @@ spec: spec: containers: - name: socket-mock-device - image: socket-mock-device:v0.1.0 + image: edgehub/socket-mock-device:v0.1.0 ports: - containerPort: 11122 From 20e7f849f924023dcecebffd2ea7c07a5c2e669c Mon Sep 17 00:00:00 2001 From: liyuqi Date: Thu, 8 Sep 2022 14:32:22 +0800 Subject: [PATCH 31/31] fix bug --- azure-pipelines/azure-pipelines.yml | 4 +-- .../edgedevice-mqtt/mosquitto.yaml | 2 +- .../mqtt_deviceshifu_configmap.yaml | 1 - .../mock-device/opcua-deployment.yaml | 2 +- .../opcua_deviceshifu_configmap.yaml | 1 - .../opcua_deviceshifu_service.yaml | 1 - .../edgedevice-opcua/requirements.txt | 2 -- .../demo_device/edgedevice-opcua/server.py | 34 ------------------- .../mockdevice/mqtt/checkoutput.sh | 14 ++++---- .../opcua/Dockerfile.mockdevice-opcua | 4 +-- .../deviceshifu/mockdevice/opcua/checkout.sh | 10 +++--- .../deviceshifu/mockdevice/socket/checkout.sh | 16 +++++---- .../opcuaDeviceShifu/server/requirements.txt | 1 - examples/socketDeviceShifu/server/server.go | 20 ++++++----- .../socketDeviceShifu/socket_edgedevice.yaml | 2 +- 15 files changed, 42 insertions(+), 72 deletions(-) delete mode 100644 examples/deviceshifu/demo_device/edgedevice-opcua/requirements.txt delete mode 100644 examples/deviceshifu/demo_device/edgedevice-opcua/server.py diff --git a/azure-pipelines/azure-pipelines.yml b/azure-pipelines/azure-pipelines.yml index 0a08ea31c..6b217d7b4 100644 --- a/azure-pipelines/azure-pipelines.yml +++ b/azure-pipelines/azure-pipelines.yml @@ -39,7 +39,6 @@ pool: stages: - stage: go_test_and_kind_e2e_test - condition: succeeded() jobs: - job: go_setup steps: @@ -392,7 +391,6 @@ stages: kubectl wait --for=condition=Available deploy/deviceshifu-mqtt-deployment -n deviceshifu --timeout=150s kubectl run mosquitto -n devices --image=eclipse-mosquitto:2.0.14 kubectl wait --for=condition=Ready pod/mosquitto -n devices --timeout=150s - kubectl exec -it mosquitto -n devices -- mosquitto_pub -h mosquitto-service -d -p 18830 -t /test/test -m "test2333" kubectl wait --for=condition=Ready pod/nginx -n deviceshifu --timeout=150s bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/mockdevice/mqtt/checkoutput.sh kubectl delete -f examples/deviceshifu/demo_device/edgedevice-mqtt @@ -493,4 +491,4 @@ stages: -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/mockdevice/opcua/Dockerfile.mockdevice-opcua \ --build-arg PROJECT_ROOT="$(System.DefaultWorkingDirectory)" $(System.DefaultWorkingDirectory) \ -t edgehub/mockdevice-opcua:$(release_tag) --push - displayName: build edgehub/mockdevice-opcua \ No newline at end of file + displayName: build edgehub/mockdevice-opcua diff --git a/examples/deviceshifu/demo_device/edgedevice-mqtt/mosquitto.yaml b/examples/deviceshifu/demo_device/edgedevice-mqtt/mosquitto.yaml index 8c78812da..75667cd5b 100644 --- a/examples/deviceshifu/demo_device/edgedevice-mqtt/mosquitto.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-mqtt/mosquitto.yaml @@ -50,4 +50,4 @@ spec: - name: mosquitto protocol: TCP port: 18830 - targetPort: 1883 \ No newline at end of file + targetPort: 1883 diff --git a/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_configmap.yaml b/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_configmap.yaml index 6ebf8d327..e22432fdc 100644 --- a/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_configmap.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-mqtt/mqtt_deviceshifu_configmap.yaml @@ -13,4 +13,3 @@ data: telemetries: device_health: properties: - diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device/opcua-deployment.yaml b/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device/opcua-deployment.yaml index 61126597e..4ae2fee20 100644 --- a/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device/opcua-deployment.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device/opcua-deployment.yaml @@ -21,4 +21,4 @@ spec: tcpSocket: port: 4840 initialDelaySeconds: 3 - periodSeconds: 3 \ No newline at end of file + periodSeconds: 3 diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_configmap.yaml b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_configmap.yaml index eafa95604..acf5d3588 100644 --- a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_configmap.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_configmap.yaml @@ -27,4 +27,3 @@ data: instruction: get_server initialDelayMs: 1000 intervalMs: 1000 - \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_service.yaml b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_service.yaml index 51d937f6b..00a9970dc 100644 --- a/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_service.yaml +++ b/examples/deviceshifu/demo_device/edgedevice-opcua/opcua_deviceshifu_service.yaml @@ -13,4 +13,3 @@ spec: selector: app: deviceshifu-opcua-deployment type: LoadBalancer - \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/requirements.txt b/examples/deviceshifu/demo_device/edgedevice-opcua/requirements.txt deleted file mode 100644 index 3f17f411a..000000000 --- a/examples/deviceshifu/demo_device/edgedevice-opcua/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -asyncua -opcua \ No newline at end of file diff --git a/examples/deviceshifu/demo_device/edgedevice-opcua/server.py b/examples/deviceshifu/demo_device/edgedevice-opcua/server.py deleted file mode 100644 index 3718dc49f..000000000 --- a/examples/deviceshifu/demo_device/edgedevice-opcua/server.py +++ /dev/null @@ -1,34 +0,0 @@ -import sys -sys.path.insert(0, "..") -import time -from opcua import ua, Server - -if __name__ == "__main__": - # setup our server - server = Server() - server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/") - - # setup our own namespace, not really necessary but should as spec - uri = "http://examples.freeopcua.github.io" - idx = server.register_namespace(uri) - - # get Objects node, this is where we should put our nodes - objects = server.get_objects_node() - - # populating our address space - myobj = objects.add_object(idx, "MyObject") - myvar = myobj.add_variable(idx, "MyVariable", 6.7) - myvar.set_writable() # Set MyVariable to be writable by clients - - # starting! - server.start() - - try: - count = 0 - while True: - time.sleep(1) - count += 0.1 - myvar.set_value(count) - finally: - #close connection, remove subcsriptions, etc - server.stop() diff --git a/examples/deviceshifu/mockdevice/mqtt/checkoutput.sh b/examples/deviceshifu/mockdevice/mqtt/checkoutput.sh index e925680da..cd5908c79 100755 --- a/examples/deviceshifu/mockdevice/mqtt/checkoutput.sh +++ b/examples/deviceshifu/mockdevice/mqtt/checkoutput.sh @@ -4,17 +4,19 @@ default='{"mqtt_message":"","mqtt_receive_timestamp":"0001-01-01 00:00:00 +0000 for i in {1..5} do - out=(shell kubectl exec -it -n deviceshifu nginx -- curl deviceshifu-mqtt/mqtt_data --connect-timeout 5) + kubectl exec -it mosquitto -n devices -- mosquitto_pub -h mosquitto-service -d -p 18830 -t /test/test -m "test2333" + out=$(kubectl exec -it -n deviceshifu nginx -- curl deviceshifu-mqtt/mqtt_data --connect-timeout 5) + echo $out + echo $default if [[ $out == "" ]] then echo "empty reply" - elif [[ $out != $default ]] + elif [[ $out == $default ]] then - echo "not euqal" - exit 0 + echo "euqal default message" else - exit 1 + exit 0 fi done -exit 1 \ No newline at end of file +exit 1 diff --git a/examples/deviceshifu/mockdevice/opcua/Dockerfile.mockdevice-opcua b/examples/deviceshifu/mockdevice/opcua/Dockerfile.mockdevice-opcua index 6fb049319..f41e137af 100644 --- a/examples/deviceshifu/mockdevice/opcua/Dockerfile.mockdevice-opcua +++ b/examples/deviceshifu/mockdevice/opcua/Dockerfile.mockdevice-opcua @@ -2,8 +2,8 @@ FROM python:3.9-slim WORKDIR /worker -COPY examples/deviceshifu/demo_device/edgedevice-opcua/requirements.txt requirements.txt -COPY examples/deviceshifu/demo_device/edgedevice-opcua/server.py server.py +COPY examples/opcuaDeviceShifu/server/requirements.txt requirements.txt +COPY examples/opcuaDeviceShifu/server/server.py server.py RUN pip3 install -r requirements.txt diff --git a/examples/deviceshifu/mockdevice/opcua/checkout.sh b/examples/deviceshifu/mockdevice/opcua/checkout.sh index 30804602c..95390417d 100644 --- a/examples/deviceshifu/mockdevice/opcua/checkout.sh +++ b/examples/deviceshifu/mockdevice/opcua/checkout.sh @@ -4,17 +4,19 @@ default='FreeOpcUa Python Server' for i in {1..5} do - out=(shell kubectl exec -it -n deviceshifu nginx -- curl deviceshifu-opcua/get_server --connect-timeout 5) + out=$(kubectl exec -it -n deviceshifu nginx -- curl deviceshifu-opcua/get_server --connect-timeout 5) + echo $out + echo $default if [[ $out == "" ]] then echo "empty reply" - elif [[ $out != $default ]] + elif [[ $out == $default ]] then - echo "not euqal" + echo "equal" exit 0 else exit 1 fi done -exit 1 \ No newline at end of file +exit 1 diff --git a/examples/deviceshifu/mockdevice/socket/checkout.sh b/examples/deviceshifu/mockdevice/socket/checkout.sh index 49de4123f..dd54575c2 100644 --- a/examples/deviceshifu/mockdevice/socket/checkout.sh +++ b/examples/deviceshifu/mockdevice/socket/checkout.sh @@ -1,20 +1,24 @@ #!bin/bash -default='{"message":"123\n","status":200}' +default='{"message":"123\n","status":200}' for i in {1..5} do - out=(kubectl exec -it -n deviceshifu nginx -- curl -XPOST -H "Content-Type:application/json" deviceshifu-socket.deviceshifu.svc.cluster.local/cmd -d '{"command":"123"}' --connect-timeout 5) - + out=$(kubectl exec -it -n deviceshifu nginx -- curl -XPOST -H "Content-Type:application/json" deviceshifu-socket.deviceshifu.svc.cluster.local/cmd -d '{"command":"123"}' --connect-timeout 5) + out=${out:13-1:3} + default=${default:13-1:3} + echo $out + echo $default if [[ $out == "" ]] then echo "empty reply" - elif [[ $out != $default ]] + elif [[ $out == $default ]] then - echo "not euqal" + echo "equal with default message~" exit 0 else + echo "not match" exit 1 fi done -exit 1 \ No newline at end of file +exit 1 diff --git a/examples/opcuaDeviceShifu/server/requirements.txt b/examples/opcuaDeviceShifu/server/requirements.txt index 3f17f411a..426a6ec3e 100644 --- a/examples/opcuaDeviceShifu/server/requirements.txt +++ b/examples/opcuaDeviceShifu/server/requirements.txt @@ -1,2 +1 @@ -asyncua opcua \ No newline at end of file diff --git a/examples/socketDeviceShifu/server/server.go b/examples/socketDeviceShifu/server/server.go index 5a1a54839..ef182ab58 100644 --- a/examples/socketDeviceShifu/server/server.go +++ b/examples/socketDeviceShifu/server/server.go @@ -19,16 +19,20 @@ func main() { if err != nil { break } - go handleReq(conn) // 启用一个协程处理请求 + + go handleReq(conn) } } func handleReq(conn net.Conn) { - data := make([]byte, 1024) - _, err := conn.Read(data) - log.Println(string(data), err) - if err != nil { - log.Println(err) - return + for { + data := make([]byte, 1024) + _, err := conn.Read(data) + log.Println(string(data), err) + if err != nil { + log.Println(err) + return + } + + conn.Write(data) } - conn.Write(data) } diff --git a/examples/socketDeviceShifu/socket_edgedevice.yaml b/examples/socketDeviceShifu/socket_edgedevice.yaml index 0ddec47ae..5f24f9d26 100644 --- a/examples/socketDeviceShifu/socket_edgedevice.yaml +++ b/examples/socketDeviceShifu/socket_edgedevice.yaml @@ -6,7 +6,7 @@ metadata: spec: sku: "testSocket" connection: Ethernet - address: 192.168.14.163:11122 #change this accordingly + address: 192.168.15.248:11122 #change this accordingly protocol: Socket protocolSettings: SocketSetting: