Skip to content

Commit 8004608

Browse files
committed
pkg/values: export Mapper and MapperFunc
1 parent 159caaf commit 8004608

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

pkg/reconciler/internal/values/values.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"helm.sh/helm/v3/pkg/chartutil"
2424
"helm.sh/helm/v3/pkg/strvals"
2525
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
26+
27+
"github.com/joelanford/helm-operator/pkg/values"
2628
)
2729

2830
type Values struct {
@@ -65,14 +67,4 @@ func (v *Values) ApplyOverrides(in map[string]string) error {
6567
return nil
6668
}
6769

68-
type Mapper interface {
69-
Map(chartutil.Values) chartutil.Values
70-
}
71-
72-
type MapperFunc func(chartutil.Values) chartutil.Values
73-
74-
var DefaultMapper = MapperFunc(func(v chartutil.Values) chartutil.Values { return v })
75-
76-
func (m MapperFunc) Map(v chartutil.Values) chartutil.Values {
77-
return m(v)
78-
}
70+
var DefaultMapper = values.MapperFunc(func(v chartutil.Values) chartutil.Values { return v })

pkg/reconciler/reconciler.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ import (
5252
"github.com/joelanford/helm-operator/pkg/reconciler/internal/conditions"
5353
internalhook "github.com/joelanford/helm-operator/pkg/reconciler/internal/hook"
5454
"github.com/joelanford/helm-operator/pkg/reconciler/internal/updater"
55-
"github.com/joelanford/helm-operator/pkg/reconciler/internal/values"
55+
internalvalues "github.com/joelanford/helm-operator/pkg/reconciler/internal/values"
56+
"github.com/joelanford/helm-operator/pkg/values"
5657
)
5758

5859
const uninstallFinalizer = "uninstall-helm-release"
@@ -245,7 +246,7 @@ func WithOverrideValues(overrides map[string]string) Option {
245246
// Validate that overrides can be parsed and applied
246247
// so that we fail fast during operator setup rather
247248
// than during the first reconciliation.
248-
m := values.New(map[string]interface{}{})
249+
m := internalvalues.New(map[string]interface{}{})
249250
if err := m.ApplyOverrides(overrides); err != nil {
250251
return err
251252
}
@@ -549,7 +550,7 @@ func (r *Reconciler) Reconcile(req ctrl.Request) (res ctrl.Result, err error) {
549550
}
550551

551552
func (r *Reconciler) getValues(obj *unstructured.Unstructured) (chartutil.Values, error) {
552-
crVals, err := values.FromUnstructured(obj)
553+
crVals, err := internalvalues.FromUnstructured(obj)
553554
if err != nil {
554555
return chartutil.Values{}, err
555556
}
@@ -768,7 +769,7 @@ func (r *Reconciler) addDefaults(mgr ctrl.Manager, controllerName string) {
768769
r.eventRecorder = mgr.GetEventRecorderFor(controllerName)
769770
}
770771
if r.valueMapper == nil {
771-
r.valueMapper = values.DefaultMapper
772+
r.valueMapper = internalvalues.DefaultMapper
772773
}
773774
}
774775

pkg/reconciler/reconciler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import (
5858
"github.com/joelanford/helm-operator/pkg/internal/testutil"
5959
"github.com/joelanford/helm-operator/pkg/reconciler/internal/conditions"
6060
helmfake "github.com/joelanford/helm-operator/pkg/reconciler/internal/fake"
61-
"github.com/joelanford/helm-operator/pkg/reconciler/internal/values"
61+
"github.com/joelanford/helm-operator/pkg/values"
6262
)
6363

6464
var _ = Describe("Reconciler", func() {

pkg/values/values.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2020 The Operator-SDK Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package values
18+
19+
import (
20+
"helm.sh/helm/v3/pkg/chartutil"
21+
)
22+
23+
type Mapper interface {
24+
Map(chartutil.Values) chartutil.Values
25+
}
26+
27+
type MapperFunc func(chartutil.Values) chartutil.Values
28+
29+
func (m MapperFunc) Map(v chartutil.Values) chartutil.Values {
30+
return m(v)
31+
}

0 commit comments

Comments
 (0)