Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions charts/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ spec:
command: ["/app/hyperfleet-api", "migrate"]
volumeMounts:
- name: secrets
mountPath: /build/secrets
mountPath: /app/secrets
readOnly: true
{{- end }}
containers:
Expand Down Expand Up @@ -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 }}
Expand Down
12 changes: 12 additions & 0 deletions cmd/hyperfleet-api/environments/e_integration_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 8 additions & 0 deletions cmd/hyperfleet-api/environments/e_unit_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
22 changes: 9 additions & 13 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"

Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
Expand All @@ -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
}