Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove offline resolution CLI variable source #495

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: likely good to use an import sorting linter to remove these diffs in the future

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.