Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit 234ae9f

Browse files
add kubernetes secrets provider and API to read secrets (#885)
Co-authored-by: Matt Johnson-Pint <mjp@hypermode.com>
1 parent f42df8b commit 234ae9f

35 files changed

+2478
-42
lines changed

.vscode/launch.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@
180180
"label": "PostgreSQL Client Example",
181181
"value": "postgresql"
182182
},
183+
{
184+
"label": "Secrets Example",
185+
"value": "secrets"
186+
},
183187
{
184188
"label": "Simple Example",
185189
"value": "simple"

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
# Change Log
44

5+
## UNRELEASED
6+
7+
- feat: add kubernetes secrets provider and API to read secrets [#885](https://github.com/hypermodeinc/modus/pull/885)
8+
59
## 2025-06-10 - Runtime 0.18.0-alpha.6
610

711
- fix: address agent lifecycle issues [#881](https://github.com/hypermodeinc/modus/pull/881)

go.work

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ use (
2222
./sdk/go/examples/textgeneration
2323
./sdk/go/examples/time
2424
./sdk/go/examples/vectors
25+
./sdk/go/examples/secrets
2526
./sdk/go/templates/default
2627
)

runtime/app/config.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ import (
1818
)
1919

2020
type AppConfig struct {
21-
environment string
22-
port int
23-
appPath string
24-
useAwsStorage bool
25-
s3Bucket string
26-
s3Path string
27-
refreshInterval time.Duration
28-
useJsonLogging bool
21+
environment string
22+
port int
23+
appPath string
24+
useAwsStorage bool
25+
s3Bucket string
26+
s3Path string
27+
useKubernetesSecret bool
28+
kubernetesSecretName string
29+
refreshInterval time.Duration
30+
useJsonLogging bool
2931
}
3032

3133
func (c *AppConfig) Environment() string {
@@ -52,6 +54,14 @@ func (c *AppConfig) S3Path() string {
5254
return c.s3Path
5355
}
5456

57+
func (c *AppConfig) UseKubernetesSecret() bool {
58+
return c.useKubernetesSecret
59+
}
60+
61+
func (c *AppConfig) KubernetesSecretName() string {
62+
return c.kubernetesSecretName
63+
}
64+
5565
func (c *AppConfig) RefreshInterval() time.Duration {
5666
return c.refreshInterval
5767
}
@@ -126,6 +136,9 @@ func CreateAppConfig() *AppConfig {
126136
fs.StringVar(&cfg.s3Bucket, "s3bucket", cfg.s3Bucket, "The S3 bucket to use, if using AWS storage.")
127137
fs.StringVar(&cfg.s3Path, "s3path", cfg.s3Path, "The path within the S3 bucket to use, if using AWS storage.")
128138

139+
fs.BoolVar(&cfg.useKubernetesSecret, "useKubernetesSecret", cfg.useKubernetesSecret, "Use Kubernetes secrets for reading secrets.")
140+
fs.StringVar(&cfg.kubernetesSecretName, "kubernetesSecretName", cfg.kubernetesSecretName, "The Kubernetes secret to read from, if using Kubernetes secrets.")
141+
129142
fs.DurationVar(&cfg.refreshInterval, "refresh", cfg.refreshInterval, "The refresh interval to reload any changes.")
130143
fs.BoolVar(&cfg.useJsonLogging, "jsonlogs", cfg.useJsonLogging, "Use JSON format for logging.")
131144

runtime/db/inferencehistory.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,11 @@ type inferenceHistory struct {
7676
func (w *runtimePostgresWriter) GetPool(ctx context.Context) (*pgxpool.Pool, error) {
7777
var initErr error
7878
w.once.Do(func() {
79-
var connStr string
80-
var err error
81-
if secrets.HasSecret("MODUS_DB") {
82-
connStr, err = secrets.GetSecretValue("MODUS_DB")
83-
} else if secrets.HasSecret("HYPERMODE_METADATA_DB") {
84-
// fallback to old secret name
85-
// TODO: remove this after the transition is complete
86-
connStr, err = secrets.GetSecretValue("HYPERMODE_METADATA_DB")
87-
} else {
79+
if !secrets.HasSecret(ctx, "MODUS_DB") {
8880
return
8981
}
9082

83+
connStr, err := secrets.GetSecretValue(ctx, "MODUS_DB")
9184
if err != nil {
9285
initErr = err
9386
return

runtime/go.mod

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ require (
5252
golang.org/x/sys v0.33.0
5353
google.golang.org/grpc v1.73.0
5454
google.golang.org/protobuf v1.36.6
55+
k8s.io/api v0.33.1
56+
k8s.io/apimachinery v0.33.1
57+
k8s.io/client-go v0.33.1
58+
sigs.k8s.io/controller-runtime v0.21.0
5559
)
5660

5761
require (
@@ -120,13 +124,19 @@ require (
120124
github.com/eapache/go-resiliency v1.7.0 // indirect
121125
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
122126
github.com/eapache/queue v1.1.0 // indirect
127+
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
128+
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
123129
github.com/felixge/fgprof v0.9.5 // indirect
124130
github.com/felixge/httpsnoop v1.0.4 // indirect
125131
github.com/flowchartsman/retry v1.2.0 // indirect
126132
github.com/fsnotify/fsnotify v1.8.0 // indirect
133+
github.com/fxamacker/cbor/v2 v2.8.0 // indirect
127134
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
128135
github.com/go-logr/logr v1.4.3 // indirect
129136
github.com/go-logr/stdr v1.2.2 // indirect
137+
github.com/go-openapi/jsonpointer v0.21.1 // indirect
138+
github.com/go-openapi/jsonreference v0.21.0 // indirect
139+
github.com/go-openapi/swag v0.23.1 // indirect
130140
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
131141
github.com/gobwas/httphead v0.1.0 // indirect
132142
github.com/gobwas/pool v0.2.1 // indirect
@@ -140,6 +150,8 @@ require (
140150
github.com/google/btree v1.1.3 // indirect
141151
github.com/google/codesearch v1.2.0 // indirect
142152
github.com/google/flatbuffers v25.2.10+incompatible // indirect
153+
github.com/google/gnostic-models v0.6.9 // indirect
154+
github.com/google/go-cmp v0.7.0 // indirect
143155
github.com/google/pprof v0.0.0-20250128161936-077ca0a936bf // indirect
144156
github.com/hashicorp/errwrap v1.1.0 // indirect
145157
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
@@ -170,6 +182,7 @@ require (
170182
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
171183
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
172184
github.com/jensneuse/byte-template v0.0.0-20231025215717-69252eb3ed56 // indirect
185+
github.com/josharian/intern v1.0.0 // indirect
173186
github.com/json-iterator/go v1.1.12 // indirect
174187
github.com/kingledion/go-tools v0.6.0 // indirect
175188
github.com/klauspost/compress v1.18.0 // indirect
@@ -178,6 +191,7 @@ require (
178191
github.com/lestrrat-go/httpcc v1.0.1 // indirect
179192
github.com/lestrrat-go/httprc/v3 v3.0.0 // indirect
180193
github.com/lestrrat-go/option v1.0.1 // indirect
194+
github.com/mailru/easyjson v0.9.0 // indirect
181195
github.com/mattn/go-colorable v0.1.13 // indirect
182196
github.com/mattn/go-isatty v0.0.20 // indirect
183197
github.com/miekg/dns v1.1.66 // indirect
@@ -237,6 +251,7 @@ require (
237251
github.com/wundergraph/astjson v0.0.0-20250106123708-be463c97e083 // indirect
238252
github.com/wundergraph/cosmo/composition-go v0.0.0-20241020204711-78f240a77c99 // indirect
239253
github.com/wundergraph/cosmo/router v0.0.0-20240729154441-b20b00e892c6 // indirect
254+
github.com/x448/float16 v0.8.4 // indirect
240255
github.com/xdg/scram v1.0.5 // indirect
241256
github.com/xdg/stringprep v1.0.3 // indirect
242257
github.com/zeebo/xxh3 v1.0.2 // indirect
@@ -254,17 +269,29 @@ require (
254269
golang.org/x/crypto v0.39.0 // indirect
255270
golang.org/x/mod v0.25.0 // indirect
256271
golang.org/x/net v0.41.0 // indirect
272+
golang.org/x/oauth2 v0.30.0 // indirect
257273
golang.org/x/sync v0.15.0 // indirect
258274
golang.org/x/term v0.32.0 // indirect
259275
golang.org/x/text v0.26.0 // indirect
260276
golang.org/x/time v0.12.0 // indirect
261277
golang.org/x/tools v0.34.0 // indirect
278+
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
262279
google.golang.org/api v0.219.0 // indirect
263280
google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 // indirect
264281
gopkg.in/DataDog/dd-trace-go.v1 v1.71.0 // indirect
265282
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
283+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
284+
gopkg.in/inf.v0 v0.9.1 // indirect
266285
gopkg.in/ini.v1 v1.67.0 // indirect
267286
gopkg.in/yaml.v2 v2.4.0 // indirect
268287
gopkg.in/yaml.v3 v3.0.1 // indirect
288+
k8s.io/apiextensions-apiserver v0.33.0 // indirect
289+
k8s.io/klog/v2 v2.130.1 // indirect
290+
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
291+
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 // indirect
269292
rogchap.com/v8go v0.9.0 // indirect
293+
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
294+
sigs.k8s.io/randfill v1.0.0 // indirect
295+
sigs.k8s.io/structured-merge-diff/v4 v4.7.0 // indirect
296+
sigs.k8s.io/yaml v1.4.0 // indirect
270297
)

0 commit comments

Comments
 (0)