Skip to content

Commit

Permalink
fix: make run bundle use proper YAML library to split documents (#6829
Browse files Browse the repository at this point in the history
)

* fix: make `run bundle` use proper YAML library to split documents

Signed-off-by: Joe Lanford <[email protected]>

* fixing linting issue in fbc registry file

Signed-off-by: Adam D. Cornett <[email protected]>

* updating unit test

Signed-off-by: Adam D. Cornett <[email protected]>

---------

Signed-off-by: Joe Lanford <[email protected]>
Signed-off-by: Adam D. Cornett <[email protected]>
Co-authored-by: Adam D. Cornett <[email protected]>
  • Loading branch information
joelanford and acornett21 authored Oct 15, 2024
1 parent 68022e3 commit 6beabcd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
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

0 comments on commit 6beabcd

Please sign in to comment.