Skip to content

Commit 93c77f4

Browse files
committed
feat: enable specification of environment variables
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
1 parent f24a0c9 commit 93c77f4

File tree

9 files changed

+52
-13
lines changed

9 files changed

+52
-13
lines changed

dagger/maintenance/catalogs.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"path/filepath"
88
"slices"
9+
"sort"
910

1011
"go.yaml.in/yaml/v3"
1112

@@ -22,13 +23,19 @@ type ImageVolumeSource struct {
2223
PullPolicy string `yaml:"pullPolicy,omitempty"`
2324
}
2425

26+
type ExtensionEnvVar struct {
27+
Name string `yaml:"name"`
28+
Value string `yaml:"value"`
29+
}
30+
2531
type ExtensionConfiguration struct {
2632
Name string `yaml:"name"`
2733
ImageVolumeSource ImageVolumeSource `yaml:"image"`
2834
ExtensionControlPath []string `yaml:"extension_control_path,omitempty"`
2935
DynamicLibraryPath []string `yaml:"dynamic_library_path,omitempty"`
3036
LdLibraryPath []string `yaml:"ld_library_path,omitempty"`
3137
BinPath []string `yaml:"bin_path,omitempty"`
38+
Env []ExtensionEnvVar `yaml:"env,omitempty"`
3239
}
3340

3441
type ImageCatalog struct {
@@ -111,3 +118,14 @@ func writeCatalogToDir(catalog *ImageCatalog, outDir *dagger.Directory) (*dagger
111118

112119
return outDir.WithNewFile(outName, buf.String()), nil
113120
}
121+
122+
func envMapToSlice(env map[string]string) []ExtensionEnvVar {
123+
result := make([]ExtensionEnvVar, 0, len(env))
124+
for name, value := range env {
125+
result = append(result, ExtensionEnvVar{Name: name, Value: value})
126+
}
127+
sort.Slice(result, func(i, j int) bool {
128+
return result[i].Name < result[j].Name
129+
})
130+
return result
131+
}

dagger/maintenance/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ func (m *Maintenance) GenerateCatalogs(
515515
DynamicLibraryPath: metadata.DynamicLibraryPath,
516516
LdLibraryPath: metadata.LdLibraryPath,
517517
BinPath: metadata.BinPath,
518+
Env: envMapToSlice(metadata.Env),
518519
}
519520

520521
img.Extensions = append(img.Extensions, extensionsConfig)

dagger/maintenance/parse.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,20 @@ type extensionVersion struct {
2525
type versionMap map[string]map[string]extensionVersion
2626

2727
type extensionMetadata struct {
28-
Name string `hcl:"name" cty:"name"`
29-
SQLName string `hcl:"sql_name" cty:"sql_name"`
30-
ImageName string `hcl:"image_name" cty:"image_name"`
31-
SharedPreloadLibraries []string `hcl:"shared_preload_libraries" cty:"shared_preload_libraries"`
32-
ExtensionControlPath []string `hcl:"extension_control_path" cty:"extension_control_path"`
33-
DynamicLibraryPath []string `hcl:"dynamic_library_path" cty:"dynamic_library_path"`
34-
LdLibraryPath []string `hcl:"ld_library_path" cty:"ld_library_path"`
35-
BinPath []string `hcl:"bin_path" cty:"bin_path"`
36-
AutoUpdateOsLibs bool `hcl:"auto_update_os_libs" cty:"auto_update_os_libs"`
37-
RequiredExtensions []string `hcl:"required_extensions" cty:"required_extensions"`
38-
CreateExtension bool `hcl:"create_extension" cty:"create_extension"`
39-
Versions versionMap `hcl:"versions" cty:"versions"`
40-
Remain hcl.Body `hcl:",remain"`
28+
Name string `hcl:"name" cty:"name"`
29+
SQLName string `hcl:"sql_name" cty:"sql_name"`
30+
ImageName string `hcl:"image_name" cty:"image_name"`
31+
SharedPreloadLibraries []string `hcl:"shared_preload_libraries" cty:"shared_preload_libraries"`
32+
ExtensionControlPath []string `hcl:"extension_control_path" cty:"extension_control_path"`
33+
DynamicLibraryPath []string `hcl:"dynamic_library_path" cty:"dynamic_library_path"`
34+
LdLibraryPath []string `hcl:"ld_library_path" cty:"ld_library_path"`
35+
BinPath []string `hcl:"bin_path" cty:"bin_path"`
36+
Env map[string]string `hcl:"env" cty:"env"`
37+
AutoUpdateOsLibs bool `hcl:"auto_update_os_libs" cty:"auto_update_os_libs"`
38+
RequiredExtensions []string `hcl:"required_extensions" cty:"required_extensions"`
39+
CreateExtension bool `hcl:"create_extension" cty:"create_extension"`
40+
Versions versionMap `hcl:"versions" cty:"versions"`
41+
Remain hcl.Body `hcl:",remain"`
4142
}
4243

4344
const (

dagger/maintenance/testingvalues.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func generateExtensionConfiguration(metadata *extensionMetadata, extensionImage
109109
DynamicLibraryPath: metadata.DynamicLibraryPath,
110110
LdLibraryPath: metadata.LdLibraryPath,
111111
BinPath: metadata.BinPath,
112+
Env: envMapToSlice(metadata.Env),
112113
}, nil
113114
}
114115

pg-crash/metadata.hcl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ metadata = {
1010
dynamic_library_path = []
1111
ld_library_path = []
1212
bin_path = []
13+
env = {}
1314
auto_update_os_libs = false
1415
required_extensions = []
1516
create_extension = false

pgaudit/metadata.hcl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ metadata = {
88
dynamic_library_path = []
99
ld_library_path = []
1010
bin_path = []
11+
env = {}
1112
auto_update_os_libs = false
1213
required_extensions = []
1314
create_extension = true

pgvector/metadata.hcl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ metadata = {
88
dynamic_library_path = []
99
ld_library_path = []
1010
bin_path = []
11+
env = {}
1112
auto_update_os_libs = false
1213
required_extensions = []
1314
create_extension = true

postgis/metadata.hcl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ metadata = {
99
dynamic_library_path = []
1010
ld_library_path = ["system"]
1111
bin_path = []
12+
env = {}
1213
auto_update_os_libs = true
1314
required_extensions = []
1415
create_extension = true

templates/metadata.hcl.tmpl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ metadata = {
5858
# Postgres process. Used in tests and to generate image catalogs.
5959
bin_path = []
6060

61+
# TODO: Remove this comment block after customizing the file.
62+
# `env`: this SHOULD be defined when your extension needs specific environment
63+
# variables to be set within the PostgreSQL process to function correctly.
64+
# This is a map of key-value pairs.
65+
# Usually empty. Used in tests and to generate image catalogs.
66+
# Examples:
67+
# { "FOO" = "foo" }
68+
# HCL uses `${}` for interpolation, so `$` must be escaped.
69+
# To use a CNPG placeholder (expanded later by the operator):
70+
# { "BAR" = "$${image_root}/bar" }
71+
# To produce a literal `${...}` that the operator should NOT expand:
72+
# { "BAZ" = "$$${not_expanded}/baz" }
73+
env = {}
74+
6175
# TODO: Remove this comment block after customizing the file.
6276
# `auto_update_os_libs`: set to true to allow the maintenance tooling
6377
# to update OS libraries automatically; look at the `postgis` example.

0 commit comments

Comments
 (0)