Skip to content

Commit

Permalink
Add cluster tags for EKS + add tag inheritance with node pools (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
vrutz authored Aug 27, 2024
1 parent 02be2c1 commit 6ce95c1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python-clusters/create-eks-cluster/cluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
"parameterSetId" : "node-pool-request",
"mandatory" : false
},
{
"name": "clusterTags",
"label": "Tags",
"type": "MAP",
"description": "Annotate the cluster's related EKS resources"
},
{
"name": "s-advanced",
"type":"SEPARATOR",
Expand Down
6 changes: 6 additions & 0 deletions python-clusters/create-eks-cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def start(self):
args = args + ["-v", "3"] # not -v 4 otherwise there is a debug line in the beginning of the output
args = args + ["--name", self.cluster_id]
args = args + get_region_arg(connection_info)
args = args + ["--tags", ",".join(["%s=%s" % (tag_key, tag_value) for tag_key, tag_value in self.config.get("clusterTags", {}).items()])]
args = args + ["--full-ecr-access"]

subnets = list(map(lambda subnet_id: subnet_id.strip(), networking_settings.get("subnets", [])))
Expand Down Expand Up @@ -100,6 +101,11 @@ def start(self):
yaml_dict["managedNodeGroups"] = yaml_dict.get("managedNodeGroups", [])
for idx, node_pool in enumerate(node_pools, 0):
if node_pool:
# Inherit cluster tags in each node pool
node_pool_tags = dict(self.config.get("clusterTags", {}))
node_pool_tags.update(node_pool.get("tags", {}))
node_pool["tags"] = node_pool_tags

yaml_node_pool = get_node_pool_yaml(node_pool, networking_settings)
yaml_node_pool["name"] = node_pool.get("nodeGroupId", "%s-ng-%s" % (self.cluster_id, idx))
yaml_dict["managedNodeGroups"].append(yaml_node_pool)
Expand Down
5 changes: 5 additions & 0 deletions python-runnables/add-node-pool/runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def run(self, progress_callback):
node_pool = self.config.get("nodePool", {})
node_group_id = node_pool.get("nodeGroupId", None)

# Inherit cluster tags in new node pool
node_pool_tags = dict(dss_cluster_config.get("config", {}).get("clusterTags", {}))
node_pool_tags.update(node_pool.get("tags", {}))
node_pool["tags"] = node_pool_tags

# first pass: get the yaml config corresponding to the command line args
args = ["create", "nodegroup"]
args = args + ["-v", "3"] # not -v 4 otherwise there is a debug line in the beginning of the output
Expand Down

0 comments on commit 6ce95c1

Please sign in to comment.