Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit fe8cc76

Browse files
committed
add catalogsource queue for non-olm catalogsources, unit and e2e tests
1 parent 2395840 commit fe8cc76

File tree

10 files changed

+943
-287
lines changed

10 files changed

+943
-287
lines changed

go.mod

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,35 @@ require (
66
github.com/blang/semver/v4 v4.0.0
77
github.com/go-air/gini v1.0.4
88
github.com/go-logr/logr v1.2.3
9-
github.com/onsi/ginkgo/v2 v2.3.1
10-
github.com/onsi/gomega v1.22.1
9+
github.com/onsi/ginkgo/v2 v2.4.0
10+
github.com/onsi/gomega v1.23.0
1111
github.com/operator-framework/api v0.17.2
1212
github.com/operator-framework/operator-registry v1.26.2
1313
github.com/spf13/cobra v1.4.0
14-
github.com/stretchr/testify v1.7.1
14+
github.com/stretchr/testify v1.8.0
1515
github.com/tidwall/gjson v1.14.3
16-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b
16+
golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10
1717
google.golang.org/grpc v1.47.0
18-
k8s.io/api v0.25.0
19-
k8s.io/apimachinery v0.25.0
18+
k8s.io/api v0.26.1
19+
k8s.io/apimachinery v0.26.1
20+
k8s.io/client-go v0.26.1
2021
sigs.k8s.io/controller-runtime v0.13.0
2122
)
2223

