From 3eba65430588aee80d1a4464ef5085ff90358096 Mon Sep 17 00:00:00 2001 From: TianTianBigWang Date: Sat, 29 Oct 2022 00:52:29 +0800 Subject: [PATCH] add example for user test raven cloud-edge comm --- core/assistant/init.go | 2 ++ example/README.md | 11 +++++++++ example/alpine-curl.Dockerfile | 9 +++++++ example/hostname.yaml | 44 ++++++++++++++++++++++++++++++++++ example/test-pod.yaml | 37 ++++++++++++++++++++++++++++ example/websocket.yaml | 44 ++++++++++++++++++++++++++++++++++ go.mod | 2 +- pkg/version/version.go | 8 +++---- 8 files changed, 152 insertions(+), 5 deletions(-) create mode 100644 example/README.md create mode 100644 example/alpine-curl.Dockerfile create mode 100644 example/hostname.yaml create mode 100644 example/test-pod.yaml create mode 100644 example/websocket.yaml diff --git a/core/assistant/init.go b/core/assistant/init.go index 01d2ba5..18c9f18 100644 --- a/core/assistant/init.go +++ b/core/assistant/init.go @@ -363,6 +363,7 @@ func applyConfigMap( return common.ApplyResource(ctx, resourceInter, obj) } +//nolint func setCurrentToMap(data map[string]interface{}, current map[string]interface{}, keys ...string) { for _, k := range keys { if v, ok := current[k]; ok { @@ -540,6 +541,7 @@ func applyDaemonSet( } } currentContainer.Image = container.Image + currentContainer.Env = envs current.Spec.Template.Spec.Containers[0] = currentContainer ds = *current } diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..bc29136 --- /dev/null +++ b/example/README.md @@ -0,0 +1,11 @@ +- kubectl apply -f examples/test-pod.yaml + +- kubectl apply -f examples/hostname.yaml + +- kubectl exec -it alpine-test -- sh + +- (在容器环境内) + + / # curl hostname-svc:12345 + + hostname-edge-84cb45ccf4-lh89n \ No newline at end of file diff --git a/example/alpine-curl.Dockerfile b/example/alpine-curl.Dockerfile new file mode 100644 index 0000000..248bced --- /dev/null +++ b/example/alpine-curl.Dockerfile @@ -0,0 +1,9 @@ +# docker buildx build --push --platform linux/arm64,linux/amd64,linux/arm,linux/ppc64le,linux/s390x \ +# -t $(REPO)/alpine-curl:$(TAG) -f alpine-curl.Dockerfile . +FROM alpine:latest + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories && \ + apk update && \ + apk add --no-cache curl + +CMD ["tail", "-f", "/dev/null"] \ No newline at end of file diff --git a/example/hostname.yaml b/example/hostname.yaml new file mode 100644 index 0000000..17071d4 --- /dev/null +++ b/example/hostname.yaml @@ -0,0 +1,44 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hostname-edge + labels: + app: hostname-edge +spec: + replicas: 1 + selector: + matchLabels: + app: hostname-edge + template: + metadata: + labels: + app: hostname-edge + spec: + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: node-role.kubernetes.io/edge + operator: Exists + - key: node-role.kubernetes.io/agent + operator: Exists + containers: + - name: hostname + image: a526102465/serve_hostname:v0.1-diplomat + imagePullPolicy: IfNotPresent + ports: + - containerPort: 9376 +--- +apiVersion: v1 +kind: Service +metadata: + name: hostname-svc +spec: + selector: + app: hostname-edge + ports: + - name: http-0 + port: 12345 + protocol: TCP + targetPort: 9376 \ No newline at end of file diff --git a/example/test-pod.yaml b/example/test-pod.yaml new file mode 100644 index 0000000..ea34805 --- /dev/null +++ b/example/test-pod.yaml @@ -0,0 +1,37 @@ +apiVersion: v1 +kind: Pod +metadata: + name: alpine-test +spec: + containers: + - name: alpine-curl + image: a526102465/alpine-curl:v0.1-diplomat + imagePullPolicy: IfNotPresent + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: node-role.kubernetes.io/edge + operator: DoesNotExist + - key: node-role.kubernetes.io/agent + operator: DoesNotExist +--- +apiVersion: v1 +kind: Pod +metadata: + name: websocket-test +spec: + containers: + - name: websocket + image: a526102465/websocket_echo:v0.1-diplomat + imagePullPolicy: IfNotPresent + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: node-role.kubernetes.io/edge + operator: DoesNotExist + - key: node-role.kubernetes.io/agent + operator: DoesNotExist \ No newline at end of file diff --git a/example/websocket.yaml b/example/websocket.yaml new file mode 100644 index 0000000..07b3d6e --- /dev/null +++ b/example/websocket.yaml @@ -0,0 +1,44 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ws-edge + labels: + app: ws-edge +spec: + replicas: 1 + selector: + matchLabels: + app: ws-edge + template: + metadata: + labels: + app: ws-edge + spec: + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: node-role.kubernetes.io/edge + operator: Exists + - key: node-role.kubernetes.io/agent + operator: Exists + containers: + - name: ws + image: a526102465/websocket_echo:v0.1-diplomat + imagePullPolicy: IfNotPresent + ports: + - containerPort: 8080 +--- +apiVersion: v1 +kind: Service +metadata: + name: ws-svc +spec: + selector: + app: ws-edge + ports: + - name: http-0 + port: 12348 + protocol: TCP + targetPort: 8080 \ No newline at end of file diff --git a/go.mod b/go.mod index 3f498f7..ec54f3b 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/99nil/dsync v0.0.0-00010101000000-000000000000 github.com/99nil/gopkg v0.0.0-20220607055250-e19b23d7661a github.com/AlecAivazis/survey/v2 v2.3.6 + github.com/docker/docker v20.10.12+incompatible github.com/go-chi/chi v1.5.4 github.com/kubeedge/kubeedge v1.11.2 github.com/natefinch/lumberjack v2.0.0+incompatible @@ -38,7 +39,6 @@ require ( github.com/dgraph-io/badger/v3 v3.2103.2 // indirect github.com/dgraph-io/ristretto v0.1.0 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v20.10.12+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.4.0 // indirect github.com/dustin/go-humanize v1.0.0 // indirect diff --git a/pkg/version/version.go b/pkg/version/version.go index 3106ff6..defb6fe 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -36,8 +36,8 @@ type Version struct { Platform string } -func Get() Version { - return Version{ +func Get() *Version { + return &Version{ Version: ver, AssistantVersion: assistantVer, KubeedgeVersion: kubeedgeVer, @@ -48,7 +48,7 @@ func Get() Version { } } -func (v Version) String() string { +func (v *Version) String() string { return fmt.Sprintf(`version: %s assistant: %s kubeedge: %s @@ -67,7 +67,7 @@ platform: %s ) } -func (v Version) EdgeString() string { +func (v *Version) EdgeString() string { if v.Version == "" { v.Version = "dev" }