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 legacy Helm code base #115

Merged
merged 5 commits into from
Dec 10, 2021
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
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ require (
github.com/onsi/gomega v1.14.0
github.com/operator-framework/operator-lib v0.3.0
github.com/prometheus/client_golang v1.11.0
github.com/sergi/go-diff v1.1.0
github.com/sirupsen/logrus v1.8.1
github.com/spf13/afero v1.2.2
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
gomodules.xyz/jsonpatch/v2 v2.2.0
gomodules.xyz/jsonpatch/v3 v3.0.1
helm.sh/helm/v3 v3.6.2
k8s.io/api v0.22.1
k8s.io/apiextensions-apiserver v0.22.1
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1263,10 +1263,6 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
gomodules.xyz/jsonpatch/v2 v2.1.0/go.mod h1:IhYNNY4jnS53ZnfE4PAmpKtDpTCj1JFXc+3mwe7XcUU=
gomodules.xyz/jsonpatch/v2 v2.2.0 h1:4pT439QV83L+G9FkcCriY6EkpcK6r6bK+A5FBUMI7qY=
gomodules.xyz/jsonpatch/v2 v2.2.0/go.mod h1:WXp+iVDkoLQqPudfQ9GBlwB2eZ5DKOnjQZCYdOS8GPY=
gomodules.xyz/jsonpatch/v3 v3.0.1 h1:Te7hKxV52TKCbNYq3t84tzKav3xhThdvSsSp/W89IyI=
gomodules.xyz/jsonpatch/v3 v3.0.1/go.mod h1:CBhndykehEwTOlEfnsfJwvkFQbSN8YZFr9M+cIHAJto=
gomodules.xyz/orderedmap v0.1.0 h1:fM/+TGh/O1KkqGR5xjTKg6bU8OKBkg7p0Y+x/J9m8Os=
gomodules.xyz/orderedmap v0.1.0/go.mod h1:g9/TPUCm1t2gwD3j3zfV8uylyYhVdCNSi+xCEIu7yTU=
google.golang.org/api v0.0.0-20160322025152-9bf6e6e569ff/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
Expand Down
58 changes: 44 additions & 14 deletions internal/cmd/helm-operator/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ import (
"strings"

"github.com/operator-framework/helm-operator-plugins/internal/flags"
"github.com/operator-framework/helm-operator-plugins/internal/legacy/controller"
"github.com/operator-framework/helm-operator-plugins/internal/legacy/release"
watches "github.com/operator-framework/helm-operator-plugins/internal/legacy/watches"
"github.com/operator-framework/helm-operator-plugins/internal/metrics"
"github.com/operator-framework/helm-operator-plugins/internal/version"
"github.com/operator-framework/helm-operator-plugins/pkg/annotation"
helmmgr "github.com/operator-framework/helm-operator-plugins/pkg/manager"
"github.com/operator-framework/helm-operator-plugins/pkg/reconciler"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader"

"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -167,30 +170,47 @@ func run(cmd *cobra.Command, f *flags.Flags) {
os.Exit(1)
}

// TODO: remove legacy watches and use watches from lib
ws, err := watches.Load(f.WatchesFile)
if err != nil {
log.Error(err, "Failed to create new manager factories.")
os.Exit(1)
}

for _, w := range ws {
// Register the controller with the factory.
err := controller.Add(mgr, controller.WatchOptions{
Namespace: namespace,
GVK: w.GroupVersionKind,
ManagerFactory: release.NewManagerFactory(mgr, w.ChartDir),
ReconcilePeriod: f.ReconcilePeriod,
WatchDependentResources: *w.WatchDependentResources,
OverrideValues: w.OverrideValues,
MaxConcurrentReconciles: f.MaxConcurrentReconciles,
Selector: w.Selector,
})

// TODO: remove this after modifying watches of hybrid lib.
cl, err := getChart(w)
if err != nil {
log.Error(err, "Failed to add manager factory to controller.")
log.Error(err, "Unable to read chart")
os.Exit(1)
}

r, err := reconciler.New(
reconciler.WithChart(*cl),
reconciler.WithGroupVersionKind(w.GroupVersionKind),
reconciler.WithOverrideValues(w.OverrideValues),
reconciler.WithSelector(w.Selector),
reconciler.SkipDependentWatches(*w.WatchDependentResources),
reconciler.WithMaxConcurrentReconciles(f.MaxConcurrentReconciles),
reconciler.WithReconcilePeriod(f.ReconcilePeriod),
reconciler.WithInstallAnnotations(annotation.DefaultInstallAnnotations...),
reconciler.WithUpgradeAnnotations(annotation.DefaultUpgradeAnnotations...),
reconciler.WithUninstallAnnotations(annotation.DefaultUninstallAnnotations...),
)
if err != nil {
log.Error(err, "unable to creste helm reconciler", "controller", "Helm")
os.Exit(1)
}

if err := r.SetupWithManager(mgr); err != nil {
log.Error(err, "unable to create controller", "Helm")
os.Exit(1)
}
log.Info("configured watch", "gvk", w.GroupVersionKind, "chartDir", w.ChartDir, "maxConcurrentReconciles", f.MaxConcurrentReconciles, "reconcilePeriod", f.ReconcilePeriod)
}

log.Info("starting manager")
// Start the Cmd
if err = mgr.Start(signals.SetupSignalHandler()); err != nil {
log.Error(err, "Manager exited non-zero.")
Expand Down Expand Up @@ -219,3 +239,13 @@ func exitIfUnsupported(options manager.Options) {
os.Exit(1)
}
}

// getChart returns the chart from the chartDir passed to the watches file.
func getChart(w watches.Watch) (*chart.Chart, error) {
c, err := loader.LoadDir(w.ChartDir)
if err != nil {
return nil, fmt.Errorf("failed to load chart dir: %w", err)
}

return c, nil
}
209 changes: 0 additions & 209 deletions internal/legacy/controller/controller.go

This file was deleted.

39 changes: 0 additions & 39 deletions internal/legacy/controller/controller_test.go

This file was deleted.

18 changes: 0 additions & 18 deletions internal/legacy/controller/doc.go

This file was deleted.

Loading