[fix] fix nginx temp configs cleanup (#12223)

Signed-off-by: Stepan Paksashvili <stepan.paksashvili@flant.com>
Co-authored-by: Stepan Paksashvili <stepan.paksashvili@flant.com>
This commit is contained in:
k8s-infra-cherrypick-robot 2024-10-22 09:44:52 -07:00 committed by GitHub
parent 085ca285ed
commit f4bcfcd363
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 11 deletions

View file

@ -643,8 +643,7 @@ func (n *NGINXController) testTemplate(cfg []byte) error {
if len(cfg) == 0 {
return fmt.Errorf("invalid NGINX configuration (empty)")
}
tmpDir := os.TempDir() + "/nginx"
tmpfile, err := os.CreateTemp(tmpDir, tempNginxPattern)
tmpfile, err := os.CreateTemp(filepath.Join(os.TempDir(), "nginx"), tempNginxPattern)
if err != nil {
return err
}
@ -1082,11 +1081,11 @@ func createOpentelemetryCfg(cfg *ngx_config.Configuration) error {
func cleanTempNginxCfg() error {
var files []string
err := filepath.Walk(os.TempDir(), func(path string, info os.FileInfo, err error) error {
err := filepath.Walk(filepath.Join(os.TempDir(), "nginx"), func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() && os.TempDir() != path {
if info.IsDir() && path != filepath.Join(os.TempDir(), "nginx") {
return filepath.SkipDir
}
@ -1105,7 +1104,7 @@ func cleanTempNginxCfg() error {
}
for _, file := range files {
err := os.Remove(file)
err = os.Remove(file)
if err != nil {
return err
}