Isolate scalar quoting oddities to one test set.

The apimachinery code path, in its final marshalling
for output, calls Marshall

  https://github.com/go-yaml/yaml/blob/v2/yaml.go#L199

This code path (via apimachinery Unstructured types)
has no JSON schema tags

  https://yaml.org/spec/1.2/spec.html#id2803311

so it adds quotes to values that smell like
booleans and ints (e.g. `false` becomes `"false"`).

The kyaml code path, OTOH, uses such tags,
so generally does not quote ints and booleans.

This PR isolates this difference in behavior to
one set of tests (using data fields in configmaps
in api/krusty/configmaps_test.go) so that
they don't confuse other tests that cover
completely different behaviors.
This commit is contained in:
jregan
2020-12-23 16:23:45 -08:00
parent 1ffd790cfb
commit 1426137883
8 changed files with 172 additions and 76 deletions

View File

@@ -1,6 +1,7 @@
package krusty_test
import (
"fmt"
"os/exec"
"testing"
@@ -128,8 +129,9 @@ stringData:
bootcmd:
- mkdir /mnt/vda
`)
m := th.Run("/app", th.MakeOptionsPluginsEnabled())
th.AssertActualEqualsExpected(m, `
opts := th.MakeOptionsPluginsEnabled()
m := th.Run("/app", opts)
expFmt := `
apiVersion: v1
kind: Secret
metadata:
@@ -152,7 +154,7 @@ metadata:
name: demo
name: demo-budget
spec:
minAvailable: 67%
minAvailable: 67%%
selector:
matchLabels:
app: cockroachdb
@@ -185,9 +187,7 @@ metadata:
annotations:
config.kubernetes.io/path: config/demo_service.yaml
prometheus.io/path: _status/vars
prometheus.io/port: "8080"
prometheus.io/scrape: "true"
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
%s
labels:
app: cockroachdb
name: demo
@@ -244,7 +244,7 @@ spec:
- /bin/bash
- -ecx
- |
# The use of qualified `+"`hostname -f`"+` is crucial:
# The use of qualified ` + "`hostname -f`" + ` is crucial:
# Other nodes aren't able to look up the unqualified hostname.
CRARGS=("start" "--logtostderr" "--insecure" "--host" "$(hostname -f)" "--http-host" "0.0.0.0")
# We only want to initialize a new cluster (by omitting the join flag)
@@ -302,7 +302,14 @@ spec:
resources:
requests:
storage: 1Gi
`)
`
th.AssertActualEqualsExpected(m, opts.IfApiMachineryElseKyaml(
fmt.Sprintf(expFmt, ` prometheus.io/port: "8080"
prometheus.io/scrape: "true"
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"`),
fmt.Sprintf(expFmt, ` prometheus.io/port: 8080
prometheus.io/scrape: true
service.alpha.kubernetes.io/tolerate-unready-endpoints: true`)))
}
func TestFnContainerTransformer(t *testing.T) {