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_integration_testing.go b/cmd/hyperfleet-api/environments/e_integration_testing.go index 8db7ea0..44fe69a 100755 --- a/cmd/hyperfleet-api/environments/e_integration_testing.go +++ b/cmd/hyperfleet-api/environments/e_integration_testing.go @@ -24,6 +24,18 @@ func (e *integrationTestingEnvImpl) OverrideConfig(c *config.ApplicationConfig) if os.Getenv("DB_DEBUG") == "true" { c.Database.Debug = true } + + // 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 } 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..edd8741 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 } @@ -90,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 } @@ -101,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 } @@ -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 -}