Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func NewNodePoolVersionController(
// - Not less than the highest active version (no downgrades)
// - Not greater than the lowest control plane version (node pools cannot exceed CP)
// - Not skip minor versions (only z-stream or +1 minor allowed)
// - Have a valid upgrade path in Cincinnati from the current version
// - Exist as a known version in Cincinnati
// - If valid, stores it in ServiceProviderNodePool.Spec.NodePoolVersion.DesiredVersion
//
// If the desired version is already among the active versions, validation is skipped
Expand Down Expand Up @@ -251,13 +251,17 @@ func prependActiveVersionIfChanged(currentVersions []api.HCPNodePoolActiveVersio
return newVersions
}

// validateDesiredNodePoolVersion checks that the desired node pool version is a valid upgrade path.
// validateDesiredNodePoolVersion checks that the desired node pool version is a valid upgrade.
// It validates:
// - The desired version is not less than the highest active node pool version (no downgrades)
// - The desired version is not greater than the lowest control plane version
// - No major version changes (unless FeatureExperimentalReleaseFeatures is registered)
// - No minor versions are skipped
// - An upgrade path exists from the current version (all the activeVersions) to the desired version (via Cincinnati)
// - The desired version exists in Cincinnati
//
// Cincinnati upgrade-edge validation is intentionally skipped — HCP nodepools use the Replace
// strategy (destroy + recreate), so only version existence matters.
// See https://hypershift.pages.dev/reference/nodepool-rollouts/#upgrade-types
//
// Returns nil if the desired version is valid, or an error describing why it's invalid.
func (c *nodePoolVersionSyncer) validateDesiredNodePoolVersion(
Expand Down Expand Up @@ -290,22 +294,19 @@ func (c *nodePoolVersionSyncer) validateDesiredNodePoolVersion(
return err
}

// Validate upgrade path exists in Cincinnati for ALL active node pool versions
for _, activeVersion := range nodePoolActiveVersions {
if activeVersion.Version != nil && !desiredVersion.EQ(*activeVersion.Version) {
if err := c.validateUpgradePathAvailable(ctx, activeVersion.Version, desiredVersion, channelGroup, clusterUUID); err != nil {
return fmt.Errorf("no valid upgrade path from active version %s: %w", activeVersion.Version.String(), err)
}
}
// Validate the desired version exists in Cincinnati (not that an edge exists from the current version).
if err := c.validateVersionExistsInCincinnati(ctx, desiredVersion, channelGroup, clusterUUID); err != nil {
return err
}

return nil
}

// validateUpgradePathAvailable checks that an upgrade path exists from current to desired version.
func (c *nodePoolVersionSyncer) validateUpgradePathAvailable(
// validateVersionExistsInCincinnati checks that the desired version exists as a node in the
// Cincinnati update graph.
func (c *nodePoolVersionSyncer) validateVersionExistsInCincinnati(
ctx context.Context,
currentVersion, desiredVersion *semver.Version,
version *semver.Version,
channelGroup string,
clusterUUID uuid.UUID,
) error {
Expand All @@ -314,23 +315,17 @@ func (c *nodePoolVersionSyncer) validateUpgradePathAvailable(
return fmt.Errorf("failed to get Cincinnati URI: %w", err)
}

targetMinorString := fmt.Sprintf("%d.%d", desiredVersion.Major, desiredVersion.Minor)
cincinnatiChannel := fmt.Sprintf("%s-%s", channelGroup, targetMinorString)

cincinnatiChannel := fmt.Sprintf("%s-%d.%d", channelGroup, version.Major, version.Minor)
cincinnatiClient := c.cincinnatiClientCache.GetOrCreateClient(clusterUUID)
// Get updates for the current version
// TODO: for nodePools we should use the arch of that nodePool
_, candidates, _, err := cincinnatiClient.GetUpdates(ctx, cincinnatiURI, "multi", "multi", cincinnatiChannel, *currentVersion)
if err != nil {
return utils.TrackError(fmt.Errorf("failed to query Cincinnati for upgrade path: %w", err))
}

for _, candidate := range candidates {
candidateVersion := semver.MustParse(candidate.Version)
if candidateVersion.EQ(*desiredVersion) {
return nil
// GetUpdates returns VersionNotFound if the version doesn't exist in the channel.
_, _, _, err = cincinnatiClient.GetUpdates(ctx, cincinnatiURI, "multi", "multi", cincinnatiChannel, *version)
if err != nil {
if cincinnati.IsCincinnatiVersionNotFoundError(err) {
return utils.TrackError(fmt.Errorf("version %s not found in Cincinnati channel %s", version, cincinnatiChannel))
}
return utils.TrackError(fmt.Errorf("failed to query Cincinnati for version existence: %w", err))
}

return utils.TrackError(fmt.Errorf("no upgrade path available from %s to %s in channel %s", currentVersion, desiredVersion, cincinnatiChannel))
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (

arohcpv1alpha1 "github.com/openshift-online/ocm-sdk-go/arohcp/v1alpha1"
configv1 "github.com/openshift/api/config/v1"
cvocincinnati "github.com/openshift/cluster-version-operator/pkg/cincinnati"
"github.com/openshift/hypershift/api/hypershift/v1beta1"

"github.com/Azure/ARO-HCP/backend/pkg/controllers/controllerutils"
Expand Down Expand Up @@ -743,7 +744,7 @@ func TestNodePoolVersionSyncer_SyncOnce_DesiredExceedsControlPlaneFails(t *testi
assert.Contains(t, err.Error(), "cannot exceed control plane version")
}

func TestNodePoolVersionSyncer_SyncOnce_NoUpgradePathInCincinnatiFails(t *testing.T) {
func TestNodePoolVersionSyncer_SyncOnce_SucceedsWithoutCincinnatiEdge(t *testing.T) {
ctx := context.Background()
ctrl := gomock.NewController(t)

Expand All @@ -757,19 +758,22 @@ func TestNodePoolVersionSyncer_SyncOnce_NoUpgradePathInCincinnatiFails(t *testin
// Create ServiceProviderCluster with control plane at 4.20.0 (allows the desired version)
createServiceProviderClusterWithVersion(t, ctx, mockResourcesDBClient, "4.20.0")

// Create ServiceProviderNodePool with active version 4.19.7
createServiceProviderNodePoolWithVersion(t, ctx, mockResourcesDBClient, "4.19.7")

// CS returns node pool with current version 4.19.7
csNodePool := newCSNodePoolWithVersion(t, "4.19.7")
mockCS.EXPECT().
GetNodePool(gomock.Any(), gomock.Any()).
Return(csNodePool, nil).
Times(1)

// Setup Cincinnati mock to return NO upgrade path (empty candidates)
// Cincinnati: version exists, no candidates
mockCincinnati.EXPECT().
GetUpdates(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
GetUpdates(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Eq(semver.MustParse("4.19.10"))).
Return(
configv1.Release{Version: "4.19.7"},
[]configv1.Release{}, // Empty - no upgrade path available
configv1.Release{Version: "4.19.10"},
[]configv1.Release{},
nil,
nil,
).
Expand All @@ -796,8 +800,76 @@ func TestNodePoolVersionSyncer_SyncOnce_NoUpgradePathInCincinnatiFails(t *testin
ctx = utils.ContextWithLogger(ctx, logr.Discard())
err := syncer.SyncOnce(ctx, testKey)

require.NoError(t, err)

// Verify the ServiceProviderNodePool DesiredVersion was updated
spnp, err := mockResourcesDBClient.ServiceProviderNodePools(
testSubscriptionID, testResourceGroupName, testClusterName, testNodePoolName,
).Get(ctx, api.ServiceProviderNodePoolResourceName)
require.NoError(t, err)
require.NotNil(t, spnp.Spec.NodePoolVersion.DesiredVersion)
expectedDesiredVersion := semver.MustParse("4.19.10")
require.True(t, expectedDesiredVersion.EQ(*spnp.Spec.NodePoolVersion.DesiredVersion))
}

func TestNodePoolVersionSyncer_SyncOnce_VersionNotInCincinnatiFails(t *testing.T) {
ctx := context.Background()
ctrl := gomock.NewController(t)

mockResourcesDBClient := databasetesting.NewMockResourcesDBClient()
mockCS := ocm.NewMockClusterServiceClientSpec(ctrl)
mockCincinnati := cincinnati.NewMockClient(ctrl)

// Create node pool with desired version 4.19.99 (does not exist in Cincinnati)
createTestNodePoolWithVersion(t, ctx, mockResourcesDBClient, "4.19.99")

// Create ServiceProviderCluster with control plane at 4.20.0
createServiceProviderClusterWithVersion(t, ctx, mockResourcesDBClient, "4.20.0")

// Create ServiceProviderNodePool with active version 4.19.7
createServiceProviderNodePoolWithVersion(t, ctx, mockResourcesDBClient, "4.19.7")

// CS returns node pool with current version 4.19.7
csNodePool := newCSNodePoolWithVersion(t, "4.19.7")
mockCS.EXPECT().
GetNodePool(gomock.Any(), gomock.Any()).
Return(csNodePool, nil).
Times(1)

// Cincinnati returns VersionNotFound for the desired version
mockCincinnati.EXPECT().
GetUpdates(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Eq(semver.MustParse("4.19.99"))).
Return(
configv1.Release{},
nil,
nil,
&cvocincinnati.Error{Reason: "VersionNotFound", Message: "version 4.19.99 not found"},
).
Times(1)

mockClientCache := cincinnati.NewMockClientCache(ctrl)
mockClientCache.EXPECT().GetOrCreateClient(gomock.Any()).Return(mockCincinnati).AnyTimes()

syncer := &nodePoolVersionSyncer{
cooldownChecker: &alwaysSyncCooldownChecker{},
clusterManagementClusterContentLister: newValidHostedClusterContentLister(t),
resourcesDBClient: mockResourcesDBClient,
clusterServiceClient: mockCS,
cincinnatiClientCache: mockClientCache,
}

testKey := controllerutils.HCPNodePoolKey{
SubscriptionID: testSubscriptionID,
ResourceGroupName: testResourceGroupName,
HCPClusterName: testClusterName,
HCPNodePoolName: testNodePoolName,
}

ctx = utils.ContextWithLogger(ctx, logr.Discard())
err := syncer.SyncOnce(ctx, testKey)

require.Error(t, err)
assert.Contains(t, err.Error(), "no upgrade path available")
assert.Contains(t, err.Error(), "not found in Cincinnati")
}

func TestNodePoolVersionSyncer_SyncOnce_DowngradeFails(t *testing.T) {
Expand Down Expand Up @@ -847,7 +919,7 @@ func TestNodePoolVersionSyncer_SyncOnce_DowngradeFails(t *testing.T) {
assert.Contains(t, err.Error(), "cannot downgrade")
}

func TestNodePoolVersionSyncer_SyncOnce_UpgradePathExistsSucceeds(t *testing.T) {
func TestNodePoolVersionSyncer_SyncOnce_ValidUpgradeSucceeds(t *testing.T) {
ctx := context.Background()
ctrl := gomock.NewController(t)

Expand All @@ -868,16 +940,12 @@ func TestNodePoolVersionSyncer_SyncOnce_UpgradePathExistsSucceeds(t *testing.T)
Return(csNodePool, nil).
Times(1)

// Setup Cincinnati mock to return valid upgrade path including desired version
// Cincinnati returns success for the desired version (version exists in the graph)
mockCincinnati.EXPECT().
GetUpdates(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(
configv1.Release{Version: "4.19.10"},
[]configv1.Release{
{Version: "4.19.12"},
{Version: "4.19.15"}, // Desired version is in candidates
{Version: "4.19.18"},
},
configv1.Release{Version: "4.19.15"},
[]configv1.Release{},
nil,
nil,
).
Expand Down Expand Up @@ -934,13 +1002,13 @@ func TestNodePoolVersionSyncer_SyncOnce_DesiredVersionUnchangedOnFailure_Changed
Return(csNodePool, nil).
Times(1)

// Phase 1: Cincinnati mock returns valid upgrade path
// Phase 1: Cincinnati confirms the desired version exists
mockCincinnati := cincinnati.NewMockClient(ctrl)
mockCincinnati.EXPECT().
GetUpdates(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(
configv1.Release{Version: "4.19.10"},
[]configv1.Release{{Version: "4.19.15"}},
configv1.Release{Version: "4.19.15"},
[]configv1.Release{},
nil,
nil,
).
Expand Down Expand Up @@ -989,13 +1057,13 @@ func TestNodePoolVersionSyncer_SyncOnce_DesiredVersionUnchangedOnFailure_Changed
require.True(t, expectedDesiredVersion.EQ(*spnp.Spec.NodePoolVersion.DesiredVersion),
"DesiredVersion should match customer version %s, got %s", "4.19.15", spnp.Spec.NodePoolVersion.DesiredVersion)

// --- Phase 2: Change version, Cincinnati fails, desired should NOT change ---
// --- Phase 2: Change to non-existent version, Cincinnati fails, desired should NOT change ---

// Update the HCPNodePool with a new desired version
// Update the HCPNodePool with a version that doesn't exist in Cincinnati
nodePool, err := mockResourcesDBClient.HCPClusters(testSubscriptionID, testResourceGroupName).
NodePools(testClusterName).Get(ctx, testNodePoolName)
require.NoError(t, err)
nodePool.Properties.Version.ID = "4.19.20"
nodePool.Properties.Version.ID = "4.19.99"
_, err = mockResourcesDBClient.HCPClusters(testSubscriptionID, testResourceGroupName).
NodePools(testClusterName).Replace(ctx, nodePool, nil)
require.NoError(t, err)
Expand All @@ -1006,22 +1074,23 @@ func TestNodePoolVersionSyncer_SyncOnce_DesiredVersionUnchangedOnFailure_Changed
Return(csNodePool, nil).
Times(1)

// Cincinnati returns VersionNotFound — version doesn't exist
mockCincinnatiFailing := cincinnati.NewMockClient(ctrl)
mockCincinnatiFailing.EXPECT().
GetUpdates(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(
configv1.Release{Version: "4.19.10"},
[]configv1.Release{}, // Empty - no upgrade path available
configv1.Release{},
nil,
nil,
&cvocincinnati.Error{Reason: "VersionNotFound", Message: "version 4.19.99 not found"},
).
AnyTimes()
mockClientCache.EXPECT().GetOrCreateClient(gomock.Any()).Return(mockCincinnatiFailing).Times(1)

// SyncOnce should fail because Cincinnati doesn't have upgrade path
// SyncOnce should fail because the version doesn't exist in Cincinnati
err = syncer.SyncOnce(ctx, testKey)
require.Error(t, err, "SyncOnce should fail when Cincinnati has no upgrade path")
assert.Contains(t, err.Error(), "no upgrade path available")
require.Error(t, err, "SyncOnce should fail when version doesn't exist in Cincinnati")
assert.Contains(t, err.Error(), "not found in Cincinnati")

// Verify that DesiredVersion was NOT changed (still 4.19.15)
spnp, err = mockResourcesDBClient.ServiceProviderNodePools(
Expand All @@ -1034,20 +1103,30 @@ func TestNodePoolVersionSyncer_SyncOnce_DesiredVersionUnchangedOnFailure_Changed
"DesiredVersion should NOT have changed after failed validation, expected %s, got %s",
"4.19.15", spnp.Spec.NodePoolVersion.DesiredVersion)

// --- Phase 3: Cincinnati succeeds, desired should change ---
// --- Phase 3: Change to existing version, should succeed ---

// Update the HCPNodePool with a version that exists in Cincinnati
nodePool, err = mockResourcesDBClient.HCPClusters(testSubscriptionID, testResourceGroupName).
NodePools(testClusterName).Get(ctx, testNodePoolName)
require.NoError(t, err)
nodePool.Properties.Version.ID = "4.19.20"
_, err = mockResourcesDBClient.HCPClusters(testSubscriptionID, testResourceGroupName).
NodePools(testClusterName).Replace(ctx, nodePool, nil)
require.NoError(t, err)

// Setup CS mocks for third sync
mockCS.EXPECT().
GetNodePool(gomock.Any(), gomock.Any()).
Return(csNodePool, nil).
Times(1)

// Cincinnati confirms the version exists
mockCincinnatiSucceeding := cincinnati.NewMockClient(ctrl)
mockCincinnatiSucceeding.EXPECT().
GetUpdates(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(
configv1.Release{Version: "4.19.10"},
[]configv1.Release{{Version: "4.19.20"}}, // Valid upgrade path
configv1.Release{Version: "4.19.20"},
[]configv1.Release{},
nil,
nil,
).
Expand All @@ -1056,7 +1135,7 @@ func TestNodePoolVersionSyncer_SyncOnce_DesiredVersionUnchangedOnFailure_Changed

// SyncOnce should succeed now
err = syncer.SyncOnce(ctx, testKey)
require.NoError(t, err, "SyncOnce should succeed when Cincinnati has valid upgrade path")
require.NoError(t, err, "SyncOnce should succeed when version exists in Cincinnati")

// Verify that DesiredVersion HAS changed to 4.19.20
spnp, err = mockResourcesDBClient.ServiceProviderNodePools(
Expand Down
Loading