merger

package
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

README

pkg/merger

The merger package resolves and merges Katalog/Komposer YAML files into a single, unified set of CRD definitions. It is the ingestion layer that sits between the raw YAML on disk (or a remote source) and the runtime Katalog struct that drives the operator.

What lives here

File Role
merger.go Merger struct, New, Merge, Enabled, All, Get, ToSpec, ToSecurity, ToNotification, ToProviders, ToUI
file.go loadKatalogFile dispatcher; loadKatalog (Katalog kind); loadKomposer (Komposer kind — sources + inline merge + accumulation)
parse.go parseKatalogDoc — YAML decode + kind validation
file_auth.go loadSourceFileWithAuth — HTTP/S fetch with bearer/basic auth; local file read
helm.go loadHelmSource — Helm chart render → Katalog template extraction
registry.go / registry_v2.go loadRegistrySource — fetch CRDs from the Orkestra registry
helper.go mergeKatalogSecurity, mergeKatalogNotification, checkDuplicate, resolveEnvVar, writeTempFile, gitClone

Merge rules

Katalog  (kind: Katalog)
  Declares CRDs directly in spec.crds.
  Must NOT declare sources — sources are a Komposer concern.

Komposer (kind: Komposer)
  Resolves sources (registry → files → helm) in that order.
  Inline spec.crds are merged last and win on name conflict.
  Top-level fields (security, notification, providers) are
  accumulated across all sources; the Komposer's own block
  wins on conflict.
Deduplication scopes
Scope Mechanism
Within one file's source tree localSeen map[string]string
Across entry-point files seen map[string]string in Merge()
Inline over source valid — triggers mergeCRDEntry
Inline over inline always an error
Top-level field accumulation

When a Komposer references multiple source Katalogs, the merger accumulates their top-level fields so that ork generate rbac and ork generate configmap against a Komposer produce the same output as running against the source Katalogs directly:

Field Accumulation strategy
security mergeKatalogSecurity — non-nil pointer fields in override win
notification mergeKatalogNotification — teams merged by name; override wins per key
providers append all, Komposer's own list replaces if non-empty

Usage

m := merger.New("katalog.yaml", "overrides.yaml")
if err := m.Merge(); err != nil { ... }

kat.Spec         = m.ToSpec()
kat.Security     = m.ToSecurity()
kat.Notification = m.ToNotification()
kat.Providers    = m.ToProviders()

All To* methods panic if called before Merge().

Developer documentation

Full step-by-step documentation is in docs/.

I want to… Go to
Understand the full merge pipeline 01 — Architecture
Understand Katalog vs Komposer rules 02 — Kinds
Add or understand a source type 03 — Sources
Debug duplicate CRD name errors 04 — Deduplication
Understand security/notification/providers inheritance 05 — Top-Level Accumulation

Documentation

Overview

pkg/merger/file.go

pkg/merger/file_auth.go

pkg/merger/helm.go

pkg/merger/helper.go

pkg/merger/merger.go

Package merger resolves and merges Katalog and Komposer YAML files into a single unified CRD map that the Katalog runtime consumes. It is the ingestion layer between raw YAML on disk (or remote sources) and the operator's live configuration.

Entry point: New(paths...).Merge() — call once; query with Enabled, All, ToSpec, ToSecurity, ToNotification, and ToProviders.

See README.md for merge rules, source-loading order, and top-level field accumulation semantics.

pkg/merger/parse.go

pkg/merger/registry.go

pkg/merger/registry_v2.go

Index

Constants

This section is empty.

Variables

View Source
var ParseKatalogDoc = parseKatalogDoc

Export

Functions

func ExportedGitHubRawURL

func ExportedGitHubRawURL(repoURL, ref, filePath string) string

Exported for tests

func ExportedGitLabRawURL

func ExportedGitLabRawURL(repoURL, ref, filePath string) string

Exported for tests

func ExportedIsGitHubURL

func ExportedIsGitHubURL(u string) bool

ExportedIsGitHubURL

func ExportedIsGitLabURL

func ExportedIsGitLabURL(u string) bool

ExportedIsGitLab

func ExportedLoadRegistrySource

func ExportedLoadRegistrySource(m *Merger, src orktypes.RegistrySource) (map[string]orktypes.CRDEntry, error)

