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

feat(sdk): client to support KFP v2 API. #7411

Merged
merged 10 commits into from
Mar 15, 2022

Conversation

chensun
Copy link
Member

@chensun chensun commented Mar 14, 2022

Description of your changes:

  • Copy over _auth.py and _client.py from deprecated folder to kfp/client.
  • Styling and formatting fix.
  • Use pipeline_manifest and runtime_config in ApiPipelineSpec.

Checklist:

Copy link
Member

@connor-mccarthy connor-mccarthy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Chen!

Just a few very small questions and potential changes -- curious what you think.


TYPE_CHECK = True

from kfp.client import Client
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding a pylint ignore comment so that is passes a linting check?

Suggested change
from kfp.client import Client
from kfp.client import Client # pylint: disable=wrong-import-position

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thanks for the suggestion!

@@ -16,9 +16,13 @@
# https://packaging.python.org/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages
__path__ = __import__("pkgutil").extend_path(__path__, __name__)

__version__ = '2.0.0b0'
__version__ = '2.0.0-alpha.0'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not this line of code

Should Copyright on this file be 2022 because we are presently modifying it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

credentials[client_id]['other_client_id'],
credentials[client_id]['other_client_secret'],
credentials[client_id]['refresh_token'], client_id)
if other_client_id is None or other_client_secret is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit / not your code:

This could be refactored to make it a little bit clearer what is returned if the predicate if other_client_id is None or other_client_secret is None is met:

    if other_client_id is None or other_client_secret is None:
        # fetch IAP auth token: service accounts
        return get_auth_token_from_sa(client_id)
    # fetch IAP auth token: user account
    # Obtain the ID token for provided Client ID with user accounts.
    # Flow: get authorization code -> exchange for refresh token -> obtain
    # and return ID token
    refresh_token = get_refresh_token_from_client_id(
        other_client_id, other_client_secret)
    credentials = {}
    if os.path.exists(LOCAL_KFP_CREDENTIAL):
        with open(LOCAL_KFP_CREDENTIAL, 'r') as f:
            credentials = json.load(f)
    credentials[client_id] = {}
    credentials[client_id]['other_client_id'] = other_client_id
    credentials[client_id]['other_client_secret'] = other_client_secret
    credentials[client_id]['refresh_token'] = refresh_token
    # TODO: handle the case when the refresh_token expires, which only
    # happens if the refresh_token is not used once for six months.
    if not os.path.exists(os.path.dirname(LOCAL_KFP_CREDENTIAL)):
        os.makedirs(os.path.dirname(LOCAL_KFP_CREDENTIAL))
    with open(LOCAL_KFP_CREDENTIAL, 'w') as f:
        json.dump(credentials, f)
    return id_token_from_refresh_token(other_client_id,
                                            other_client_secret, refresh_token,
                                            client_id)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file and client.py as well may have many refactoring opportunities, let alone the pylint errors.
Will leave those for later PRs-- feel empowered to propose refactoring PRs as well :)


token = None

# "existing_token" is designed to accept token generated outside of SDK.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about removing this commented out code? I don't know much about its origin, but we're not using it here nor in deprecated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not knowing much about the origin either, but existing_token seems to me it's still used as an optional parameter.
Maybe this chunk of comments should really be moved into the docstring instead.

@@ -138,6 +139,6 @@ def find_version(*file_path_parts):
'console_scripts': [
'dsl-compile = kfp.deprecated.compiler.main:main',
'dsl-compile-v2 = kfp.compiler.main:main',
'kfp=kfp.__main__:main'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not this line of code

Copyright 2022 here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@chensun
Copy link
Member Author

chensun commented Mar 15, 2022

/test kubeflow-pipelines-samples-v2

@chensun
Copy link
Member Author

chensun commented Mar 15, 2022

/retest

chensun and others added 4 commits March 15, 2022 16:37
…7400)

* chore(sdk): clean, dedup, reconcile, organize requirements

* apply yapf formatting

* correct copyright
* chore(sdk): fix test missing tempdir cleanup

* fix test path

* fix test path

* clean up setUp method

* change string placeholder from s to test_dir
@chensun
Copy link
Member Author

chensun commented Mar 15, 2022

/retest

@google-oss-prow
Copy link

google-oss-prow bot commented Mar 15, 2022

@chensun: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
kubeflow-pipelines-v2-go-test ea5483c link true /test kubeflow-pipelines-v2-go-test
kubeflow-pipeline-upgrade-test ea5483c link true /test kubeflow-pipeline-upgrade-test
kubeflow-pipeline-e2e-test ea5483c link true /test kubeflow-pipeline-e2e-test
kubeflow-pipeline-backend-test ea5483c link true /test kubeflow-pipeline-backend-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Copy link
Member

@connor-mccarthy connor-mccarthy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Chen!

/approve
/lgtm

@google-oss-prow google-oss-prow bot added the lgtm label Mar 15, 2022
@google-oss-prow
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: connor-mccarthy

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@chensun
Copy link
Member Author

chensun commented Mar 15, 2022

/retest

@google-oss-prow google-oss-prow bot merged commit b741926 into kubeflow:master Mar 15, 2022
@chensun chensun deleted the v2-client branch March 16, 2022 06:54
abaland pushed a commit to abaland/pipelines that referenced this pull request May 29, 2022
* copy _client.py and _auth.py from deprecated folder

* Make kfp.Client support v2 API (IR).

* fix test golden

* address comments

* copyright year

* chore(backend): clean up pipelinespec.Value usage (kubeflow#7407)

* chore(sdk): clean, dedup, reconcile, organize requirements (kubeflow#7400)

* chore(sdk): clean, dedup, reconcile, organize requirements

* apply yapf formatting

* correct copyright

* chore(sdk): fix test missing tempdir cleanup (kubeflow#7403)

* chore(sdk): fix test missing tempdir cleanup

* fix test path

* fix test path

* clean up setUp method

* change string placeholder from s to test_dir

* release note

Co-authored-by: Connor McCarthy <mccarthy.connor.james@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants