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

Set the ValuesSchema and DefaultValues in Carvel pkgs #4023

Merged
merged 3 commits into from
Jan 6, 2022

Conversation

antgamdia
Copy link
Contributor

@antgamdia antgamdia commented Jan 4, 2022

Description of the change

This PR is aimed at providing a set of initial values for users when installing/upgrading a Carvel package. Particularly, in this PR:

  • The raw schema is passed through the wire (for the custom form, if ever implemented - see Provide initial values when installing a Carvel package #3853 (comment))
  • The default values are calculated as follows: if a .Default property exists, use it; otherwise, fall back to each data type default value (eg., "" or 0)
  • Several tests have been written since I noticed the server_utils_test wasn't being tested.

Benefits

Users will get more information about the values that a package requires, being a similar UX as in other pkg formats (Helm).

Possible drawbacks

Some problems arise:

Applicable issues

Additional information

IRL example:
image

Signed-off-by: Antonio Gamez Diaz <agamez@vmware.com>
Copy link
Contributor

@absoludity absoludity left a comment

Choose a reason for hiding this comment

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

LGTM, though is it not possible for the rendered default values to be commented out as we'd discussed before the break? The Carvel team was pretty keen to be able to differentiate between values that are explicitly set by the user and default values, whereas generating them like this removes that distinction. I guess there are issues with rendering the default values commented out so the user can just uncomment any parts they want to set?

(I realise this would be different to helm, where we include the provided values, but it is a different situation - Carvel doesn't provide values.yaml, and the carvel team seem pretty particular about this, so might be worth investigating).

// In short, it differs from upstream in that:
// -- 1. Prevent deep copy of int as it panics
// -- 2. For type object scan the first level properties for any defaults to create an empty map to populate
// -- 3. If the property does not have a default, add one based on the type ("", false,)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the details there.

missingDefaultObject: {}
missingDefaultString: ""
valueWithDefault: 80
`},
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this should be 7 test cases (you've even added the infra for iterating the test cases) that you've put in one test-case? (ie. it will fail if any of the parts fail). Not a big deal and fine as is, just unexpected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha, you're right; I started writing the different cases at the same time, but I forgot to split them apart. Done (+ few additional test cases more)

}

defaultValues(in, tt.schema)
if !reflect.DeepEqual(in, expected) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing there's a reason that the upstream change doesn't use cmp.Equal instead of reflect.DeepEqual? Either way we probably want to keep the code as similar as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same... I don't know, but I tried to keep it as aligned as possible to the upstream version :S

@antgamdia
Copy link
Contributor Author

LGTM, though is it not possible for the rendered default values to be commented out as we'd discussed before the break?

I did try to comment them out and even add some comments with the .description or even .examples, however, I wasn't able to add them in in the yaml. Comments and yaml has always been a pain, but there are some implementations supporting them (using Nodes in go-yaml v3) but I don't see any quick way to access every node to add the comments there.

An alternative would be re-implementing the default function to directly write the yaml nodes instead of relying on an ulterior marshaling process. However, it seemed non-trivial and given that we may want to add the "advanced form tab", it wouldn't be that useful then.

What I have done, instead, is to comment out the whole generated string afterward (appending the # direcly). Note that our ACE text editor has the ctrl + /` keybind enabled, so we can uncomment in block easily.

image.
See what you think.

Signed-off-by: Antonio Gamez Diaz <agamez@vmware.com>
@absoludity
Copy link
Contributor

Looks awesome. +1 from me for providing them commented out.

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.

Provide initial values when installing a Carvel package
2 participants