Skip to content

Commit c214cad

Browse files
authored
feat(config): Auto-detect ko.build OCI images and set config paths (#100)
Signed-off-by: Matthias Riegler <[email protected]>
1 parent cec8ca8 commit c214cad

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

config/option.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package config
22

3+
import (
4+
"os"
5+
"path"
6+
)
7+
38
// Options are options for the [ConfigFactory] implementations.
49
type Options struct {
510
FileName string
@@ -8,13 +13,20 @@ type Options struct {
813

914
// DefaultConfigOptions are the default options used in the [DefaultConfigFactory].
1015
func DefaultConfigOptions() Options {
11-
return Options{
16+
opts := Options{
1217
FileName: "config",
1318
FilePaths: []string{
1419
".",
1520
"./configs",
1621
},
1722
}
23+
24+
// check if the OCI image has been build using ko and use KO_DATA_PATH as config root
25+
if val, ok := os.LookupEnv("KO_DATA_PATH"); ok {
26+
opts.FilePaths = append(opts.FilePaths, val, path.Join(val, "configs"))
27+
}
28+
29+
return opts
1830
}
1931

2032
// ConfigOption are functional options for the [ConfigFactory] implementations.

config/option_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,19 @@ func TestWithFilePaths(t *testing.T) {
2424

2525
assert.Equal(t, []string{"path1", "path2"}, opts.FilePaths)
2626
}
27+
28+
func TestDefaultConfigOptions(t *testing.T) {
29+
opts := config.DefaultConfigOptions()
30+
31+
assert.Equal(t, "config", opts.FileName)
32+
assert.Equal(t, []string{".", "./configs"}, opts.FilePaths)
33+
}
34+
35+
func TestDefaultConfigOptions_KoBuild(t *testing.T) {
36+
t.Setenv("KO_DATA_PATH", "/var/run/ko")
37+
38+
opts := config.DefaultConfigOptions()
39+
40+
assert.Equal(t, "config", opts.FileName)
41+
assert.Equal(t, []string{".", "./configs", "/var/run/ko", "/var/run/ko/configs"}, opts.FilePaths)
42+
}

0 commit comments

Comments
 (0)