Skip to content

Commit

Permalink
Change CNF API file directory to /cnfapi (#124)
Browse files Browse the repository at this point in the history
This prevents directory overwriting issues that arose when multiple
CNFs mounted their /run/stonework/proto into single volume. Now every
CNF type should have its API mounted to a separate volume.

Signed-off-by: Peter Motičák <[email protected]>
  • Loading branch information
pemoticak authored Sep 11, 2023
1 parent 024d341 commit df7319f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
17 changes: 12 additions & 5 deletions cmd/stonework/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import (
const (
protoFileExt = ".proto"
ligatoApiFileDir = "/api"
protoFileDir = "/run/stonework/proto"
cnfApiFileDir = "/cnfapi"

modelSpecExtNum = 50222
modelTmplExtNum = 50223
Expand Down Expand Up @@ -121,7 +121,7 @@ func registerModels(files linker.Files, specExtDesc, tmplExtDesc protoreflect.Ex
// no model spec detected, continue with next message
continue
}
spec, err := util.ConvertProto(&generic.ModelSpec{}, dynSpec)
specMsg, err := util.ConvertProto(&generic.ModelSpec{}, dynSpec)
if err != nil {
return err
}
Expand All @@ -130,8 +130,15 @@ func registerModels(files linker.Files, specExtDesc, tmplExtDesc protoreflect.Ex
tmpl := proto.GetExtension(opts, tmplExtDesc.Type()).(string)
modelOpts = append(modelOpts, models.WithNameTemplate(tmpl))
}
spec := models.ToSpec(specMsg.(*generic.ModelSpec))
modelName := spec.ModelName()
modelMsg := dynamicpb.NewMessage(msgDesc)
_, err = models.DefaultRegistry.Register(modelMsg, models.ToSpec(spec.(*generic.ModelSpec)), modelOpts...)
if _, err := models.DefaultRegistry.GetModel(modelName); err == nil {
// model already registered, print warning and continue with next message
logging.DefaultLogger.Warnf("Cannot register cnf model: model with name %s is already registered", modelName)
continue
}
_, err = models.DefaultRegistry.Register(modelMsg, spec, modelOpts...)
if err != nil {
return err
}
Expand All @@ -145,12 +152,12 @@ func main() {
fmt.Println(http.ListenAndServe("0.0.0.0:6060", nil))
}()

if _, err := os.Stat(protoFileDir); !os.IsNotExist(err) {
if _, err := os.Stat(cnfApiFileDir); !os.IsNotExist(err) {
ligatoApiFiles, err := compileProtoFiles(findProtoFiles(ligatoApiFileDir), ligatoApiFileDir)
if err != nil {
logging.DefaultLogger.Fatal(err)
}
files, err := compileProtoFiles(findProtoFiles(protoFileDir), protoFileDir, ligatoApiFileDir)
files, err := compileProtoFiles(findProtoFiles(cnfApiFileDir), cnfApiFileDir, ligatoApiFileDir)
if err != nil {
logging.DefaultLogger.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions docker/mockcnf/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ COPY ./docker/mockcnf/supervisor-novpp.conf /etc/mockcnf-novpp/supervisor.conf
COPY ./docker/mockcnf/init_hook-novpp.sh /usr/bin/init_hook-novpp.sh

# Copy proto api (mockcnf models)
RUN mkdir -p /run/stonework
RUN cp -r ./proto/mockcnf /run/stonework/proto
RUN mkdir -p /api/mockcnf
RUN cp -r ./proto/mockcnf /api/mockcnf

# Install script for packet tracing on VPP
COPY ./docker/vpptrace.sh /usr/bin/vpptrace.sh
Expand Down
3 changes: 3 additions & 0 deletions examples/testing/100-mock-cnf-module/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ version: '3.3'

volumes:
runtime_data: {}
mockcnfapi: {}

services:
stonework:
Expand All @@ -36,6 +37,7 @@ services:
- "6060:6060" # pprof
volumes:
- runtime_data:/run/stonework
- mockcnfapi:/cnfapi/mockcnf
- /sys/bus/pci:/sys/bus/pci
- /dev:/dev
- /run/docker.sock:/run/docker.sock
Expand All @@ -57,6 +59,7 @@ services:
privileged: true
volumes:
- runtime_data:/run/stonework
- mockcnfapi:/api
environment:
INITIAL_LOGLVL: "debug"
MICROSERVICE_LABEL: "mockcnf1"
Expand Down

0 comments on commit df7319f

Please sign in to comment.