-
Notifications
You must be signed in to change notification settings - Fork 54
/
bundle.go
67 lines (55 loc) · 2.21 KB
/
bundle.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
package variables
import (
"fmt"
"github.com/operator-framework/deppy/pkg/deppy"
"github.com/operator-framework/deppy/pkg/deppy/constraint"
"github.com/operator-framework/deppy/pkg/deppy/input"
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
)
var _ deppy.Variable = &BundleVariable{}
type BundleVariable struct {
*input.SimpleVariable
bundle *catalogmetadata.Bundle
dependencies []*catalogmetadata.Bundle
}
func (b *BundleVariable) Bundle() *catalogmetadata.Bundle {
return b.bundle
}
func (b *BundleVariable) Dependencies() []*catalogmetadata.Bundle {
return b.dependencies
}
func NewBundleVariable(bundle *catalogmetadata.Bundle, dependencies []*catalogmetadata.Bundle) *BundleVariable {
dependencyIDs := make([]deppy.Identifier, 0, len(dependencies))
for _, dependency := range dependencies {
dependencyIDs = append(dependencyIDs, BundleVariableID(dependency))
}
var constraints []deppy.Constraint
if len(dependencyIDs) > 0 {
constraints = append(constraints, constraint.Dependency(dependencyIDs...))
}
return &BundleVariable{
SimpleVariable: input.NewSimpleVariable(BundleVariableID(bundle), constraints...),
bundle: bundle,
dependencies: dependencies,
}
}
var _ deppy.Variable = &BundleUniquenessVariable{}
type BundleUniquenessVariable struct {
*input.SimpleVariable
}
// NewBundleUniquenessVariable creates a new variable that instructs the resolver to choose at most a single bundle
// from the input 'atMostID'. Examples:
// 1. restrict the solution to at most a single bundle per package
// 2. restrict the solution to at most a single bundler per provided gvk
// this guarantees that no two operators provide the same gvk and no two version of the same operator are running at the same time
func NewBundleUniquenessVariable(id deppy.Identifier, atMostIDs ...deppy.Identifier) *BundleUniquenessVariable {
return &BundleUniquenessVariable{
SimpleVariable: input.NewSimpleVariable(id, constraint.AtMost(1, atMostIDs...)),
}
}
// BundleVariableID returns an ID for a given bundle.
func BundleVariableID(bundle *catalogmetadata.Bundle) deppy.Identifier {
return deppy.Identifier(
fmt.Sprintf("%s-%s-%s", bundle.CatalogName, bundle.Package, bundle.Name),
)
}