Skip to content

Commit 27ae95e

Browse files
authored
Merge pull request #598 from LiilyZhang/zhang/k8sMMS
Issue open-horizon#3982 - MMSinCluster: add MMS example operator and services
2 parents 65f1e35 + b139c77 commit 27ae95e

File tree

14 files changed

+468
-0
lines changed

14 files changed

+468
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM alpine:latest
2+
3+
RUN apk --no-cache --update add jq bash
4+
5+
COPY *.sh /
6+
WORKDIR /
7+
CMD /service.sh
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Make targets for building the IBM example hello mms consumer service for edge cluster
2+
3+
# This imports the variables from horizon/hzn.json. You can ignore these lines, but do not remove them.
4+
-include horizon/.hzn.json.tmp.mk
5+
6+
# Default ARCH to the architecture of this machines (as horizon/golang describes it)
7+
export ARCH ?= $(shell hzn architecture)
8+
9+
# Build the docker image for the current architecture
10+
build:
11+
docker build --platform linux/$(ARCH) -t $(DOCKER_IMAGE_BASE)_$(ARCH):$(SERVICE_VERSION) -f ./Dockerfile .
12+
13+
# Push the docker image
14+
push:
15+
docker push $(DOCKER_IMAGE_BASE)_$(ARCH):$(SERVICE_VERSION)
16+
17+
clean:
18+
-docker rmi $(DOCKER_IMAGE_BASE)_$(ARCH):$(SERVICE_VERSION) 2> /dev/null || :
19+
20+
# This imports the variables from horizon/hzn.cfg. You can ignore these lines, but do not remove them.
21+
horizon/.hzn.json.tmp.mk: horizon/hzn.json
22+
@ hzn util configconv -f $< > $@
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"HZN_ORG_ID": "IBM",
3+
"MetadataVars": {
4+
"DOCKER_IMAGE_BASE": "openhorizon/ibm.hello-k8s-mms-consumer",
5+
"SERVICE_NAME": "ibm.hello-k8s-mms-consumer",
6+
"SERVICE_VERSION": "1.0.0"
7+
}
8+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
OBJECT_TYPES_STRING=$MMS_OBJECT_TYPES # operator need to put MMS_OBJECT_TYPES in the deployment as env from the userinput configmap, eg: "model model1 model2"
4+
OBJECT_ID=config.json # this is the file we are watching in this example mms consumer service
5+
# this file is in shared volume. Operator should bind as /ess-store/<objectType>-<objectID>
6+
7+
echo "Object types to check: $OBJECT_TYPES_STRING"
8+
IFS=' ' read -r -a objecttypes <<< "$OBJECT_TYPES_STRING"
9+
10+
while true; do
11+
for objecttype in "${objecttypes[@]}"
12+
do
13+
MMS_FILE_NAME="/ess-store/$objecttype-$OBJECT_ID"
14+
echo "MMS_FILE_NAME: $MMS_FILE_NAME"
15+
if [[ -f $MMS_FILE_NAME ]]; then
16+
eval $(jq -r 'to_entries[] | .key + "=\"" + .value + "\""' $MMS_FILE_NAME)
17+
echo "$MMS_FILE_NAME: Hello from ${HW_WHO} from objectType: $objecttype, objectId: $OBJECT_ID!"
18+
else
19+
echo "file $MMS_FILE_NAME not found"
20+
fi
21+
22+
done
23+
sleep 20
24+
done
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM alpine:latest
2+
3+
RUN apk --no-cache --update add curl
4+
5+
COPY start.sh /
6+
COPY service /usr/local/bin/
7+
8+
RUN mkdir -p /ess-store
9+
10+
WORKDIR /
11+
CMD /start.sh
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Makefile for hello mms helper service for k8s
2+
3+
# This imports the variables from horizon/hzn.json. You can ignore these lines, but do not remove them.
4+
-include horizon/.hzn.json.tmp.mk
5+
6+
# Default ARCH to the architecture of this machines (as horizon/golang describes it)
7+
export ARCH ?= $(shell hzn architecture)
8+
9+
# Build the docker image for the current architecture
10+
build:
11+
docker build --platform linux/$(ARCH) -t $(DOCKER_IMAGE_BASE)_$(ARCH):$(SERVICE_VERSION) -f ./Dockerfile .
12+
13+
service: service.go
14+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build service.go
15+
16+
# Push the docker image
17+
push:
18+
docker push $(DOCKER_IMAGE_BASE)_$(ARCH):$(SERVICE_VERSION)
19+
20+
clean:
21+
-docker rmi $(DOCKER_IMAGE_BASE)_$(ARCH):$(SERVICE_VERSION) 2> /dev/null || :
22+
23+
# This imports the variables from horizon/hzn.cfg. You can ignore these lines, but do not remove them.
24+
horizon/.hzn.json.tmp.mk: horizon/hzn.json
25+
@ hzn util configconv -f $< > $@
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"HW_WHO": "k8sMMS"
3+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module github.com/open-horizon/examples/edge/services/hellok8sMMS/k8s_mms_helper
2+
3+
go 1.20
4+
5+
require (
6+
github.com/golang/glog v1.2.0
7+
github.com/open-horizon/edge-sync-service v1.10.1
8+
)
9+
10+
require (
11+
github.com/open-horizon/edge-utilities v0.0.0-20190711093331-0908b45a7152 // indirect
12+
golang.org/x/sync v0.6.0 // indirect
13+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68=
2+
github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
3+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
4+
github.com/open-horizon/edge-sync-service v1.10.1 h1:+b+YTPqyxyhieixaFoV03Bs0Fmy5HGZtOIkhMG8OkMo=
5+
github.com/open-horizon/edge-sync-service v1.10.1/go.mod h1:yCK3f59UHnoLU0Tz2/RhuLGygJFlZoqlP8kpmQ3Gqd4=
6+
github.com/open-horizon/edge-utilities v0.0.0-20190711093331-0908b45a7152 h1:YEvNOMo3ANOQ3AwsU0cCcBA4nKHDLUlyUCRWk5rBf68=
7+
github.com/open-horizon/edge-utilities v0.0.0-20190711093331-0908b45a7152/go.mod h1:YCsJWhuG0VERquI0geFKoneCSOVAyMdSmylGz5OlZdE=
8+
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
9+
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export HZN_ORG_ID=anaxsquad
2+
export DOCKER_IMAGE_BASE=quay.io/zhangle/hello-k8s-mms-helper
3+
export SERVICE_NAME=hello-k8s-mms-helper
4+
export SERVICE_VERSION=1.0.0
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"HZN_ORG_ID": "IBM",
3+
"MetadataVars": {
4+
"DOCKER_IMAGE_BASE": "openhorizon/ibm.hello-k8s-mms-helper",
5+
"SERVICE_NAME": "ibm.hello-k8s-mms-helper",
6+
"SERVICE_VERSION": "1.0.0"
7+
}
8+
}
7.34 MB
Binary file not shown.

0 commit comments

Comments
 (0)