You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generating modules and extensions is not yet supported, but will be very soon!
102
+
### Generating a module
103
+
104
+
You also need a definition to create a module using the `kraken` command. The default name for this definition is `module.yaml` in the module directory. Canonically, we use `<project>/modules/<module>` for module directories.
105
+
106
+
Module defintions are a more complicated than app definitions. They need to define all of the mutations and discoveries that a module can do. Here's an annotated example:
107
+
108
+
```yaml
109
+
---
110
+
# The package_url is the Go-style path to the module. This must be a full url.
# If with_polling is true, the module will be generated with a polling loop.
113
+
# The timer for the polling loop uses a config, so with_config is implied.
114
+
with_polling: true
115
+
# If with_config is specified, a stub for a protobuf config will be generated.
116
+
with_config: true
117
+
# This list declares any URLs we descover.
118
+
# The state of our own service and any URLs used in `mutates` sections of mutations below are automatically added.
119
+
# In this case, we're letting Kraken know that we discover things about `/RunState`, even though it's not part
120
+
# of our mutations.
121
+
discoveries:
122
+
- "/RunState"
123
+
# This section declares mutations. The key can be anything, but it must be unique. Ideally, it should be something descriptive.
124
+
# In this example we declare two mutations, one discovers /PhysState when it's unknown, the other mutates power from OFF to ON.
125
+
mutations:
126
+
"Discover":
127
+
mutates:
128
+
"/PhysState":
129
+
from: "PHYS_UNKNOWN"
130
+
to: "POWER_OFF"
131
+
requires:
132
+
"/Platoform": "test"
133
+
timeout: "10s"
134
+
fail_to:
135
+
url: "/PhysState"
136
+
value: "PHYS_ERROR"
137
+
"PowerON":
138
+
mutates:
139
+
"/PhysState":
140
+
from: "POWER_OFF"
141
+
to: "POWER_ON"
142
+
requires:
143
+
"/Platform": "test"
144
+
timeout: "10s"
145
+
fail_to:
146
+
url: "/PhysState"
147
+
value: "PHYS_ERROR"
148
+
```
149
+
150
+
Once we have the definition in place, we can generate the module with:
151
+
152
+
```bash
153
+
$ mkdir -p modules/test
154
+
$ cd modules/test
155
+
<create module.yaml>
156
+
$ kraken module generate
157
+
INFO[0000] module "test" generated at modules/test
158
+
```
159
+
160
+
If we selected `with_config: true`, we will need to generate the protobuf code from the provided `proto` file. You can add some variables to `test.config.proto` first, then:
161
+
162
+
```bash
163
+
$ cd modules/test
164
+
$ go generate
165
+
```
166
+
167
+
This will create `test.config.pb.go` (note: you need `protoc` and `gogo-proto` installed).
168
+
169
+
At this point, the module can be built and run, though it won't really do anything. It will add to the generated graph, so this is a good point to make sure the graph output of an app that links this module is sane.
170
+
171
+
Finally, you'll want to edit `test.go`. Unlike `test.mod.go`, which shouldn't be edited by hand, `test.go` is a stub to get you started and you'll need to edit it. You'll need to add real function hanlders for your mutations in `func Init()`. If you made a polling loop you probably want to put some stuff in `func Poll()`. In general, look for comments starting with `// TODO:` for areas where you might want to alter things.
172
+
173
+
If you change your module definition, you can update your module without overwriting `test.go`.
174
+
175
+
```bash
176
+
$ kraken module update
177
+
```
178
+
179
+
This will *only* update `test.mod.go`. Note: you may need to make manual changes to make `test.go` match, e.g. if you changed your list of mutations.
0 commit comments