From af4972b041c4a3b96b74ee15c054a02c038e1240 Mon Sep 17 00:00:00 2001 From: Joe Lanford Date: Thu, 5 Sep 2024 21:03:09 -0400 Subject: [PATCH 1/3] fix: make `run bundle` use proper YAML library to split documents Signed-off-by: Joe Lanford --- .../fragments/fix-run-bundle-yaml-split.yaml | 5 +++++ .../registry/fbcindex/fbc_registry_pod.go | 21 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 changelog/fragments/fix-run-bundle-yaml-split.yaml diff --git a/changelog/fragments/fix-run-bundle-yaml-split.yaml b/changelog/fragments/fix-run-bundle-yaml-split.yaml new file mode 100644 index 00000000000..e3edd3b7b4c --- /dev/null +++ b/changelog/fragments/fix-run-bundle-yaml-split.yaml @@ -0,0 +1,5 @@ +entries: + - description: > + Fix naive YAML split in `run bundle` command. + kind: "bugfix" + breaking: false diff --git a/internal/olm/operator/registry/fbcindex/fbc_registry_pod.go b/internal/olm/operator/registry/fbcindex/fbc_registry_pod.go index bba5264a1f9..bf9963a874b 100644 --- a/internal/olm/operator/registry/fbcindex/fbc_registry_pod.go +++ b/internal/olm/operator/registry/fbcindex/fbc_registry_pod.go @@ -15,9 +15,12 @@ package fbcindex import ( + "bufio" "context" "errors" "fmt" + "io" + "k8s.io/apimachinery/pkg/util/yaml" "path" "strings" "time" @@ -399,8 +402,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 { From 113d91f6e5226c99f29cca0de4a5bf7334e61dfb Mon Sep 17 00:00:00 2001 From: "Adam D. Cornett" Date: Tue, 15 Oct 2024 14:43:22 -0700 Subject: [PATCH 2/3] fixing linting issue in fbc registry file Signed-off-by: Adam D. Cornett --- internal/olm/operator/registry/fbcindex/fbc_registry_pod.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/olm/operator/registry/fbcindex/fbc_registry_pod.go b/internal/olm/operator/registry/fbcindex/fbc_registry_pod.go index bf9963a874b..ec898394ef9 100644 --- a/internal/olm/operator/registry/fbcindex/fbc_registry_pod.go +++ b/internal/olm/operator/registry/fbcindex/fbc_registry_pod.go @@ -20,11 +20,12 @@ import ( "errors" "fmt" "io" - "k8s.io/apimachinery/pkg/util/yaml" "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" From c306232b1690f492b62a3698e4cde0a4108fc7cd Mon Sep 17 00:00:00 2001 From: "Adam D. Cornett" Date: Tue, 15 Oct 2024 15:31:12 -0700 Subject: [PATCH 3/3] updating unit test Signed-off-by: Adam D. Cornett --- .../olm/operator/registry/fbcindex/fbc_registry_pod_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/olm/operator/registry/fbcindex/fbc_registry_pod_test.go b/internal/olm/operator/registry/fbcindex/fbc_registry_pod_test.go index 0581f6e172b..cd545426505 100644 --- a/internal/olm/operator/registry/fbcindex/fbc_registry_pod_test.go +++ b/internal/olm/operator/registry/fbcindex/fbc_registry_pod_test.go @@ -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()