Skip to content

Commit

Permalink
enforce rfc1123 compatibility for olm.package.name (#1307)
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Keister <jordan@nimblewidget.com>
  • Loading branch information
grokspawn committed May 14, 2024
1 parent 2c49e9c commit 6bb0a3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions alpha/declcfg/declcfg_to_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/blang/semver/v4"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation"

"github.com/operator-framework/operator-registry/alpha/model"
"github.com/operator-framework/operator-registry/alpha/property"
Expand All @@ -22,6 +23,10 @@ func ConvertToModel(cfg DeclarativeConfig) (model.Model, error) {
return nil, fmt.Errorf("duplicate package %q", p.Name)
}

if errs := validation.IsDNS1123Label(p.Name); len(errs) > 0 {
return nil, fmt.Errorf("invalid package name %q: %v", p.Name, errs)
}

mpkg := &model.Package{
Name: p.Name,
Description: p.Description,
Expand Down
11 changes: 11 additions & 0 deletions alpha/declcfg/declcfg_to_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ func TestConvertToModel(t *testing.T) {
Bundles: []Bundle{newTestBundle("foo", "0.1.0")},
},
},
{
name: "Error/PackageBreaksRFC1123",
assertion: hasError(`invalid package name "foo.bar": [must not contain dots]`),
cfg: DeclarativeConfig{
Packages: []Package{
newTestPackage("foo.bar", "alpha", svgSmallCircle),
},
Channels: []Channel{newTestChannel("foo", "alpha", ChannelEntry{Name: "foo.v0.1.0"})},
Bundles: []Bundle{newTestBundle("foo", "0.1.0")},
},
},
{
name: "Error/DuplicateChannel",
assertion: hasError(`package "foo" has duplicate channel "alpha"`),
Expand Down

0 comments on commit 6bb0a3e

Please sign in to comment.