kubeedge icon indicating copy to clipboard operation
kubeedge copied to clipboard

Virtualdevice mapper registration failed

Open luchaoshi45 opened this issue 1 year ago • 8 comments

I have kcloude (192.168.1.200) and kedge1 (192.168.1.201). I try to debug my mapper because I can't guarantee that every line of code is correct. For example, I use kubedege1.17, and I want to generate a mapper for virtualdevice. I clone kubeedge 1.17 to kedge1 and then use make template to generate a template, refer to kubeedge 1.15's virtualdevice mapper to modify the file, and then use Goland to debug my code.

The mapper-framework I used is https://github.com/kubeedge/kubeedge/tree/release-1.17/staging/src/github.com/kubeedge/mapper-framework I want to migrate mapeer: https://github.com/kubeedge/mappers-go/pull/112/commits/2138b6ef6fec527704e04b9e11e1f215f95fb6ab#diff-ae84a7a7fd552878514d679c7678de47bdd5a011dadbbe24f8abe65cc35eef33

Errors during debugging -> deviceList, deviceModelList, err are all empty

staging/src/github.com/kubeedge/virtualdevice/cmd/main.go deviceList, deviceModelList, err := grpcclient.RegisterMapper(true) deviceList, deviceModelList, err are all nil

func main() {
	var err error
	var c *config.Config

	klog.InitFlags(nil)
	defer klog.Flush()

	if c, err = config.Parse(); err != nil {
		klog.Fatal(err)
	}
	klog.Infof("config: %+v", c)

	klog.Infoln("Mapper will register to edgecore")
	deviceList, deviceModelList, err := grpcclient.RegisterMapper(true)
	if err != nil {
		klog.Fatal(err)
	}
	klog.Infoln("Mapper register finished")

	panel := device.NewDevPanel()
	err = panel.DevInit(deviceList, deviceModelList)
	if err != nil && !errors.Is(err, device.ErrEmptyData) {
		klog.Fatal(err)
	}
	klog.Infoln("devInit finished")
	go panel.DevStart()

	// start http server
	httpServer := httpserver.NewRestServer(panel, c.Common.HTTPPort)
	go httpServer.StartServer()

	// start grpc server
	grpcServer := grpcserver.NewServer(
		grpcserver.Config{
			SockPath: c.GrpcServer.SocketPath,
			Protocol: common.ProtocolCustomized,
		},
		panel,
	)
	defer grpcServer.Stop()
	if err = grpcServer.Start(); err != nil {
		klog.Fatal(err)
	}

}

Environment

Linux kedge1 6.5.0-18-generic #18~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 7 11:40:03 UTC 2 x86_64 x86_64 x86_64 GNU/Linux go version go1.22.2 linux/amd64

NAME       STATUS   ROLES           AGE   VERSION
kedge1     Ready    agent,edge      8d    v1.28.6-kubeedge-v1.17.0
kmaster1   Ready    control-plane   8d    v1.27.15
  • Kubernetes version (use 1.27.15):
  • KubeEdge version(e.g. cloudcore --1.17.0 and edgecore --1.17.0): image image

luchaoshi45 avatar Jul 07 '24 11:07 luchaoshi45

/sig device-iot cc @wbc6080

Shelley-BaoYue avatar Jul 08 '24 01:07 Shelley-BaoYue

The description of the problem is a little unclear. Have you submitted the configuration files of device-model and device-instance yaml to the kubeedge cluster? Is the mapper configuration file set correctly? Does the mapper log output Mapper register finished? If there are no problems with the above, you can check edgecore's logs.

wbc6080 avatar Jul 08 '24 02:07 wbc6080

Thank you very much for your reply, here is my yaml file

virtualdevice-instance.yaml

cat virtualdevice-instance.yaml
apiVersion: devices.kubeedge.io/v1beta1
kind: Device
metadata:
  name: random-instance-01
  labels:
    model: random-01
spec:
  deviceModelRef:
    name: random-01
  protocol:
    protocolName: virtualProtocol  # in your mapper, this should be replaced by the protocol name your use
    configData:
      deviceID: 2
      serialPort: '/dev/ttyS0'
      baudRate: 9600
      dataBits: 8
      parity: even
      stopBits: 1
      protocolID: 1
  nodeName: kedge1 # config
  properties:
    - name: random-int
      visitors:
        protocolName: virtualProtocol # in your mapper, this should be replaced by the protocol name your use
        configData:
          dataType: int
      reportCycle: 10000000000
      collectCycle: 10000000000
      reportToCloud: true
      pushMethod:
        mqtt:
          address: tcp://127.0.0.1:1883 # replace it by the url of your mqtt client
          topic: random-int
          qos: 0
          retained: false
    - name: random-float
      visitors:
        protocolName: virtualProtocol
        configData:
          dataType: float
      reportCycle: 10000000000
      collectCycle: 10000000000
      reportToCloud: true
      pushMethod:
        mqtt:
          address: tcp://127.0.0.1:1883
          topic: random-float
          qos: 0
          retained: false
