Skip to content

OCPBUGS-78424: [release-4.20] Use resource group when generating default Azure image#1475

Open
patrickdillon wants to merge 3 commits intoopenshift:release-4.20from
patrickdillon:azure-default-img-bug
Open

OCPBUGS-78424: [release-4.20] Use resource group when generating default Azure image#1475
patrickdillon wants to merge 3 commits intoopenshift:release-4.20from
patrickdillon:azure-default-img-bug

Conversation

@patrickdillon
Copy link
Contributor

@patrickdillon patrickdillon commented Mar 13, 2026

Prior to this, the default always assumed the resource group was in the form infraID-rg, but that is not the case for users
installing into existing resource groups. Instead, read it off the infrastructure config.

Now that Azure has moved to marketplace images, hive, vendoring the installer, cannot safely generate an image for all versions, so it is passing an empty value to MAO, depending on its defaults, which uncovered this bug.

#1441 changed the default for 4.21 to marketplace images, so this only affects 4.20 and earlier.

Summary by CodeRabbit

  • Bug Fixes
    • Azure virtual machine provisioning now correctly incorporates the resource group name when determining default image resources, ensuring proper resource identification during machine provisioning.

Test that if a custom resource group is set, the default image
uses that in the resource id.
Prior to this, the default always assumed the resource group
was in the form infraID-rg, but that is not the case for users
installing into existing resource groups. Instead, read it off
the infrastructure config.
The resource group is required on the infrastructure resource, so
it should be safe to always read it. To be completely defensive
we can assume the default resource group in the impossible
case that resource group is not specified.
@openshift-ci-robot openshift-ci-robot added jira/severity-critical Referenced Jira bug's severity is critical for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Mar 13, 2026
@openshift-ci-robot
Copy link
Contributor

@patrickdillon: This pull request references Jira Issue OCPBUGS-78424, which is invalid:

  • release note text must be set and not match the template OR release note type must be set to "Release Note Not Required". For more information you can reference the OpenShift Bug Process.
  • expected Jira Issue OCPBUGS-78424 to depend on a bug targeting a version in 4.21.0, 4.21.z and in one of the following states: VERIFIED, RELEASE PENDING, CLOSED (ERRATA), CLOSED (CURRENT RELEASE), CLOSED (DONE), CLOSED (DONE-ERRATA), but no dependents were found

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Prior to this, the default always assumed the resource group was in the form infraID-rg, but that is not the case for users
installing into existing resource groups. Instead, read it off the infrastructure config.

Now that Azure has moved to marketplace images, hive, vendoring the installer, cannot safely generate an image for all versions, so it is passing an empty value to MAO, depending on its defaults, which uncovered this bug.

#1441 changed the default for 4.21 to marketplace images, so this only affects 4.20 and earlier.

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 openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

Walkthrough

The pull request modifies Azure image resource ID construction to accept an explicit resource group parameter. The defaultAzureImageResourceID function signature is updated to accept a resource group value, and call sites are adjusted to supply the resource group. Tests are refactored to support per-test platform status handling for Azure scenarios.

Changes

Cohort / File(s) Summary
Azure Image Resource ID Construction
pkg/webhooks/machine_webhook.go
Updated defaultAzureImageResourceID function signature to accept resource group as a parameter instead of deriving it from clusterID. Call site in defaultAzure now derives resource group from defaultAzureResourceGroup(clusterID) with optional override from config.platformStatus.Azure.ResourceGroupName.
Machine Webhook Tests
pkg/webhooks/machine_webhook_test.go
Added strings import. Updated defaultAzureImageResourceID call sites to pass resource group parameter. Introduced per-test platformStatus field in test cases and per-case defaulter instantiation logic in TestDefaultAzureProviderSpec.
Machine Set Webhook Tests
pkg/webhooks/machineset_webhook_test.go
Updated defaultAzureImageResourceID call in TestMachineSetUpdate to include resource group parameter.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Test Structure And Quality ❓ Inconclusive Check criteria reference Ginkgo-specific patterns but code uses traditional Go testing with table-driven tests, creating a scope mismatch. Clarify whether check applies to all test frameworks and provide adapted criteria for traditional Go tests, or confirm it only applies to Ginkgo-based tests.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: updating default Azure image generation to use the resource group from Infrastructure config instead of assuming an infraID-rg pattern.
Stable And Deterministic Test Names ✅ Passed This codebase does not use Ginkgo BDD testing framework. Tests use standard Go testing with testify assertions, so Ginkgo test name stability requirements do not apply.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.11.3)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can disable sequence diagrams in the walkthrough.

Disable the reviews.sequence_diagrams setting to disable sequence diagrams in the walkthrough.

@openshift-ci openshift-ci bot requested review from damdo and nrb March 13, 2026 03:40
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 13, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign nrb for approval. For more information see the Code Review Process.

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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@patrickdillon
Copy link
Contributor Author

/jira refresh

@openshift-ci-robot
Copy link
Contributor

@patrickdillon: This pull request references Jira Issue OCPBUGS-78424, which is invalid:

  • expected Jira Issue OCPBUGS-78424 to depend on a bug targeting a version in 4.21.0, 4.21.z and in one of the following states: VERIFIED, RELEASE PENDING, CLOSED (ERRATA), CLOSED (CURRENT RELEASE), CLOSED (DONE), CLOSED (DONE-ERRATA), but no dependents were found

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

Details

In response to this:

/jira refresh

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 openshift-eng/jira-lifecycle-plugin repository.

@patrickdillon
Copy link
Contributor Author

