Fix api tests that accomodated bad label and anno quoting.

This commit is contained in:
monopole
2021-01-15 17:36:39 -08:00
parent cb59e0ef5f
commit cb42142161
4 changed files with 30 additions and 40 deletions

View File

@@ -28,7 +28,9 @@ metadata:
`)}}, `)}},
Filters: []kio.Filter{Filter{ Filters: []kio.Filter{Filter{
Annotations: map[string]string{ Annotations: map[string]string{
"foo": "bar", "foo": "bar",
"booleanValue": "true",
"numberValue": "42",
}, },
FsSlice: fss, FsSlice: fss,
}}, }},
@@ -44,12 +46,16 @@ metadata:
// metadata: // metadata:
// name: instance // name: instance
// annotations: // annotations:
// booleanValue: "true"
// foo: bar // foo: bar
// numberValue: "42"
// --- // ---
// apiVersion: example.com/v1 // apiVersion: example.com/v1
// kind: Bar // kind: Bar
// metadata: // metadata:
// name: instance // name: instance
// annotations: // annotations:
// booleanValue: "true"
// foo: bar // foo: bar
// numberValue: "42"
} }

View File

@@ -4,7 +4,6 @@
package krusty_test package krusty_test
import ( import (
"fmt"
"testing" "testing"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
@@ -28,7 +27,8 @@ func TestBasicIO_1(t *testing.T) {
// return an error (that is then ignored by GetAnnotations) // return an error (that is then ignored by GetAnnotations)
// } // }
// The error happens when any annotation value can be interpreted as // The error happens when any annotation value can be interpreted as
// a boolean or number. // a boolean or number. Such annotations cannot be successfully applied
// to an object in a cluster unless they are quoted.
t.SkipNow() t.SkipNow()
} }
th.WriteK(".", ` th.WriteK(".", `
@@ -49,6 +49,7 @@ spec:
`) `)
m := th.Run(".", opts) m := th.Run(".", opts)
// The annotations are sorted by key, hence the order change. // The annotations are sorted by key, hence the order change.
// Quotes are added intentionally.
th.AssertActualEqualsExpected( th.AssertActualEqualsExpected(
m, ` m, `
apiVersion: v1 apiVersion: v1
@@ -56,8 +57,8 @@ kind: Service
metadata: metadata:
annotations: annotations:
color: green color: green
happy: true happy: "true"
port: 8080 port: "8080"
name: demo name: demo
spec: spec:
clusterIP: None clusterIP: None
@@ -71,9 +72,7 @@ func TestBasicIO_2(t *testing.T) {
resources: resources:
- service.yaml - service.yaml
`) `)
// All the annotation values are quoted. // All the annotation values are quoted in the input.
// The apimachinery code path retains the quotes, the kyaml
// path drops them at the moment.
th.WriteF("service.yaml", ` th.WriteF("service.yaml", `
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
@@ -88,20 +87,16 @@ spec:
`) `)
m := th.Run(".", opts) m := th.Run(".", opts)
// The annotations are sorted by key, hence the order change. // The annotations are sorted by key, hence the order change.
expFmt := ` th.AssertActualEqualsExpected(m, `
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
annotations: annotations:
color: green color: green
happy: %s happy: "true"
port: %s port: "8080"
name: demo name: demo
spec: spec:
clusterIP: None clusterIP: None
` `)
th.AssertActualEqualsExpected(
m, opts.IfApiMachineryElseKyaml(
fmt.Sprintf(expFmt, `"true"`, `"8080"`),
fmt.Sprintf(expFmt, `true`, `8080`)))
} }

View File

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

View File

@@ -757,9 +757,9 @@ kind: Service
metadata: metadata:
annotations: annotations:
prometheus.io/path: _status/vars prometheus.io/path: _status/vars
prometheus.io/port: %s prometheus.io/port: "8080"
prometheus.io/scrape: %s prometheus.io/scrape: "true"
service.alpha.kubernetes.io/tolerate-unready-endpoints: %s service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
labels: labels:
app: cockroachdb app: cockroachdb
name: dev-base-cockroachdb name: dev-base-cockroachdb
@@ -929,12 +929,8 @@ metadata:
` `
th.AssertActualEqualsExpected(m, th.AssertActualEqualsExpected(m,
opts.IfApiMachineryElseKyaml( opts.IfApiMachineryElseKyaml(
fmt.Sprintf( fmt.Sprintf(expFmt, `8080`, `8080`, `8080`, `8080`),
expFmt, fmt.Sprintf(expFmt, `"8080"`, `"8080"`, `"8080"`, `"8080"`),
`"8080"`, `"true"`, `"true"`, `8080`, `8080`, `8080`, `8080`),
fmt.Sprintf(
expFmt,
`8080`, `true`, `true`, `"8080"`, `"8080"`, `"8080"`, `"8080"`),
)) ))
} }