status:
  twins:
    - propertyName: random-int
      reported:
        metadata:
          timestamp: '1550049403598'
          type: integer
        value: "100"
      observedDesired:
        metadata:
          timestamp: '1550049403598'
          type: integer
        value: "100"
    - propertyName: random-float
      reported:
        metadata:
          timestamp: '1550049403598'
          type: float
        value: "30"
      observedDesired:
        metadata:
          timestamp: '1550049403598'
          type: float

virtualdevice-model.yaml

cat virtualdevice-model.yaml
apiVersion: devices.kubeedge.io/v1beta1
kind: DeviceModel
metadata:
  name: random-01
  namespace: default
spec:
  protocol: virtualProtocol
  properties:
    - name: random-int
      description: random int
      type: INT
      maximum: '100'
      accessMode: ReadWrite
    - name: random-float
      description: random float
      type: FLOAT

luchaoshi45 avatar Jul 08 '24 15:07 luchaoshi45

deployment.yaml

cat deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mapper-test
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: demo
  template:
    metadata:
      labels:
        app: demo
    spec:
      nodeName: kedge1
      containers:
        - name: demo
          volumeMounts:
            - mountPath: /etc/kubeedge
              name: test-volume
          env:
            - name: TOKEN
              valueFrom:
                secretKeyRef:
                  name: mysecret
                  key: token
          image: virtualdevice  # Fill in the name of the image you created
          imagePullPolicy: IfNotPresent
          command: [ "/bin/sh","-c" ]
          args: [ "/kubeedge/main --config-file /kubeedge/config.yaml --v 4" ]
      volumes:
        - name: test-volume
          hostPath:
            path: /etc/kubeedge

secret.yaml

cat secret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  token: dXNlcl90b2tlbl9oZXJlCg== 

configmap.yaml

cat configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: cm-mapper
data:
  configData: |
    grpc_server:
      socket_path: /etc/kubeedge/virtualdevice.sock
    common:
      name: Virtualdevice-mapper
      version: v1.17.0
      api_version: v1.0.0
      protocol: # TODO add your protocol name
      address: 127.0.0.1
      edgecore_sock: /etc/kubeedge/dmi.sock
    dev_init:
      mode: register

luchaoshi45 avatar Jul 08 '24 15:07 luchaoshi45

I used kubectl logs xxxx and I couldn’t seem to see any output, so I debugged the code directly on edge1 using goland breakpoints. The screenshot above is a screenshot taken during goland debugging. The returned device list, device model list and error are all empty. Finally, it can be printed that the registration is successful, but the random number has not changed. I guess it is the device list, device model list and error. The reason is empty.

staging/src/github.com/kubeedge/virtualdevice/cmd/main.go
deviceList, deviceModelList, err := grpcclient.RegisterMapper(true)
deviceList, deviceModelList, err are all nil

luchaoshi45 avatar Jul 08 '24 15:07 luchaoshi45

configmap.yaml

cat configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: cm-mapper
data:
  configData: |
    grpc_server:
      socket_path: /etc/kubeedge/virtualdevice.sock
    common:
      name: Virtualdevice-mapper
      version: v1.17.0
      api_version: v1.0.0
      protocol: # TODO add your protocol name
      address: 127.0.0.1
      edgecore_sock: /etc/kubeedge/dmi.sock
    dev_init:
      mode: register

The protocol name also needs to be filled in the mapper configuration file, which must be consistent with device-instance and device-model. Edgecore sends the device list to the mapper by matching the protocol name.

wbc6080 avatar Jul 09 '24 01:07 wbc6080

By the way, kubeedge needs to enable the logs/exec function to query pod logs. You can follow this document https://kubeedge.io/docs/advanced/debug

Of course, you can also run mapper directly in binary locally to debug it first. https://kubeedge.io/docs/developer/mappers/#3-deploy-your-mapper

wbc6080 avatar Jul 09 '24 01:07 wbc6080

Thank you for your reply, I will try it later.

luchaoshi45 avatar Jul 10 '24 01:07 luchaoshi45

Hello 👋 Looks like there was no activity on this issue for last 90 days. Do you mind updating us on the status? Is this still reproducible or needed? If yes, just comment on this PR or push a commit. Thanks! 🤗 If there will be no activity for 60 days, this issue will be closed (we can always reopen an issue if we need!).

stale[bot] avatar Jul 19 '25 01:07 stale[bot]