@@ -18,11 +18,11 @@ package main
1818
1919import (
2020 "context"
21- "errors"
2221 "flag"
2322 "fmt"
2423 "os"
2524
25+ "github.com/operator-framework/deppy/pkg/deppy/input"
2626 "github.com/operator-framework/deppy/pkg/deppy/solver"
2727 rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
2828 "k8s.io/apimachinery/pkg/runtime"
@@ -34,12 +34,19 @@ import (
3434
3535 catalogd "github.com/operator-framework/catalogd/pkg/apis/core/v1beta1"
3636 operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
37- "github.com/operator-framework/operator-controller/internal/resolution/entitysources"
3837 "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/bundles_and_dependencies"
38+ "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/crd_constraints"
3939 "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity"
4040 "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/olm"
4141)
4242
43+ const (
44+ flagNamePackageName = "package-name"
45+ flagNamePackageVersion = "package-version"
46+ flagNamePackageChannel = "package-channel"
47+ flagNameIndexRef = "index-ref"
48+ )
49+
4350var (
4451 scheme = runtime .NewScheme ()
4552)
@@ -52,46 +59,64 @@ func init() {
5259}
5360
5461func main () {
62+ ctx := context .Background ()
63+
5564 var packageName string
5665 var packageVersion string
5766 var packageChannel string
58- flag .StringVar (& packageName , "package-name" , "" , "Name of the package to resolve" )
59- flag .StringVar (& packageVersion , "package-version" , "" , "Version of the package" )
60- flag .StringVar (& packageChannel , "package-channel" , "" , "Channel of the package" )
67+ var indexRef string
68+ flag .StringVar (& packageName , flagNamePackageName , "" , "Name of the package to resolve" )
69+ flag .StringVar (& packageVersion , flagNamePackageVersion , "" , "Version of the package" )
70+ flag .StringVar (& packageChannel , flagNamePackageChannel , "" , "Channel of the package" )
71+ // TODO: Consider adding support of multiple refs
72+ flag .StringVar (& indexRef , flagNameIndexRef , "" , "Index reference (FBC image or dir)" )
6173 flag .Parse ()
6274
63- if err := validateFlags (packageName ); err != nil {
75+ if err := validateFlags (packageName , indexRef ); err != nil {
6476 fmt .Println (err )
6577 flag .Usage ()
6678 os .Exit (1 )
6779 }
6880
69- err := run (packageName , packageVersion , packageChannel )
81+ err := run (ctx , packageName , packageVersion , packageChannel , indexRef )
7082 if err != nil {
7183 fmt .Println (err )
7284 os .Exit (1 )
7385 }
7486}
7587
76- func validateFlags (packageName string ) error {
88+ func validateFlags (packageName , indexRef string ) error {
7789 if packageName == "" {
78- return errors .New ("missing required -package-name flag" )
90+ return fmt .Errorf ("missing required -%s flag" , flagNamePackageName )
91+ }
92+
93+ if indexRef == "" {
94+ return fmt .Errorf ("missing required -%s flag" , flagNameIndexRef )
7995 }
8096
8197 return nil
8298}
8399
84- func run (packageName , packageVersion , packageChannel string ) error {
85- ctx := context .Background ()
100+ func run (ctx context.Context , packageName , packageVersion , packageChannel , catalogRef string ) error {
86101 client , err := client .New (config .GetConfigOrDie (), client.Options {Scheme : scheme })
87102 if err != nil {
88103 return fmt .Errorf ("failed to create client: %w" , err )
89104 }
90105
91- packageVariableSource := NewPackageVariableSource (packageName , packageVersion , packageChannel )
92106 resolver := solver .NewDeppySolver (
93- entitysources .NewCatalogdEntitySource (client ),
94- append (olm.NestedVariableSource {packageVariableSource }, olm .NewOLMVariableSource (client )... ),
107+ NewIndexRefEntitySourceEntitySource (catalogRef ),
108+ olm.NestedVariableSource {
109+ NewPackageVariableSource (packageName , packageVersion , packageChannel ),
110+ func (inputVariableSource input.VariableSource ) (input.VariableSource , error ) {
111+ return olm .NewOperatorVariableSource (client , inputVariableSource ), nil
112+ },
113+ func (inputVariableSource input.VariableSource ) (input.VariableSource , error ) {
114+ return bundles_and_dependencies .NewBundlesAndDepsVariableSource (inputVariableSource ), nil
115+ },
116+ func (inputVariableSource input.VariableSource ) (input.VariableSource , error ) {
117+ return crd_constraints .NewCRDUniquenessConstraintsVariableSource (inputVariableSource ), nil
118+ },
119+ },
95120 )
96121
97122 bundleImage , err := resolve (ctx , resolver , packageName )
0 commit comments