Skip to content

Commit 6beabcd

Browse files
fix: make run bundle use proper YAML library to split documents (#6829)
* fix: make `run bundle` use proper YAML library to split documents Signed-off-by: Joe Lanford <joe.lanford@gmail.com> * fixing linting issue in fbc registry file Signed-off-by: Adam D. Cornett <adc@redhat.com> * updating unit test Signed-off-by: Adam D. Cornett <adc@redhat.com> --------- Signed-off-by: Joe Lanford <joe.lanford@gmail.com> Signed-off-by: Adam D. Cornett <adc@redhat.com> Co-authored-by: Adam D. Cornett <adc@redhat.com>
1 parent 68022e3 commit 6beabcd

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
entries:
2+
- description: >
3+
Fix naive YAML split in `run bundle` command.
4+
kind: "bugfix"
5+
breaking: false

internal/olm/operator/registry/fbcindex/fbc_registry_pod.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515
package fbcindex
1616

1717
import (
18+
"bufio"
1819
"context"
1920
"errors"
2021
"fmt"
22+
"io"
2123
"path"
2224
"strings"
2325
"time"
2426

27+
"k8s.io/apimachinery/pkg/util/yaml"
28+
2529
"github.com/operator-framework/api/pkg/operators/v1alpha1"
2630
log "github.com/sirupsen/logrus"
2731
corev1 "k8s.io/api/core/v1"
@@ -399,8 +403,22 @@ func (f *FBCRegistryPod) createConfigMaps(cs *v1alpha1.CatalogSource) ([]*corev1
399403
// properly have all the FBC contents rendered in the registry pod.
400404
func (f *FBCRegistryPod) partitionedConfigMaps() ([]*corev1.ConfigMap, error) {
401405
var err error
402-
// Split on the YAML separator `---`
403-
yamlDefs := strings.Split(f.FBCContent, "---")
406+
407+
var yamlDefs []string
408+
yamlReader := yaml.NewYAMLReader(bufio.NewReader(strings.NewReader(f.FBCContent)))
409+
for {
410+
doc, err := yamlReader.Read()
411+
if errors.Is(err, io.EOF) {
412+
break
413+
}
414+
if err != nil {
415+
return nil, err
416+
}
417+
if len(doc) == 0 {
418+
continue
419+
}
420+
yamlDefs = append(yamlDefs, string(doc))
421+
}
404422

405423
configMaps, err := f.getConfigMaps(yamlDefs)
406424
if err != nil {

internal/olm/operator/registry/fbcindex/fbc_registry_pod_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ var _ = Describe("FBCRegistryPod", func() {
200200
largeYaml := largeYamlBuilder.String()
201201
rp.FBCContent = largeYaml
202202

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

206206
cms, err := rp.partitionedConfigMaps()

0 commit comments

Comments
 (0)