Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deviceShifu LwM2M Implement #1001

Merged
merged 12 commits into from
Oct 15, 2024
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ buildx-push-image-deviceshifu-tcp-tcp:
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-tcp-tcp:${IMAGE_VERSION} --push

buildx-build-image-deviceshifu-http-lwm2m:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuLwM2M \
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-http-lwm2m:${IMAGE_VERSION} --push

buildx-push-image-shifu-controller:
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm -f $(PROJECT_ROOT)/pkg/k8s/crd/Dockerfile \
--build-arg PROJECT_ROOT="$(PROJECT_ROOT)" $(PROJECT_ROOT) \
Expand Down Expand Up @@ -142,6 +147,11 @@ buildx-build-image-deviceshifu-http-http:
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-http-http:${IMAGE_VERSION} --load

buildx-build-image-deviceshifu-http-lwm2m:
rhoninl marked this conversation as resolved.
Show resolved Hide resolved
docker buildx build --platform=linux/$(shell go env GOARCH) -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuLwM2M \
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
-t edgehub/deviceshifu-http-lwm2m:${IMAGE_VERSION} --load

buildx-build-image-deviceshifu-http-mqtt:
docker buildx build --platform=linux/$(shell go env GOARCH) -f ${PROJECT_ROOT}/dockerfiles/Dockerfile.deviceshifuMQTT \
--build-arg PROJECT_ROOT="${PROJECT_ROOT}" ${PROJECT_ROOT} \
Expand Down
34 changes: 34 additions & 0 deletions cmd/deviceshifu/cmdlwm2m/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"os"

"github.com/edgenesis/shifu/pkg/deviceshifu/deviceshifubase"
"github.com/edgenesis/shifu/pkg/deviceshifu/deviceshifulwm2m"
"github.com/edgenesis/shifu/pkg/logger"

"k8s.io/apimachinery/pkg/util/wait"
)

func main() {
deviceName := os.Getenv("EDGEDEVICE_NAME")
namespace := os.Getenv("EDGEDEVICE_NAMESPACE")

deviceShifuMetadata := &deviceshifubase.DeviceShifuMetaData{
Name: deviceName,
ConfigFilePath: deviceshifubase.DeviceConfigmapFolderPath,
KubeConfigPath: deviceshifubase.KubernetesConfigDefault,
Namespace: namespace,
}

ds, err := deviceshifulwm2m.New(deviceShifuMetadata)
if err != nil {
logger.Fatalf("Error creating deviceshifu: %v", err)
}

if err := ds.Start(wait.NeverStop); err != nil {
logger.Fatalf("Error starting deviceshifu: %v", err)
}

select {}
}
27 changes: 27 additions & 0 deletions dockerfiles/Dockerfile.deviceshifuLwM2M
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:1.23.1 as builder

WORKDIR /shifu

COPY go.mod go.mod
COPY go.sum go.sum
COPY pkg/k8s pkg/k8s
COPY cmd/deviceshifu/cmdlwm2m cmd/deviceshifu/cmdlwm2m
COPY pkg/deviceshifu pkg/deviceshifu
COPY pkg/logger pkg/logger

RUN go mod download

# Build the Go app
ARG TARGETOS
ARG TARGETARCH

RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -o /output/deviceshifu cmd/deviceshifu/cmdlwm2m/main.go

FROM gcr.io/distroless/static-debian11
WORKDIR /
COPY --from=builder /output/deviceshifu deviceshifu

# Command to run the executable
USER 65532:65532
ENTRYPOINT ["/deviceshifu"]
6 changes: 3 additions & 3 deletions docs/design/deviceshifu/design-deviceShifu-lwm2m.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type LwM2MSetting struct {
SecurityMode *SecurityMode `json:"securityMode,omitempty"`
DTLSMode *DTLSMode `json:"dtlsMode,omitempty"`

CipherSuites []CiperSuite `json:"cipherSuites,omitempty"`
CipherSuites []CipherSuite `json:"cipherSuites,omitempty"`
PSKIdentity *string `json:"pskIdentity,omitempty"`
PSKKey *string `json:"pskKey,omitempty"`
}
Expand All @@ -145,10 +145,10 @@ const (
// ...
)

