Skip to content

Commit

Permalink
fix: remove trailing dashes for multidoc yaml (#1335)
Browse files Browse the repository at this point in the history
Fixes #1330 #1296

Signed-off-by: Tim Heurich <[email protected]>
  • Loading branch information
theurichde authored Oct 5, 2023
1 parent c38f2e8 commit 616f31b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 2 additions & 4 deletions pkg/kubeseal/kubeseal.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ func resourceOutput(out io.Writer, outputFormat string, codecs runtimeserializer
contentType = runtime.ContentTypeJSON
case "yaml":
contentType = runtime.ContentTypeYAML
fmt.Fprint(out, "---\n")
default:
return fmt.Errorf("unsupported output format: %s", outputFormat)
}
Expand All @@ -402,11 +403,8 @@ func resourceOutput(out io.Writer, outputFormat string, codecs runtimeserializer
}
_, _ = out.Write(buf)

switch contentType {
case runtime.ContentTypeJSON:
if contentType == runtime.ContentTypeJSON {
fmt.Fprint(out, "\n")
case runtime.ContentTypeYAML:
fmt.Fprint(out, "---\n")
}
return nil
}
Expand Down
14 changes: 12 additions & 2 deletions pkg/kubeseal/kubeseal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,25 @@ func TestSealWithMultiDocSecrets(t *testing.T) {
t.Fatalf("Error writing to buffer: %v", err)
}

t.Logf("input is: %s", inbuf.String())
t.Logf("input is:\n%s", inbuf.String())

outbuf := bytes.Buffer{}
if err := Seal(clientConfig, outputFormat, &inbuf, &outbuf, scheme.Codecs, key, ssv1alpha1.NamespaceWideScope, false, "", ""); err != nil {
t.Fatalf("seal() returned error: %v", err)
}

outBytes := outbuf.Bytes()
t.Logf("output is %s", outBytes)
t.Logf("output is:\n%s", outBytes)

if tc.asYaml {
if !strings.HasPrefix(string(outBytes), "---") {
t.Errorf("YAML output should start with ---")
}

if strings.HasSuffix(string(outBytes), "---\n") {
t.Errorf("YAML output should not end with ---")
}
}

decoder := yaml.NewYAMLOrJSONDecoder(bytes.NewReader(outBytes), 4096)
var gotSecrets []*ssv1alpha1.SealedSecret
Expand Down

0 comments on commit 616f31b

Please sign in to comment.