Skip to content

Commit

Permalink
grpc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
grokspawn committed Nov 8, 2023
1 parent f2285a2 commit 731c5f6
Show file tree
Hide file tree
Showing 9 changed files with 453 additions and 244 deletions.
6 changes: 3 additions & 3 deletions alpha/declcfg/declcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ type Deprecation struct {
}

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

type Meta struct {
Expand Down
74 changes: 69 additions & 5 deletions alpha/declcfg/declcfg_to_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func ConvertToModel(cfg DeclarativeConfig) (model.Model, error) {
mpkgs[p.Name] = mpkg
}

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

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

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

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

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

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

Expand All @@ -168,6 +168,70 @@ func ConvertToModel(cfg DeclarativeConfig) (model.Model, error) {
}
}

// deprecationsDuplicateCheck tracks the set of package names
// and is used to detect duplicate packages.
deprecationsDuplicateCheck := map[string]bool{}

for _, deprecation := range cfg.Deprecations {

// no need to validate schema, since it could not be unmarshaled if missing/invalid

if deprecation.Package == "" {
return nil, fmt.Errorf("package name must be set for deprecation %q", deprecation.Name)
}

// name must be empty string (unset) since it's a valid Meta element but not meaningful for deprecations
if deprecation.Name != "" {
return nil, fmt.Errorf("name must not be set for deprecation %q", deprecation.Name)
}

// must refer to package in this catalog
mpkg, ok := mpkgs[deprecation.Package]
if !ok {
return nil, fmt.Errorf("cannot deprecate unknown package %q with entry %q", deprecation.Package, deprecation.Name)
}

// must be unique per package
_, ok = deprecationsDuplicateCheck[deprecation.Package]
if ok {
return nil, fmt.Errorf("expected a maximum of one deprecation per package: %q", deprecation.Package)
}
deprecationsDuplicateCheck[deprecation.Package] = true

for _, entry := range deprecation.Deprecations {
if entry.Scope == "" {
return nil, fmt.Errorf("scope must be set for deprecation entry %q", deprecation.Name)
}

switch entry.Scope {
case SchemaBundle:
if !packageBundles[deprecation.Package].Has(entry.Reference) {
return nil, fmt.Errorf("cannot deprecate bundle %q for package %q: bundle not found", entry.Reference, deprecation.Package)
}
for _, mch := range mpkg.Channels {
if mb, ok := mch.Bundles[entry.Reference]; ok {
if ok {
if mb.IsDeprecated() {
return nil, fmt.Errorf("cannot deprecate bundle %q for package %q: bundle already deprecated", deprecation.Name, deprecation.Package)
}
mb.Deprecation.Message = entry.Message
}
}
}
case SchemaChannel:
if _, ok := mpkg.Channels[entry.Reference]; !ok {
return nil, fmt.Errorf("cannot deprecate channel %q for package %q: channel not found", entry.Reference, deprecation.Package)
}
case SchemaPackage:
// no-op
default:
return nil, fmt.Errorf("cannot deprecate unknown scope %q for package %q", entry.Scope, deprecation.Package)
}

}

}

if err := mpkgs.Validate(); err != nil {
return nil, err
}
Expand Down
18 changes: 9 additions & 9 deletions alpha/declcfg/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ func TestLoadFS(t *testing.T) {
Package: "kiali",
Name: "bobs-discount-name",
Deprecations: []DeprecationEntry{
{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"`)},
{Schema: "olm.package", Name: "kiali", Message: json.RawMessage(`"package kiali is end of life. Please use 'kiali-new' package for support.\n"`)},
{Schema: "olm.channel", Name: "alpha", Message: json.RawMessage(`"channel alpha is no longer supported. Please switch to channel 'stable'.\n"`)},
{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"},
{Scope: "olm.package", Reference: "kiali", Message: "package kiali is end of life. Please use 'kiali-new' package for support.\n"},
{Scope: "olm.channel", Reference: "alpha", Message: "channel alpha is no longer supported. Please switch to channel 'stable'.\n"},
},
},
},
Expand Down Expand Up @@ -903,16 +903,16 @@ schema: olm.catalog.deprecation
package: kiali
name: bobs-discount-name
deprecations:
- schema: olm.bundle
name: kiali-operator.v1.68.0
- 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.
- schema: olm.package
name: kiali
- scope: olm.package
reference: kiali
message: |
package kiali is end of life. Please use 'kiali-new' package for support.
- schema: olm.channel
name: alpha
- scope: olm.channel
reference: alpha
message: |
channel alpha is no longer supported. Please switch to channel 'stable'.`),
}
Expand Down
27 changes: 26 additions & 1 deletion alpha/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ import (
"github.com/operator-framework/operator-registry/alpha/property"
)

const (
ScopePackage = "olm.package"
ScopeChannel = "olm.channel"
ScopeBundle = "olm.bundle"
)

type DeprecationMessage struct {
Message string
}

func (p Package) IsDeprecated() bool {
return p.Deprecation.Message != ""
}

func (c Channel) IsDeprecated() bool {
return c.Deprecation.Message != ""
}

func (b Bundle) IsDeprecated() bool {
return b.Deprecation.Message != ""
}

func init() {
t := types.NewType("svg", "image/svg+xml")
filetype.AddMatcher(t, svg.Is)
Expand Down Expand Up @@ -44,6 +66,7 @@ type Package struct {
Icon *Icon
DefaultChannel *Channel
Channels map[string]*Channel
Deprecation DeprecationMessage
}

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

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

func (b *Bundle) Validate() error {
Expand Down
9 changes: 4 additions & 5 deletions pkg/api/grpc_health_v1/health.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions pkg/api/grpc_health_v1/health_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 731c5f6

Please sign in to comment.