-
Notifications
You must be signed in to change notification settings - Fork 1.5k
OCPBUGS-62209: Fix zones from defaultMachinePlatform ignored when pla… #10087
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
Open
jcpowermac
wants to merge
1
commit into
openshift:main
Choose a base branch
from
jcpowermac:OCPBUGS-62209
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package vsphere | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| // TestSet_PreservesZonesFromDefaultMachinePlatform tests that zones from defaultMachinePlatform | ||
| // are preserved when pool-specific platform config is set without zones. | ||
| // This reproduces the bug reported in OCPBUGS-62209. | ||
| func TestSet_PreservesZonesFromDefaultMachinePlatform(t *testing.T) { | ||
| // Simulate the scenario from the bug report: | ||
| // 1. defaultMachinePlatform has zones defined | ||
| // 2. controlPlane/compute platform has CPU/memory but no zones | ||
| // 3. Zones from defaultMachinePlatform should be preserved | ||
|
|
||
| // Create default machine pool platform (simulating defaultVSphereMachinePoolPlatform()) | ||
| mpool := MachinePool{ | ||
| NumCPUs: 4, | ||
| NumCoresPerSocket: 4, | ||
| MemoryMiB: 16384, | ||
| OSDisk: OSDisk{ | ||
| DiskSizeGB: 120, | ||
| }, | ||
| } | ||
|
|
||
| // Create defaultMachinePlatform with zones (from install-config) | ||
| defaultMachinePlatform := &MachinePool{ | ||
| Zones: []string{"us-east-1a"}, | ||
| } | ||
|
|
||
| // Create pool-specific config with CPU/memory but no zones | ||
| // This simulates: controlPlane.platform.vsphere = {cpus: 8, memoryMB: 32768} | ||
| poolSpecificConfig := &MachinePool{ | ||
| NumCPUs: 8, | ||
| MemoryMiB: 32768, | ||
| } | ||
|
|
||
| // Apply defaults first (this should set zones) | ||
| mpool.Set(defaultMachinePlatform) | ||
| assert.Equal(t, []string{"us-east-1a"}, mpool.Zones, "Zones should be set from defaultMachinePlatform") | ||
|
|
||
| // Apply pool-specific config (this should NOT clear zones) | ||
| mpool.Set(poolSpecificConfig) | ||
|
|
||
| // BUG: This test will fail if zones are being lost | ||
| assert.Equal(t, []string{"us-east-1a"}, mpool.Zones, "Zones should be preserved after applying pool-specific config") | ||
| assert.Equal(t, int32(8), mpool.NumCPUs, "NumCPUs should be updated from pool-specific config") | ||
| assert.Equal(t, int64(32768), mpool.MemoryMiB, "MemoryMiB should be updated from pool-specific config") | ||
| } | ||
|
|
||
| // TestSet_ExplicitEmptyZonesOverwriteDefault tests that if a pool explicitly | ||
| // sets zones to empty, it should NOT overwrite zones from default. | ||
| func TestSet_ExplicitEmptyZones(t *testing.T) { | ||
| mpool := MachinePool{} | ||
|
|
||
| // Set zones via default | ||
| defaultPlatform := &MachinePool{ | ||
| Zones: []string{"us-east-1a", "us-east-1b"}, | ||
| } | ||
| mpool.Set(defaultPlatform) | ||
| assert.Equal(t, []string{"us-east-1a", "us-east-1b"}, mpool.Zones) | ||
|
|
||
| // Apply config with empty zones (nil) | ||
| poolConfig := &MachinePool{ | ||
| NumCPUs: 8, | ||
| Zones: nil, // explicitly nil | ||
| } | ||
| mpool.Set(poolConfig) | ||
|
|
||
| // Zones should be preserved because len(nil) == 0 | ||
| assert.Equal(t, []string{"us-east-1a", "us-east-1b"}, mpool.Zones, "Zones should be preserved when source has nil zones") | ||
|
|
||
| // Apply config with empty array | ||
| poolConfig2 := &MachinePool{ | ||
| NumCPUs: 16, | ||
| Zones: []string{}, // explicitly empty array | ||
| } | ||
| mpool.Set(poolConfig2) | ||
|
|
||
| // Zones should still be preserved because len([]string{}) == 0 | ||
| assert.Equal(t, []string{"us-east-1a", "us-east-1b"}, mpool.Zones, "Zones should be preserved when source has empty zones array") | ||
| } | ||
|
|
||
| // TestSet_ZonesCanBeOverwritten tests that zones CAN be overwritten if explicitly set | ||
| func TestSet_ZonesCanBeOverwritten(t *testing.T) { | ||
| mpool := MachinePool{ | ||
| Zones: []string{"us-east-1a"}, | ||
| } | ||
|
|
||
| // Overwrite with different zones | ||
| newConfig := &MachinePool{ | ||
| Zones: []string{"us-west-1a", "us-west-1b"}, | ||
| } | ||
| mpool.Set(newConfig) | ||
|
|
||
| assert.Equal(t, []string{"us-west-1a", "us-west-1b"}, mpool.Zones, "Zones should be overwritten when explicitly set") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
❓ I think test cases in this file are testing the
Setfunc, right?installer/pkg/types/vsphere/machinepool.go
Line 94 in 4180662
I am just unsure it is "truly" reproduce OCPBUGS-62209, where zones are defaulted in validation (where it should not be). I guess we can adjust the comments (golint is also failing here 😁)?