Skip to content

Commit

Permalink
feat: environment vars for extension service
Browse files Browse the repository at this point in the history
This allows setting environment variables for the extension service.

Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
frezbo committed Sep 13, 2022
1 parent 0c0cb67 commit 4367491
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/app/machined/pkg/system/services/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func (svc *Extension) getOCIOptions() []oci.SpecOpts {
ociOpts = append(ociOpts, oci.WithWriteableSysfs)
}

if svc.Spec.Container.Environment != nil {
ociOpts = append(ociOpts, oci.WithEnv(svc.Spec.Container.Environment))
}

if svc.Spec.Container.Security.MaskedPaths != nil {
ociOpts = append(ociOpts, oci.WithMaskedPaths(svc.Spec.Container.Security.MaskedPaths))
}
Expand Down
20 changes: 20 additions & 0 deletions internal/app/machined/pkg/system/services/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,24 @@ func TestGetOCIOptions(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, true, spec.Root.Readonly)
})

t.Run("allows setting extra env vars", func(t *testing.T) {
// given
svc := &services.Extension{
Spec: &extservices.Spec{
Container: extservices.Container{
Environment: []string{
"FOO=BAR",
},
},
},
}

// when
spec, err := generateOCISpec(svc)

// then
assert.NoError(t, err)
assert.Equal(t, []string{"FOO=BAR"}, spec.Process.Env)
})
}
2 changes: 2 additions & 0 deletions pkg/machinery/extensions/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type Spec struct {
type Container struct {
// Entrypoint for the service, relative to the container rootfs.
Entrypoint string `yaml:"entrypoint"`
// Environment variables for the service.
Environment []string `yaml:"environment"`
// Args to pass to the entrypoint.
Args []string `yaml:"args"`
// Volume mounts.
Expand Down
3 changes: 3 additions & 0 deletions website/content/v1.3/advanced/extension-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Format of the extension service config:
name: hello-world
container:
entrypoint: ./hello-world
environment:
- XDG_RUNTIME_DIR=/run
args:
- -f
mounts:
Expand All @@ -52,6 +54,7 @@ The extension service will be registered as a Talos service under an `ext-<name>
### `container`

* `entrypoint` defines the container entrypoint relative to the container root filesystem (`/usr/local/lib/containers/<name>`)
* `environment` defines the container environment variables
* `args` defines the additional arguments to pass to the entrypoint
* `mounts` defines the volumes to be mounted into the container root

Expand Down

0 comments on commit 4367491

Please sign in to comment.