Skip to content

Commit

Permalink
Merge pull request #598 from LiilyZhang/zhang/k8sMMS
Browse files Browse the repository at this point in the history
Issue open-horizon#3982 - MMSinCluster: add MMS example operator and services
  • Loading branch information
LiilyZhang authored May 7, 2024
2 parents 65f1e35 + b139c77 commit 27ae95e
Show file tree
Hide file tree
Showing 14 changed files with 468 additions and 0 deletions.
7 changes: 7 additions & 0 deletions edge/services/hellok8sMMS/k8s_mms_consumer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine:latest

RUN apk --no-cache --update add jq bash

COPY *.sh /
WORKDIR /
CMD /service.sh
22 changes: 22 additions & 0 deletions edge/services/hellok8sMMS/k8s_mms_consumer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Make targets for building the IBM example hello mms consumer service for edge cluster

# This imports the variables from horizon/hzn.json. You can ignore these lines, but do not remove them.
-include horizon/.hzn.json.tmp.mk

# Default ARCH to the architecture of this machines (as horizon/golang describes it)
export ARCH ?= $(shell hzn architecture)

# Build the docker image for the current architecture
build:
docker build --platform linux/$(ARCH) -t $(DOCKER_IMAGE_BASE)_$(ARCH):$(SERVICE_VERSION) -f ./Dockerfile .

# Push the docker image
push:
docker push $(DOCKER_IMAGE_BASE)_$(ARCH):$(SERVICE_VERSION)

clean:
-docker rmi $(DOCKER_IMAGE_BASE)_$(ARCH):$(SERVICE_VERSION) 2> /dev/null || :

# This imports the variables from horizon/hzn.cfg. You can ignore these lines, but do not remove them.
horizon/.hzn.json.tmp.mk: horizon/hzn.json
@ hzn util configconv -f $< > $@
8 changes: 8 additions & 0 deletions edge/services/hellok8sMMS/k8s_mms_consumer/horizon/hzn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"HZN_ORG_ID": "IBM",
"MetadataVars": {
"DOCKER_IMAGE_BASE": "openhorizon/ibm.hello-k8s-mms-consumer",
"SERVICE_NAME": "ibm.hello-k8s-mms-consumer",
"SERVICE_VERSION": "1.0.0"
}
}
24 changes: 24 additions & 0 deletions edge/services/hellok8sMMS/k8s_mms_consumer/service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

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"
OBJECT_ID=config.json # this is the file we are watching in this example mms consumer service
# this file is in shared volume. Operator should bind as /ess-store/<objectType>-<objectID>

echo "Object types to check: $OBJECT_TYPES_STRING"
IFS=' ' read -r -a objecttypes <<< "$OBJECT_TYPES_STRING"

while true; do
for objecttype in "${objecttypes[@]}"
do
MMS_FILE_NAME="/ess-store/$objecttype-$OBJECT_ID"
echo "MMS_FILE_NAME: $MMS_FILE_NAME"
if [[ -f $MMS_FILE_NAME ]]; then
eval $(jq -r 'to_entries[] | .key + "=\"" + .value + "\""' $MMS_FILE_NAME)
echo "$MMS_FILE_NAME: Hello from ${HW_WHO} from objectType: $objecttype, objectId: $OBJECT_ID!"
else
echo "file $MMS_FILE_NAME not found"
fi

done
sleep 20
done
11 changes: 11 additions & 0 deletions edge/services/hellok8sMMS/k8s_mms_helper/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM alpine:latest

RUN apk --no-cache --update add curl

COPY start.sh /
COPY service /usr/local/bin/

RUN mkdir -p /ess-store

WORKDIR /
CMD /start.sh
25 changes: 25 additions & 0 deletions edge/services/hellok8sMMS/k8s_mms_helper/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Makefile for hello mms helper service for k8s

# This imports the variables from horizon/hzn.json. You can ignore these lines, but do not remove them.
-include horizon/.hzn.json.tmp.mk

# Default ARCH to the architecture of this machines (as horizon/golang describes it)
export ARCH ?= $(shell hzn architecture)

# Build the docker image for the current architecture
build:
docker build --platform linux/$(ARCH) -t $(DOCKER_IMAGE_BASE)_$(ARCH):$(SERVICE_VERSION) -f ./Dockerfile .

service: service.go
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build service.go

# Push the docker image
push:
docker push $(DOCKER_IMAGE_BASE)_$(ARCH):$(SERVICE_VERSION)

clean:
-docker rmi $(DOCKER_IMAGE_BASE)_$(ARCH):$(SERVICE_VERSION) 2> /dev/null || :

# This imports the variables from horizon/hzn.cfg. You can ignore these lines, but do not remove them.
horizon/.hzn.json.tmp.mk: horizon/hzn.json
@ hzn util configconv -f $< > $@
3 changes: 3 additions & 0 deletions edge/services/hellok8sMMS/k8s_mms_helper/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"HW_WHO": "k8sMMS"
}
13 changes: 13 additions & 0 deletions edge/services/hellok8sMMS/k8s_mms_helper/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module github.com/open-horizon/examples/edge/services/hellok8sMMS/k8s_mms_helper

go 1.20

require (
github.com/golang/glog v1.2.0
github.com/open-horizon/edge-sync-service v1.10.1
)

require (
github.com/open-horizon/edge-utilities v0.0.0-20190711093331-0908b45a7152 // indirect
golang.org/x/sync v0.6.0 // indirect
)
9 changes: 9 additions & 0 deletions edge/services/hellok8sMMS/k8s_mms_helper/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68=
github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/open-horizon/edge-sync-service v1.10.1 h1:+b+YTPqyxyhieixaFoV03Bs0Fmy5HGZtOIkhMG8OkMo=
github.com/open-horizon/edge-sync-service v1.10.1/go.mod h1:yCK3f59UHnoLU0Tz2/RhuLGygJFlZoqlP8kpmQ3Gqd4=
github.com/open-horizon/edge-utilities v0.0.0-20190711093331-0908b45a7152 h1:YEvNOMo3ANOQ3AwsU0cCcBA4nKHDLUlyUCRWk5rBf68=
github.com/open-horizon/edge-utilities v0.0.0-20190711093331-0908b45a7152/go.mod h1:YCsJWhuG0VERquI0geFKoneCSOVAyMdSmylGz5OlZdE=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export HZN_ORG_ID=anaxsquad
export DOCKER_IMAGE_BASE=quay.io/zhangle/hello-k8s-mms-helper
export SERVICE_NAME=hello-k8s-mms-helper
export SERVICE_VERSION=1.0.0
8 changes: 8 additions & 0 deletions edge/services/hellok8sMMS/k8s_mms_helper/horizon/hzn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"HZN_ORG_ID": "IBM",
"MetadataVars": {
"DOCKER_IMAGE_BASE": "openhorizon/ibm.hello-k8s-mms-helper",
"SERVICE_NAME": "ibm.hello-k8s-mms-helper",
"SERVICE_VERSION": "1.0.0"
}
}
Binary file added edge/services/hellok8sMMS/k8s_mms_helper/service
Binary file not shown.
Loading

0 comments on commit 27ae95e

Please sign in to comment.