type CiperSuite string
type CipherSuite string

const (
CiperSuite_TLS_ECDHE_ECDSA_WITH_AES_128_CCM CiperSuite = "TLS_ECDHE_ECDSA_WITH_AES_128_CCM"
CipherSuite_TLS_ECDHE_ECDSA_WITH_AES_128_CCM CipherSuite = "TLS_ECDHE_ECDSA_WITH_AES_128_CCM"
// ...
)
```
Expand Down
21 changes: 21 additions & 0 deletions examples/lwm2mdeviceShifu/lwm2m-deviceshifu-configmap.yaml
rhoninl marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: deviceshifu-lwm2m
namespace: deviceshifu
data:
# device name and image address
driverProperties: |
driverSku: LwM2M Device
driverImage: lwm2m-device:v0.0.1
# available instructions
instructions: |
instructions:
temperature:
rhoninl marked this conversation as resolved.
Show resolved Hide resolved
protocolPropertyList:
ObjectId: /3303/0/5700
EnableObserve: false
reset:
protocolPropertyList:
ObjectId: /3303/0/5605
EnableObserve: false
38 changes: 38 additions & 0 deletions examples/lwm2mdeviceShifu/lwm2m-deviceshifu-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: deviceshifu-lwm2m-deployment
name: deviceshifu-lwm2m-deployment
namespace: deviceshifu
spec:
replicas: 1
selector:
matchLabels:
app: deviceshifu-lwm2m-deployment
template:
metadata:
labels:
app: deviceshifu-lwm2m-deployment
spec:
containers:
- image: edgehub/deviceshifu-http-lwm2m:nightly
name: deviceshifu-lwm2m
ports:
- containerPort: 8080
volumeMounts:
- name: deviceshifu-config
mountPath: "/etc/edgedevice/config"
readOnly: true
env:
- name: EDGEDEVICE_NAME
value: "edgedevice-lwm2m"
- name: EDGEDEVICE_NAMESPACE
value: "devices"
- name: LOG_LEVEL
value: debug
volumes:
- name: deviceshifu-config
configMap:
name: deviceshifu-lwm2m
rhoninl marked this conversation as resolved.
Show resolved Hide resolved
serviceAccountName: edgedevice-sa
27 changes: 27 additions & 0 deletions examples/lwm2mdeviceShifu/lwm2m-deviceshifu-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: deviceshifu-lwm2m-deployment
name: deviceshifu-lwm2m
namespace: deviceshifu
spec:
ports:
- name: deviceshifu
port: 80
protocol: TCP
nodePort: 30080
targetPort: 8080
- name: lwm2mserver-coap
port: 5683
protocol: UDP
nodePort: 30000
targetPort: 5683
- name: lwm2mserver-coaps
port: 5684
protocol: UDP
nodePort: 30001
targetPort: 5684
selector:
app: deviceshifu-lwm2m-deployment
type: NodePort
18 changes: 18 additions & 0 deletions examples/lwm2mdeviceShifu/lwm2m-edgedevice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: shifu.edgenesis.io/v1alpha1
kind: EdgeDevice
metadata:
name: edgedevice-lwm2m
namespace: devices
spec:
sku: "LwM2M Device"
connection: Ethernet
protocol: LwM2M
protocolSettings:
LwM2MSetting:
endpointName: test
securityMode: DTLS
dtlsMode: PSK
cipherSuites:
- TLS_PSK_WITH_AES_128_CCM_8
pskIdentity: hint
pskKey: ABC123
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ require (
github.com/mochi-co/mqtt v1.3.2
github.com/onsi/ginkgo/v2 v2.20.2
github.com/onsi/gomega v1.34.2
github.com/pion/dtls/v2 v2.2.8-0.20240201071732-2597464081c8
github.com/plgd-dev/go-coap/v3 v3.1.6
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
github.com/taosdata/driver-go/v3 v3.5.8
Expand All @@ -32,6 +34,7 @@ require (
require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
github.com/dsnet/golib/memfile v1.0.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/fatih/color v1.13.0 // indirect
Expand All @@ -43,13 +46,18 @@ require (
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/pion/transport/v3 v3.0.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rs/xid v1.6.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/tools v0.24.0 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
Expand Down
Loading
Loading