fix kyaml issue with multiline scalars

This commit is contained in:
Natasha Sarkar
2021-07-14 15:01:53 -07:00
parent b5091a566a
commit 477d8930e0
6 changed files with 36 additions and 21 deletions

View File

@@ -1699,8 +1699,8 @@ func yaml_emitter_write_single_quoted_scalar(emitter *yaml_emitter_t, value []by
if !put_break(emitter) { if !put_break(emitter) {
return false return false
} }
} i++
if !write_break(emitter, value, &i) { } else if !write_break(emitter, value, &i) {
return false return false
} }
//emitter.indention = true //emitter.indention = true

View File

@@ -2653,7 +2653,7 @@ func yaml_parser_scan_flow_scalar(parser *yaml_parser_t, token *yaml_token_t, si
// Do we need to fold line breaks? // Do we need to fold line breaks?
if len(leading_break) > 0 && leading_break[0] == '\n' { if len(leading_break) > 0 && leading_break[0] == '\n' {
if len(trailing_breaks) == 0 { if len(trailing_breaks) == 0 {
s = append(s, ' ') s = append(s, '\n')
} else { } else {
s = append(s, trailing_breaks...) s = append(s, trailing_breaks...)
} }

View File

@@ -51,8 +51,6 @@ items:
`, `,
}, },
// TODO: See issue #https://github.com/kubernetes-sigs/kustomize/issues/4066
// the line breaks in scalar values are lost.
{ {
name: "round_trip_with_multiline_scalar", name: "round_trip_with_multiline_scalar",
input: ` input: `
@@ -87,10 +85,14 @@ spec:
description: CanonicalService is the Schema for the canonicalservices API description: CanonicalService is the Schema for the canonicalservices API
properties: properties:
apiVersion: apiVersion:
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string type: string
kind: kind:
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string type: string
`, `,
}, },

View File

@@ -1,3 +1,6 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package yaml package yaml
import ( import (

View File

@@ -1,3 +1,6 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package yaml package yaml
import ( import (

View File

@@ -20,14 +20,16 @@ spec:
description: Workspace is the Schema for the workspaces API description: Workspace is the Schema for the workspaces API
properties: properties:
apiVersion: apiVersion:
description: 'APIVersion defines the versioned schema of this representation description: |-
APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string type: string
kind: kind:
description: 'Kind is a string value representing the REST resource this description: |-
Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string type: string
metadata: metadata:
type: object type: object
@@ -111,8 +113,9 @@ spec:
description: The key to select. description: The key to select.
type: string type: string
name: name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names description: |-
TODO: Add other useful fields. apiVersion, kind, uid?' Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string type: string
optional: optional:
description: Specify whether the ConfigMap or its key description: Specify whether the ConfigMap or its key
@@ -122,10 +125,11 @@ spec:
- key - key
type: object type: object
fieldRef: fieldRef:
description: 'Selects a field of the pod: supports metadata.name, description: |-
Selects a field of the pod: supports metadata.name,
metadata.namespace, metadata.labels, metadata.annotations, metadata.namespace, metadata.labels, metadata.annotations,
spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP,
status.podIPs.' status.podIPs.
properties: properties:
apiVersion: apiVersion:
description: Version of the schema the FieldPath is written description: Version of the schema the FieldPath is written
@@ -139,14 +143,16 @@ spec:
- fieldPath - fieldPath
type: object type: object
resourceFieldRef: resourceFieldRef:
description: 'Selects a resource of the container: only resources description: |-
Selects a resource of the container: only resources
limits and requests (limits.cpu, limits.memory, limits.ephemeral-storage, limits and requests (limits.cpu, limits.memory, limits.ephemeral-storage,
requests.cpu, requests.memory and requests.ephemeral-storage) requests.cpu, requests.memory and requests.ephemeral-storage)
are currently supported.' are currently supported.
properties: properties:
containerName: containerName:
description: 'Container name: required for volumes, optional description: |-
for env vars' Container name: required for volumes, optional
for env vars
type: string type: string
divisor: divisor:
anyOf: anyOf:
@@ -170,8 +176,9 @@ spec:
be a valid secret key. be a valid secret key.
type: string type: string
name: name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names description: |-
TODO: Add other useful fields. apiVersion, kind, uid?' Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string type: string
optional: optional:
description: Specify whether the Secret or its key must description: Specify whether the Secret or its key must