uranusjr commented on a change in pull request #20819:
URL: https://github.com/apache/airflow/pull/20819#discussion_r782706766



##########
File path: airflow/providers/amazon/aws/hooks/eks.py
##########
@@ -135,13 +146,12 @@ def create_nodegroup(
         :rtype: Dict
         """
         eks_client = self.conn
+
         # The below tag is mandatory and must have a value of either 'owned' 
or 'shared'
         # A value of 'owned' denotes that the subnets are exclusive to the 
nodegroup.
         # The 'shared' value allows more than one resource to use the subnet.
-        tags = {'kubernetes.io/cluster/' + clusterName: 'owned'}
-        if "tags" in kwargs:
-            tags = {**tags, **kwargs["tags"]}
-            kwargs.pop("tags")
+        tags = kwargs.pop("tags", {})
+        tags[f'kubernetes.io/cluster/{clusterName}'] = 'owned'

Review comment:
       If “before” means the code currently in `main`, yes it would, because 
`{**tags, **kwargs["tags"]}` means that if any key in `kwargs["tags"]` would 
override the value under the same key in `tags`.
   
   ```python
   >>> a = {"x": 1}
   >>> b = {"x": 2}
   >>> {**a, **b}
   {"x": 2}
   ```
   
   So the backward compatible implementation would be something like
   
   ```python
   resolved_tags = tags or {}
   cluster_tag_key = f'kubernetes.io/cluster/{clusterName}'
   if cluster_tag_key not in resolved_tags:
       resolved_tags[cluster_tag_key] = 'owned'
   ```
   
   or `setdefault` might work as well.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to