src: direct serialization of Function metadata as func.yaml#641
src: direct serialization of Function metadata as func.yaml#641knative-prow-robot merged 2 commits intoknative:mainfrom
Conversation
|
@lkingland: The label(s) DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: lkingland The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
cd1920e to
f0fd92c
Compare
Codecov Report
@@ Coverage Diff @@
## main #641 +/- ##
==========================================
- Coverage 37.45% 37.31% -0.15%
==========================================
Files 38 41 +3
Lines 3887 3859 -28
==========================================
- Hits 1456 1440 -16
+ Misses 2243 2229 -14
- Partials 188 190 +2
Continue to review full report at Codecov.
|
7b5ebd8 to
501714f
Compare
a200779 to
b35e22a
Compare
b35e22a to
f207248
Compare
Functions now save directly to func.yaml using .Write(). Fixes a serialization error where defaults were not respected on load. Moves runtime and template defaults into function constructor. Extracts Function validation (was config validation) into separate functions. Extracts associated test files (validation) into separate unit test files. Updates schema generator to use Function
f207248 to
4123166
Compare
Thanks for the lgtm @zroubalik . I made a few changes since then, and would greatly appreciate a quick re-review if you have time, |
lance
left a comment
There was a problem hiding this comment.
This is a big PR! I do very much like the fact that we no longer have both Config and Function. This is much cleaner.
I have to admit, I did not completely validate all of the copy/paste that went into some of the refactoring. I do like what you have done with, for example, the function environment variable handling now being in its own file. As long as all of the existing tests pass, I'll assume that all is good in that regard. There is only one place where it seems like a test has been commented out which has me wondering.
/lgtm
/hold to follow up on commented test and a few very very minor nits that don't really need to be held for but since we're holding anyway, I mentioned them
|
/unhold |
Changes
🧹 direct serialization of Function metadata as func.yaml
This PR recognizes the logical equivalence of the Function and Config objects, merging the two and in so doing reduces some complexity, and frees up the concept of config for use by non-source-controlled function-local/user-local settings and transient state.
/kind cleanup
Details
The Config object was created after the initial Function draft. Its purpose was to enable manipulation of metadata about a Function. This separation between the Function and Config objects was partly to help keep the update minimally invasive, and possibly to draw a distinction between lifecycle functions such as "build" and "deploy" from metadata accessors such as "envs" and "labels". The Config object and its accessors have proved to be stable, well developed and useful. The distinction now needs to be removed.
The impetus for making this change now is that forthcoming features require the more idiomatic usage of the term "config". To summarize, "config" denotes aspects of the system which are configurable, but are not part of the Function itself. This includes things like installed repositories, user settings (preferred language/repository), build stamps/hashes, running function PIDs, etc. Taking the venerable
gitas an example: upon checking out a repository, the items configurable via theconfigsubcommand are not included, but are rather populated based off local global presets or user-initiated action. They are either repo-local or user-local. They are not actually part of the repository insofar as being source controlled themselves. This is the purpose of "dotfiles". In the very-similar case of Functions, this currently includes Repositories, but is soon to be expanded to include metadata about settings such as preferred Function language, and state to enablefunc invoke, etc.Looking from the top down, we can understand the necessity of this change by realizing that func.yaml is the serialized form of Function metadata, meaning that (when combined with source code), it is the Function itself. Support for this position is made clear by the existence of the following mapping:
As can be seen above, since almost every field of a "Config" is mapped directly to a "Function" instance, it is a strong indication they are actually the same concept.
It is worth discussing a potential point in opposition to this change: it impies the need to flatten our command structure. Previously, at the root level were only lifecycle commands such as
buildanddeploy. Let's call these "Verbs". Metadata-manipulation subcommands were held beneathconfigsuch asenvsandlabels. Let's call these "Nouns".At first blush it may seem wrong or confusing to commingle these as root subcommands. The problem here, however, is not that this is linguistically incorrect, but rather that our chosen CLI library does not to my knowledge support grouping in the help text. Again taking 'git' as our example: at the root are both verbs such as
git cloneandgit init, as well as nouns such asgit branchandgit tag. The distinction comes in the form of properly formatted help text, which groups these subcommands under appropriate headings (this can be seen by running the commandgitwith no further arguments).If the team agrees, we could emulate this user experience by providing a somewhat customized help text which groups our commands under appropriate headings as well. It will require a bit of customization, however, as it does not appear that the Cobra CLI library supports this directly. This change should also move the
repositoriessubcommand in the opposite direction: from the root to be a subcommand ofconfig, because these settings fit the description of being non-source-controled, local system configuration.To enumerate the set of challenges which necessitate this change now:
repositoriesmanagement subcommand is not modifying the Function metadata, nor are its changes source controlled, and therefore should befunc config repos .... However this is not currently possible while theconfigsubcommand represents the Function's actual metadata.func invokesubcommand. This state is part of config, but not part of the function's serialized state, so it is dependent on this PRs change as well.--globaloption, keeping the (again, local-only non-source-controlled configuration) in either./.func/config.yamlor~/.config/func/config.yaml.func config build ...) which are local-only, and not part of the source-controlled Function metadata. This is another example of a setting that should go in a config file, but not in func.yaml.