-
Notifications
You must be signed in to change notification settings - Fork 208
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
check for plugins file schema version and type #2532
check for plugins file schema version and type #2532
Conversation
62cd202
to
5ab29af
Compare
Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com>
5ab29af
to
40fb44e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is changing the file format used from what was just published in v1.0.5, we'll need to communicate that this is a breaking change and update the release notes on 1.0.5 to call out that it's a bad release effectively.
In addition to the usual announcements, since this is a breaking change (and a bad release), you should draft a blog post to go out at the same time as the new release that explains what went wrong, which version to use, and provides an explanation of the install multiple plugins feature. I recommend saying that's its a great way to quickly set up your Porter environment with your required plugins so that people get an idea of when you would use this feature. Probably don't mention the Porter Operator change that caused us to want this feature since it's not shipped yet, so let's focus on how people can use it right now.
if o.Version != "" { | ||
return fmt.Errorf("plugin version should not be specified when --file is provided") | ||
// version should not be set to anything other than the default value | ||
if o.Version != "" && o.Version != "latest" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When --version is empty, it defaults to latest so I'm not sure I get what this is checking for or guarding against? The error message just says that they can't specify --version at all so can't we just stick with the original check that version was specified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When no version is specified by users, the o.Version
is default to latest
. The original check would fail bc the o.Version
is not empty.
The check here is to guard that users didn't try to set a version value through the flag. o.Version
should not have value other than "latest" or empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I didn't realize that we were defaulting to "latest" so early, I'm assuming it's the flag default. Makes sense! 👍
} | ||
|
||
func (spec InstallPluginsSpec) Validate() error { | ||
if InstallPluginsSchemaVersion != schema.Version(spec.SchemaVersion) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just remembered that we are missing schemaType validation on our other resources. I had created a branch to fix that and then got pulled off onto other things and forgot to submit a PR.
Let's do a check here for the schemaType as well, so that if they enter in a value other than what's expected, we don't try to process the file further. For example, they accidentally pass a bundle or installation file to the -f parameter.
I'll submit my PR afterwards that adds the check to the other resources.
Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com>
pkg/schema/plugins.schema.json
Outdated
"plugins": { | ||
"description": "The definition of plugins to install", | ||
"type": "object", | ||
"default": "1.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This default shouldn't be defined here. I assume you meant to define it directly on schemaVersion?
pkg/schema/plugins.schema.json
Outdated
}, | ||
"feedURL": { | ||
"description": "The URL of an atom feed where the plugin can be downloaded.", | ||
"key": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is how the properties json schema field works for objects. Have you tested this against the json schema validator (https://www.jsonschemavalidator.net/) with both matching and incorrect schema to make sure it's correct?
Here is how I have defined an object with unknown keys in porter elsewhere (for custom action metadata):
pkg/schema/plugins.schema.json
Outdated
"type": "object", | ||
"properties": { | ||
"version": { | ||
"description": "The version for the plugin.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like to give the user hints that will show up in the hover text / documentation that will help them understand how to fill out the file better:
"description": "The version for the plugin.", | |
"description": "The version for the plugin. Defaults to latest when unspecified", |
pkg/schema/plugins.schema.json
Outdated
"type": "string" | ||
}, | ||
"feedURL": { | ||
"description": "The URL of an atom feed where the plugin can be downloaded.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"description": "The URL of an atom feed where the plugin can be downloaded.", | |
"description": "The URL of an atom feed where the plugin can be downloaded. Defaults to the official Porter plugin feed.", |
pkg/schema/plugins.schema.json
Outdated
"type": "string" | ||
}, | ||
"url": { | ||
"description": "The URL from where the plugin can be downloaded", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field is hard to guess, so I always like to include an example of how to download from github releases:
"description": "The URL from where the plugin can be downloaded", | |
"description": "The URL from where the plugin can be downloaded. For example, https://github.com/MChorfa/porter-helm3/releases/download", |
pkg/schema/plugins.schema.json
Outdated
"value": { | ||
}, | ||
"plugins": { | ||
"description": "The definition of plugins to install", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would help to give people a hint that the field names under plugins should be the name of the plugin
"description": "The definition of plugins to install", | |
"description": "A map of plugins to install, keyed by the plugin name", |
Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
This reminds me that we need to update the porter vs code extension to check for schemaType and apply the proper json schema to the current document, e.g. if the open document is for porter and has "schemaType: Plugins", then vs code should apply this plugins json schema so that the user gets autocomplete.
I'll create another issue to work out the details but wanted to let you know how this schema will be used elsewhere too. 👍
Here's the issue to track showing autocomplete using our other json schema documents: getporter/vscode-extension#47 |
Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com>
* Refactor PrintLintResults() to ensure lint warnings are printed. Signed-off-by: James Blair <mail@jamesblair.net> * Bump github.com/moby/buildkit from 0.11.0 to 0.11.1 (#2528) Bumps [github.com/moby/buildkit](https://github.com/moby/buildkit) from 0.11.0 to 0.11.1. Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * check for plugins file schema version and type (#2532) * check for plugins file schema version and type Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com> * Update contributors list. Signed-off-by: James Blair <mail@jamesblair.net> * Add unit tests for ensuring lint warnings are printed. Signed-off-by: James Blair <mail@jamesblair.net> --------- Signed-off-by: James Blair <mail@jamesblair.net> Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Yingrong Zhao <yingrong.zhao@gmail.com>
* check for plugins file schema version and type Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com>
* Refactor PrintLintResults() to ensure lint warnings are printed. Signed-off-by: James Blair <mail@jamesblair.net> * Bump github.com/moby/buildkit from 0.11.0 to 0.11.1 (getporter#2528) Bumps [github.com/moby/buildkit](https://github.com/moby/buildkit) from 0.11.0 to 0.11.1. Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * check for plugins file schema version and type (getporter#2532) * check for plugins file schema version and type Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com> * Update contributors list. Signed-off-by: James Blair <mail@jamesblair.net> * Add unit tests for ensuring lint warnings are printed. Signed-off-by: James Blair <mail@jamesblair.net> --------- Signed-off-by: James Blair <mail@jamesblair.net> Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Yingrong Zhao <yingrong.zhao@gmail.com>
What does this change
Previously, the
SchemaType
andSchemaVersion
are not parsed or validated. This PR adds the corresponding logic to properly process these fieldsWhat issue does it fix
Notes for the reviewer
Put any questions or notes for the reviewer here.
Checklist
Reviewer Checklist