Skip to content

Commit 1cdcd7f

Browse files
Remove legacy Helm code base (#115)
* Remove legacy reconciler and use hybridReconciler instead * Add option to configure watches with predicates * Revert helm/watches * Remove legacy helm codebase * add tests for parsepredicateSelector Signed-off-by: varshaprasad96 <[email protected]>
1 parent 2c20f02 commit 1cdcd7f

File tree

22 files changed

+103
-2399
lines changed

22 files changed

+103
-2399
lines changed

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ require (
1212
github.com/onsi/gomega v1.14.0
1313
github.com/operator-framework/operator-lib v0.3.0
1414
github.com/prometheus/client_golang v1.11.0
15-
github.com/sergi/go-diff v1.1.0
1615
github.com/sirupsen/logrus v1.8.1
1716
github.com/spf13/afero v1.2.2
1817
github.com/spf13/cobra v1.1.3
1918
github.com/spf13/pflag v1.0.5
2019
github.com/stretchr/testify v1.7.0
2120
gomodules.xyz/jsonpatch/v2 v2.2.0
22-
gomodules.xyz/jsonpatch/v3 v3.0.1
2321
helm.sh/helm/v3 v3.6.2
2422
k8s.io/api v0.22.1
2523
k8s.io/apiextensions-apiserver v0.22.1

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,10 +1263,6 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
12631263
gomodules.xyz/jsonpatch/v2 v2.1.0/go.mod h1:IhYNNY4jnS53ZnfE4PAmpKtDpTCj1JFXc+3mwe7XcUU=
12641264
gomodules.xyz/jsonpatch/v2 v2.2.0 h1:4pT439QV83L+G9FkcCriY6EkpcK6r6bK+A5FBUMI7qY=
12651265
gomodules.xyz/jsonpatch/v2 v2.2.0/go.mod h1:WXp+iVDkoLQqPudfQ9GBlwB2eZ5DKOnjQZCYdOS8GPY=
1266-
gomodules.xyz/jsonpatch/v3 v3.0.1 h1:Te7hKxV52TKCbNYq3t84tzKav3xhThdvSsSp/W89IyI=
1267-
gomodules.xyz/jsonpatch/v3 v3.0.1/go.mod h1:CBhndykehEwTOlEfnsfJwvkFQbSN8YZFr9M+cIHAJto=
1268-
gomodules.xyz/orderedmap v0.1.0 h1:fM/+TGh/O1KkqGR5xjTKg6bU8OKBkg7p0Y+x/J9m8Os=
1269-
gomodules.xyz/orderedmap v0.1.0/go.mod h1:g9/TPUCm1t2gwD3j3zfV8uylyYhVdCNSi+xCEIu7yTU=
12701266
google.golang.org/api v0.0.0-20160322025152-9bf6e6e569ff/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
12711267
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
12721268
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=

internal/cmd/helm-operator/run/cmd.go

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ import (
2323
"strings"
2424

2525
"github.com/operator-framework/helm-operator-plugins/internal/flags"
26-
"github.com/operator-framework/helm-operator-plugins/internal/legacy/controller"
27-
"github.com/operator-framework/helm-operator-plugins/internal/legacy/release"
2826
watches "github.com/operator-framework/helm-operator-plugins/internal/legacy/watches"
2927
"github.com/operator-framework/helm-operator-plugins/internal/metrics"
3028
"github.com/operator-framework/helm-operator-plugins/internal/version"
29+
"github.com/operator-framework/helm-operator-plugins/pkg/annotation"
3130
helmmgr "github.com/operator-framework/helm-operator-plugins/pkg/manager"
31+
"github.com/operator-framework/helm-operator-plugins/pkg/reconciler"
32+
"helm.sh/helm/v3/pkg/chart"
33+
"helm.sh/helm/v3/pkg/chart/loader"
34+
3235
"github.com/spf13/cobra"
3336
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3437
ctrl "sigs.k8s.io/controller-runtime"
@@ -167,30 +170,47 @@ func run(cmd *cobra.Command, f *flags.Flags) {
167170
os.Exit(1)
168171
}
169172

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

176180
for _, w := range ws {
177-
// Register the controller with the factory.
178-
err := controller.Add(mgr, controller.WatchOptions{
179-
Namespace: namespace,
180-
GVK: w.GroupVersionKind,
181-
ManagerFactory: release.NewManagerFactory(mgr, w.ChartDir),
182-
ReconcilePeriod: f.ReconcilePeriod,
183-
WatchDependentResources: *w.WatchDependentResources,
184-
OverrideValues: w.OverrideValues,
185-
MaxConcurrentReconciles: f.MaxConcurrentReconciles,
186-
Selector: w.Selector,
187-
})
181+
182+
// TODO: remove this after modifying watches of hybrid lib.
183+
cl, err := getChart(w)
188184
if err != nil {
189-
log.Error(err, "Failed to add manager factory to controller.")
185+
log.Error(err, "Unable to read chart")
186+
os.Exit(1)
187+
}
188+
189+
r, err := reconciler.New(
190+
reconciler.WithChart(*cl),
191+
reconciler.WithGroupVersionKind(w.GroupVersionKind),
192+
reconciler.WithOverrideValues(w.OverrideValues),
193+
reconciler.WithSelector(w.Selector),
194+
reconciler.SkipDependentWatches(*w.WatchDependentResources),
195+
reconciler.WithMaxConcurrentReconciles(f.MaxConcurrentReconciles),
196+
reconciler.WithReconcilePeriod(f.ReconcilePeriod),
197+
reconciler.WithInstallAnnotations(annotation.DefaultInstallAnnotations...),
198+
reconciler.WithUpgradeAnnotations(annotation.DefaultUpgradeAnnotations...),
199+
reconciler.WithUninstallAnnotations(annotation.DefaultUninstallAnnotations...),
200+
)
201+
if err != nil {
202+
log.Error(err, "unable to creste helm reconciler", "controller", "Helm")
203+
os.Exit(1)
204+
}
205+
206+
if err := r.SetupWithManager(mgr); err != nil {
207+
log.Error(err, "unable to create controller", "Helm")
190208
os.Exit(1)
191209
}
210+
log.Info("configured watch", "gvk", w.GroupVersionKind, "chartDir", w.ChartDir, "maxConcurrentReconciles", f.MaxConcurrentReconciles, "reconcilePeriod", f.ReconcilePeriod)
192211
}
193212

213+
log.Info("starting manager")
194214
// Start the Cmd
195215
if err = mgr.Start(signals.SetupSignalHandler()); err != nil {
196216
log.Error(err, "Manager exited non-zero.")
@@ -219,3 +239,13 @@ func exitIfUnsupported(options manager.Options) {
219239
os.Exit(1)
220240
}
221241
}
242+
243+
// getChart returns the chart from the chartDir passed to the watches file.
244+
func getChart(w watches.Watch) (*chart.Chart, error) {
245+
c, err := loader.LoadDir(w.ChartDir)
246+
if err != nil {
247+
return nil, fmt.Errorf("failed to load chart dir: %w", err)
248+
}
249+
250+
return c, nil
251+
}

internal/legacy/controller/controller.go

Lines changed: 0 additions & 209 deletions
This file was deleted.

internal/legacy/controller/controller_test.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

internal/legacy/controller/doc.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)