Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
To follow best practices for error and exception handling in Go and to prevent regressions,
err113 and gosec checks in golang-ci-linter are now enabled.
  • Loading branch information
mrkisaolamb authored and openshift-merge-bot[bot] committed Feb 26, 2025
1 parent 52d6965 commit eb9a7af
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ linters:
- ginkgolinter
- gofmt
- govet
- gosec
- errname
- err113
run:
timeout: 5m
11 changes: 5 additions & 6 deletions controllers/placementapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func ensureSecret(
return "",
ctrl.Result{},
*secret,
fmt.Errorf("Secret %s not found", secretName)
fmt.Errorf("%w: Secret %s not found", err, secretName)
}
conditionUpdater.Set(condition.FalseCondition(
condition.InputReadyCondition,
Expand All @@ -113,7 +113,7 @@ func ensureSecret(
for _, field := range expectedFields {
val, ok := secret.Data[field]
if !ok {
err := fmt.Errorf("field '%s' not found in secret/%s", field, secretName.Name)
err := fmt.Errorf("%w: field '%s' not found in secret/%s", util.ErrFieldNotFound, field, secretName.Name)
conditionUpdater.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.ErrorReason,
Expand Down Expand Up @@ -827,7 +827,7 @@ func (r *PlacementAPIReconciler) initConditions(
// fields to index to reconcile when change
const (
passwordSecretField = ".spec.secret"
caBundleSecretNameField = ".spec.tls.caBundleSecretName"
caBundleSecretNameField = ".spec.tls.caBundleSecretName" // #nosec G101
tlsAPIInternalField = ".spec.tls.api.internal.secretName"
tlsAPIPublicField = ".spec.tls.api.public.secretName"
topologyField = ".spec.topologyRef.Name"
Expand Down Expand Up @@ -1228,13 +1228,12 @@ func (r *PlacementAPIReconciler) ensureDeployment(
if networkReady {
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
} else {
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
instance.Status.Conditions.Set(condition.FalseCondition(
condition.NetworkAttachmentsReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.NetworkAttachmentsReadyErrorMessage,
err.Error()))
condition.NetworkAttachmentsErrorMessage,
instance.Spec.NetworkAttachments))

return ctrl.Result{}, err
}
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ const (

AccountName = "test-placement-account"

PublicCertSecretName = "public-tls-certs"
PublicCertSecretName = "public-tls-certs" // #nosec G101

InternalCertSecretName = "internal-tls-certs"
InternalCertSecretName = "internal-tls-certs" // #nosec G101

CABundleSecretName = "combined-ca-bundle"
CABundleSecretName = "combined-ca-bundle" // #nosec G101

interval = time.Millisecond * 200
)
Expand Down Expand Up @@ -201,7 +201,7 @@ var _ = BeforeSuite(func() {
dialer := &net.Dialer{Timeout: time.Duration(10) * time.Second}
addrPort := fmt.Sprintf("%s:%d", webhookInstallOptions.LocalServingHost, webhookInstallOptions.LocalServingPort)
Eventually(func() error {
conn, err := tls.DialWithDialer(dialer, "tcp", addrPort, &tls.Config{InsecureSkipVerify: true})
conn, err := tls.DialWithDialer(dialer, "tcp", addrPort, &tls.Config{InsecureSkipVerify: true}) // #nosec G402
if err != nil {
return err
}
Expand Down

0 comments on commit eb9a7af

Please sign in to comment.