2324
require (
24-
github.com/PuerkitoBio/purell v1.1.1 // indirect
25-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
2625
github.com/davecgh/go-spew v1.1.1 // indirect
27-
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
26+
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
27+
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
2828
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
29+
github.com/go-logr/zapr v1.2.3 // indirect
2930
github.com/go-openapi/jsonpointer v0.19.5 // indirect
30-
github.com/go-openapi/jsonreference v0.19.5 // indirect
31+
github.com/go-openapi/jsonreference v0.20.0 // indirect
3132
github.com/go-openapi/swag v0.19.14 // indirect
3233
github.com/gogo/protobuf v1.3.2 // indirect
3334
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3435
github.com/golang/protobuf v1.5.2 // indirect
3536
github.com/google/gnostic v0.5.7-v3refs // indirect
36-
github.com/google/go-cmp v0.5.8 // indirect
37+
github.com/google/go-cmp v0.5.9 // indirect
3738
github.com/google/gofuzz v1.2.0 // indirect
3839
github.com/h2non/filetype v1.1.1 // indirect
3940
github.com/h2non/go-is-svg v0.0.0-20160927212452-35e8c4b0612c // indirect
@@ -50,21 +51,23 @@ require (
5051
github.com/spf13/pflag v1.0.5 // indirect
5152
github.com/tidwall/match v1.1.1 // indirect
5253
github.com/tidwall/pretty v1.2.0 // indirect
53-
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
54-
golang.org/x/sys v0.0.0-20220907062415-87db552b00fd // indirect
55-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
56-
golang.org/x/text v0.3.7 // indirect
54+
go.uber.org/atomic v1.7.0 // indirect
55+
go.uber.org/multierr v1.6.0 // indirect
56+
go.uber.org/zap v1.21.0 // indirect
57+
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
58+
golang.org/x/sys v0.3.0 // indirect
59+
golang.org/x/term v0.3.0 // indirect
60+
golang.org/x/text v0.5.0 // indirect
5761
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
5862
google.golang.org/appengine v1.6.7 // indirect
5963
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
60-
google.golang.org/protobuf v1.28.0 // indirect
64+
google.golang.org/protobuf v1.28.1 // indirect
6165
gopkg.in/inf.v0 v0.9.1 // indirect
6266
gopkg.in/yaml.v2 v2.4.0 // indirect
6367
gopkg.in/yaml.v3 v3.0.1 // indirect
64-
k8s.io/client-go v0.25.0 // indirect
65-
k8s.io/klog/v2 v2.70.1 // indirect
66-
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
67-
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
68+
k8s.io/klog/v2 v2.80.1 // indirect
69+
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
70+
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
6871
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
6972
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
7073
sigs.k8s.io/yaml v1.3.0 // indirect

go.sum

Lines changed: 59 additions & 40 deletions
Large diffs are not rendered by default.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package catalogsource_test
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/onsi/ginkgo/v2"
7+
. "github.com/onsi/gomega"
8+
)
9+
10+
func TestDeppy(t *testing.T) {
11+
RegisterFailHandler(Fail)
12+
13+
RunSpecs(t, "Deppy Suite")
14+
}

pkg/deppy/input/catalogsource/registry_bundle_to_entity.go

Lines changed: 70 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,27 @@ type DefaultChannel struct {
2525
DefaultChannel string `json:"defaultchannel"`
2626
}
2727

28-
type BundleSource struct {
29-
// possibly extend with support for other types of sources
30-
Path string `json:"bundlepath,omitempty"`
31-
}
32-
33-
const TypeDefaultChannel = "olm.package.defaultchannel"
34-
const TypeBundleSource = "olm.bundle.path"
28+
const (
29+
TypeDefaultChannel = "olm.package.defaultChannel"
30+
TypeBundleSource = "olm.bundle.path"
31+
TypeLabel = "olm.label"
32+
TypeLabelRequired = "olm.label.required"
33+
)
3534

36-
func entityFromBundle(catsrcID string, pkg *catalogsourceapi.Package, bundle *catalogsourceapi.Bundle) (*input.Entity, error) {
35+
func EntityFromBundle(catsrcID string, pkg *catalogsourceapi.Package, bundle *catalogsourceapi.Bundle) (*input.Entity, error) {
3736
properties := map[string]string{}
3837
var errs []error
3938

40-
// All properties are json encoded lists of values, regarless of property type.
41-
// They can all be handled by unmarshalling into an (interface{}) - deppy does not need to know how to handle different types of properties.
42-
propsList := map[string]map[string]struct{}{
43-
property.TypeGVK: {},
44-
property.TypeGVKRequired: {},
45-
// property.TypePackage: {},
46-
property.TypePackageRequired: {},
47-
// property.TypeChannel: {},
39+
// Multivalue properties
40+
propsList := map[string]map[string]struct{}{}
41+
42+
setPropertyValue := func(key, value string) {
43+
if _, ok := propsList[key]; !ok {
44+
propsList[key] = map[string]struct{}{}
45+
}
46+
if _, ok := propsList[key][value]; !ok {
47+
propsList[key][value] = struct{}{}
48+
}
4849
}
4950

5051
for _, prvAPI := range bundle.ProvidedApis {
@@ -53,7 +54,7 @@ func entityFromBundle(catsrcID string, pkg *catalogsourceapi.Package, bundle *ca
5354
errs = append(errs, err)
5455
continue
5556
}
56-
propsList[property.TypeGVK][string(apiValue)] = struct{}{}
57+
setPropertyValue(property.TypeGVK, string(apiValue))
5758
}
5859

5960
for _, reqAPI := range bundle.RequiredApis {
@@ -62,72 +63,31 @@ func entityFromBundle(catsrcID string, pkg *catalogsourceapi.Package, bundle *ca
6263
errs = append(errs, err)
6364
continue
6465
}
65-
propsList[property.TypeGVKRequired][string(apiValue)] = struct{}{}
66+
setPropertyValue(property.TypeGVKRequired, string(apiValue))
6667
}
6768

6869
for _, reqAPI := range bundle.Dependencies {
69-
propsList[property.TypeGVKRequired][reqAPI.Value] = struct{}{}
70+
switch reqAPI.Type {
71+
case property.TypeGVK:
72+
setPropertyValue(property.TypeGVKRequired, reqAPI.Value)
73+
case property.TypePackage:
74+
setPropertyValue(property.TypePackageRequired, reqAPI.Value)
75+
case TypeLabel: // legacy property
76+
setPropertyValue(TypeLabelRequired, reqAPI.Value)
77+
default:
78+
setPropertyValue(reqAPI.Type, reqAPI.Value)
79+
}
7080
}
7181

72-
pkgValue, err := util.JSONMarshal(property.Package{
73-
PackageName: bundle.PackageName,
74-
Version: bundle.Version,
75-
})
76-
if err != nil {
77-
errs = append(errs, err)
78-
} else {
79-
properties[property.TypePackage] = string(pkgValue)
80-
// propsList[property.TypePackage][string(pkgValue)] = struct{}{}
82+
ignoredProperties := map[string]struct{}{
83+
property.TypeBundleObject: {},
8184
}
8285

83-
upValue, err := util.JSONMarshal(UpgradeEdge{
84-
Channel: property.Channel{
85-
ChannelName: bundle.ChannelName,
86-
},
87-
Replaces: bundle.Replaces,
88-
Skips: bundle.Skips,
89-
SkipRange: bundle.SkipRange,
90-
// Version: bundle.Version,
91-
})
92-
if err != nil {
93-
errs = append(errs, err)
94-
} else {
95-
properties[property.TypeChannel] = string(upValue)
96-
// propsList[property.TypeChannel][string(upValue)] = struct{}{}
97-
}
98-
99-
defaultValue, err := util.JSONMarshal(DefaultChannel{
100-
DefaultChannel: pkg.DefaultChannelName,
101-
})
102-
if err != nil {
103-
errs = append(errs, err)
104-
} else {
105-
propsList[TypeDefaultChannel] = map[string]struct{}{string(defaultValue): {}}
106-
}
107-
108-
//sourceValue, err := util.JSONMarshal(BundleSource{
109-
// Path: bundle.BundlePath,
110-
//})
111-
//if err != nil {
112-
// errs = append(errs, err)
113-
//} else {
114-
// propsList[TypeBundleSource] = map[string]struct{}{string(sourceValue): {}}
115-
//}
116-
properties[TypeBundleSource] = bundle.BundlePath
117-
11886
for _, p := range bundle.Properties {
119-
if p.Type == property.TypeChannel || p.Type == property.TypePackage || p.Type == TypeDefaultChannel {
120-
// avoid duplicates
87+
if _, ok := ignoredProperties[p.Type]; ok {
12188
continue
12289
}
123-
//if p.Type == property.TypePackage {
124-
// // override the inferred package if explicitly specified in bundle properties
125-
// propsList[p.Type] = map[string]struct{}{p.Value: {}}
126-
//}
127-
if _, ok := propsList[p.Type]; !ok {
128-
propsList[p.Type] = map[string]struct{}{}
129-
}
130-
propsList[p.Type][p.Value] = struct{}{}
90+
setPropertyValue(p.Type, p.Value)
13191
}
13292

13393
for pType, pValues := range propsList {
@@ -157,10 +117,45 @@ func entityFromBundle(catsrcID string, pkg *catalogsourceapi.Package, bundle *ca
157117
}
158118
properties[pType] = string(pValue)
159119
}
120+
121+
// Singleton properties.
122+
// `olm.package`, `olm.channel`, `olm.defaultChannel`
123+
pkgValue, err := util.JSONMarshal(property.Package{
124+
PackageName: bundle.PackageName,
125+
Version: bundle.Version,
126+
})
127+
if err != nil {
128+
errs = append(errs, err)
129+
} else {
130+
properties[property.TypePackage] = string(pkgValue)
131+
}
132+
133+
upValue, err := util.JSONMarshal(UpgradeEdge{
134+
Channel: property.Channel{
135+
ChannelName: bundle.ChannelName,
136+
},
137+
Replaces: bundle.Replaces,
138+
Skips: bundle.Skips,
139+
SkipRange: bundle.SkipRange,
140+
// Version: bundle.Version,
141+
})
142+
if err != nil {
143+
errs = append(errs, err)
144+
} else {
145+
properties[property.TypeChannel] = string(upValue)
146+
}
147+
148+
properties[TypeDefaultChannel] = pkg.DefaultChannelName
149+
properties[TypeBundleSource] = bundle.BundlePath
150+
160151
if len(errs) > 0 {
161152
return nil, fmt.Errorf("failed to parse properties for bundle %s/%s in %s: %v", bundle.GetPackageName(), bundle.GetVersion(), catsrcID, errors.NewAggregate(errs))
162153
}
163154

164-
entityID := deppy.Identifier(fmt.Sprintf("%s/%s/%s/%s", catsrcID, bundle.PackageName, bundle.ChannelName, bundle.Version))
165-
return input.NewEntity(entityID, properties), nil
155+
// Since multiple instances of bundle may exist for different channels, entityID must include reference to channel
156+
entityIDFromBundle := func(catsrcID string, bundle *catalogsourceapi.Bundle) deppy.Identifier {
157+
return deppy.Identifier(fmt.Sprintf("%s/%s/%s/%s", catsrcID, bundle.PackageName, bundle.ChannelName, bundle.Version))
158+
}
159+
160+
return input.NewEntity(entityIDFromBundle(catsrcID, bundle), properties), nil
166161
}

0 commit comments

Comments
 (0)