Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make run bundle use proper YAML library to split documents #6829

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/fragments/fix-run-bundle-yaml-split.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
entries:
- description: >
Fix naive YAML split in `run bundle` command.
kind: "bugfix"
breaking: false
22 changes: 20 additions & 2 deletions internal/olm/operator/registry/fbcindex/fbc_registry_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
package fbcindex

import (
"bufio"
"context"
"errors"
"fmt"
"io"
"path"
"strings"
"time"

"k8s.io/apimachinery/pkg/util/yaml"

"github.com/operator-framework/api/pkg/operators/v1alpha1"
log "github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -399,8 +403,22 @@ func (f *FBCRegistryPod) createConfigMaps(cs *v1alpha1.CatalogSource) ([]*corev1
// properly have all the FBC contents rendered in the registry pod.
func (f *FBCRegistryPod) partitionedConfigMaps() ([]*corev1.ConfigMap, error) {
var err error
// Split on the YAML separator `---`
yamlDefs := strings.Split(f.FBCContent, "---")

var yamlDefs []string
yamlReader := yaml.NewYAMLReader(bufio.NewReader(strings.NewReader(f.FBCContent)))
for {
doc, err := yamlReader.Read()
if errors.Is(err, io.EOF) {
break
}
if err != nil {
return nil, err
}
if len(doc) == 0 {
continue
}
yamlDefs = append(yamlDefs, string(doc))
}

configMaps, err := f.getConfigMaps(yamlDefs)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ var _ = Describe("FBCRegistryPod", func() {
largeYaml := largeYamlBuilder.String()
rp.FBCContent = largeYaml

expectedYaml := strings.TrimPrefix(strings.TrimSpace(largeYaml), "---\n")
expectedYaml := strings.TrimSpace(largeYaml)
expectedYaml = regexp.MustCompile(`\n\n+`).ReplaceAllString(expectedYaml, "\n")

cms, err := rp.partitionedConfigMaps()
Expand Down
Loading