Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for keyring errors when initializing Flyte for_sandbox config client #2962

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/monodocs_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ jobs:
DOCSEARCH_API_KEY: fake_docsearch_api_key # must be set to get doc build to succeed
run: |
conda activate monodocs-env
pip install grpcio-health-checking==1.49.0
make -C docs clean html SPHINXOPTS="-W -vvv"
5 changes: 5 additions & 0 deletions .github/workflows/pythonbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ jobs:
tags: localhost:30000/flytekit:dev
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Install dependencies
run: |
pip install grpcio
pip install grpcio-tools
pip install grpcio-health-checking
- name: Integration Test with coverage
env:
FLYTEKIT_IMAGE: localhost:30000/flytekit:dev
Expand Down
2 changes: 2 additions & 0 deletions dev-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ ipykernel

orjson
kubernetes>=12.0.1

grpcio-health-checking==1.49.0
2 changes: 2 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,5 @@ zipp==3.19.1

# The following packages are considered to be unsafe in a requirements file:
# setuptools

grpcio-health-checking==1.49.0
47 changes: 41 additions & 6 deletions flytekit/clients/raw.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import logging
import typing

import grpc
Expand All @@ -10,6 +11,7 @@
from flyteidl.service import dataproxy_pb2_grpc as dataproxy_service
from flyteidl.service import signal_pb2_grpc as signal_service
from flyteidl.service.dataproxy_pb2_grpc import DataProxyServiceStub
from grpc_health.v1 import health_pb2, health_pb2_grpc

from flytekit.clients.auth_helper import (
get_channel,
Expand All @@ -18,6 +20,12 @@
wrap_exceptions_channel,
)
from flytekit.configuration import PlatformConfig
from flytekit.exceptions.system import FlyteSystemUnavailableException
from flytekit.exceptions.user import (
FlyteEntityAlreadyExistsException,
FlyteEntityNotExistException,
FlyteInvalidInputException,
)
from flytekit.loggers import logger


Expand Down Expand Up @@ -51,12 +59,18 @@
# 32KB for error messages, 20MB for actual messages.
options = (("grpc.max_metadata_size", 32 * 1024), ("grpc.max_receive_message_length", 20 * 1024 * 1024))
self._cfg = cfg
self._channel = wrap_exceptions_channel(
cfg,
upgrade_channel_to_authenticated(
cfg, upgrade_channel_to_proxy_authenticated(cfg, get_channel(cfg, options=options))
),
)
base_channel = get_channel(cfg, options=options)

if self.check_grpc_health_with_authentication(base_channel):
self._channel = wrap_exceptions_channel(cfg, base_channel)
else:
self._channel = wrap_exceptions_channel(

Check warning on line 67 in flytekit/clients/raw.py

View check run for this annotation

Codecov / codecov/patch

flytekit/clients/raw.py#L67

Added line #L67 was not covered by tests
cfg,
upgrade_channel_to_authenticated(
cfg, upgrade_channel_to_proxy_authenticated(cfg, get_channel(cfg, options=options))
),
)

self._stub = _admin_service.AdminServiceStub(self._channel)
self._signal = signal_service.SignalServiceStub(self._channel)
self._dataproxy_stub = dataproxy_service.DataProxyServiceStub(self._channel)
Expand All @@ -67,6 +81,27 @@
# metadata will hold the value of the token to send to the various endpoints.
self._metadata = None

@staticmethod
def check_grpc_health_with_authentication(in_channel):
health_stub = health_pb2_grpc.HealthStub(in_channel)
request = health_pb2.HealthCheckRequest()
try:
response = health_stub.Check(request)

Check warning on line 89 in flytekit/clients/raw.py

View check run for this annotation

Codecov / codecov/patch

flytekit/clients/raw.py#L86-L89

Added lines #L86 - L89 were not covered by tests
if response.status == health_pb2.HealthCheckResponse.SERVING:
logging.info("Service is healthy and ready to serve.")
return True
except grpc.RpcError as e:

Check warning on line 93 in flytekit/clients/raw.py

View check run for this annotation

Codecov / codecov/patch

flytekit/clients/raw.py#L91-L93

Added lines #L91 - L93 were not covered by tests
if e.code() == grpc.StatusCode.UNAUTHENTICATED:
return False

Check warning on line 95 in flytekit/clients/raw.py

View check run for this annotation

Codecov / codecov/patch

flytekit/clients/raw.py#L95

Added line #L95 was not covered by tests
elif e.code() == grpc.StatusCode.ALREADY_EXISTS:
raise FlyteEntityAlreadyExistsException() from e

Check warning on line 97 in flytekit/clients/raw.py

View check run for this annotation

Codecov / codecov/patch

flytekit/clients/raw.py#L97

Added line #L97 was not covered by tests
elif e.code() == grpc.StatusCode.NOT_FOUND:
raise FlyteEntityNotExistException() from e

Check warning on line 99 in flytekit/clients/raw.py

View check run for this annotation

Codecov / codecov/patch

flytekit/clients/raw.py#L99

