Skip to content

Commit

Permalink
poc for schema import
Browse files Browse the repository at this point in the history
  • Loading branch information
grokspawn committed Oct 24, 2023
1 parent b137480 commit 6840347
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 4 deletions.
24 changes: 20 additions & 4 deletions alpha/declcfg/declcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ const (
SchemaPackage = "olm.package"
SchemaChannel = "olm.channel"
SchemaBundle = "olm.bundle"
SchemaDeprecation = "olm.catalog.deprecation"
)

type DeclarativeConfig struct {
Packages []Package
Channels []Channel
Bundles []Bundle
Others []Meta
Packages []Package
Channels []Channel
Bundles []Bundle
Deprecations map[string]Deprecation // mapping package name to deprecation
Others []Meta
}

type Package struct {
Expand Down Expand Up @@ -90,6 +92,20 @@ type RelatedImage struct {
Image string `json:"image"`
}


type Deprecation struct {
Schema string `json:"schema"`
Package string `json:"package"`
Name string `json:"name,omitempty"`
Deprecations []DeprecationEntry `json:"deprecations"`
}

type DeprecationEntry struct {
Schema string `json:"schema"`
Name string `json:"name,omitempty"`
Message json.RawMessage `json:"message"`
}

type Meta struct {
Schema string
Package string
Expand Down
12 changes: 12 additions & 0 deletions alpha/declcfg/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,18 @@ func LoadReader(r io.Reader) (*DeclarativeConfig, error) {
return fmt.Errorf("parse bundle: %v", err)
}
cfg.Bundles = append(cfg.Bundles, b)
case SchemaDeprecation:
var d Deprecation
if err := json.Unmarshal(in.Blob, &d); err != nil {
return fmt.Errorf("parse deprecation: %v", err)
}
if cfg.Deprecations == nil {
cfg.Deprecations = make(map[string]Deprecation)
}
if _, ok := cfg.Deprecations[d.Package]; ok {
return fmt.Errorf("deprecation for package %q already exists", d.Package)
}
cfg.Deprecations[d.Package] = d
case "":
return fmt.Errorf("object '%s' is missing root schema field", string(in.Blob))
default:
Expand Down
Loading

0 comments on commit 6840347

Please sign in to comment.