Skip to content

Commit

Permalink
fix(kumactl): in apply support empty docs (#10951)
Browse files Browse the repository at this point in the history
When a document had just 1 comment this would cause problems
when doing `kumactl apply -f`.
We now strip comments before doing anything which would ignore this doc

Signed-off-by: Charly Molter <[email protected]>
  • Loading branch information
lahabana authored Jul 23, 2024
1 parent e0201f8 commit 7075f0e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Just a starting comment
---
name: sample1
# --- Checking a random separation doesn't break everything
Expand Down
6 changes: 5 additions & 1 deletion pkg/util/yaml/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import (
"strings"
)

var sep = regexp.MustCompile("(?:^|\\s*\n)---\\s*")
var (
sep = regexp.MustCompile("(?:^|\\s*\n)---\\s*")
comment = regexp.MustCompile("^#.*$")
)

// SplitYAML takes YAMLs separated by `---` line and splits it into multiple YAMLs. Empty entries are ignored
func SplitYAML(yamls string) []string {
Expand All @@ -14,6 +17,7 @@ func SplitYAML(yamls string) []string {
trimYAMLs := strings.TrimSpace(yamls)
docs := sep.Split(trimYAMLs, -1)
for _, doc := range docs {
doc = comment.ReplaceAllString(doc, "")
if doc == "" {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/federation/federation_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ func TestE2E(t *testing.T) {
}

var (
_ = PDescribe("Federation with Kube Global", Label("job-3"), federation.FederateKubeZoneCPToKubeGlobal, Ordered)
_ = PDescribe("Federation with Universal Global", Label("job-3"), federation.FederateKubeZoneCPToUniversalGlobal, Ordered)
_ = Describe("Federation with Kube Global", Label("job-3"), federation.FederateKubeZoneCPToKubeGlobal, Ordered)
_ = Describe("Federation with Universal Global", Label("job-3"), federation.FederateKubeZoneCPToUniversalGlobal, Ordered)
)

0 comments on commit 7075f0e

Please sign in to comment.