Skip to content

Commit

Permalink
Merge pull request #1542 from andreadecorte/OCM-3911
Browse files Browse the repository at this point in the history
OCM-3911 | feat: use HCP specific endpoints for versions and upgrades
  • Loading branch information
openshift-ci[bot] authored Oct 17, 2023
2 parents 3e56ce5 + 4532de6 commit 9cb50e9
Show file tree
Hide file tree
Showing 16 changed files with 218 additions and 644 deletions.
2 changes: 1 addition & 1 deletion cmd/create/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ func run(cmd *cobra.Command, _ []string) {
// OpenShift version:
version := args.version
channelGroup := args.channelGroup
versionList, err := versions.GetVersionList(r, channelGroup, isSTS, isHostedCP, true)
versionList, err := versions.GetVersionList(r, channelGroup, isSTS, isHostedCP, true, true)
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions cmd/create/machinepool/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func addNodePool(cmd *cobra.Command, clusterKey string, cluster *cmv1.Cluster, r
clusterVersion := cluster.Version().RawID()
// This is called in HyperShift, but we don't want to exclude version which are HCP disabled for node pools
// so we pass the relative parameter as false
versionList, err := versions.GetVersionList(r, channelGroup, true, false, false)
versionList, err := versions.GetVersionList(r, channelGroup, true, true, false, false)
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
Expand All @@ -85,7 +85,7 @@ func addNodePool(cmd *cobra.Command, clusterKey string, cluster *cmv1.Cluster, r
}

// Filter the available list of versions for a hosted machine pool
filteredVersionList := versions.GetFilteredVersionListForCreation(versionList, minVersion, clusterVersion)
filteredVersionList := versions.GetFilteredVersionList(versionList, minVersion, clusterVersion)
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
Expand Down
15 changes: 2 additions & 13 deletions cmd/describe/machinepool/cmd_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package machinepool

import (
"bytes"
"fmt"
"net/http"
"time"
Expand Down Expand Up @@ -260,12 +259,7 @@ func formatNodePool() string {
np, err := cmv1.NewNodePool().ID(nodePoolName).Version(version).
AWSNodePool(awsNodePool).AvailabilityZone("us-east-1a").Build()
Expect(err).To(BeNil())
var npJson bytes.Buffer

err = cmv1.MarshalNodePool(np, &npJson)
Expect(err).To(BeNil())

return npJson.String()
return test.FormatResource(np)
}

// formatMachinePool simulates the output of APIs for a fake machine pool
Expand All @@ -274,12 +268,7 @@ func formatMachinePool() string {
mp, err := cmv1.NewMachinePool().ID(nodePoolName).AWS(awsMachinePoolPool).InstanceType("m5.xlarge").
AvailabilityZones("us-east-1a", "us-east-1b", "us-east-1c").Build()
Expect(err).To(BeNil())
var mpJson bytes.Buffer

err = cmv1.MarshalMachinePool(mp, &mpJson)
Expect(err).To(BeNil())

return mpJson.String()
return test.FormatResource(mp)
}

func buildNodePoolUpgradePolicy() *cmv1.NodePoolUpgradePolicy {
Expand Down
82 changes: 20 additions & 62 deletions cmd/describe/upgrade/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,75 +63,23 @@ var _ = Describe("Describe upgrade", func() {
var clusterID = "cluster1"
var nodePoolID = "nodepool85"

const nodePoolResponse = `{
"kind": "NodePool",
"href": "/api/clusters_mgmt/v1/clusters/243nmgjr5v2q9rn5sf3456euj2lcq5tn/node_pools/workers",
"id": "workers",
"replicas": 2,
"auto_repair": true,
"aws_node_pool": {
"instance_type": "m5.xlarge",
"instance_profile": "rosa-service-managed-integration-243nmgjr5v2q9rn5sf3456euj2lcq5tn-ad-int1-worker",
"tags": {
"api.openshift.com/environment": "integration",
"api.openshift.com/id": "243nmgjr5v2q9rn5sf3456euj2lcq5tn",
"api.openshift.com/legal-entity-id": "1jIHnIbrnLH9kQD57W0BuPm78f1",
"api.openshift.com/name": "ad-int1",
"api.openshift.com/nodepool-hypershift": "ad-int1-workers",
"api.openshift.com/nodepool-ocm": "workers",
"red-hat-clustertype": "rosa",
"red-hat-managed": "true"
}
},
"availability_zone": "us-west-2a",
"subnet": "subnet-0e3a4046c1c2f1078",
"status": {
"current_replicas": 0,
"message": "WaitingForAvailableMachines: NodeProvisioning"
},
"version": {
"kind": "VersionLink",
"id": "openshift-v4.12.%s",
"href": "/api/clusters_mgmt/v1/versions/openshift-v4.12.%s"
},
"tuning_configs": []
}`
version41224 := cmv1.NewVersion().ID("openshift-v4.12.24").RawID("4.12.24").ReleaseImage("1").
HREF("/api/clusters_mgmt/v1/versions/openshift-v4.12.24").Enabled(true).ChannelGroup("stable").
ROSAEnabled(true).HostedControlPlaneEnabled(true).AvailableUpgrades("4.12.25", "4.12.26")
nodePool, err := cmv1.NewNodePool().ID("workers").Replicas(2).AutoRepair(true).Version(version41224).Build()
Expect(err).To(BeNil())

// nolint:lll
const nodePoolUpgradePolicy = `{
"kind": "NodePoolUpgradePolicyList",
"page": 1,
"size": 1,
"total": 1,
"items": [
{
"kind": "NodePoolUpgradePolicy",
"id": "e2800d05-3534-11ee-b9bc-0a580a811709",
"href": "/api/clusters_mgmt/v1/clusters/25f96obptkqc5mh9vdc779jiqb3sihnn/node_pools/workers/upgrade_policies/e2800d05-3534-11ee-b9bc-0a580a811709",
"schedule_type": "manual",
"upgrade_type": "NodePool",
"version": "4.12.25",
"next_run": "2023-08-07T15:22:00Z",
"cluster_id": "25f96obptkqc5mh9vdc779jiqb3sihnn",
"node_pool_id": "workers",
"enable_minor_version_upgrades": true,
"creation_timestamp": "2023-08-07T15:12:54.967835Z",
"last_update_timestamp": "2023-08-07T15:12:54.967835Z",
"state": {
"value": "scheduled",
"description": "Upgrade scheduled."
}
}
]
}`
upgradePolicies := make([]*cmv1.NodePoolUpgradePolicy, 0)
upgradePolicies = append(upgradePolicies, buildNodePoolUpgradePolicy())

BeforeEach(func() {
testRuntime.InitRuntime()
})
It("Upgrade policy found, no error", func() {
args.nodePool = nodePoolID
testRuntime.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, nodePoolResponse))
testRuntime.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, nodePoolUpgradePolicy))
testRuntime.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, test.FormatResource(nodePool)))
testRuntime.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK,
test.FormatNodePoolUpgradePolicyList(upgradePolicies)))
err := describeHypershiftUpgrades(testRuntime.RosaRuntime, clusterID, nodePoolID)
Expect(err).To(BeNil())
})
Expand All @@ -143,3 +91,13 @@ var _ = Describe("Describe upgrade", func() {
})
})
})

