From dc4ecbe5f21d247314de6bf681cb4f5857dd8493 Mon Sep 17 00:00:00 2001 From: Adithya Kolla <71282729+KollaAdithya@users.noreply.github.com> Date: Tue, 8 Aug 2023 10:06:57 -0700 Subject: [PATCH] fix: skip interpolation of array of strings if the style of node is literal (#5157) Resolves #5155 Literal style helps to break a string into new lines. In Copilot version v1.29 we supported interpolation of sequence of strings. There is caveat here If the manifest has `Literal Style`(Blocked Scalar) node i.e for example if the manifest contains ```yaml labels: "test": | ["label1","label2"] ``` This will lead to unmarshal errors. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License. --- internal/pkg/manifest/interpolate.go | 2 +- internal/pkg/manifest/interpolate_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/internal/pkg/manifest/interpolate.go b/internal/pkg/manifest/interpolate.go index 4f8346d5157..f65ffa51f7c 100644 --- a/internal/pkg/manifest/interpolate.go +++ b/internal/pkg/manifest/interpolate.go @@ -74,7 +74,7 @@ func (i *Interpolator) applyInterpolation(node *yaml.Node) error { return err } var s []string - if err = json.Unmarshal([]byte(interpolated), &s); err == nil && len(s) != 0 { + if err = json.Unmarshal([]byte(interpolated), &s); err == nil && len(s) != 0 && node.Style != yaml.LiteralStyle { seqNode := &yaml.Node{ Kind: yaml.SequenceNode, } diff --git a/internal/pkg/manifest/interpolate_test.go b/internal/pkg/manifest/interpolate_test.go index 44e734b12be..283a65f1914 100644 --- a/internal/pkg/manifest/interpolate_test.go +++ b/internal/pkg/manifest/interpolate_test.go @@ -54,6 +54,14 @@ image: # Docker build arguments. For additional overrides: https://aws.github.io/copilot-cli/docs/manifest/backend-service/#image-build location: ${0accountID}.dkr.${repo-provider}.${region}.amazonaws.com/vault/${COPILOT_ENVIRONMENT_NAME}:${tag} port: 80 + labels: | + ["label1","label2"] + "com.datadoghq.ad.instances": | + [ + { + "prometheus_url": "http://metrics", + } + ] cpu: 256#${CPU} memory: 512 # ${Memory} @@ -89,6 +97,14 @@ image: # Docker build arguments. For additional overrides: https://aws.github.io/copilot-cli/docs/manifest/backend-service/#image-build location: ${0accountID}.dkr.${repo-provider}..amazonaws.com/vault/test:latest port: 80 + labels: | + ["label1","label2"] + "com.datadoghq.ad.instances": | + [ + { + "prometheus_url": "http://metrics", + } + ] cpu: 256#512 memory: 512 # ${Memory} variables: