Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Create new generic bundle provisioner
Browse files Browse the repository at this point in the history
Also, remove plain and registry bundle provisioners and move their logic
into the respective bundle deployment provisioners.

Signed-off-by: Joe Lanford <[email protected]>
  • Loading branch information
joelanford committed Dec 16, 2023
1 parent b4e9976 commit 13fadd2
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 69 deletions.
23 changes: 12 additions & 11 deletions cmd/core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"github.com/operator-framework/rukpak/internal/controllers/bundle"
"github.com/operator-framework/rukpak/internal/controllers/bundledeployment"
"github.com/operator-framework/rukpak/internal/finalizer"
"github.com/operator-framework/rukpak/internal/provisioner/generic"
"github.com/operator-framework/rukpak/internal/provisioner/plain"
"github.com/operator-framework/rukpak/internal/provisioner/registry"
"github.com/operator-framework/rukpak/internal/source"
Expand Down Expand Up @@ -247,28 +248,28 @@ func main() {

if err := bundle.SetupWithManager(mgr, systemNsCluster.GetCache(), systemNamespace, append(
commonBundleProvisionerOptions,
bundle.WithProvisionerID(plain.ProvisionerID),
bundle.WithHandler(bundle.HandlerFunc(plain.HandleBundle)),
bundle.WithProvisionerID(generic.ProvisionerID),
bundle.WithHandler(bundle.HandlerFunc(generic.HandleBundle)),
)...); err != nil {
setupLog.Error(err, "unable to create controller", "controller", rukpakv1alpha1.BundleKind, "provisionerID", plain.ProvisionerID)
setupLog.Error(err, "unable to create controller", "controller", rukpakv1alpha1.BundleKind, "provisionerID", generic.ProvisionerID)
os.Exit(1)
}

if err := bundle.SetupWithManager(mgr, systemNsCluster.GetCache(), systemNamespace, append(
commonBundleProvisionerOptions,
bundle.WithProvisionerID(registry.ProvisionerID),
bundle.WithHandler(bundle.HandlerFunc(registry.HandleBundle)),
if err := bundledeployment.SetupWithManager(mgr, append(
commonBDProvisionerOptions,
bundledeployment.WithProvisionerID(plain.ProvisionerID),
bundledeployment.WithHandler(bundledeployment.HandlerFunc(plain.HandleBundleDeployment)),
)...); err != nil {
setupLog.Error(err, "unable to create controller", "controller", rukpakv1alpha1.BundleKind, "provisionerID", registry.ProvisionerID)
setupLog.Error(err, "unable to create controller", "controller", rukpakv1alpha1.BundleDeploymentKind, "provisionerID", plain.ProvisionerID)
os.Exit(1)
}

if err := bundledeployment.SetupWithManager(mgr, append(
commonBDProvisionerOptions,
bundledeployment.WithProvisionerID(plain.ProvisionerID),
bundledeployment.WithHandler(bundledeployment.HandlerFunc(plain.HandleBundleDeployment)),
bundledeployment.WithProvisionerID(registry.ProvisionerID),
bundledeployment.WithHandler(bundledeployment.HandlerFunc(registry.HandleBundleDeployment)),
)...); err != nil {
setupLog.Error(err, "unable to create controller", "controller", rukpakv1alpha1.BundleDeploymentKind, "provisionerID", plain.ProvisionerID)
setupLog.Error(err, "unable to create controller", "controller", rukpakv1alpha1.BundleDeploymentKind, "provisionerID", registry.ProvisionerID)
os.Exit(1)
}
//+kubebuilder:scaffold:builder
Expand Down
3 changes: 2 additions & 1 deletion cmd/rukpakctl/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"

"github.com/operator-framework/rukpak/internal/provisioner/generic"
"github.com/operator-framework/rukpak/internal/provisioner/plain"
"github.com/operator-framework/rukpak/internal/rukpakctl"
"github.com/operator-framework/rukpak/internal/util"
Expand Down Expand Up @@ -85,6 +86,6 @@ one version to the next.
cmd.Flags().StringVar(&uploadServiceName, "upload-service-name", util.DefaultUploadServiceName, "the name of the service of the upload manager.")
cmd.Flags().StringVar(&caSecretName, "ca-secret-name", "rukpak-ca", "the name of the secret in the system namespace containing the root CAs used to authenticate the upload service.")
cmd.Flags().StringVar(&bundleDeploymentProvisionerClassName, "bundle-deployment-provisioner-class", plain.ProvisionerID, "Provisioner class name to set on bundle deployment.")
cmd.Flags().StringVar(&bundleProvisionerClassName, "bundle-provisioner-class", plain.ProvisionerID, "Provisioner class name to set on bundle.")
cmd.Flags().StringVar(&bundleProvisionerClassName, "bundle-provisioner-class", generic.ProvisionerID, "Provisioner class name to set on bundle.")
return cmd
}
17 changes: 17 additions & 0 deletions internal/provisioner/generic/generic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package generic

import (
"context"
"io/fs"

rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
)

const (
// ProvisionerID is the unique plain provisioner ID
ProvisionerID = "core-rukpak-io-generic"
)

func HandleBundle(_ context.Context, fsys fs.FS, _ *rukpakv1alpha1.Bundle) (fs.FS, error) {
return fsys, nil
}
11 changes: 4 additions & 7 deletions internal/provisioner/plain/plain.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ const (
manifestsDir = "manifests"
)

func HandleBundle(_ context.Context, fsys fs.FS, _ *rukpakv1alpha1.Bundle) (fs.FS, error) {
func HandleBundleDeployment(_ context.Context, fsys fs.FS, bd *rukpakv1alpha1.BundleDeployment) (*chart.Chart, chartutil.Values, error) {
if err := ValidateBundle(fsys); err != nil {
return nil, err
return nil, nil, err
}
return fsys, nil
}

func HandleBundleDeployment(_ context.Context, fsys fs.FS, bd *rukpakv1alpha1.BundleDeployment) (*chart.Chart, chartutil.Values, error) {
chrt, err := chartFromBundle(fsys, bd)
chrt, err := ChartFromBundle(fsys, bd)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -81,7 +78,7 @@ func getObjects(bundle fs.FS, manifest fs.DirEntry) ([]client.Object, error) {
return util.ManifestObjects(manifestReader, manifestPath)
}

func chartFromBundle(fsys fs.FS, bd *rukpakv1alpha1.BundleDeployment) (*chart.Chart, error) {
func ChartFromBundle(fsys fs.FS, bd *rukpakv1alpha1.BundleDeployment) (*chart.Chart, error) {
objects, err := getBundleObjects(fsys)
if err != nil {
return nil, fmt.Errorf("read bundle objects from bundle: %v", err)
Expand Down
16 changes: 12 additions & 4 deletions internal/provisioner/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"fmt"
"io/fs"

"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chartutil"

rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
"github.com/operator-framework/rukpak/internal/convert"
"github.com/operator-framework/rukpak/internal/provisioner/plain"
Expand All @@ -15,14 +18,19 @@ const (
ProvisionerID = "core-rukpak-io-registry"
)

func HandleBundle(_ context.Context, fsys fs.FS, _ *rukpakv1alpha1.Bundle) (fs.FS, error) {
func HandleBundleDeployment(_ context.Context, fsys fs.FS, bd *rukpakv1alpha1.BundleDeployment) (*chart.Chart, chartutil.Values, error) {
plainFS, err := convert.RegistryV1ToPlain(fsys)
if err != nil {
return nil, fmt.Errorf("convert registry+v1 bundle to plain+v0 bundle: %v", err)
return nil, nil, fmt.Errorf("convert registry+v1 bundle to plain+v0 bundle: %v", err)
}

if err := plain.ValidateBundle(plainFS); err != nil {
return nil, fmt.Errorf("validate bundle: %v", err)
return nil, nil, fmt.Errorf("validate bundle: %v", err)
}

chrt, err := plain.ChartFromBundle(plainFS, bd)
if err != nil {
return nil, nil, err
}
return plainFS, nil
return chrt, nil, nil
}
Loading

0 comments on commit 13fadd2

Please sign in to comment.