You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/01/12 03:07:05 UTC

[GitHub] [airflow] uranusjr commented on a change in pull request #20819: Adds support for optional kwargs in the EKS Operators

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



##########
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:
       How about changing this function to
   
   ```python
   def create_nodegroup(
       self,
       clusterName: str,
       nodegroupName: str,
       subnets: List[str],
       nodeRole: str,
       *,
       tags: Optional[dict] = None
       **kwargs,
   ) -> Dict:
       ...
       if tags is not None:
           resolved_tags = tags
       else:
           resolved_tags = {}
       resolved_tags[f'kubernetes.io/cluster/{clusterName}'] = 'owned'
   ```
   
   to better leverage Python’s built-in syntax. The `kwargs.pop()` or `if key in kwargs` pattern was a pragmatic workaround on Python 2, but now that keyword-only arguments are available, they make the API both easier to read and write.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org