Miretpl commented on code in PR #71349:
URL: https://github.com/apache/airflow/pull/71349#discussion_r4575987464


##########
providers/google/tests/unit/google/cloud/hooks/test_kubernetes_engine.py:
##########
@@ -582,6 +590,212 @@ async def test_read_logs(self, read_namespaced_pod_log, 
get_conn_mock, async_hoo
         assert "Test string #1" in logs
         assert "Test string #2" in logs
 
+    @staticmethod
+    def _mock_token(tokens):
+        token = mock.AsyncMock()
+        token.get.side_effect = list(tokens)
+        return token
+
+    @pytest.mark.asyncio
+    @mock.patch(GKE_STRING.format("GKEKubernetesAsyncHook.get_token"), 
new_callable=mock.AsyncMock)
+    @mock.patch(GKE_STRING.format("GKEKubernetesAsyncHook._build_client"))
+    async def test_get_conn_caches_client_and_token(self, mock_build_client, 
mock_get_token, async_hook):
+        mock_get_token.return_value = self._mock_token(["token-1", "token-1"])
+        mock_build_client.return_value = mock.MagicMock(default_headers={})

Review Comment:
   Same comment as the previous one regarding `spec`



##########
providers/google/tests/unit/google/cloud/hooks/test_kubernetes_engine.py:
##########
@@ -582,6 +590,212 @@ async def test_read_logs(self, read_namespaced_pod_log, 
get_conn_mock, async_hoo
         assert "Test string #1" in logs
         assert "Test string #2" in logs
 
+    @staticmethod
+    def _mock_token(tokens):
+        token = mock.AsyncMock()

Review Comment:
   Could you specify `spec`/`autospec` for `AsyncMock`? When it is empty, it 
mocks everything by default.



##########
providers/google/pyproject.toml:
##########
@@ -172,7 +172,7 @@ dependencies = [
     "apache-airflow-providers-apache-beam>=6.2.2",
 ]
 "cncf.kubernetes" = [
-    "apache-airflow-providers-cncf-kubernetes>=10.25.0",
+    "apache-airflow-providers-cncf-kubernetes>=10.25.0",  # use next version

Review Comment:
   Do we need this comment? 🤔



##########
providers/google/src/airflow/providers/google/cloud/hooks/kubernetes_engine.py:
##########
@@ -478,6 +482,27 @@ def apply_from_yaml_file(
         )
 
 
+class _GKEAsyncApiClient(async_client.ApiClient):
+    """Retry a rejected GKE token once with refreshed credentials."""
+
+    def __init__(
+        self,
+        configuration: async_client.Configuration,
+        refresh_token: Callable[[], Awaitable[str | None]],
+    ) -> None:
+        super().__init__(configuration=configuration)
+        self._refresh_token = refresh_token
+
+    async def call_api(self, *args: Any, **kwargs: Any) -> Any:
+        try:
+            return await super().call_api(*args, **kwargs)
+        except async_client.ApiException as error:
+            if error.status != 401:

Review Comment:
   I don't like it really, but we can do that. I learned not so long ago that 
Google has that approach, so I guess it should be fine to have something 
similar in their provider.



-- 
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