Skip to content

Commit 731c5f6

Browse files
committed
grpc changes
1 parent f2285a2 commit 731c5f6

File tree

9 files changed

+453
-244
lines changed

9 files changed

+453
-244
lines changed

alpha/declcfg/declcfg.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ type Deprecation struct {
100100
}
101101

102102
type DeprecationEntry struct {
103-
Schema string `json:"schema"`
104-
Name string `json:"name,omitempty"`
105-
Message json.RawMessage `json:"message"`
103+
Scope string `json:"scope"`
104+
Reference string `json:"reference,omitempty"`
105+
Message string `json:"message"`
106106
}
107107

108108
type Meta struct {

alpha/declcfg/declcfg_to_model.go

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func ConvertToModel(cfg DeclarativeConfig) (model.Model, error) {
3737
mpkgs[p.Name] = mpkg
3838
}
3939

40-
channelDefinedEntries := map[string]sets.String{}
40+
channelDefinedEntries := map[string]sets.Set[string]{}
4141
for _, c := range cfg.Channels {
4242
mpkg, ok := mpkgs[c.Package]
4343
if !ok {
@@ -62,7 +62,7 @@ func ConvertToModel(cfg DeclarativeConfig) (model.Model, error) {
6262
Properties: c.Properties,
6363
}
6464

65-
cde := sets.NewString()
65+
cde := sets.Set[string]{}
6666
for _, entry := range c.Entries {
6767
if _, ok := mch.Bundles[entry.Name]; ok {
6868
return nil, fmt.Errorf("invalid package %q, channel %q: duplicate entry %q", c.Package, c.Name, entry.Name)
@@ -89,7 +89,7 @@ func ConvertToModel(cfg DeclarativeConfig) (model.Model, error) {
8989

9090
// packageBundles tracks the set of bundle names for each package
9191
// and is used to detect duplicate bundles.
92-
packageBundles := map[string]sets.String{}
92+
packageBundles := map[string]sets.Set[string]{}
9393

9494
for _, b := range cfg.Bundles {
9595
if b.Package == "" {
@@ -102,7 +102,7 @@ func ConvertToModel(cfg DeclarativeConfig) (model.Model, error) {
102102

103103
bundles, ok := packageBundles[b.Package]
104104
if !ok {
105-
bundles = sets.NewString()
105+
bundles = sets.Set[string]{}
106106
}
107107
if bundles.Has(b.Name) {
108108
return nil, fmt.Errorf("package %q has duplicate bundle %q", b.Package, b.Name)
@@ -151,7 +151,7 @@ func ConvertToModel(cfg DeclarativeConfig) (model.Model, error) {
151151

152152
for pkg, entries := range channelDefinedEntries {
153153
if entries.Len() > 0 {
154-
return nil, fmt.Errorf("no olm.bundle blobs found in package %q for olm.channel entries %s", pkg, entries.List())
154+
return nil, fmt.Errorf("no olm.bundle blobs found in package %q for olm.channel entries %s", pkg, sets.List[string](entries))
155155
}
156156
}
157157

@@ -168,6 +168,70 @@ func ConvertToModel(cfg DeclarativeConfig) (model.Model, error) {
168168
}
169169
}
170170

171+
// deprecationsDuplicateCheck tracks the set of package names
172+
// and is used to detect duplicate packages.
173+
deprecationsDuplicateCheck := map[string]bool{}
174+
175+
for _, deprecation := range cfg.Deprecations {
176+
177+
// no need to validate schema, since it could not be unmarshaled if missing/invalid
178+
179+
if deprecation.Package == "" {
180+
return nil, fmt.Errorf("package name must be set for deprecation %q", deprecation.Name)
181+
}
182+
183+
// name must be empty string (unset) since it's a valid Meta element but not meaningful for deprecations
184+
if deprecation.Name != "" {
185+
return nil, fmt.Errorf("name must not be set for deprecation %q", deprecation.Name)
186+
}
187+
188+
// must refer to package in this catalog
189+
mpkg, ok := mpkgs[deprecation.Package]
190+
if !ok {
191+
return nil, fmt.Errorf("cannot deprecate unknown package %q with entry %q", deprecation.Package, deprecation.Name)
192+
}
193+
194+
// must be unique per package
195+
_, ok = deprecationsDuplicateCheck[deprecation.Package]
196+
if ok {
197+
return nil, fmt.Errorf("expected a maximum of one deprecation per package: %q", deprecation.Package)
198+
}
199+
deprecationsDuplicateCheck[deprecation.Package] = true
200+
201+
for _, entry := range deprecation.Deprecations {
202+
if entry.Scope == "" {
203+
return nil, fmt.Errorf("scope must be set for deprecation entry %q", deprecation.Name)
204+
}
205+
206+
switch entry.Scope {
207+
case SchemaBundle:
208+
if !packageBundles[deprecation.Package].Has(entry.Reference) {
209+
return nil, fmt.Errorf("cannot deprecate bundle %q for package %q: bundle not found", entry.Reference, deprecation.Package)
210+
}
211+
for _, mch := range mpkg.Channels {
212+
if mb, ok := mch.Bundles[entry.Reference]; ok {
213+
if ok {
214+
if mb.IsDeprecated() {
215+
return nil, fmt.Errorf("cannot deprecate bundle %q for package %q: bundle already deprecated", deprecation.Name, deprecation.Package)
216+
}
217+
mb.Deprecation.Message = entry.Message
218+
}
219+
}
220+
}
221+
case SchemaChannel:
222+
if _, ok := mpkg.Channels[entry.Reference]; !ok {
223+
return nil, fmt.Errorf("cannot deprecate channel %q for package %q: channel not found", entry.Reference, deprecation.Package)
224+
}
225+
case SchemaPackage:
226+
// no-op
227+
default:
228+
return nil, fmt.Errorf("cannot deprecate unknown scope %q for package %q", entry.Scope, deprecation.Package)
229+
}
230+
231+
}
232+
233+
}
234+
171235
if err := mpkgs.Validate(); err != nil {
172236
return nil, err
173237
}

alpha/declcfg/load_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,9 @@ func TestLoadFS(t *testing.T) {
342342
Package: "kiali",
343343
Name: "bobs-discount-name",
344344
Deprecations: []DeprecationEntry{
345-
{Schema: "olm.bundle", Name: "kiali-operator.v1.68.0", Message: json.RawMessage(`"kiali-operator.v1.68.0 is deprecated. Uninstall and install kiali-operator.v1.72.0 for support.\n"`)},
346-
{Schema: "olm.package", Name: "kiali", Message: json.RawMessage(`"package kiali is end of life. Please use 'kiali-new' package for support.\n"`)},
347-
{Schema: "olm.channel", Name: "alpha", Message: json.RawMessage(`"channel alpha is no longer supported. Please switch to channel 'stable'.\n"`)},
345+
{Scope: "olm.bundle", Reference: "kiali-operator.v1.68.0", Message: "kiali-operator.v1.68.0 is deprecated. Uninstall and install kiali-operator.v1.72.0 for support.\n"},
346+
{Scope: "olm.package", Reference: "kiali", Message: "package kiali is end of life. Please use 'kiali-new' package for support.\n"},
347+
{Scope: "olm.channel", Reference: "alpha", Message: "channel alpha is no longer supported. Please switch to channel 'stable'.\n"},
348348
},
349349
},
350350
},
@@ -903,16 +903,16 @@ schema: olm.catalog.deprecation
903903
package: kiali
904904
name: bobs-discount-name
905905
deprecations:
906-
- schema: olm.bundle
907-
name: kiali-operator.v1.68.0
906+
- scope: olm.bundle
907+
reference: kiali-operator.v1.68.0
908908
message: |
909909
kiali-operator.v1.68.0 is deprecated. Uninstall and install kiali-operator.v1.72.0 for support.
910-
- schema: olm.package
911-
name: kiali
910+
- scope: olm.package
911+
reference: kiali
912912
message: |
913913
package kiali is end of life. Please use 'kiali-new' package for support.
914-
- schema: olm.channel
915-
name: alpha
914+
- scope: olm.channel
915+
reference: alpha
916916
message: |
917917
channel alpha is no longer supported. Please switch to channel 'stable'.`),
918918
}

alpha/model/model.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ import (
1616
"github.com/operator-framework/operator-registry/alpha/property"
1717
)
1818

19+
const (
20+
ScopePackage = "olm.package"
21+
ScopeChannel = "olm.channel"
22+
ScopeBundle = "olm.bundle"
23+
)
24+
25+
type DeprecationMessage struct {
26+
Message string
27+
}
28+
29+
func (p Package) IsDeprecated() bool {
30+
return p.Deprecation.Message != ""
31+
}
32+
33+
func (c Channel) IsDeprecated() bool {
34+
return c.Deprecation.Message != ""
35+
}
36+
37+
func (b Bundle) IsDeprecated() bool {
38+
return b.Deprecation.Message != ""
39+
}
40+
1941
func init() {
2042
t := types.NewType("svg", "image/svg+xml")
2143
filetype.AddMatcher(t, svg.Is)
@@ -44,6 +66,7 @@ type Package struct {
4466
Icon *Icon
4567
DefaultChannel *Channel
4668
Channels map[string]*Channel
69+
Deprecation DeprecationMessage
4770
}
4871

4972
func (m *Package) Validate() error {
@@ -137,7 +160,8 @@ type Channel struct {
137160
// NOTICE: The field Properties of the type Channel is for internal use only.
138161
// DO NOT use it for any public-facing functionalities.
139162
// This API is in alpha stage and it is subject to change.
140-
Properties []property.Property
163+
Properties []property.Property
164+
Deprecation DeprecationMessage
141165
}
142166

143167
// TODO(joelanford): This function determines the channel head by finding the bundle that has 0
@@ -274,6 +298,7 @@ type Bundle struct {
274298
// These fields are used to compare bundles in a diff.
275299
PropertiesP *property.Properties
276300
Version semver.Version
301+
Deprecation DeprecationMessage
277302
}
278303

279304
func (b *Bundle) Validate() error {

pkg/api/grpc_health_v1/health.pb.go

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/api/grpc_health_v1/health_grpc.pb.go

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)