Skip to content
Open
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
4 changes: 3 additions & 1 deletion internal/ocimirror/ociref.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
"github.com/google/go-containerregistry/pkg/name"
)

var imageFieldPattern = regexp.MustCompile(`(?m)^[\s-]*image:\s+["']?([^\s"']+)["']?`)
// imageFieldPattern matches `image: <ref>` only when <ref> is on the same line.
// Avoids false matches when `image:` opens a nested map (e.g. CRD field schemas).
var imageFieldPattern = regexp.MustCompile(`(?m)^[\s-]*image:[\t ]+["']?([^\s"']+)["']?\s*$`)

// ExtractUniqueOCIRefs extracts and deduplicates all OCI image references from YAML manifests.
func ExtractUniqueOCIRefs(manifests string) []string {
Expand Down
17 changes: 17 additions & 0 deletions internal/ocimirror/ociref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ containers:
images := ExtractUniqueOCIRefs(manifests)
Expect(images).To(HaveLen(2))
})

It("should ignore `image:` used as a CRD field name with nested children", func() {
// Regression: OpenSearch index templates declare `image` as a field, not a container ref.
manifests := `
mappings:
properties:
container:
properties:
image:
properties:
name:
type: keyword
tag:
type: keyword
`
Expect(ExtractUniqueOCIRefs(manifests)).To(BeEmpty())
})
})

Describe("SplitOCIRef", func() {
Expand Down
Loading