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

Introduce additional metadata field to Context #81

Merged

Conversation

mpanchajanya
Copy link
Contributor

@mpanchajanya mpanchajanya commented Jul 21, 2023

What this PR does / why we need it

  • At the moment, Tanzu Plugin Runtime - Context configuration does not provide a means to add any additional metadata.
    This proposal introduces a new AdditionalMetadata map field to Context to be able to provide additional data for each context. This way we don't have to release a new version of runtime every time we add a new property to the context object.
    Example: TMC will need to store a few additional properties for each context and the fields could change in future. In TMC Self-Managed with VCD's login flow, it requires "VCD org" and "VCD OIDC client ID" to be persisted in context, so that TMC Plugins can auto-refresh or re-trigger the token flow if needed when a TMC plugin command is called.

Example usage:

  • Add two new properties to context
ctx := &Context {
 Name: tanzu-ctx,
 AdditionalMetadata : map[string]interface{
  “token” : “test-token”
  “issuer” : “test-issuer”
 }
}
SetContext(ctx)  // ctx will  now have both token and issuer metadata

  • Update the existing additional metadata of a context
# To merge the additional metadata

ctx := GetContext()
ctx.AdditionalMetadata[“token”]=”updated-token”
SetContext(ctx)  // ctx will now have both issuer and token metadata


# To replace the additional metadata

ctx := GetContext()
ctx.AdditionalMetadata := map[string]interface{}{
 “token”=”only-token”,
}
SetContext(ctx) // Ctx will only have token metadata

# To delete the entire additional metadata

ctx := GetContext()
ctx.AdditionalMetadata := map[string]interface{}{}
SetContext(ctx) // Ctx will not have any additional metadata

Which issue(s) this PR fixes

Fixes #

Describe testing done for PR

Added unit tests and integrated tests

Release note

 Introduce new additionalMetadata field in Context

Additional information

Special notes for your reviewer

@mpanchajanya mpanchajanya force-pushed the context_api/additional_metadata branch from 28d5cf9 to ce90c7d Compare July 24, 2023 13:27
@mpanchajanya mpanchajanya self-assigned this Jul 24, 2023
@mpanchajanya mpanchajanya marked this pull request as ready for review July 24, 2023 14:59
@mpanchajanya mpanchajanya requested a review from a team as a code owner July 24, 2023 14:59
@mpanchajanya mpanchajanya force-pushed the context_api/additional_metadata branch from 91a209b to 858b04a Compare July 25, 2023 00:34
Copy link
Contributor

@anujc25 anujc25 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks

@mpanchajanya mpanchajanya merged commit 9248596 into vmware-tanzu:main Jul 25, 2023
4 checks passed
@marckhouzam marckhouzam added this to the v1.0.0 milestone Oct 20, 2023
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