@@ -34,6 +34,10 @@ import (
34
34
"github.com/openshift/rosa/pkg/rosa"
35
35
)
36
36
37
+ const (
38
+ clusterAutoscalerLimitMessage = "Cluster Autoscaler limit (MaxNodes)"
39
+ )
40
+
37
41
var fetchMessage string = "Fetching %s '%s' for cluster '%s'"
38
42
var notFoundMessage string = "Machine pool '%s' not found"
39
43
@@ -948,6 +952,43 @@ func (m *machinePool) CreateNodePools(r *rosa.Runtime, cmd *cobra.Command, clust
948
952
}
949
953
}
950
954
955
+ sumOfReplicas := replicas
956
+ sumOfMaxReplicas := maxReplicas
957
+ sumOfMinReplicas := minReplicas
958
+
959
+ for _ , np := range cluster .NodePools ().Items () {
960
+ // If autoscaling, calculate min and max, use min and max in separate messages below
961
+ autoscaling , ok := np .GetAutoscaling ()
962
+ if ! ok || autoscaling == nil {
963
+ npReplicas , ok := np .GetReplicas ()
964
+ if ! ok {
965
+ return fmt .Errorf ("Failed to get node pool replicas for hosted cluster '%s': %v" , clusterKey , err )
966
+ }
967
+ sumOfReplicas += npReplicas
968
+ } else {
969
+ sumOfMaxReplicas += autoscaling .MaxReplica ()
970
+ sumOfMinReplicas += autoscaling .MinReplica ()
971
+ }
972
+ }
973
+
974
+ // Informational message for cluster autoscaler + scaling out to max nodes
975
+ if autoscaling {
976
+ r .Reporter .Infof ("Scaling max replicas to the maximum allowed value is subject to cluster autoscaler" +
977
+ " configuration" )
978
+ }
979
+
980
+ // Informational message for sum of replicas > MaxNodesTotal
981
+ if sumOfReplicas + sumOfMaxReplicas > hcpMaxNodesLimit {
982
+ r .Reporter .Infof ("Actual maximum replicas can be lowered, since the replicas defined exceeds " +
983
+ "%s" , clusterAutoscalerLimitMessage )
984
+ }
985
+
986
+ // Informational message for min-replicas or replicas > MaxNodesTotal
987
+ if sumOfReplicas + sumOfMinReplicas > hcpMaxNodesLimit {
988
+ r .Reporter .Infof ("Actual total nodes in the cluster will be more than the maximum nodes configured " +
989
+ "in the cluster autoscaler" )
990
+ }
991
+
951
992
if version != "" {
952
993
npBuilder .Version (cmv1 .NewVersion ().ID (version ))
953
994
}
@@ -1776,6 +1817,43 @@ func editNodePool(cmd *cobra.Command, nodePoolID string,
1776
1817
}
1777
1818
}
1778
1819
1820
+ sumOfReplicas := replicas
1821
+ sumOfMaxReplicas := maxReplicas
1822
+ sumOfMinReplicas := minReplicas
1823
+
1824
+ for _ , np := range cluster .NodePools ().Items () {
1825
+ // If autoscaling, calculate min and max, use min and max in separate messages below
1826
+ autoscaling , ok := np .GetAutoscaling ()
1827
+ if ! ok || autoscaling == nil {
1828
+ npReplicas , ok := np .GetReplicas ()
1829
+ if ! ok {
1830
+ return fmt .Errorf ("Failed to get node pool replicas for hosted cluster '%s': %v" , clusterKey , err )
1831
+ }
1832
+ sumOfReplicas += npReplicas
1833
+ } else {
1834
+ sumOfMaxReplicas += autoscaling .MaxReplica ()
1835
+ sumOfMinReplicas += autoscaling .MinReplica ()
1836
+ }
1837
+ }
1838
+
1839
+ // Informational message for cluster autoscaler + scaling out to max nodes
1840
+ if autoscaling {
1841
+ r .Reporter .Infof ("Scaling max replicas to the maximum allowed value is subject to cluster autoscaler" +
1842
+ " configuration" )
1843
+ }
1844
+
1845
+ // Informational message for sum of replicas > MaxNodesTotal
1846
+ if sumOfReplicas + sumOfMaxReplicas > hcpMaxNodesLimit {
1847
+ r .Reporter .Infof ("Actual maximum replicas can be lowered, since the replicas defined exceeds " +
1848
+ "%s" , clusterAutoscalerLimitMessage )
1849
+ }
1850
+
1851
+ // Informational message for min-replicas or replicas > MaxNodesTotal
1852
+ if sumOfReplicas + sumOfMinReplicas > hcpMaxNodesLimit {
1853
+ r .Reporter .Infof ("Actual total nodes in the cluster will be more than the maximum nodes configured " +
1854
+ "in the cluster autoscaler" )
1855
+ }
1856
+
1779
1857
update , err := npBuilder .Build ()
1780
1858
if err != nil {
1781
1859
return fmt .Errorf ("Failed to create machine pool for hosted cluster '%s': %v" , clusterKey , err )
0 commit comments