Skip to content

Commit 15193ad

Browse files
committed
poc for schema import
1 parent b137480 commit 15193ad

File tree

3 files changed

+223
-7
lines changed

3 files changed

+223
-7
lines changed

alpha/declcfg/declcfg.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ import (
1616
)
1717

1818
const (
19-
SchemaPackage = "olm.package"
20-
SchemaChannel = "olm.channel"
21-
SchemaBundle = "olm.bundle"
19+
SchemaPackage = "olm.package"
20+
SchemaChannel = "olm.channel"
21+
SchemaBundle = "olm.bundle"
22+
SchemaDeprecation = "olm.catalog.deprecation"
2223
)
2324

2425
type DeclarativeConfig struct {
25-
Packages []Package
26-
Channels []Channel
27-
Bundles []Bundle
28-
Others []Meta
26+
Packages []Package
27+
Channels []Channel
28+
Bundles []Bundle
29+
Deprecations map[string]Deprecation // mapping package name to deprecation
30+
Others []Meta
2931
}
3032

3133
type Package struct {
@@ -90,6 +92,19 @@ type RelatedImage struct {
9092
Image string `json:"image"`
9193
}
9294

95+
type Deprecation struct {
96+
Schema string `json:"schema"`
97+
Package string `json:"package"`
98+
Name string `json:"name,omitempty"`
99+
Deprecations []DeprecationEntry `json:"deprecations"`
100+
}
101+
102+
type DeprecationEntry struct {
103+
Schema string `json:"schema"`
104+
Name string `json:"name,omitempty"`
105+
Message json.RawMessage `json:"message"`
106+
}
107+
93108
type Meta struct {
94109
Schema string
95110
Package string

alpha/declcfg/load.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,18 @@ func LoadReader(r io.Reader) (*DeclarativeConfig, error) {
297297
return fmt.Errorf("parse bundle: %v", err)
298298
}
299299
cfg.Bundles = append(cfg.Bundles, b)
300+
case SchemaDeprecation:
301+
var d Deprecation
302+
if err := json.Unmarshal(in.Blob, &d); err != nil {
303+
return fmt.Errorf("parse deprecation: %v", err)
304+
}
305+
if cfg.Deprecations == nil {
306+
cfg.Deprecations = make(map[string]Deprecation)
307+
}
308+
if _, ok := cfg.Deprecations[d.Package]; ok {
309+
return fmt.Errorf("deprecation for package %q already exists", d.Package)
310+
}
311+
cfg.Deprecations[d.Package] = d
300312
case "":
301313
return fmt.Errorf("object '%s' is missing root schema field", string(in.Blob))
302314
default:

0 commit comments

Comments
 (0)