Skip to content

Commit

Permalink
Merge branch 'main' into rebuild-base-images
Browse files Browse the repository at this point in the history
  • Loading branch information
pdabelf5 committed Feb 29, 2024
2 parents 40d704b + ddaea41 commit a8c0583
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
11 changes: 7 additions & 4 deletions internal/nginx/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (lm *LocalManager) Quit() {
// Version returns NGINX version
func (lm *LocalManager) Version() Version {
binaryFilename := getBinaryFileName(lm.debug)
out, err := exec.Command(binaryFilename, "-v").CombinedOutput()
out, err := exec.Command(binaryFilename, "-v").CombinedOutput() //nolint:gosec // G204: Subprocess launched with variable - false positive, variable resolves to a const
if err != nil {
glog.Fatalf("Failed to get nginx version: %v", err)
}
Expand Down Expand Up @@ -456,13 +456,16 @@ func verifyConfigVersion(httpClient *http.Client, configVersion int, timeout tim
if err != nil {
return fmt.Errorf("error doing request: %w", err)
}
defer resp.Body.Close()
err = nil
defer func() {
err = resp.Body.Close()
}()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("API returned non-success status: %v", resp.StatusCode)
}

return nil
return err
}

// SetOpenTracing sets the value of OpenTracing for the Manager
Expand All @@ -481,7 +484,7 @@ func (lm *LocalManager) AppProtectPluginStart(appDone chan error, logLevel strin

glog.V(3).Info("Starting AppProtect Plugin")
startupParams := strings.Fields(appPluginParams)
cmd := exec.Command(appProtectPluginStartCmd, startupParams...)
cmd := exec.Command(appProtectPluginStartCmd, startupParams...) //nolint:gosec // G204: Subprocess launched with variable - false positive, variable resolves to a const

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stdout
Expand Down
8 changes: 6 additions & 2 deletions internal/nginx/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ func createFileAndWrite(name string, b []byte) error {
return fmt.Errorf("failed to open %v: %w", name, err)
}

defer w.Close()
defer func() {
if tempErr := w.Close(); tempErr != nil {
err = tempErr
}
}()

_, err = w.Write(b)
if err != nil {
return fmt.Errorf("failed to write to %v: %w", name, err)
}

return nil
return err
}

func createFileAndWriteAtomically(filename string, tempPath string, mode os.FileMode, content []byte) {
Expand Down
9 changes: 7 additions & 2 deletions internal/nginx/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ func (c *verifyClient) GetConfigVersion() (int, error) {
if err != nil {
return 0, fmt.Errorf("error getting client: %w", err)
}
defer resp.Body.Close()
err = nil
defer func() {
if tempErr := resp.Body.Close(); tempErr != nil {
err = tempErr
}
}()

if resp.StatusCode != http.StatusOK {
return 0, fmt.Errorf("non-200 response: %v", resp.StatusCode)
Expand All @@ -63,7 +68,7 @@ func (c *verifyClient) GetConfigVersion() (int, error) {
if err != nil {
return 0, fmt.Errorf("error converting string to int: %w", err)
}
return v, nil
return v, err
}

// WaitForCorrectVersion calls the config version endpoint until it gets the expectedVersion,
Expand Down
4 changes: 0 additions & 4 deletions pkg/apis/configuration/validation/virtualserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ func makeVirtualServer() v1.VirtualServer {
}
}

func createPointerFromString(s string) *string {
return &s
}

func TestValidateFailsOnMissingBackupPort(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit a8c0583

Please sign in to comment.