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

Experimental: Add support to create the Tanzu Hub client #175

Merged
merged 7 commits into from
May 1, 2024

Conversation

anujc25
Copy link
Contributor

@anujc25 anujc25 commented Apr 12, 2024

What this PR does / why we need it

  • Adds support to create authenticated Tanzu Hub client for the specified tanzu context
  • The Tanzu Hub client exposes a graphQL client implemented using github.com/Khan/genqlient/graphql to query the hub resources with graphQL APIs.
  • Also provides a Makefile to help plugin authors initialize and generate the stub for the graphQL queries.

Which issue(s) this PR fixes

Fixes #

Describe testing done for PR

Release note

Experimental: Add support to create the Tanzu Hub client

Additional information

Special notes for your reviewer

config/tanzu_context.go Outdated Show resolved Hide resolved
client/hub/client.go Outdated Show resolved Hide resolved
client/hub/client.go Outdated Show resolved Hide resolved
@vuil
Copy link
Contributor

vuil commented Apr 15, 2024

Have you thought about where instructions/tooling pertaining to generation of query stubs from Hub schema should reside.
I am not sure if they fit in plugin-tooling.mk, but some convenient make targets might be worth considering

@anujc25 anujc25 force-pushed the hub-client-support branch 4 times, most recently from fd49571 to ef08f99 Compare April 23, 2024 06:06
@anujc25 anujc25 changed the title Add support to create Tanzu Hub client Experimental: Add support to create the Tanzu Hub client Apr 23, 2024
@anujc25 anujc25 marked this pull request as ready for review April 23, 2024 06:29
@anujc25 anujc25 requested a review from a team as a code owner April 23, 2024 06:29
client/hub/README.md Outdated Show resolved Hide resolved
client/hub/README.md Outdated Show resolved Hide resolved
client/hub/README.md Outdated Show resolved Hide resolved
To create a Tanzu Hub client, plugin authors can just use the `CreateHubClient(contextName string)` API
by providing the `tanzu` context name. An authenticated Tanzu Hub client for the specified tanzu context will be returned.
This client includes an authenticated GraphQLClient from the `github.com/Khan/genqlient`
that can be used to do GraphQL queries. Internally it configures the client with a CSP access token for each request.
Copy link
Contributor

Choose a reason for hiding this comment

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

a CSP access token -> an access token

do we have plans to auto-refresh the token? Given the CLI single command invocation use case (assuming we are not dealing with very long-running operations), this might not be too relevant.
If we are open to the possibility, it might be worth mentioning here and add a TODO in client.go

Also worth mentioning (especially for folks jumping to this doc mostly to learn about hub client integration) that the client if authenticated is assured at least 10-15m access to the graphQL endpoint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Copy link
Contributor

@vuil vuil left a comment

Choose a reason for hiding this comment

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

Nice!
If you are thinking of address the comments in this change.
I would also suggest updating README.md to mention the EXPERIMENTAL nature of the hub client introduction


TANZU_HUB_PKG_BASE_DIR ?= $(ROOT_DIR)/pkg
TANZU_HUB_PKG_DIR=$(TANZU_HUB_PKG_BASE_DIR)/hub
TANZU_HUB_INIT_FILES := queries.graphql main.go genqlient.yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I wonder if we should put (commented out) a very simple example query in queries.graphql.

hack/hub/tanzuhub.mk Outdated Show resolved Hide resolved
Copy link
Contributor

@marckhouzam marckhouzam left a comment

Choose a reason for hiding this comment

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

This is really cool! Nice way to help project use the client.
Some questions to help me confirm I understood things properly.

client/hub/README.md Outdated Show resolved Hide resolved
client/hub/README.md Outdated Show resolved Hide resolved
client/hub/README.md Outdated Show resolved Hide resolved
for filename in $(TANZU_HUB_INIT_FILES); do \
[ -f $(TANZU_HUB_PKG_DIR)/$$filename ] && echo "Skipping $(TANZU_HUB_PKG_DIR)/$$filename (already exists)" || wget -O "$(TANZU_HUB_PKG_DIR)/$(filename)" $(TANZU_HUB_INIT_PKG_URL)/$$filename ; \
done
wget -O "$(TANZU_HUB_PKG_DIR)/schema.graphql" $(TANZU_HUB_SCHEMA_FILE_URL)
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is the schema. I assume it should not be modified by the local project?

  1. should it be checked-in to git? mine is 98k lines
  2. can this schema change?
  3. should a new version be fetched each time the code is compiled? Or should the project dev run make tanzu-hub-stub-init once in a while to refresh? or do we not need to re-download at all?

Copy link
Contributor Author

@anujc25 anujc25 May 1, 2024

Choose a reason for hiding this comment

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

  1. It does not harm to check in that file in the plugin repository as plugins can manage how it should be consumed and when it needs to be updated. But as schema can change, I don't think we should check it into this repository.
  2. Yes it can change.
  3. The expectation at the moment is to run the make tanzu-hub-stub-init to refresh the schema file.

.PHONY: tanzu-hub-stub-init
tanzu-hub-stub-init: # Initialize a Tanzu Hub package with stub, schema.graphql and queries.graphql to generate graphQL client APIs
mkdir -p $(TANZU_HUB_PKG_DIR)
for filename in $(TANZU_HUB_INIT_FILES); do \
Copy link
Contributor

Choose a reason for hiding this comment

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

So these three files are stubs but once created, the user may modify then so we don't want to overwrite them, correct? Or is it only queries.graphql that we need to "protect"? Could the user want to regenerate the other files to update them to a new TPR release? In such a case, how about putting the files that can be changed under a generated/ directory that the user can delete at any time and then run make tanzu-hub-stub-init again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will need time to think about this a bit more. Considering this is an experimental feature, we should be okay to do this change later as well.

Copy link
Contributor

@marckhouzam marckhouzam left a comment

Choose a reason for hiding this comment

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

Ok, this is great!
I'll let you decide what you want to do about the comments as I just started playing with this.

LGTM whatever you decide.

config/tanzu_context.go Show resolved Hide resolved
config/tanzu_context.go Show resolved Hide resolved
@marckhouzam marckhouzam added this to the v1.3.0 milestone May 1, 2024
@anujc25 anujc25 merged commit ad724a2 into vmware-tanzu:main May 1, 2024
4 checks passed
vuil pushed a commit to vuil/tanzu-plugin-runtime that referenced this pull request May 7, 2024
…u#175)

- Adds support to create authenticated Tanzu Hub client for the specified tanzu context
- The Tanzu Hub client exposes a graphQL client implemented using github.com/Khan/genqlient/graphql to query the hub resources with graphQL APIs.
- Also provides a Makefile to help plugin authors initialize and generate the stub for the graphQL queries.
vuil pushed a commit that referenced this pull request May 7, 2024
- Adds support to create authenticated Tanzu Hub client for the specified tanzu context
- The Tanzu Hub client exposes a graphQL client implemented using github.com/Khan/genqlient/graphql to query the hub resources with graphQL APIs.
- Also provides a Makefile to help plugin authors initialize and generate the stub for the graphQL queries.
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.

4 participants