โ† Back to Pull requests

๐ŸŒฑ nilnil linter #2579

Merged
SD-13 merged 4 files (26 lines) on Jun 23, 2025 19:40 UTC
View on GitHub
SD-13 SD-13 commented on Jun 01, 2025 17:27 UTC
Author

<!-- please add an icon to the title of this PR (see https://sigs.k8s.io/cluster-api/CONTRIBUTING.md#contributing-a-patch), and delete this line and similar ones -->
<!-- the icon will be either โš ๏ธ (:warning:, major or breaking changes), โœจ (:sparkles:, feature additions), ๐Ÿ› (:bug:, patch and bugfixes), ๐Ÿ“– (:book:, documentation or proposals), or ๐ŸŒฑ (:seedling:, minor or other) -->

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #2446

Diff: 26 lines (+14 / -12) across 4 files Reviewer: lentzi90 Review duration: 31813m
All Vouch review confidence checks passed
Residual risk 0.02 = Change Risk (0.27) ร— (1 โˆ’ Review Confidence (0.92)). Review depth and reviewer attention state are adequate.
Model 1 ยท Change Risk (XGBoost)
Score: 0.27 ยท 26 lines diff across 4 files
0.27
Model 2 ยท Review Depth (DistilBERT)
Depth Score: 0.92 ยท 5 substantive comment(s)
0.92
Model 3 ยท Review Timing & Attention
Session adequacy: 100% ยท Reviewer familiarity: 50%
91%
Bedrock Claude 3 ยท Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 ยท Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.197
Real PR Conversation Timeline
22 items
metal3-io-bot metal3-io-bot commented on Jun 01, 2025 17:27 UTC
Bot

Hi @SD-13. Thanks for your PR.

I'm waiting for a metal3-io member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

<details>

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
</details>

SD-13 SD-13 commented on Jun 01, 2025 17:29 UTC
Author

@tuminoid I am new to golang and still learning semantic errors. I would really appreciate if you can leave some early feedback on this. Thanks!

tuminoid tuminoid commented on Jun 16, 2025 13:05 UTC
Contributor

@tuminoid I am new to golang and still learning semantic errors. I would really appreciate if you can leave some early feedback on this. Thanks!

Sorry I missed your message.
/ok-to-test

This needs some time to review as returning errors instead of nil. nil might break the system as sometimes we have cases nil, nil is the expected output. For example in BMO nilnil PR: https://github.com/metal3-io/baremetal-operator/pull/2514 we had these cases.

I don't have time to review it before my vacations, so I'll ping other guys to check it.
/cc @adilGhaffarDev @lentzi90

lentzi90 lentzi90 commented on code on Jun 18, 2025 05:59 UTC
Code Review
baremetal/metal3machine_manager.go:1
@@ -761,11 +764,12 @@ func getHost(ctx context.Context, m3Machine *infrav1.Metal3Machine, cl client.Cl
 ) (*bmov1alpha1.BareMetalHost, error) {
 	annotations := m3Machine.ObjectMeta.GetAnnotations()
 	if annotations == nil {
-		return nil, nil
+		return nil, ErrAnnotationsNotFound

This is not really something we consider an error. We need to keep it as nil and tell the linter to ignore it instead.

		return nil, nil //nolint:nilnil

lentzi90 lentzi90 commented on code on Jun 18, 2025 06:00 UTC
Code Review
baremetal/metal3machine_manager.go:1
@@ -761,11 +764,12 @@ func getHost(ctx context.Context, m3Machine *infrav1.Metal3Machine, cl client.Cl
 ) (*bmov1alpha1.BareMetalHost, error) {
 	annotations := m3Machine.ObjectMeta.GetAnnotations()
 	if annotations == nil {
-		return nil, nil
+		return nil, ErrAnnotationsNotFound
 	}
 	hostKey, ok := annotations[HostAnnotation]
+	var ErrHostKeyNotFound = errors.New("host key not found")
 	if !ok {
-		return nil, nil
+		return nil, ErrHostKeyNotFound

		return nil, nil //nolint:nilnil

lentzi90 lentzi90 commented on code on Jun 18, 2025 06:01 UTC
Code Review
baremetal/metal3machine_manager.go:1
@@ -779,9 +783,11 @@ func getHost(ctx context.Context, m3Machine *infrav1.Metal3Machine, cl client.Cl
 		Namespace: hostNamespace,
 	}
 	err = cl.Get(ctx, key, &host)
+
+	var ErrAnnotatedHostNotFound = errors.New("Annotated host not found")
 	if apierrors.IsNotFound(err) {
 		mLog.Info("Annotated host not found", "host", hostKey)
-		return nil, nil
+		return nil, ErrAnnotatedHostNotFound

This is also deliberate. We ignore the error only if the BMH is not found. All other errors are returned.

		return nil, nil //nolint:nilnil

lentzi90 lentzi90 commented on code on Jun 18, 2025 06:05 UTC
Code Review
baremetal/metal3machine_manager.go:1
@@ -1008,8 +1014,11 @@ func (m *MachineManager) nodeReuseLabelExists(_ context.Context, host *bmov1alph
 
 // getBMCSecret will return the BMCSecret associated with BMH.
 func (m *MachineManager) getBMCSecret(ctx context.Context, host *bmov1alpha1.BareMetalHost) (*corev1.Secret, error) {
-	if host == nil || host.Spec.BMC.CredentialsName == "" {
-		return nil, nil
+
+	if host == nil {
+		return nil, ErrHostIsEmpty
+	} else if host.Spec.BMC.CredentialsName == "" {
+		return nil, ErrCredentialsSecretIsEmpty

This I think is fine, but please remove the extra newlines above.

lentzi90 lentzi90 commented on code on Jun 18, 2025 06:05 UTC
Code Review
baremetal/metal3remediation_manager.go:1
@@ -391,7 +392,7 @@ func (r *RemediationManager) GetNode(ctx context.Context, clusterClient v1.CoreV
 
 	node, err := clusterClient.Nodes().Get(ctx, capiMachine.Status.NodeRef.Name, metav1.GetOptions{})
 	if apierrors.IsNotFound(err) {
-		return nil, nil
+		return nil, ErrNodeIsNotFound

		return nil, nil //nolint:nilnil

lentzi90 lentzi90 commented on code on Jun 18, 2025 06:05 UTC
Code Review
baremetal/utils.go:1
@@ -199,8 +203,9 @@ func fetchM3DataTemplate(ctx context.Context,
 	clusterName string,
 ) (*infrav1.Metal3DataTemplate, error) {
 	// If the user did not specify a Metal3DataTemplate, just keep going.
+	var ErrTemplateRefIsNil = errors.New("Template ref is nil")
 	if templateRef == nil {
-		return nil, nil
+		return nil, ErrTemplateRefIsNil

		return nil, nil //nolint:nilnil

lentzi90 lentzi90 commented on code on Jun 18, 2025 06:06 UTC
Code Review
baremetal/utils.go:1
@@ -294,7 +300,7 @@ func getM3Machine(ctx context.Context, cl client.Client, mLog logr.Logger,
 				mLog.Info(errMessage)
 				return nil, WithTransientError(errors.New(errMessage), requeueAfter)
 			}
-			return nil, nil
+			return nil, ErrMetal3MachineNotFound

			return nil, nil //nolint:nilnil

lentzi90 lentzi90 commented on code on Jun 18, 2025 06:15 UTC
Code Review
baremetal/utils.go:1
@@ -306,14 +312,14 @@ func getM3Machine(ctx context.Context, cl client.Client, mLog logr.Logger,
 
 	// Verify that the Metal3Machine fulfills the conditions.
 	if tmpM3Machine.Spec.DataTemplate == nil {
-		return nil, nil
+		return nil, ErrMissingDataTemplateName
 	}
 	if tmpM3Machine.Spec.DataTemplate.Name != dataTemplate.Name {
-		return nil, nil
+		return nil, ErrDataTemplateNameMismatch
 	}
 	if tmpM3Machine.Spec.DataTemplate.Namespace != "" &&
 		tmpM3Machine.Spec.DataTemplate.Namespace != dataTemplate.Namespace {
-		return nil, nil
+		return nil, ErrDataTemplateNamespaceMismatch

These I am not so sure about. I think we could clean them up but that would be a bit bigger refactor.
For now I think the better way forward is to put nil //nolint:nilnil also here.

SD-13 SD-13 commented on Jun 18, 2025 12:07 UTC
Author

Hello @lentzi90 Thanks for reviewing my PR!
I addressed your comments, can you please take another look?
Thanks!

lentzi90 lentzi90 commented on code on Jun 18, 2025 12:28 UTC
Code Review
baremetal/metal3machine_manager.go:1
@@ -1008,8 +1008,10 @@ func (m *MachineManager) nodeReuseLabelExists(_ context.Context, host *bmov1alph
 
 // getBMCSecret will return the BMCSecret associated with BMH.
 func (m *MachineManager) getBMCSecret(ctx context.Context, host *bmov1alpha1.BareMetalHost) (*corev1.Secret, error) {
-	if host == nil || host.Spec.BMC.CredentialsName == "" {
-		return nil, nil
+	if host == nil {
+		return nil, errors.New("Host is empty")
+	} else if host.Spec.BMC.CredentialsName == "" {
+		return nil, errors.New("Credentials secret is empty")

Looks like this is still causing a unit test to fail. We will need to either change that unit test or revert and put nolint here as well

SD-13 SD-13 commented on code on Jun 18, 2025 12:35 UTC
Code Review
baremetal/metal3machine_manager.go:1
@@ -1008,8 +1008,10 @@ func (m *MachineManager) nodeReuseLabelExists(_ context.Context, host *bmov1alph
 
 // getBMCSecret will return the BMCSecret associated with BMH.
 func (m *MachineManager) getBMCSecret(ctx context.Context, host *bmov1alpha1.BareMetalHost) (*corev1.Secret, error) {
-	if host == nil || host.Spec.BMC.CredentialsName == "" {
-		return nil, nil
+	if host == nil {
+		return nil, errors.New("Host is empty")
+	} else if host.Spec.BMC.CredentialsName == "" {
+		return nil, errors.New("Credentials secret is empty")

I am trying to modify that unit test accordingly.

SD-13 SD-13 commented on code on Jun 18, 2025 18:26 UTC
Code Review
baremetal/metal3machine_manager.go:1
@@ -1008,8 +1008,10 @@ func (m *MachineManager) nodeReuseLabelExists(_ context.Context, host *bmov1alph
 
 // getBMCSecret will return the BMCSecret associated with BMH.
 func (m *MachineManager) getBMCSecret(ctx context.Context, host *bmov1alpha1.BareMetalHost) (*corev1.Secret, error) {
-	if host == nil || host.Spec.BMC.CredentialsName == "" {
-		return nil, nil
+	if host == nil {
+		return nil, errors.New("Host is empty")
+	} else if host.Spec.BMC.CredentialsName == "" {
+		return nil, errors.New("Credentials secret is empty")

I added nolint for now.

SD-13 SD-13 commented on Jun 18, 2025 18:30 UTC
Author

/retest

lentzi90 lentzi90 commented on Jun 19, 2025 05:38 UTC
Reviewer

/approve

metal3-io-bot metal3-io-bot commented on Jun 19, 2025 05:39 UTC
Bot

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: <a href="https://github.com/metal3-io/cluster-api-provider-metal3/pull/2579#pullrequestreview-2941627165" title="Approved">lentzi90</a>

The full list of commands accepted by this bot can be found here.

The pull request process is described here

<details >
Needs approval from an approver in each of these files:

  • ~~OWNERS~~ [lentzi90]
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":[]} -->

    adilGhaffarDev adilGhaffarDev commented on Jun 19, 2025 06:28 UTC
    Contributor

    /test metal3-centos-e2e-integration-test-main
    /test metal3-ubuntu-e2e-integration-test-main
    /lgtm

    Rozzii Rozzii commented on Jun 23, 2025 11:39 UTC
    Reviewer

    /override metal3-centos-e2e-integration-test-main
    The centos based tests are facing an unrelated issue, the actual test has passed.https://jenkins.nordix.org/blue/organizations/jenkins/metal3-centos-e2e-integration-test-main/detail/metal3-centos-e2e-integration-test-main/1391/pipeline

    metal3-io-bot metal3-io-bot commented on Jun 23, 2025 11:39 UTC
    Bot

    @Rozzii: Overrode contexts on behalf of Rozzii: metal3-centos-e2e-integration-test-main

    <details>

    In response to this:

    >/override metal3-centos-e2e-integration-test-main
    >The centos based tests are facing an unrelated issue, the actual test has passed.https://jenkins.nordix.org/blue/organizations/jenkins/metal3-centos-e2e-integration-test-main/detail/metal3-centos-e2e-integration-test-main/1391/pipeline

    Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
    </details>

    Reviewers
    Assignees
    SD-13 SD-13
    Labels
    risk: low confidence: 91.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk ยท Model 1 (XGBoost)
    Predicted defect probability (0.00โ€“1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 27.1% (LOW) ยท Higher = larger blast radius
    27.1%
    Review Confidence
    Review Confidence ยท Models 2 & 3
    Scrutiny score (0.00โ€“1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 91.7% ยท Lower = rushed or shallow review
    91.7%
    Residual Risk
    Residual Risk ยท Core Equation
    Residual = Change ร— (1 โˆ’ Confidence)
    Unmitigated risk surviving review. โ‰ฅ 0.65 triggers an automated re-queue to protect production.
    Score: 2.2% ยท Safe to merge
    2.2%