Skip to content

Commit 7a3840b

Browse files
committed
OCM-14214 | fix: Calculate default NP values when create/edit np
1 parent f1af655 commit 7a3840b

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

cmd/edit/machinepool/cmd_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ var _ = Describe("Edit Machinepool", func() {
109109
t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, hypershiftClusterReady))
110110
// First get
111111
t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, nodePoolResponse))
112+
// Second get
113+
t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, nodePoolResponse))
112114
// Edit
113115
t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, ""))
114116
t.SetCluster(clusterId, mockClusterReady)
@@ -129,6 +131,8 @@ var _ = Describe("Edit Machinepool", func() {
129131
t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, hypershiftClusterReady))
130132
// First get
131133
t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, nodePoolAutoResponse))
134+
// Second get
135+
t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, nodePoolResponse))
132136
// Edit
133137
t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, ""))
134138
t.SetCluster(clusterId, mockClusterReady)

pkg/machinepool/machinepool.go

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -957,18 +957,20 @@ func (m *machinePool) CreateNodePools(r *rosa.Runtime, cmd *cobra.Command, clust
957957
sumOfMaxReplicas := maxReplicas
958958
sumOfMinReplicas := minReplicas
959959

960-
for _, np := range cluster.NodePools().Items() {
960+
nodepools, err := r.OCMClient.GetNodePools(cluster.ID())
961+
if err != nil {
962+
r.Reporter.Errorf("Error getting node pools from cluster '%s': %s", cluster.ID(), err)
963+
}
964+
965+
for _, np := range nodepools {
961966
// If autoscaling, calculate min and max, use min and max in separate messages below
962-
autoscaling, ok := np.GetAutoscaling()
963-
if !ok || autoscaling == nil {
964-
npReplicas, ok := np.GetReplicas()
965-
if !ok {
966-
return fmt.Errorf("Failed to get node pool replicas for hosted cluster '%s': %v", clusterKey, err)
967-
}
967+
npAutoscaling, ok := np.GetAutoscaling()
968+
if !ok || npAutoscaling == nil {
969+
npReplicas, _ := np.GetReplicas()
968970
sumOfReplicas += npReplicas
969971
} else {
970-
sumOfMaxReplicas += autoscaling.MaxReplica()
971-
sumOfMinReplicas += autoscaling.MinReplica()
972+
sumOfMaxReplicas += npAutoscaling.MaxReplica()
973+
sumOfMinReplicas += npAutoscaling.MinReplica()
972974
}
973975
}
974976

@@ -1833,18 +1835,20 @@ func editNodePool(cmd *cobra.Command, nodePoolID string,
18331835
sumOfMaxReplicas := maxReplicas
18341836
sumOfMinReplicas := minReplicas
18351837

1836-
for _, np := range cluster.NodePools().Items() {
1838+
nodepools, err := r.OCMClient.GetNodePools(cluster.ID())
1839+
if err != nil {
1840+
r.Reporter.Errorf("Error getting node pools from cluster '%s': %s", cluster.ID(), err)
1841+
}
1842+
1843+
for _, np := range nodepools {
18371844
// If autoscaling, calculate min and max, use min and max in separate messages below
1838-
autoscaling, ok := np.GetAutoscaling()
1839-
if !ok || autoscaling == nil {
1840-
npReplicas, ok := np.GetReplicas()
1841-
if !ok {
1842-
return fmt.Errorf("Failed to get node pool replicas for hosted cluster '%s': %v", clusterKey, err)
1843-
}
1845+
npAutoscaling, ok := np.GetAutoscaling()
1846+
if !ok || npAutoscaling == nil {
1847+
npReplicas, _ := np.GetReplicas()
18441848
sumOfReplicas += npReplicas
18451849
} else {
1846-
sumOfMaxReplicas += autoscaling.MaxReplica()
1847-
sumOfMinReplicas += autoscaling.MinReplica()
1850+
sumOfMaxReplicas += npAutoscaling.MaxReplica()
1851+
sumOfMinReplicas += npAutoscaling.MinReplica()
18481852
}
18491853
}
18501854

pkg/machinepool/machinepool_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,8 @@ var _ = Describe("NodePools", func() {
14851485
nodePoolObj, err := cmv1.NewNodePool().ID("np-1").Build()
14861486
Expect(err).ToNot(HaveOccurred())
14871487
t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, FormatResources(nodePoolObj)))
1488+
nodePoolResponse := test.FormatNodePoolList([]*cmv1.NodePool{nodePoolObj})
1489+
t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, nodePoolResponse))
14881490
err = machinePool.CreateNodePools(t.RosaRuntime, cmd, clusterKey, cluster, nil, &args)
14891491
Expect(err).To(Not(HaveOccurred()))
14901492
})

0 commit comments

Comments
 (0)