func buildNodePoolUpgradePolicy() *cmv1.NodePoolUpgradePolicy {
t, err := time.Parse(time.RFC3339, "2023-06-02T12:30:00Z")
Expect(err).To(BeNil())
state := cmv1.NewUpgradePolicyState().Value(cmv1.UpgradePolicyStateValuePending)
policy, err := cmv1.NewNodePoolUpgradePolicy().ScheduleType(cmv1.ScheduleTypeManual).
UpgradeType(cmv1.UpgradeTypeNodePool).Version("4.12.25").State(state).NextRun(t).Build()
Expect(err).To(BeNil())
return policy
}
16 changes: 8 additions & 8 deletions cmd/list/upgrade/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"text/tabwriter"

cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
"github.com/openshift/rosa/cmd/upgrade/machinepool"
"github.com/openshift/rosa/pkg/interactive/confirm"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -104,16 +103,17 @@ func runWithRuntime(r *rosa.Runtime, _ *cobra.Command) error {
}

// Get available node pool upgrades
availableUpgrades, err = machinepool.GetAvailableVersion(r, cluster, nodePool)
if err != nil {
return err
}
availableUpgrades = ocm.GetNodePoolAvailableUpgrades(nodePool)
} else {
// Control plane or cluster updates
r.Reporter.Debugf("Loading available upgrades for cluster '%s'", clusterKey)
availableUpgrades, err = r.OCMClient.GetAvailableUpgrades(ocm.GetVersionID(cluster))
if err != nil {
return fmt.Errorf("Failed to get available upgrades for cluster '%s': %v", clusterKey, err)
if isHypershift {
availableUpgrades = ocm.GetAvailableUpgradesByCluster(cluster)
} else {
availableUpgrades, err = r.OCMClient.GetAvailableUpgrades(ocm.GetVersionID(cluster))
if err != nil {
return fmt.Errorf("Failed to get available upgrades for cluster '%s': %v", clusterKey, err)
}
}

if len(availableUpgrades) == 0 {
Expand Down
Loading

0 comments on commit 9cb50e9

Please sign in to comment.