Skip to content

Commit

Permalink
Remove offline resolution CLI variable source
Browse files Browse the repository at this point in the history
Signed-off-by: Mikalai Radchuk <[email protected]>
  • Loading branch information
m1kola committed Oct 31, 2023
1 parent 7156464 commit 432c2f7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 60 deletions.
52 changes: 36 additions & 16 deletions cmd/resolutioncli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import (
"fmt"
"os"

"github.com/operator-framework/deppy/pkg/deppy/solver"
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
Expand All @@ -32,24 +31,25 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/fake"

catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
"github.com/operator-framework/deppy/pkg/deppy/solver"
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"

operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
"github.com/operator-framework/operator-controller/internal/controllers"
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
)

const pocMessage = `This command is a proof of concept for off-cluster resolution and is not intended for production use!
Please provide your feedback and ideas via https://github.com/operator-framework/operator-controller/discussions/262`

const (
flagNamePackageName = "package-name"
flagNamePackageVersion = "package-version"
flagNamePackageChannel = "package-channel"
flagNameIndexRef = "index-ref"
flagNameInputDir = "input-dir"
flagNamePackageName = "package-name"
flagNamePackageVersionRange = "package-version"
flagNamePackageChannel = "package-channel"
flagNameIndexRef = "index-ref"
flagNameInputDir = "input-dir"
)

var (
Expand All @@ -71,12 +71,12 @@ func main() {
ctx := context.Background()

var packageName string
var packageVersion string
var packageVersionRange string
var packageChannel string
var indexRef string
var inputDir string
flag.StringVar(&packageName, flagNamePackageName, "", "Name of the package to resolve")
flag.StringVar(&packageVersion, flagNamePackageVersion, "", "Version of the package")
flag.StringVar(&packageVersionRange, flagNamePackageVersionRange, "", "Version or version range of the package")
flag.StringVar(&packageChannel, flagNamePackageChannel, "", "Channel of the package")
// TODO: Consider adding support of multiple refs
flag.StringVar(&indexRef, flagNameIndexRef, "", "Index reference (FBC image or dir)")
Expand All @@ -89,7 +89,7 @@ func main() {
os.Exit(1)
}

err := run(ctx, packageName, packageVersion, packageChannel, indexRef, inputDir)
err := run(ctx, packageName, packageChannel, packageVersionRange, indexRef, inputDir)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
Expand All @@ -108,7 +108,19 @@ func validateFlags(packageName, indexRef string) error {
return nil
}

func run(ctx context.Context, packageName, packageVersion, packageChannel, indexRef, inputDir string) error {
func run(ctx context.Context, packageName, packageChannel, packageVersionRange, indexRef, inputDir string) error {
// Using the fake Kubernetes client and creating objects
// in it from manifests & CLI flags is fine for PoC.
// But when/if we decide to proceed with CLI/offline resolution
// we will need to come up with a better way to create inputs
// for resolver when working with CLI.
//
// We will need to think about multiple types of inputs:
// - How to read required package (what we want to install/update)
// - How to read bundles from multiple catalogs
// - How to take into account cluster information. Some package
// will have constraints like "need Kubernetes version to be >= X"
// or "need >= 3 worker nodes").
clientBuilder := fake.NewClientBuilder().WithScheme(scheme)

if inputDir != "" {
Expand All @@ -120,14 +132,22 @@ func run(ctx context.Context, packageName, packageVersion, packageChannel, index
clientBuilder.WithRuntimeObjects(objects...)
}

clientBuilder.WithRuntimeObjects(&operatorsv1alpha1.Operator{
ObjectMeta: metav1.ObjectMeta{
Name: "resolutioncli-input-operator",
},
Spec: operatorsv1alpha1.OperatorSpec{
PackageName: packageName,
Channel: packageChannel,
Version: packageVersionRange,
},
})

cl := clientBuilder.Build()
catalogClient := newIndexRefClient(indexRef)

resolver := solver.NewDeppySolver(
append(
variablesources.NestedVariableSource{newPackageVariableSource(catalogClient, packageName, packageVersion, packageChannel)},
controllers.NewVariableSource(cl, catalogClient)...,
),
controllers.NewVariableSource(cl, catalogClient),
)

bundleImage, err := resolve(ctx, resolver, packageName)
Expand Down
44 changes: 0 additions & 44 deletions cmd/resolutioncli/variable_source.go

This file was deleted.

0 comments on commit 432c2f7

Please sign in to comment.