Skip to content

Commit 6840347

Browse files
committed
poc for schema import
1 parent b137480 commit 6840347

File tree

3 files changed

+221
-4
lines changed

3 files changed

+221
-4
lines changed

alpha/declcfg/declcfg.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ const (
1919
SchemaPackage = "olm.package"
2020
SchemaChannel = "olm.channel"
2121
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,20 @@ type RelatedImage struct {
9092
Image string `json:"image"`
9193
}
9294

95+
96+
type Deprecation struct {
97+
Schema string `json:"schema"`
98+
Package string `json:"package"`
99+
Name string `json:"name,omitempty"`
100+
Deprecations []DeprecationEntry `json:"deprecations"`
101+
}
102+
103+
type DeprecationEntry struct {
104+
Schema string `json:"schema"`
105+
Name string `json:"name,omitempty"`
106+
Message json.RawMessage `json:"message"`
107+
}
108+
93109
type Meta struct {
94110
Schema string
95111
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)