From b6add0c2d9779b77dd1cfe68a634b05d11304f56 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 24 Jan 2019 14:46:30 -0800 Subject: [PATCH] fix empty_dir formatting --- yaml/pretty/pipeline.go | 20 +++++++++++++++---- yaml/pretty/testdata/pipeline_volumes.yml | 2 ++ .../testdata/pipeline_volumes.yml.golden | 2 ++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/yaml/pretty/pipeline.go b/yaml/pretty/pipeline.go index a982c1d..874ba6b 100644 --- a/yaml/pretty/pipeline.go +++ b/yaml/pretty/pipeline.go @@ -189,10 +189,16 @@ func printVolumes(w writer, v []*yaml.Volume) { s.WriteTagValue("name", v.Name) if v := v.EmptyDir; v != nil { s.WriteTag("temp") - s.IndentIncrease() - s.WriteTagValue("medium", v.Medium) - s.WriteTagValue("size_limit", v.SizeLimit) - s.IndentDecrease() + if isEmptyDirEmpty(v) { + w.WriteByte(' ') + w.WriteByte('{') + w.WriteByte('}') + } else { + s.IndentIncrease() + s.WriteTagValue("medium", v.Medium) + s.WriteTagValue("size_limit", v.SizeLimit) + s.IndentDecrease() + } } if v := v.HostPath; v != nil { @@ -263,3 +269,9 @@ func isConditionsEmpty(v yaml.Conditions) bool { func isConditionEmpty(v yaml.Condition) bool { return len(v.Exclude) == 0 && len(v.Include) == 0 } + +// helper function returns true if the emptydir +// object is empty. +func isEmptyDirEmpty(v *yaml.VolumeEmptyDir) bool { + return v.SizeLimit == 0 && len(v.Medium) == 0 +} diff --git a/yaml/pretty/testdata/pipeline_volumes.yml b/yaml/pretty/testdata/pipeline_volumes.yml index ec7eaeb..40a295c 100644 --- a/yaml/pretty/testdata/pipeline_volumes.yml +++ b/yaml/pretty/testdata/pipeline_volumes.yml @@ -21,6 +21,8 @@ volumes: - name: temp temp: medium: memory +- name: empty + temp: {} - name: sock host: path: /var/run/docker.sock diff --git a/yaml/pretty/testdata/pipeline_volumes.yml.golden b/yaml/pretty/testdata/pipeline_volumes.yml.golden index 6039de8..e9f38b2 100644 --- a/yaml/pretty/testdata/pipeline_volumes.yml.golden +++ b/yaml/pretty/testdata/pipeline_volumes.yml.golden @@ -25,6 +25,8 @@ volumes: - name: temp temp: medium: memory +- name: empty + temp: {} - name: sock host: path: /var/run/docker.sock