Skip to content

Commit

Permalink
Add E2E for data-values-file reading a dir
Browse files Browse the repository at this point in the history
  • Loading branch information
jtigger committed May 23, 2022
1 parent dcb2ded commit ca1e4c8
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/data-values-directory/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
This example demonstrates how ytt handles specifying a directory for Data Values
inputs. (originally https://kubernetes.slack.com/archives/CH8KCCKA5/p1651167583289939)

With this:
```
├── config
│ ├── config.yml
│ └── values-schema.yml
└── values <-- any YAML under here is assumed to be plain Data Values
├── appdev-overrides <-- sorted by full pathname, alphabetically
│ └── values.yaml
└── operator-overrides
├── 50-operations-overrides.yml
├── 99-opssec-overrides.yml
└── approvals.toml <-- non YAML files are ignored.
```

Executing this:

```console
$ ytt -f examples/data-values-directory/config.yml \
--data-values-file examples/data-values-directory/values/
```
8 changes: 8 additions & 0 deletions examples/data-values-directory/config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! In the real-world, this configuration would be the manifests that describe
#! this application's deployment. For this example, we simply render the
#! net values; this is the point of this example.

#@ load("@ytt:data", "data")

---
values: #@ data.values
10 changes: 10 additions & 0 deletions examples/data-values-directory/config/values-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#@data/values-schema
---
name: suggestion-service
instances: 0
accept_insecure_conns: true
#@schema/nullable
cache:
driver: ""
#@schema/type any=True
config: {}
6 changes: 6 additions & 0 deletions examples/data-values-directory/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -e

./ytt -f examples/data-values-directory/config/ \
--data-values-file examples/data-values-directory/values/
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
instances: 1
accept_insecure_conns: true
cache:
driver: in-memory
config:
maxEntries: 1024
strategy: MRU
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# 2022-05-13: avg + rms over last 3 months
instances: 4

cache:
driver: redis
config:
host: localhost:6379
tls-client-cert-file: client.crt
tls-client-key-file: client.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# Policy 1.31a: all north-south connections must be encrypted.
accept_insecure_conns: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[[approvals]]
dept = "operations"
user = "[email protected]"

[[approvals]]
dept = "Operations Security"
user = "[email protected]"
12 changes: 12 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ float: 123.123

require.Equal(t, expectedOutput, actualOutput)
})
t.Run("--data-values-file enumerates YAML files from given directory", func(t *testing.T) {
testDir := "../../examples/data-values-directory"
flags := yttFlags{
{"--data-values-file": testDir + "/values"},
}
actualOutput := runYtt(t, testInputFiles{testDir + "/config"}, "", flags, nil)

expectedOutput, err := ioutil.ReadFile(filepath.Join(testDir, "expected.txt"))
require.NoError(t, err)

require.Equal(t, string(expectedOutput), actualOutput)
})
})
t.Run("can be 'required'", func(t *testing.T) {
expectedFileOutput, err := ioutil.ReadFile("../../examples/data-values-required/expected.txt")
Expand Down

0 comments on commit ca1e4c8

Please sign in to comment.