-
Notifications
You must be signed in to change notification settings - Fork 498
CNTRLPLANE-3020: Adopt coreos/stream-metadata-go upstream library #8673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -437,12 +437,14 @@ func getWindowsAMI(region string, specifiedArch string, releaseImage *releaseinf | |
| } | ||
|
|
||
| // Access the rhel-coreos-extensions aws-winli data | ||
| winliData := archData.RHCOS.AWSWinLi | ||
| if winliData.Regions == nil { | ||
| if archData.RHELCoreOSExtensions == nil { | ||
| return "", fmt.Errorf("no rhel-coreos-extensions data found in release image metadata") | ||
| } | ||
| if archData.RHELCoreOSExtensions.AwsWinLi == nil || archData.RHELCoreOSExtensions.AwsWinLi.Regions == nil { | ||
| return "", fmt.Errorf("no aws-winli regions data found in release image metadata") | ||
| } | ||
|
|
||
| regionData, exists := winliData.Regions[region] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The triple nil-check is correct, but a single error message for three different failure modes makes debugging harder. Consider splitting: if archData.RHELCoreOSExtensions == nil {
return "", fmt.Errorf("no rhel-coreos-extensions data found in release image metadata")
}
if archData.RHELCoreOSExtensions.AwsWinLi == nil || archData.RHELCoreOSExtensions.AwsWinLi.Regions == nil {
return "", fmt.Errorf("no aws-winli regions data found in release image metadata")
}Also — could you add test cases for |
||
| regionData, exists := archData.RHELCoreOSExtensions.AwsWinLi.Regions[region] | ||
| if !exists { | ||
| return "", fmt.Errorf("no Windows AMI found for region %s in release image metadata", region) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,33 +133,39 @@ func getAzureMarketplaceMetadata(releaseImage *releaseinfo.ReleaseImage, arch st | |
| // Extract marketplace metadata from the RHCOS extensions | ||
| // Structure: .architectures.<arch>.rhel-coreos-extensions.marketplace.azure.no-purchase-plan | ||
| // Check for nil safety before accessing nested fields | ||
| if archData.RHCOS.Marketplace.Azure.NoPurchasePlan.HyperVGen1 == nil && | ||
| archData.RHCOS.Marketplace.Azure.NoPurchasePlan.HyperVGen2 == nil { | ||
| if archData.RHELCoreOSExtensions == nil || | ||
| archData.RHELCoreOSExtensions.Marketplace == nil || | ||
| archData.RHELCoreOSExtensions.Marketplace.Azure == nil || | ||
| archData.RHELCoreOSExtensions.Marketplace.Azure.NoPurchasePlan == nil { | ||
| return nil, nil // No marketplace data available | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cascading nil check is well done. One question: should |
||
| } | ||
|
|
||
| azureMarketplace := archData.RHELCoreOSExtensions.Marketplace.Azure.NoPurchasePlan | ||
| if azureMarketplace.Gen1 == nil && azureMarketplace.Gen2 == nil { | ||
| return nil, nil // No marketplace data available | ||
| } | ||
| azureMarketplace := archData.RHCOS.Marketplace.Azure.NoPurchasePlan | ||
|
|
||
| // Convert from release info format to our internal format | ||
| result := &azureMarketplaceMetadata{ | ||
| NoPurchasePlan: &azureMarketplaceImageInfo{}, | ||
| } | ||
|
|
||
| if azureMarketplace.HyperVGen1 != nil { | ||
| if azureMarketplace.Gen1 != nil { | ||
| result.NoPurchasePlan.HyperVGen1 = &hyperv1.AzureMarketplaceImage{ | ||
| Publisher: azureMarketplace.HyperVGen1.Publisher, | ||
| Offer: azureMarketplace.HyperVGen1.Offer, | ||
| SKU: azureMarketplace.HyperVGen1.SKU, | ||
| Version: azureMarketplace.HyperVGen1.Version, | ||
| Publisher: azureMarketplace.Gen1.Publisher, | ||
| Offer: azureMarketplace.Gen1.Offer, | ||
| SKU: azureMarketplace.Gen1.SKU, | ||
| Version: azureMarketplace.Gen1.Version, | ||
| ImageGeneration: ptr.To(hyperv1.Gen1), | ||
| } | ||
| } | ||
|
|
||
| if azureMarketplace.HyperVGen2 != nil { | ||
| if azureMarketplace.Gen2 != nil { | ||
| result.NoPurchasePlan.HyperVGen2 = &hyperv1.AzureMarketplaceImage{ | ||
| Publisher: azureMarketplace.HyperVGen2.Publisher, | ||
| Offer: azureMarketplace.HyperVGen2.Offer, | ||
| SKU: azureMarketplace.HyperVGen2.SKU, | ||
| Version: azureMarketplace.HyperVGen2.Version, | ||
| Publisher: azureMarketplace.Gen2.Publisher, | ||
| Offer: azureMarketplace.Gen2.Offer, | ||
| SKU: azureMarketplace.Gen2.SKU, | ||
| Version: azureMarketplace.Gen2.Version, | ||
| ImageGeneration: ptr.To(hyperv1.Gen2), | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,9 @@ import ( | |
|
|
||
| capiazure "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" | ||
| clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1" | ||
|
|
||
| "github.com/coreos/stream-metadata-go/stream" | ||
| "github.com/coreos/stream-metadata-go/stream/rhcos" | ||
| ) | ||
|
|
||
| func TestAzureMachineTemplateSpec(t *testing.T) { | ||
|
|
@@ -946,6 +949,34 @@ func TestDefaultAzureNodePoolImage(t *testing.T) { | |
| expectedImageType: "", | ||
| expectedMarketplaceImage: nil, | ||
| }, | ||
| { | ||
| name: "skip defaulting when RHELCoreOSExtensions is nil", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win Use "When ... it should ..." format for test case name. The test case name should follow the "When ... it should ..." format as per coding guidelines for unit tests. 📝 Suggested rename- name: "skip defaulting when RHELCoreOSExtensions is nil",
+ name: "When RHELCoreOSExtensions is nil, it should skip defaulting",🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| nodePool: &hyperv1.NodePool{ | ||
| Spec: hyperv1.NodePoolSpec{ | ||
| Arch: hyperv1.ArchitectureAMD64, | ||
| Platform: hyperv1.NodePoolPlatform{ | ||
| Type: hyperv1.AzurePlatform, | ||
| Azure: &hyperv1.AzureNodePoolPlatform{ | ||
| Image: hyperv1.AzureVMImage{}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| releaseImage: &releaseinfo.ReleaseImage{ | ||
| ImageStream: &imageapi.ImageStream{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: "4.20.0"}, | ||
| }, | ||
| StreamMetadata: &stream.Stream{ | ||
| Architectures: map[string]stream.Arch{ | ||
| "x86_64": { | ||
| Images: stream.Images{}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| expectedImageType: "", | ||
| expectedMarketplaceImage: nil, | ||
| }, | ||
| { | ||
| name: "skip defaulting when no marketplace metadata available", | ||
| nodePool: &hyperv1.NodePool{ | ||
|
|
@@ -1113,28 +1144,28 @@ func TestDefaultAzureNodePoolImage(t *testing.T) { | |
|
|
||
| // createMockReleaseImage creates a mock release image for testing | ||
| func createMockReleaseImage(version string, hasMarketplaceMetadata bool) *releaseinfo.ReleaseImage { | ||
| architecture := releaseinfo.CoreOSArchitecture{ | ||
| Artifacts: map[string]releaseinfo.CoreOSArtifact{}, | ||
| Images: releaseinfo.CoreOSImages{}, | ||
| RHCOS: releaseinfo.CoreRHCOSImage{ | ||
| AzureDisk: releaseinfo.CoreAzureDisk{ | ||
| architecture := stream.Arch{ | ||
| Artifacts: map[string]stream.PlatformArtifacts{}, | ||
| Images: stream.Images{}, | ||
| RHELCoreOSExtensions: &rhcos.Extensions{ | ||
| AzureDisk: &rhcos.AzureDisk{ | ||
| Release: "9.6.20250701-0", | ||
| URL: "https://rhcos.blob.core.windows.net/imagebucket/rhcos-9.6.20250701-0-azure.x86_64.vhd", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| if hasMarketplaceMetadata { | ||
| architecture.RHCOS.Marketplace = releaseinfo.CoreMarketplace{ | ||
| Azure: releaseinfo.CoreAzureMarketplace{ | ||
| NoPurchasePlan: releaseinfo.CoreAzureMarketplaceNoPurchasePlan{ | ||
| HyperVGen1: &releaseinfo.CoreAzureMarketplaceImage{ | ||
| architecture.RHELCoreOSExtensions.Marketplace = &rhcos.Marketplace{ | ||
| Azure: &rhcos.AzureMarketplace{ | ||
| NoPurchasePlan: &rhcos.AzureMarketplaceImages{ | ||
| Gen1: &rhcos.AzureMarketplaceImage{ | ||
| Publisher: "azureopenshift", | ||
| Offer: "aro4", | ||
| SKU: "aro_419", | ||
| Version: "419.6.20250523", | ||
| }, | ||
| HyperVGen2: &releaseinfo.CoreAzureMarketplaceImage{ | ||
| Gen2: &rhcos.AzureMarketplaceImage{ | ||
| Publisher: "azureopenshift", | ||
| Offer: "aro4", | ||
| SKU: "419-v2", | ||
|
|
@@ -1145,12 +1176,12 @@ func createMockReleaseImage(version string, hasMarketplaceMetadata bool) *releas | |
| } | ||
| } | ||
|
|
||
| architectures := map[string]releaseinfo.CoreOSArchitecture{ | ||
| architectures := map[string]stream.Arch{ | ||
| "x86_64": architecture, | ||
| "aarch64": architecture, // ARM64 uses the same marketplace metadata | ||
| } | ||
|
|
||
| streamMetadata := &releaseinfo.CoreOSStreamMetadata{ | ||
| streamMetadata := &stream.Stream{ | ||
| Stream: "test-stream", | ||
| Architectures: architectures, | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: openshift/hypershift
Length of output: 491
🏁 Script executed:
Repository: openshift/hypershift
Length of output: 291
🏁 Script executed:
Repository: openshift/hypershift
Length of output: 183
🏁 Script executed:
Repository: openshift/hypershift
Length of output: 2296
🏁 Script executed:
Repository: openshift/hypershift
Length of output: 1962
🏁 Script executed:
Repository: openshift/hypershift
Length of output: 1962
Supply-chain checks for
github.com/coreos/stream-metadata-go v0.4.11v0.4.11(GitHub Security Advisories / OSV came back empty).LICENSEindicates the Apache License.v0.4.11is a published non-prerelease GitHub release andhttps://proxy.golang.org/.../@v/v0.4.11.zipis available (not yanked).Confirm the Apache license fits your repo/org’s approved-license policy.
🤖 Prompt for AI Agents