Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Parameterize config paths. Fixes #12911. #12912

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
8 changes: 4 additions & 4 deletions internal/ingress/controller/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
}

if klog.V(2).Enabled() {
src, err := os.ReadFile(cfgPath)
src, err := os.ReadFile(cfgPath())
if err != nil {
return err
}
Expand All @@ -719,7 +719,7 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
return err
}
//nolint:gosec //Ignore G204 error
diffOutput, err := exec.Command("diff", "-I", "'# Configuration.*'", "-u", cfgPath, tmpfile.Name()).CombinedOutput()
diffOutput, err := exec.Command("diff", "-I", "'# Configuration.*'", "-u", cfgPath(), tmpfile.Name()).CombinedOutput()
if err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
ws, ok := exitError.Sys().(syscall.WaitStatus)
Expand All @@ -740,7 +740,7 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
}
}

err = os.WriteFile(cfgPath, content, file.ReadWriteByUser)
err = os.WriteFile(cfgPath(), content, file.ReadWriteByUser)
if err != nil {
return err
}
Expand Down Expand Up @@ -1105,7 +1105,7 @@ func (n *NGINXController) createLuaConfig(cfg *ngx_config.Configuration) error {
if err != nil {
return err
}
return os.WriteFile(luaCfgPath, jsonCfg, file.ReadWriteByUser)
return os.WriteFile(luaCfgPath(), jsonCfg, file.ReadWriteByUser)
}

func cleanTempNginxCfg() error {
Expand Down
22 changes: 18 additions & 4 deletions internal/ingress/controller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ func rlimitMaxNumFiles() int {
}

const (
defBinary = "/usr/bin/nginx"
cfgPath = "/etc/nginx/nginx.conf"
luaCfgPath = "/etc/nginx/lua/cfg.json"
defBinary = "/usr/bin/nginx"
)

// NginxExecTester defines the interface to execute
Expand All @@ -115,6 +113,22 @@ type NginxCommand struct {
Binary string
}

func luaCfgPath() string {
cfgPath := os.Getenv("NGINX_LUA_CONFIG_PATH")
if cfgPath == "" {
return "/etc/nginx/lua/cfg.json"
}
return cfgPath
}

func cfgPath() string {
cfgPath := os.Getenv("NGINX_CONFIG_PATH")
if cfgPath == "" {
return "/etc/nginx/nginx.conf"
}
return cfgPath
}

// NewNginxCommand returns a new NginxCommand from which path
// has been detected from environment variable NGINX_BINARY or default
func NewNginxCommand() NginxCommand {
Expand All @@ -134,7 +148,7 @@ func NewNginxCommand() NginxCommand {
func (nc NginxCommand) ExecCommand(args ...string) *exec.Cmd {
cmdArgs := []string{}

cmdArgs = append(cmdArgs, "-c", cfgPath)
cmdArgs = append(cmdArgs, "-c", cfgPath())
cmdArgs = append(cmdArgs, args...)
//nolint:gosec // Ignore G204 error
return exec.Command(nc.Binary, cmdArgs...)
Expand Down
Loading