fix(pkg): address ignored errors with logging and documentation#610
Conversation
Pull Request Test Coverage Report for Build 21755908155Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
There was a problem hiding this comment.
Pull request overview
This PR aims to eliminate previously ignored errors by either logging failures (for status updates) or documenting why certain cleanup errors are safe to ignore. In addition, it introduces new CLI commands and expands the CLI entrypoint wiring/help text.
Changes:
- Add warning logs when AWS provider status-condition updates fail (
pkg/provider/aws/create.go). - Replace
//nolint:errcheck///nolint:gosecon variousClose()calls with explanatory comments (pkg/provisioner/*,pkg/utils/*). - Add new CLI commands (
validate,provision) and update CLI command registration/help text (cmd/cli/*).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 20 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/utils/kubeconfig.go | Replaces nolint’d Close() calls with “Ignore” comments during cleanup. |
| pkg/utils/ip.go | Replaces nolint’d resp.Body.Close() with an “Ignore” comment. |
| pkg/provisioner/provisioner.go | Documents previously nolint’d Close() calls across provisioning/cleanup flows. |
| pkg/provider/aws/create.go | Logs warnings when condition/status updates fail instead of silently ignoring errors. |
| cmd/cli/validate/validate.go | Adds a new holodeck validate command to preflight environment configs. |
| cmd/cli/provision/provision.go | Adds a new holodeck provision command (instance mode + SSH mode). |
| cmd/cli/main.go | Registers additional CLI commands and expands CLI help examples. |
pkg/provisioner/provisioner.go
Outdated
| @@ -250,7 +250,7 @@ func (p *Provisioner) createKindConfig(env v1alpha1.Environment) error { | |||
| if err != nil { | |||
| return fmt.Errorf("failed to create session: %v", err) | |||
| } | |||
| defer session.Close() // nolint:errcheck, gosec | |||
| defer session.Close() // Ignore: cleanup error - resource is being cleaned up anyway | |||
There was a problem hiding this comment.
defer session.Close() ignores the returned error and will be flagged by gosec now that the nolint is removed. Handle/log the close error (or keep an explicit linter suppression).
| // Close the writing pipe and wait for the session to finish | ||
| remoteFile.Close() // nolint:errcheck, gosec | ||
| remoteFile.Close() // Ignore: cleanup error - resource is being cleaned up anyway | ||
| if err := session.Wait(); err != nil { |
There was a problem hiding this comment.
remoteFile.Close() returns an error; gosec will still flag this as unchecked (G104) without the nolint. Handle/log the error (and consider defering the close right after StdinPipe() succeeds to simplify the control flow).
pkg/provisioner/provisioner.go
Outdated
| if err := session.Run("sudo mkdir -p /etc/kubernetes"); err != nil { | ||
| session.Close() // nolint:errcheck, gosec | ||
| session.Close() // Ignore: cleanup error - resource is being cleaned up anyway | ||
| return fmt.Errorf("failed to create directory on remote host: %v", err) | ||
| } | ||
| session.Close() // nolint:errcheck, gosec | ||
| session.Close() // Ignore: cleanup error - resource is being cleaned up anyway |
There was a problem hiding this comment.
These session.Close() calls still ignore returned errors; gosec will flag them now that the nolint is removed (G104). Capture/log the Close error (or restructure with a single defer so you don't need multiple closes in the error paths).
| "github.com/NVIDIA/holodeck/cmd/cli/describe" | ||
| "github.com/NVIDIA/holodeck/cmd/cli/dryrun" | ||
| "github.com/NVIDIA/holodeck/cmd/cli/get" | ||
| "github.com/NVIDIA/holodeck/cmd/cli/list" | ||
| oscmd "github.com/NVIDIA/holodeck/cmd/cli/os" |
There was a problem hiding this comment.
The CLI imports/registers commands (describe/get/scp/ssh/update) that do not exist under cmd/cli in this PR, which will break go build for the CLI. Either add these packages (and their NewCommand exports) or remove the imports/command registrations and related examples from the help text.
| if err != nil { | ||
| return "", fmt.Errorf("error fetching IP from %s: %v", url, err) | ||
| } | ||
| defer resp.Body.Close() // nolint:errcheck, gosec, staticcheck | ||
| defer resp.Body.Close() // Ignore: cleanup error - response body is being cleaned up anyway | ||
|
|
There was a problem hiding this comment.
defer resp.Body.Close() ignores the returned error; gosec (G307) will flag this without the nolint. Wrap it in a deferred func that checks/logs the close error (or keep a targeted //nolint:gosec with justification).
| session, err := p.Client.NewSession() | ||
| if err == nil { | ||
| session.Close() // nolint:errcheck, gosec | ||
| session.Close() // Ignore: cleanup error - resource is being cleaned up anyway | ||
| // Connection is alive, close it | ||
| if err := p.Client.Close(); err != nil { | ||
| return fmt.Errorf("failed to close ssh client: %w", err) |
There was a problem hiding this comment.
Same issue here: session.Close() returns an error and gosec will flag the unchecked error (G104). Handle/log the Close error rather than only documenting it in a comment.
pkg/provisioner/provisioner.go
Outdated
| if err := session.Run(fmt.Sprintf("sudo mv %s %s", tempRemotePath, remoteFilePath)); err != nil { | ||
| session.Close() // nolint:errcheck, gosec | ||
| session.Close() // Ignore: cleanup error - resource is being cleaned up anyway | ||
| return fmt.Errorf("failed to move kubeadm config to final destination: %v", err) | ||
| } | ||
| session.Close() // nolint:errcheck, gosec | ||
| session.Close() // Ignore: cleanup error - resource is being cleaned up anyway |
There was a problem hiding this comment.
Same here: session.Close() errors are still unchecked and will be flagged by gosec. Handle/log the Close error rather than relying on a comment.
| if err != nil { | ||
| return fmt.Errorf("failed to start SFTP session: %v", err) | ||
| } | ||
| defer client.Close() // nolint:errcheck, gosec | ||
| defer client.Close() // Ignore: cleanup error - resource is being cleaned up anyway | ||
|
|
There was a problem hiding this comment.
defer client.Close() ignores the returned error; gosec will flag this as an unchecked error (G104/G307). Wrap in a deferred func and log (or otherwise handle) the close error.
pkg/utils/kubeconfig.go
Outdated
| return fmt.Errorf("error creating local file: %v", err) | ||
| } | ||
| defer localFile.Close() // nolint:errcheck, gosec | ||
| defer localFile.Close() // Ignore: cleanup error - resource is being cleaned up anyway |
There was a problem hiding this comment.
defer localFile.Close() ignores the returned error and will be flagged by gosec (G307). Prefer a deferred func that captures/logs the Close error, especially since this is writing the kubeconfig to disk.
| defer localFile.Close() // Ignore: cleanup error - resource is being cleaned up anyway | |
| defer func() { | |
| if cerr := localFile.Close(); cerr != nil { | |
| log.Info(fmt.Sprintf("error closing local kubeconfig file %s: %v", dest, cerr)) | |
| } | |
| }() |
pkg/provisioner/provisioner.go
Outdated
|
|
||
| go func() { | ||
| defer writer.Close() // nolint:errcheck, gosec | ||
| defer writer.Close() // Ignore: cleanup error - resource is being cleaned up anyway |
There was a problem hiding this comment.
defer writer.Close() ignores the returned error; gosec will still flag this without the nolint (G104/G307 depending on rule). Wrap the Close in a deferred func that checks/logs the error.
| defer writer.Close() // Ignore: cleanup error - resource is being cleaned up anyway | |
| defer func() { | |
| if err := writer.Close(); err != nil { | |
| logger.Error("failed to close pipe writer", "error", err) | |
| } | |
| }() |
1b1ece5 to
f9354a5
Compare
- Replace ignored status update errors in create.go with proper logging - 12 status update calls now log warnings instead of silently ignoring errors - updateProgressingCondition and updateDegradedCondition errors are now visible - Document Close() errors in provisioner.go, kubeconfig.go, and ip.go - Added explanatory comments for 14 Close() operations - These cleanup errors are acceptable as resources are being cleaned up anyway All changes compile successfully. Status update failures are now visible in logs, improving observability of state tracking issues. Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
f9354a5 to
ac00335
Compare
…IA#610) - Replace ignored status update errors in create.go with proper logging - 12 status update calls now log warnings instead of silently ignoring errors - updateProgressingCondition and updateDegradedCondition errors are now visible - Document Close() errors in provisioner.go, kubeconfig.go, and ip.go - Added explanatory comments for 14 Close() operations - These cleanup errors are acceptable as resources are being cleaned up anyway All changes compile successfully. Status update failures are now visible in logs, improving observability of state tracking issues. Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
…IA#610) - Replace ignored status update errors in create.go with proper logging - 12 status update calls now log warnings instead of silently ignoring errors - updateProgressingCondition and updateDegradedCondition errors are now visible - Document Close() errors in provisioner.go, kubeconfig.go, and ip.go - Added explanatory comments for 14 Close() operations - These cleanup errors are acceptable as resources are being cleaned up anyway All changes compile successfully. Status update failures are now visible in logs, improving observability of state tracking issues. Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
…IA#610) - Replace ignored status update errors in create.go with proper logging - 12 status update calls now log warnings instead of silently ignoring errors - updateProgressingCondition and updateDegradedCondition errors are now visible - Document Close() errors in provisioner.go, kubeconfig.go, and ip.go - Added explanatory comments for 14 Close() operations - These cleanup errors are acceptable as resources are being cleaned up anyway All changes compile successfully. Status update failures are now visible in logs, improving observability of state tracking issues. Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
…IA#610) - Replace ignored status update errors in create.go with proper logging - 12 status update calls now log warnings instead of silently ignoring errors - updateProgressingCondition and updateDegradedCondition errors are now visible - Document Close() errors in provisioner.go, kubeconfig.go, and ip.go - Added explanatory comments for 14 Close() operations - These cleanup errors are acceptable as resources are being cleaned up anyway All changes compile successfully. Status update failures are now visible in logs, improving observability of state tracking issues. Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
…IA#610) - Replace ignored status update errors in create.go with proper logging - 12 status update calls now log warnings instead of silently ignoring errors - updateProgressingCondition and updateDegradedCondition errors are now visible - Document Close() errors in provisioner.go, kubeconfig.go, and ip.go - Added explanatory comments for 14 Close() operations - These cleanup errors are acceptable as resources are being cleaned up anyway All changes compile successfully. Status update failures are now visible in logs, improving observability of state tracking issues. Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
…IA#610) - Replace ignored status update errors in create.go with proper logging - 12 status update calls now log warnings instead of silently ignoring errors - updateProgressingCondition and updateDegradedCondition errors are now visible - Document Close() errors in provisioner.go, kubeconfig.go, and ip.go - Added explanatory comments for 14 Close() operations - These cleanup errors are acceptable as resources are being cleaned up anyway All changes compile successfully. Status update failures are now visible in logs, improving observability of state tracking issues. Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
Summary
Address 28 instances of ignored errors (
//nolint:errcheck) inpkg/by either:Changes
pkg/provider/aws/create.go (12 errors fixed)
Status update functions were silently ignoring errors. Now they log warnings:
pkg/provisioner/provisioner.go (13 errors documented)
Close() errors in cleanup paths are now documented:
pkg/utils/kubeconfig.go & ip.go (3 errors documented)
Added explanatory comments for cleanup close operations.
Impact
nolint:errcheckTest plan
go build ./pkg/...- compiles successfullygo test ./pkg/...- verify no regressions