From b9eb632945d7b3a957e1691e5c49f7db7fb2186e Mon Sep 17 00:00:00 2001 From: Ciaran Roche Date: Wed, 4 Mar 2026 16:00:33 +0000 Subject: [PATCH 1/4] HYPERFLEET-710: Fix config file resolution broken by -trimpath build flag Replace runtime.Caller(0)-based GetProjectRootDir() with os.Getwd() for resolving relative config file paths. runtime.Caller(0) returns the Go module path when built with -trimpath, causing the db-migrate init container to crash looking for paths like: github.com/openshift-hyperfleet/hyperfleet-api/secrets/db.host instead of the correct /app/secrets/db.host. Also fixes the Helm deployment template secret mount path from /build/secrets to /app/secrets to match the Dockerfile WORKDIR, and clears secret file paths in unit test environment since it uses a mock DB. Co-Authored-By: Claude Opus 4.6 --- charts/templates/deployment.yaml | 4 ++-- .../environments/e_unit_testing.go | 8 ++++++++ pkg/config/config.go | 18 +++++++----------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/charts/templates/deployment.yaml b/charts/templates/deployment.yaml index fd1e55e..ffb06c5 100644 --- a/charts/templates/deployment.yaml +++ b/charts/templates/deployment.yaml @@ -40,7 +40,7 @@ spec: command: ["/app/hyperfleet-api", "migrate"] volumeMounts: - name: secrets - mountPath: /build/secrets + mountPath: /app/secrets readOnly: true {{- end }} containers: @@ -113,7 +113,7 @@ spec: mountPath: /tmp {{- if or .Values.database.external.enabled .Values.database.postgresql.enabled }} - name: secrets - mountPath: /build/secrets + mountPath: /app/secrets readOnly: true {{- end }} {{- if .Values.extraVolumeMounts }} diff --git a/cmd/hyperfleet-api/environments/e_unit_testing.go b/cmd/hyperfleet-api/environments/e_unit_testing.go index 81127e3..642fa35 100755 --- a/cmd/hyperfleet-api/environments/e_unit_testing.go +++ b/cmd/hyperfleet-api/environments/e_unit_testing.go @@ -24,6 +24,14 @@ func (e *unitTestingEnvImpl) OverrideConfig(c *config.ApplicationConfig) error { if os.Getenv("DB_DEBUG") == "true" { c.Database.Debug = true } + + // Clear secret file paths — unit tests use a mock DB and don't need real credentials + c.Database.HostFile = "" + c.Database.PortFile = "" + c.Database.NameFile = "" + c.Database.UsernameFile = "" + c.Database.PasswordFile = "" + return nil } diff --git a/pkg/config/config.go b/pkg/config/config.go index 326b7ba..4b62b29 100755 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -5,7 +5,6 @@ import ( "fmt" "os" "path/filepath" - "runtime" "strconv" "strings" @@ -79,7 +78,7 @@ func (c *ApplicationConfig) ReadFiles() []string { // Read the contents of file into integer value func readFileValueInt(file string, val *int) error { fileContents, err := ReadFile(file) - if err != nil { + if err != nil || fileContents == "" { return err } @@ -122,10 +121,14 @@ func ReadFile(file string) (string, error) { return "", nil } - // Ensure the absolute file path is used + // Resolve relative paths from the current working directory absFilePath := unquotedFile if !filepath.IsAbs(unquotedFile) { - absFilePath = filepath.Join(GetProjectRootDir(), unquotedFile) + wd, wdErr := os.Getwd() + if wdErr != nil { + return "", fmt.Errorf("failed to get working directory: %w", wdErr) + } + absFilePath = filepath.Join(wd, unquotedFile) } // Read the file @@ -135,10 +138,3 @@ func ReadFile(file string) (string, error) { } return string(buf), nil } - -// GetProjectRootDir Return project root path based on the relative path of this file -func GetProjectRootDir() string { - _, b, _, _ := runtime.Caller(0) - basepath := filepath.Dir(filepath.Join(b, "..", "..")) - return basepath -} From df9403943376bde302e819bfd1e180e9c0800dfd Mon Sep 17 00:00:00 2001 From: Ciaran Roche Date: Wed, 4 Mar 2026 16:30:20 +0000 Subject: [PATCH 2/4] HYPERFLEET-710: Clear secret file paths in integration test environment Integration tests use testcontainers for DB and don't need file-based credentials. Without this, the integration test environment fails to initialize when secrets files aren't present at the test CWD. Co-Authored-By: Claude Opus 4.6 --- cmd/hyperfleet-api/environments/e_integration_testing.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/hyperfleet-api/environments/e_integration_testing.go b/cmd/hyperfleet-api/environments/e_integration_testing.go index 8db7ea0..44cf212 100755 --- a/cmd/hyperfleet-api/environments/e_integration_testing.go +++ b/cmd/hyperfleet-api/environments/e_integration_testing.go @@ -24,6 +24,14 @@ func (e *integrationTestingEnvImpl) OverrideConfig(c *config.ApplicationConfig) if os.Getenv("DB_DEBUG") == "true" { c.Database.Debug = true } + + // Clear secret file paths — integration tests use testcontainers and don't need file-based credentials + c.Database.HostFile = "" + c.Database.PortFile = "" + c.Database.NameFile = "" + c.Database.UsernameFile = "" + c.Database.PasswordFile = "" + return nil } From acf115e25724ed8101c45704fe43114d4e3a3baa Mon Sep 17 00:00:00 2001 From: Ciaran Roche Date: Thu, 5 Mar 2026 08:56:55 +0000 Subject: [PATCH 3/4] HYPERFLEET-710: Set default DB config for integration test environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Integration tests use testcontainers which creates a fresh PostgreSQL with whatever credentials are provided — the values are arbitrary. Set defaults directly instead of relying on secret files existing relative to the test CWD. Co-Authored-By: Claude Opus 4.6 --- cmd/hyperfleet-api/environments/e_integration_testing.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/hyperfleet-api/environments/e_integration_testing.go b/cmd/hyperfleet-api/environments/e_integration_testing.go index 44cf212..44fe69a 100755 --- a/cmd/hyperfleet-api/environments/e_integration_testing.go +++ b/cmd/hyperfleet-api/environments/e_integration_testing.go @@ -25,12 +25,16 @@ func (e *integrationTestingEnvImpl) OverrideConfig(c *config.ApplicationConfig) c.Database.Debug = true } - // Clear secret file paths — integration tests use testcontainers and don't need file-based credentials + // Integration tests use testcontainers — set defaults directly instead of reading from secret files c.Database.HostFile = "" c.Database.PortFile = "" c.Database.NameFile = "" c.Database.UsernameFile = "" c.Database.PasswordFile = "" + c.Database.Name = "hyperfleet_test" + c.Database.Username = "test" + c.Database.Password = "test" + c.Database.Port = 5432 return nil } From 0342d742065eb6eaacf0dc6932f57d828edb6d45 Mon Sep 17 00:00:00 2001 From: Ciaran Roche Date: Thu, 5 Mar 2026 10:13:50 +0000 Subject: [PATCH 4/4] HYPERFLEET-710: Skip overwriting config values when file path is empty All readFileValue* functions now skip parsing when ReadFile returns empty contents (no file configured). Previously readFileValueString would overwrite existing values with "" even when the file path was cleared, causing OverrideConfig defaults to be lost. Co-Authored-By: Claude Opus 4.6 --- pkg/config/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 4b62b29..edd8741 100755 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -89,7 +89,7 @@ func readFileValueInt(file string, val *int) error { // Read the contents of file into string value func readFileValueString(file string, val *string) error { fileContents, err := ReadFile(file) - if err != nil { + if err != nil || fileContents == "" { return err } @@ -100,7 +100,7 @@ func readFileValueString(file string, val *string) error { // Read the contents of file into boolean value func readFileValueBool(file string, val *bool) error { fileContents, err := ReadFile(file) - if err != nil { + if err != nil || fileContents == "" { return err }