@CodeRabbit review

@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/webhooks/machine_webhook_test.go (1)

9-9: Good targeted regression; add the empty-name fallback next to it.

Explicitly building the expected ResourceID here is a solid way to avoid a tautological test. I’d add one more case for PlatformStatus.Azure != nil with ResourceGroupName == "", since the defensive fallback path is distinct from the existing default case where Azure status is absent.

🧪 Suggested follow-up case
+		{
+			testCase: "it falls back to the default resource group when platform status resource group is empty",
+			providerSpec: &machinev1beta1.AzureMachineProviderSpec{
+				Image: machinev1beta1.Image{},
+			},
+			platformStatus: &osconfigv1.PlatformStatus{
+				Type: osconfigv1.AzurePlatformType,
+				Azure: &osconfigv1.AzurePlatformStatus{
+					ResourceGroupName: "",
+				},
+			},
+			modifyDefault: func(p *machinev1beta1.AzureMachineProviderSpec) {
+				p.Image = machinev1beta1.Image{
+					ResourceID: defaultAzureImageResourceID(clusterID, defaultAzureResourceGroup(clusterID)),
+				}
+			},
+			expectedOk:       true,
+			expectedError:    "",
+			expectedWarnings: itWarnings,
+		},

Also applies to: 3453-3475

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/webhooks/machine_webhook_test.go` at line 9, Add a targeted test case in
pkg/webhooks/machine_webhook_test.go that covers PlatformStatus.Azure != nil
with PlatformStatus.Azure.ResourceGroupName == "" to exercise the defensive
empty-name fallback path; build the expected ResourceID explicitly (as done in
the other cases) and assert equality against the function under test (the same
helper that produces ResourceID in the file), ensuring the test is not
tautological by hardcoding the expected ResourceID value for the empty-name
fallback scenario.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/webhooks/machine_webhook.go`:
- Around line 922-927: The admissionConfig used in createMachineDefaulter is
missing platformStatus which causes a nil dereference when code in
getMachineDefaulterOperation accesses config.platformStatus.Azure; update
createMachineDefaulter to set admissionConfig.platformStatus =
infra.Status.PlatformStatus (same way createMachineValidator does) so
platformStatus is populated before calling getMachineDefaulterOperation and the
Azure branch (providerSpec.Image.ResourceID defaulting) no longer panics.

---

Nitpick comments:
In `@pkg/webhooks/machine_webhook_test.go`:
- Line 9: Add a targeted test case in pkg/webhooks/machine_webhook_test.go that
covers PlatformStatus.Azure != nil with PlatformStatus.Azure.ResourceGroupName
== "" to exercise the defensive empty-name fallback path; build the expected
ResourceID explicitly (as done in the other cases) and assert equality against
the function under test (the same helper that produces ResourceID in the file),
ensuring the test is not tautological by hardcoding the expected ResourceID
value for the empty-name fallback scenario.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 81b79d9e-aa4a-48b3-9186-a671751f0b75

📥 Commits

Reviewing files that changed from the base of the PR and between 4a9b90e and f203cde.

📒 Files selected for processing (3)
  • pkg/webhooks/machine_webhook.go
  • pkg/webhooks/machine_webhook_test.go
  • pkg/webhooks/machineset_webhook_test.go

Comment on lines 922 to +927
if providerSpec.Image == (machinev1beta1.Image{}) {
providerSpec.Image.ResourceID = defaultAzureImageResourceID(config.clusterID)
rg := defaultAzureResourceGroup(config.clusterID)
if config.platformStatus.Azure != nil && config.platformStatus.Azure.ResourceGroupName != "" {
rg = config.platformStatus.Azure.ResourceGroupName
}
providerSpec.Image.ResourceID = defaultAzureImageResourceID(config.clusterID, rg)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Nil pointer dereference: config.platformStatus is not set in createMachineDefaulter.

At line 924, the code accesses config.platformStatus.Azure, but platformStatus is never set in the admissionConfig within createMachineDefaulter (lines 442-448). The platformStatus parameter is only passed to getMachineDefaulterOperation, not stored in the config.

This will cause a panic when the defaulting webhook runs for Azure machines.

Compare with createMachineValidator (lines 394-401), which correctly sets platformStatus: infra.Status.PlatformStatus in the admissionConfig.

🐛 Proposed fix: Set platformStatus in createMachineDefaulter
 func createMachineDefaulter(platformStatus *osconfigv1.PlatformStatus, clusterID string) *machineDefaulterHandler {
 	return &machineDefaulterHandler{
 		admissionHandler: &admissionHandler{
-			admissionConfig:   &admissionConfig{clusterID: clusterID},
+			admissionConfig:   &admissionConfig{clusterID: clusterID, platformStatus: platformStatus},
 			webhookOperations: getMachineDefaulterOperation(platformStatus),
 		},
 	}
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/webhooks/machine_webhook.go` around lines 922 - 927, The admissionConfig
used in createMachineDefaulter is missing platformStatus which causes a nil
dereference when code in getMachineDefaulterOperation accesses
config.platformStatus.Azure; update createMachineDefaulter to set
admissionConfig.platformStatus = infra.Status.PlatformStatus (same way
createMachineValidator does) so platformStatus is populated before calling
getMachineDefaulterOperation and the Azure branch (providerSpec.Image.ResourceID
defaulting) no longer panics.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 13, 2026

@patrickdillon: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/unit f203cde link true /test unit

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. jira/severity-critical Referenced Jira bug's severity is critical for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants