carvel-dev / carvel-dev/ytt

Overlay'ed data values set to Starlark expressions are schema-type compatible

Open
#342 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.9k
Forks
167
PR merge metrics
No merged PRs in 30d

Description

**As a** Configuration Consumer
**I want** to overlay my Data Values with using an `@overlay/replace` function and have the result be schema type-checkable
**So that** such configuration documents can properly benefit from schema-enforced checks

## Context
As detailed in the comments, below, currently when an overlay includes an `@overlay/replace via=...` the result of that function is converted to its Go equivalent and not AST (i.e. composed of instances of `Node`).
Specifically:
- a Starlark List (i.e. `[]`) is converted to `[]interface{}`
- a Starlark Dictionary (i.e. `{}` is converted to an `orderedmap.Map`

Schema expects to check against a `ytt` AST and fails when type-checking against these values.

## Acceptance Criteria

### 🟢 Starlark expressions that conform to schema

**Given** A schema
```yaml
#! schema.yml
#@schema/match data_values=True
---
db_conn:
- hostname: ""
```
**And** a conforming data value that includes YAML inserted from a Starlark expression
```yaml
#! values.yml
#@data/values
---
#@overlay/replace via=lambda l,r: [{"hostname": "db.example.com"}]
db_conn:
```

**When** I run `ytt`
**Then** The result passes schema checks
```console
$ ytt -f schema.yml -f values.yml --enable-experiment-schema --data-values-inspect
db_conn:
- hostname: db.example.com
```

### 🔴 Starlark expressions that do _not_ conform to schema

**Given** A schema
```yaml
#! schema.yml
#@schema/match data_values=True
---
db_conn:
- hostname: ""
```
**And** a _non_-conforming data value that includes YAML inserted from a Starlark expression
```yaml
#! values.yml
#@data/values
---
#@overlay/replace via=lambda l,r: [{"hostname": 42}]
db_conn:
```

**When** I run `ytt`
**Then** The result fails schema checks
```console
$ ytt -f schema.yml -f values.yml --enable-experiment-schema --data-values-inspect
ytt: Error: Overlaying data values (in following order: values.yml):
values.yml:4 | db_conn:
|
| TYPE MISMATCH - the value of this item is not what schema expected:
| found: integer
| expected: string (by schema.yml:4)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.