Skip to content

Commit 211fd11

Browse files
authored
🌟 Adds GKE autoscaling resource (#5459)
* Adds GKE autoscaling resource Signed-off-by: scottford-io <scott@scottford.io> * Updates spell checker Signed-off-by: scottford-io <scott@scottford.io> --------- Signed-off-by: scottford-io <scott@scottford.io>
1 parent dfcf035 commit 211fd11

File tree

5 files changed

+197
-0
lines changed

5 files changed

+197
-0
lines changed

.github/actions/spelling/expect.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ atlassian
44
auditlog
55
Auths
66
autoaccept
7+
autoprovisioned
78
autoscaler
89
backupconfiguration
910
backupsetting

providers/gcp/resources/gcp.lr

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,31 @@ private gcp.project.gkeService.cluster.nodepool @defaults("name") {
17651765
status string
17661766
// Node management configuration
17671767
management dict
1768+
// Autoscaler configuration for this NodePool
1769+
autoscaling gcp.project.gkeService.cluster.nodepool.autoscaling
1770+
}
1771+
1772+
private gcp.project.gkeService.cluster.nodepool.autoscaling @defaults( "enabled" ) {
1773+
// Is autoscaling enabled for this node pool.
1774+
enabled bool
1775+
// Minimum number of nodes for one location in the node pool. Must be greater
1776+
// than or equal to 0 and less than or equal to max_node_count.
1777+
minNodeCount int
1778+
// Maximum number of nodes for one location in the node pool. Must be >=
1779+
// min_node_count. There has to be enough quota to scale up the cluster.
1780+
maxNodeCount int
1781+
// Can this node pool be deleted automatically.
1782+
autoprovisioned bool
1783+
// Minimum number of nodes in the node pool. Must be greater than or equal
1784+
// to 0 and less than or equal to total_max_node_count.
1785+
// The total_*_node_count fields are mutually exclusive with the *_node_count
1786+
// fields.
1787+
totalMinNodeCount int
1788+
// Maximum number of nodes in the node pool. Must be greater than or equal to
1789+
// total_min_node_count. There has to be enough quota to scale up the cluster.
1790+
// The total_*_node_count fields are mutually exclusive with the *_node_count
1791+
// fields.
1792+
totalMaxNodeCount int
17681793
}
17691794

17701795
// Google Kubernetes Engine (GKE) node pool-Level network configuration

providers/gcp/resources/gcp.lr.go

Lines changed: 131 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

providers/gcp/resources/gcp.lr.manifest.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,8 @@ resources:
15311531
url: https://cloud.google.com/kubernetes-engine/docs/best-practices/networking
15321532
gcp.project.gkeService.cluster.nodepool:
15331533
fields:
1534+
autoscaling:
1535+
min_mondoo_version: 9.0.0
15341536
config: {}
15351537
id: {}
15361538
initialNodeCount: {}
@@ -1549,6 +1551,19 @@ resources:
15491551
refs:
15501552
- title: About node pools
15511553
url: https://cloud.google.com/kubernetes-engine/docs/concepts/node-pools
1554+
gcp.project.gkeService.cluster.nodepool.autoscaling:
1555+
fields:
1556+
autoprovisioned: {}
1557+
enabled: {}
1558+
maxNodeCount: {}
1559+
minNodeCount: {}
1560+
totalMaxNodeCount: {}
1561+
totalMinNodeCount: {}
1562+
is_private: true
1563+
min_mondoo_version: 9.0.0
1564+
platform:
1565+
name:
1566+
- gcp
15521567
gcp.project.gkeService.cluster.nodepool.config:
15531568
fields:
15541569
accelerators: {}

providers/gcp/resources/gke.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,11 @@ func createMqlNodePool(runtime *plugin.Runtime, np *containerpb.NodePool, cluste
613613
return nil, err
614614
}
615615

616+
mqlPoolAutoscaling, err := createMqlNodePoolAutoscaling(runtime, np, nodePoolId)
617+
if err != nil {
618+
return nil, err
619+
}
620+
616621
var management map[string]interface{}
617622
if np.Management != nil {
618623
var upgradeOpts map[string]interface{}
@@ -640,6 +645,7 @@ func createMqlNodePool(runtime *plugin.Runtime, np *containerpb.NodePool, cluste
640645
"instanceGroupUrls": llx.ArrayData(convert.SliceAnyToInterface(np.InstanceGroupUrls), types.String),
641646
"status": llx.StringData(np.Status.String()),
642647
"management": llx.DictData(management),
648+
"autoscaling": llx.ResourceData(mqlPoolAutoscaling, "gcp.project.gkeService.cluster.nodepool.autoscaling"),
643649
})
644650
}
645651

@@ -824,6 +830,25 @@ func createMqlNodePoolNetworkConfig(runtime *plugin.Runtime, np *containerpb.Nod
824830
})
825831
}
826832

833+
func createMqlNodePoolAutoscaling(runtime *plugin.Runtime, nodepool *containerpb.NodePool, nodePoolId string) (plugin.Resource, error) {
834+
autoscalingCfg := nodepool.Autoscaling
835+
if autoscalingCfg == nil {
836+
return nil, nil
837+
}
838+
839+
autoscalingId := fmt.Sprintf("gcp.project.gkeService.cluster.nodepool.autoscaling/%s", nodePoolId)
840+
841+
return CreateResource(runtime, "gcp.project.gkeService.cluster.nodepool.autoscaling", map[string]*llx.RawData{
842+
"__id": llx.StringData(autoscalingId),
843+
"minNodeCount": llx.IntData(autoscalingCfg.MinNodeCount),
844+
"maxNodeCount": llx.IntData(autoscalingCfg.MaxNodeCount),
845+
"autoprovisioned": llx.BoolData(autoscalingCfg.Autoprovisioned),
846+
"enabled": llx.BoolData(autoscalingCfg.Enabled),
847+
"totalMinNodeCount": llx.IntData(autoscalingCfg.TotalMinNodeCount),
848+
"totalMaxNodeCount": llx.IntData(autoscalingCfg.TotalMaxNodeCount),
849+
})
850+
}
851+
827852
func createMqlAccelerator(runtime *plugin.Runtime, acc *containerpb.AcceleratorConfig, nodePoolId string, i int) (plugin.Resource, error) {
828853
accId := fmt.Sprintf("%s/accelerators/%d", nodePoolId, i)
829854

0 commit comments

Comments
 (0)