Skip to content

Commit 60eb2b1

Browse files
grokspawntmshort
authored andcommitted
enforce rfc1123 compatibility for olm.package.name (#1307)
Signed-off-by: Jordan Keister <[email protected]> Upstream-repository: operator-registry Upstream-commit: 6bb0a3e9d60393e61992c0654bc663341c652ba0
1 parent 87e7019 commit 60eb2b1

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

staging/operator-registry/alpha/declcfg/declcfg_to_model.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/blang/semver/v4"
77
"k8s.io/apimachinery/pkg/util/sets"
8+
"k8s.io/apimachinery/pkg/util/validation"
89

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

26+
if errs := validation.IsDNS1123Label(p.Name); len(errs) > 0 {
27+
return nil, fmt.Errorf("invalid package name %q: %v", p.Name, errs)
28+
}
29+
2530
mpkg := &model.Package{
2631
Name: p.Name,
2732
Description: p.Description,

staging/operator-registry/alpha/declcfg/declcfg_to_model_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ func TestConvertToModel(t *testing.T) {
215215
Bundles: []Bundle{newTestBundle("foo", "0.1.0")},
216216
},
217217
},
218+
{
219+
name: "Error/PackageBreaksRFC1123",
220+
assertion: hasError(`invalid package name "foo.bar": [must not contain dots]`),
221+
cfg: DeclarativeConfig{
222+
Packages: []Package{
223+
newTestPackage("foo.bar", "alpha", svgSmallCircle),
224+
},
225+
Channels: []Channel{newTestChannel("foo", "alpha", ChannelEntry{Name: "foo.v0.1.0"})},
226+
Bundles: []Bundle{newTestBundle("foo", "0.1.0")},
227+
},
228+
},
218229
{
219230
name: "Error/DuplicateChannel",
220231
assertion: hasError(`package "foo" has duplicate channel "alpha"`),

vendor/github.com/operator-framework/operator-registry/alpha/declcfg/declcfg_to_model.go

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

0 commit comments

Comments
 (0)