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

refactor plugin interface to take PluginRequest rather than obj and args #76

Merged
merged 1 commit into from
Nov 1, 2021

Conversation

sseago
Copy link
Contributor

@sseago sseago commented Sep 23, 2021

Refactor plugin interface to take PluginRequest rather than separate obj and args.
This allows for sending raw object json to a binary plugin for testing without
an expected separate line of entry for optional args.

@sseago sseago changed the title refactor plugin interface to take PluginRequest rather than separate … refactor plugin interface to take PluginRequest rather than obj and args Sep 23, 2021
@cooktheryan
Copy link

Going to follow this as I may need to make changes based on this

@sseago
Copy link
Contributor Author

sseago commented Sep 23, 2021

@cooktheryan This is to deal with the issue around needing to explicitly send ctrl-D when invoking a plugin without args. This PR replaces the expectation of two separate stdin transmissions of an unstructured obj and (optionally) an extras map with a single PluginRequest, which is a struct with an (anonymous/inline) unstructured obj and an extras map. In the "no extras provided" case, this restores the original behavior where piping a single kubernetes resource object json to the plugin will execute without needing ctrl-D, but when you do need args, the "extras" field is added as another top level entry to the unstructured map.

@sseago
Copy link
Contributor Author

sseago commented Sep 24, 2021

@cooktheryan Once this merges, the changes you'll need to make will be minimal. The Run func will take a struct containing the unstructured obj and extras map rather than two different args. See transform/binary-plugin/examples/route/route.go for an example of a plugin that needs the unstructured obj from the new method arg and transform/binary-plugin/examples/test/annotation/annotation.go for an example of a plugin that uses the extras field.

@sseago
Copy link
Contributor Author

sseago commented Sep 24, 2021

Return value of Run is unchanged.

@shawn-hurley
Copy link
Contributor

Do we need to consider making a release before we do this for gi tops primer to pin to?

@jmontleon as you are helping get that settled do you have thoughts?

@sseago
Copy link
Contributor Author

sseago commented Sep 24, 2021

@shawn-hurley A release might make sense since we're changing APIs here. If anyone is using main builds, then having a tag before this is merged could be helpful.

@sseago
Copy link
Contributor Author

sseago commented Sep 24, 2021

as @alaypatel07 pointed out, this PR needs to update the plugin README as well.

@shawn-hurley
Copy link
Contributor

fixes #49

@sseago
Copy link
Contributor Author

sseago commented Oct 1, 2021

Updated binary-plugin/README.md and rebased to pull in recent main commits.

Refactor plugin interface to take PluginRequest rather than separate obj and args.
This allows for sending raw object json to a binary plugin for testing without
an expected separate line of entry for optional args.
Copy link
Contributor

@shawn-hurley shawn-hurley left a comment

Choose a reason for hiding this comment

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

VISACK
/lgtm

@@ -73,16 +73,16 @@ func Run(u *unstructured.Unstructured, extras map[string]string) (transform.Plug
whiteOut = true
case "BuildConfig":
logger.Info("found build config, processing")
patch, err = UpdateBuildConfig(*u, inputFields)
patch, err = UpdateBuildConfig(u, inputFields)
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on removal of sending patches

@sseago sseago merged commit 72b0752 into migtools:main Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants