Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nvthongswansea committed Sep 10, 2024
1 parent 1e4718c commit 2c71d1d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
12 changes: 8 additions & 4 deletions cluster-autoscaler/cloudprovider/gridscale/gridscale_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,21 @@ func (m *Manager) Refresh() error {
if k8sCluster.Properties.Status != gridscaleK8sActiveStatus {
return fmt.Errorf("k8s cluster status is not active: %s", k8sCluster.Properties.Status)
}
nodePools, ok := k8sCluster.Properties.Parameters["pools"].([]map[string]interface{})
nodePools, ok := k8sCluster.Properties.Parameters["pools"].([]interface{})
if !ok {
return errors.New("'pools' is not found in cluster parameters")
}
nodeGroupList := make([]*NodeGroup, 0)
for _, nodePoolProperties := range nodePools {
for _, pool := range nodePools {
nodePoolProperties, ok := pool.(map[string]interface{})
if !ok {
return errors.New("node pool properties is not a map")
}
nodePoolName, ok := nodePoolProperties["name"].(string)
if !ok {
return errors.New("'name' is not found in node pool properties")
}
nodePoolCount, ok := nodePoolProperties["count"].(int)
nodePoolCount, ok := nodePoolProperties["count"].(float64)
if !ok {
return errors.New("'count' is not found in node pool properties")
}
Expand All @@ -148,7 +152,7 @@ func (m *Manager) Refresh() error {
name: nodePoolName,
clusterUUID: m.clusterUUID,
client: m.client,
nodeCount: nodePoolCount,
nodeCount: int(nodePoolCount),
minSize: m.minNodeCount,
maxSize: m.maxNodeCount,
}
Expand Down
33 changes: 24 additions & 9 deletions cluster-autoscaler/cloudprovider/gridscale/gridscale_node_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,23 @@ func (n *NodeGroup) IncreaseSize(delta int) error {
}
paramenters := k8sCluster.Properties.Parameters
// Update the node count of the node group
nodePools, ok := paramenters["pools"].([]map[string]interface{})
nodePools, ok := paramenters["pools"].([]interface{})
if !ok {
return errors.New("'pools' is not found in cluster parameters")
}
// find the node pool that we want to update
for i, nodePoolProperties := range nodePools {
for i, pool := range nodePools {
nodePoolProperties, ok := pool.(map[string]interface{})
if !ok {
return errors.New("node pool properties is not a map")
}
nodePoolName, ok := nodePoolProperties["name"].(string)
if !ok {
return errors.New("'name' is not found in node pool properties")
}
if nodePoolName == n.name {
nodePools[i]["count"] = targetSize
nodePoolProperties["count"] = targetSize
nodePools[i] = nodePoolProperties
break
}
}
Expand Down Expand Up @@ -138,18 +143,23 @@ func (n *NodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
}
paramenters := k8sCluster.Properties.Parameters
// Update the node count of the node group
nodePools, ok := paramenters["pools"].([]map[string]interface{})
nodePools, ok := paramenters["pools"].([]interface{})
if !ok {
return errors.New("'pools' is not found in cluster parameters")
}
// find the node pool that we want to update
for i, nodePoolProperties := range nodePools {
for i, pool := range nodePools {
nodePoolProperties, ok := pool.(map[string]interface{})
if !ok {
return errors.New("node pool properties is not a map")
}
nodePoolName, ok := nodePoolProperties["name"].(string)
if !ok {
return errors.New("'name' is not found in node pool properties")
}
if nodePoolName == n.name {
nodePools[i]["count"] = targetSize
nodePoolProperties["count"] = targetSize
nodePools[i] = nodePoolProperties
break
}
}
Expand Down Expand Up @@ -189,18 +199,23 @@ func (n *NodeGroup) DecreaseTargetSize(delta int) error {
}
paramenters := k8sCluster.Properties.Parameters
// Update the node count of the node group
nodePools, ok := paramenters["pools"].([]map[string]interface{})
nodePools, ok := paramenters["pools"].([]interface{})
if !ok {
return errors.New("'pools' is not found in cluster parameters")
}
// find the node pool that we want to update
for i, nodePoolProperties := range nodePools {
for i, pool := range nodePools {
nodePoolProperties, ok := pool.(map[string]interface{})
if !ok {
return errors.New("node pool properties is not a map")
}
nodePoolName, ok := nodePoolProperties["name"].(string)
if !ok {
return errors.New("'name' is not found in node pool properties")
}
if nodePoolName == n.name {
nodePools[i]["count"] = targetSize
nodePoolProperties["count"] = targetSize
nodePools[i] = nodePoolProperties
break
}
}
Expand Down

0 comments on commit 2c71d1d

Please sign in to comment.