-
Notifications
You must be signed in to change notification settings - Fork 46
/
bundle_predicates.go
99 lines (88 loc) · 2.89 KB
/
bundle_predicates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package filter
import (
mmsemver "github.com/Masterminds/semver/v3"
bsemver "github.com/blang/semver/v4"
"github.com/operator-framework/operator-registry/alpha/declcfg"
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
)
func WithPackageName(packageName string) Predicate[catalogmetadata.Bundle] {
return func(bundle *catalogmetadata.Bundle) bool {
return bundle.Package == packageName
}
}
func InMastermindsSemverRange(semverRange *mmsemver.Constraints) Predicate[catalogmetadata.Bundle] {
return func(bundle *catalogmetadata.Bundle) bool {
bVersion, err := bundle.Version()
if err != nil {
return false
}
// No error should occur here because the simple version was successfully parsed by blang
// We are unaware of any tests cases that would cause one to fail but not the other
// This will cause code coverage to drop for this line. We don't ignore the error because
// there might be that one extreme edge case that might cause one to fail but not the other
mVersion, err := mmsemver.NewVersion(bVersion.String())
if err != nil {
return false
}
return semverRange.Check(mVersion)
}
}
func InBlangSemverRange(semverRange bsemver.Range) Predicate[catalogmetadata.Bundle] {
return func(bundle *catalogmetadata.Bundle) bool {
bundleVersion, err := bundle.Version()
if err != nil {
return false
}
return semverRange(*bundleVersion)
}
}
func InChannel(channelName string) Predicate[catalogmetadata.Bundle] {
return func(bundle *catalogmetadata.Bundle) bool {
for _, ch := range bundle.InChannels {
if ch.Name == channelName {
return true
}
}
return false
}
}
func WithBundleImage(bundleImage string) Predicate[catalogmetadata.Bundle] {
return func(bundle *catalogmetadata.Bundle) bool {
return bundle.Image == bundleImage
}
}
func LegacySuccessor(installedBundle *catalogmetadata.Bundle) Predicate[catalogmetadata.Bundle] {
isSuccessor := func(candidateBundleEntry declcfg.ChannelEntry) bool {
if candidateBundleEntry.Replaces == installedBundle.Name {
return true
}
for _, skip := range candidateBundleEntry.Skips {
if skip == installedBundle.Name {
return true
}
}
if candidateBundleEntry.SkipRange != "" {
installedBundleVersion, _ := installedBundle.Version()
skipRange, _ := bsemver.ParseRange(candidateBundleEntry.SkipRange)
if installedBundleVersion != nil && skipRange != nil && skipRange(*installedBundleVersion) {
return true
}
}
return false
}
return func(candidateBundle *catalogmetadata.Bundle) bool {
for _, ch := range candidateBundle.InChannels {
for _, chEntry := range ch.Entries {
if candidateBundle.Name == chEntry.Name && isSuccessor(chEntry) {
return true
}
}
}
return false
}
}
func WithDeprecation(deprecated bool) Predicate[catalogmetadata.Bundle] {
return func(bundle *catalogmetadata.Bundle) bool {
return bundle.HasDeprecation() == deprecated
}
}