Added line #L99 was not covered by tests
elif e.code() == grpc.StatusCode.INVALID_ARGUMENT:
raise FlyteInvalidInputException(request) from e

Check warning on line 101 in flytekit/clients/raw.py

View check run for this annotation

Codecov / codecov/patch

flytekit/clients/raw.py#L101

Added line #L101 was not covered by tests
elif e.code() == grpc.StatusCode.UNAVAILABLE:
raise FlyteSystemUnavailableException() from e

Check warning on line 103 in flytekit/clients/raw.py

View check run for this annotation

Codecov / codecov/patch

flytekit/clients/raw.py#L103

Added line #L103 was not covered by tests

@classmethod
def with_root_certificate(cls, cfg: PlatformConfig, root_cert_file: str) -> RawSynchronousFlyteClient:
b = None
Expand Down
11 changes: 7 additions & 4 deletions tests/flytekit/unit/clients/test_friendly.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,29 @@
from flytekit.clients.friendly import SynchronousFlyteClient as _SynchronousFlyteClient
from flytekit.configuration import PlatformConfig
from flytekit.models.project import Project as _Project

from grpc_health.v1 import health_pb2

@mock.patch("flytekit.clients.friendly._RawSynchronousFlyteClient.update_project")
def test_update_project(mock_raw_update_project):
@mock.patch("flytekit.clients.raw.RawSynchronousFlyteClient.check_grpc_health_with_authentication", return_value=health_pb2.HealthCheckResponse.SERVING)
def test_update_project(mock_check_health, mock_raw_update_project):
client = _SynchronousFlyteClient(PlatformConfig.for_endpoint("a.b.com", True))
project = _Project("foo", "name", "description", state=_Project.ProjectState.ACTIVE)
client.update_project(project)
mock_raw_update_project.assert_called_with(project.to_flyte_idl())


@mock.patch("flytekit.clients.friendly._RawSynchronousFlyteClient.list_projects")
def test_list_projects_paginated(mock_raw_list_projects):
@mock.patch("flytekit.clients.raw.RawSynchronousFlyteClient.check_grpc_health_with_authentication", return_value=health_pb2.HealthCheckResponse.SERVING)
def test_list_projects_paginated(mock_check_health, mock_raw_list_projects):
client = _SynchronousFlyteClient(PlatformConfig.for_endpoint("a.b.com", True))
client.list_projects_paginated(limit=100, token="")
project_list_request = _project_pb2.ProjectListRequest(limit=100, token="", filters=None, sort_by=None)
mock_raw_list_projects.assert_called_with(project_list_request=project_list_request)


@mock.patch("flytekit.clients.friendly._RawSynchronousFlyteClient.create_upload_location")
def test_create_upload_location(mock_raw_create_upload_location):
@mock.patch("flytekit.clients.raw.RawSynchronousFlyteClient.check_grpc_health_with_authentication", return_value=health_pb2.HealthCheckResponse.SERVING)
def test_create_upload_location(mock_check_health, mock_raw_create_upload_location):
client = _SynchronousFlyteClient(PlatformConfig.for_endpoint("a.b.com", True))
client.get_upload_signed_url("foo", "bar", bytes(), "baz.qux", timedelta(minutes=42), add_content_md5_metadata=True)
duration_pb = Duration()
Expand Down
9 changes: 6 additions & 3 deletions tests/flytekit/unit/clients/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

from flytekit.clients.raw import RawSynchronousFlyteClient
from flytekit.configuration import PlatformConfig

from grpc_health.v1 import health_pb2

@mock.patch("flytekit.clients.raw._admin_service")
@mock.patch("flytekit.clients.raw.grpc.insecure_channel")
def test_update_project(mock_channel, mock_admin):
@mock.patch.object(RawSynchronousFlyteClient, "check_grpc_health_with_authentication", return_value=True)
def test_update_project(mock_check_health, mock_channel, mock_admin):
mock_health_stub = mock.Mock()
client = RawSynchronousFlyteClient(PlatformConfig(endpoint="a.b.com", insecure=True))
project = _project_pb2.Project(id="foo", name="name", description="description", state=_project_pb2.Project.ACTIVE)
client.update_project(project)
Expand All @@ -17,7 +19,8 @@ def test_update_project(mock_channel, mock_admin):

@mock.patch("flytekit.clients.raw._admin_service")
@mock.patch("flytekit.clients.raw.grpc.insecure_channel")
def test_list_projects_paginated(mock_channel, mock_admin):
@mock.patch("flytekit.clients.raw.RawSynchronousFlyteClient.check_grpc_health_with_authentication", return_value=health_pb2.HealthCheckResponse.SERVING)
def test_list_projects_paginated(mock_check_health, mock_channel, mock_admin):
client = RawSynchronousFlyteClient(PlatformConfig(endpoint="a.b.com", insecure=True))
project_list_request = _project_pb2.ProjectListRequest(limit=100, token="", filters=None, sort_by=None)
client.list_projects(project_list_request)
Expand Down
Loading