ExportedLoadRegistrySource loads from the deprecated catalog-map registry protocol (sources.registry with katalog: map[string]RegistryRef). Tests that verify catalog-map-based registry loading use this export.

func ExportedValidatePatternStructure

func ExportedValidatePatternStructure(dir, url, version string) error

ExportedValidatePatternStructure

Types

type Merger

type Merger struct {
	// contains filtered or unexported fields
}

Merger loads one or more Katalog files, resolves their sources (files, URLs, Helm charts), merges all CRD entries, and exposes the result through Enabled(), All(), and Get().

Entry point: one or more file paths from the CLI or konstructOrkestra. Everything else — source resolution, Helm rendering, deduplication — is internal to the merger.

Merge rules:

  • Sources within a Katalog are loaded before spec.crds
  • Inline spec.crds win on name conflict (local overrides remote)
  • Duplicate names across independent Katalog files are errors
  • disabled CRDs are preserved and filtered by Enabled()

func New

func New(paths ...string) *Merger

New creates a Merger with the given entry point file paths or URLs. Accepts one or more paths — the same as passing --katalog multiple times or comma separated.

func (*Merger) APIMetadata

func (m *Merger) APIMetadata() apiMetadata

APIMetadata returns the merged result as a KatalogMeta with apiversion and kind.

func (*Merger) Add

func (m *Merger) Add(paths ...string) *Merger

Add appends additional entry point paths after construction. Returns the Merger for chaining.

func (*Merger) All

func (m *Merger) All() map[string]orktypes.CRDEntry

All returns all CRD entries including disabled ones.

func (*Merger) Count

func (m *Merger) Count() int

Count returns total CRD count across all sources.

func (*Merger) Enabled

func (m *Merger) Enabled() map[string]orktypes.CRDEntry

Enabled returns only CRD entries where enabled: true.

func (*Merger) EnabledCount

func (m *Merger) EnabledCount() int

EnabledCount returns the number of enabled CRDs.

func (*Merger) Get

func (m *Merger) Get(name string) (orktypes.CRDEntry, bool)

Get returns a CRD entry by name. Returns (entry, true) if found.

func (*Merger) GetRegistryURL

func (m *Merger) GetRegistryURL() string

func (*Merger) Merge

func (m *Merger) Merge() error

Merge loads all entry points and their declared sources, resolves Helm charts, and produces a single deduplicated CRD map. Safe to call multiple times — re-merges on each call.

func (*Merger) SetRegistryURL

func (m *Merger) SetRegistryURL(url string)

func (*Merger) ToNotification added in v0.2.5

func (m *Merger) ToNotification() *orktypes.KatalogNotification

ToNotification returns the merged notification configuration of the merged result. When a Komposer references multiple source Katalogs, teams from all sources are merged — source teams are inherited and the Komposer's own teams win on conflict. Used by KomposeKatalogFromYaml to populate Katalog.Notification.

func (*Merger) ToProviders

func (m *Merger) ToProviders() []orktypes.KatalogProviderRequirement

ToProviders returns the top-level provider requirements of the merged result. Used by KomposeKatalogFromYaml to populate Katalog.Providers.

func (*Merger) ToSecurity

func (m *Merger) ToSecurity() orktypes.KatalogSecurity

ToSecurity returns the security config of the merged result as a KatalogSecurity Used by NewKatalog consume the merged result.

func (*Merger) ToSpec

func (m *Merger) ToSpec() orktypes.KatalogSpec

ToSpec returns the merged result as a KatalogSpec. Used by NewKatalog and generate.Registry to consume the merged result.

func (*Merger) ToUI

func (m *Merger) ToUI() *orktypes.KatalogForUI

ToUI returns a UI-friendly representation of the merged Katalog. This method extracts only the fields needed for display in the Control Center:

  • API version and kind (always "Katalog" at runtime)
  • Metadata (name, description, version, author, license)
  • All merged CRD definitions

Internal fields (Scheme, GroupVersionKind, etc.) are excluded because they have `yaml:"-" json:"-"` tags and won't be serialized to JSON.

This method is used by the /katalog/raw endpoint to provide a clean, readable view of the Katalog that created the current operator.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL