-
Notifications
You must be signed in to change notification settings - Fork 137
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
Private lib schema #319
Private lib schema #319
Conversation
02d2f76
to
e86994c
Compare
I really like this choice. It gives the author the ability to support both modes. Include both a |
5b9eb3a
to
2e038a0
Compare
2e038a0
to
3223f2f
Compare
pkg/yttlibrary/overlay/array.go
Outdated
@@ -43,6 +43,8 @@ func (o Op) mergeArrayItem( | |||
} | |||
if replace { | |||
leftArray.Items[leftIdx].Value = newItem.Value | |||
//todo: should we be setting the position elsewhere? | |||
leftArray.Items[leftIdx].Position = newItem.Position |
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.
can we keep position related improvements separate from this PR. it's a bit hard to tell if these are the only places where we need to change this -- would love to see holistic evaluation within overlay module.
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.
... yup and that PR would precede this one — this fix addresses an actual bug: the wrong file is attributed a value.
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.
These position changes are now necessary to report the position of the overlay in the schema error message, if it's acceptable, we want to keep the change made to the position of arrays and maps here in this PR, and then address this more comprehensively in the Overlay Positions PR.
pkg/cmd/template/cmd.go
Outdated
}) | ||
|
||
libraryCtx := workspace.LibraryExecutionContext{Current: rootLibrary, Root: rootLibrary} | ||
libraryLoader := libraryExecutionFactory.New(libraryCtx) | ||
|
||
schemaDocs, err := libraryLoader.Schemas() | ||
currSchema, err := libraryLoader.Schemas() |
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.
is it worth renaming libraryLoader -> rootLibraryLoader
@@ -73,10 +73,6 @@ func NewMapType(m *yamlmeta.Map) (*MapType, error) { | |||
} | |||
mapType.Items = append(mapType.Items, mapItemType) | |||
} | |||
annotations := template.NewAnnotations(m) |
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.
note for self: removed because it's dead code.
if err != nil { | ||
return nil, nil, fmt.Errorf("Templating file '%s': %s", fileInLib.File.RelativePath(), err) | ||
} | ||
_, checkSchema := o.loader.schema.(*schema.DocumentSchema) |
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.
something to think about... why do we need a boolean here? why cant we just tell schema to type check against itself. all schemas should be able to do it succesfully.
|
||
for _, valuesDoc := range valuesDocs { | ||
dv, err := NewDataValues(valuesDoc) | ||
allDvs, err := o.collectDataValuesDocs(files) |
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.
nice little refactor!
return nil, fmt.Errorf("Overlaying additional data values on top of "+ | ||
"data values from files (marked as @data/values): %s", err) | ||
} | ||
func (o DataValuesPreProcessing) NewEmptyDataValuesDocument() *yamlmeta.Document { |
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.
seems like this method could be inlined where it's used, or at least made private.
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.
... in part because there's no need for any code outside this module to generate an empty Data Values.
pkg/workspace/library_loader.go
Outdated
@@ -46,30 +46,36 @@ func NewLibraryLoader(libraryCtx LibraryExecutionContext, | |||
} | |||
} | |||
|
|||
func (ll *LibraryLoader) Schemas() ([]*yamlmeta.Document, error) { | |||
func (ll *LibraryLoader) Schemas() (Schema, error) { |
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.
if we are returning a single schema should this method be named Schema() as well?
docs, _, err := DocExtractor{resultDocSet}.Extract(AnnotationSchemaMatch) | ||
if err != nil { | ||
return nil, err | ||
docs, _, err := DocExtractor{resultDocSet}.Extract(AnnotationSchemaMatch) |
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.
if we get multiple schema docs i would expect that we would blow up for now since we do not allow merging schemas.
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.
Correct, we have a story coming up to allow multiple schema docs #294. Prior to this story we would also blow up if we get multiple docs, so we haven't added guards for that case.
pkg/workspace/library_module.go
Outdated
@@ -318,7 +317,8 @@ func (l *libraryValue) libraryValues(ll *LibraryLoader) (*DataValues, []*DataVal | |||
} | |||
} | |||
|
|||
dvs, foundChildDVss, err := ll.Values(append(dvss, afterLibModDVss...), &schema.AnySchema{}) | |||
schema, err := ll.Schemas() |
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.
missing err check.
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.
😨
pkg/workspace/library_module.go
Outdated
@@ -318,7 +317,8 @@ func (l *libraryValue) libraryValues(ll *LibraryLoader) (*DataValues, []*DataVal | |||
} | |||
} | |||
|
|||
dvs, foundChildDVss, err := ll.Values(append(dvss, afterLibModDVss...), &schema.AnySchema{}) | |||
schema, err := ll.Schemas() | |||
dvs, foundChildDVss, err := ll.Values(append(dvss, afterLibModDVss...), schema) |
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 seems that we are using ll.Schemas() and then passing it to ll.Values(). i would argue Values() shouldnt require schema as input and should just use ll.Schemas() internally.
3223f2f
to
58b1ec2
Compare
8d599c5
to
a548806
Compare
9059336
to
88b3db5
Compare
Signed-off-by: John Ryan <[email protected]># Please enter the commit message for your changes. Lines starting
- ensure that every overlay of data values (regardless of source) is checked against schema (if enabled). - inline ApplyWithDefaults() - Provide direct error messages by reporting schema errors instead of overlay errors when possible Co-authored-by: Garrett Cheadle <[email protected]>
- Does not yet type check schema - Does not respect `--schema-enabled` flag Co-authored-by: Garrett Cheadle <[email protected]>
Signed-off-by: Garrett Cheadle <[email protected]>
* ytt does not place annotations on maps Signed-off-by: Steven Locke <[email protected]>
- DataValues.HasLib() => DataValues.HasLibRef() (without interpretion, conveys that data values has a reference to a library) - Schema.AsDataValues() => Schema.DefaultDataValues() (slightly more revealing of intented use) - in data_values_pre_processing.go, sorted some function definitions in order of usage. (eases reading when order of usage matches order of definition)
Renaming: - use snake_case for test names to significantly improve readability. (such methods are *never* invoked) - use [slightly] more verbose sentence structure to expose relevant details, in a fluid expression, remaining frugal with words. - reword sub-test names to be phrases extending the containing test name as a sentence. Also: - delete two (2) redundant test cases - reorder tests and sub-tests like an outline of a feature spec.
Signed-off-by: John Ryan <[email protected]>
- Test that when schema is disabled, schema is not used Signed-off-by: John Ryan <[email protected]>
Co-authored-by: Garrett Cheadle <[email protected]>
- Rename Schemas() to Schema() - Rename variables to use qualifier - noun naming scheme
- dvpp has Schema instead of templateLoader
- move logic for schema assinging type and dvs checking themselves into typeAndCheck() - change swtich statement in dvpp to if statements - make newEmptyDataValuesDocument() private Signed-off-by: Cari Dean <[email protected]>
- In favor of a more complete solution, we are removing this typecheck to be addressed in a later issue. - Skipping tests where the overlay fails, but we want a schema error. Signed-off-by: Garrett Cheadle <[email protected]>
14b98a8
to
5a79068
Compare
As part of this PR we decided on some UX decisions described below:
--enable-experiement-schema
flag is not present, and a schema file is provided, a warning is shown. New in this PR the relative path to the file is also shown. (Consider the case where root library has a schema, and a private library has a schema, there will be two warning messages now).--enable-experiement-schema
behaves:When the
--enable-experiement-schema
flag is present, and a schema file is given in the root or in a private library, it is used as the base data values and type checked.When
--enable-experiement-schema
flag is not enabled, then if a schema file appears anywhere, the schema is IGNORED and a warning is given. This is because the schema flag is protecting the user against non-GA code.We decided to split this original PR into three separate ones.