Skip to content

Commit 6e763a8

Browse files
committed
fix: Channel spec not getting applied correctly
1 parent 8c4ddcd commit 6e763a8

6 files changed

Lines changed: 15 additions & 59 deletions

File tree

controllers/weightsandbiases_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,17 @@ func (r *WeightsAndBiasesReconciler) Reconcile(ctx context.Context, req ctrl.Req
110110
// This can happen on first one.
111111
log.Info("No active spec found.")
112112
}
113-
license := utils.GetLicense(crdSpec, userInputSpec)
113+
114+
license := utils.GetLicense(crdSpec, userInputSpec, currentActiveSpec)
114115
deployerSpec, err := deployer.GetSpec(license, currentActiveSpec)
115116
if err != nil {
116117
log.Info("Failed to get spec from deployer", "error", err)
117118
}
118119

119120
desiredSpec := new(spec.Spec)
120121
desiredSpec.Merge(operator.Defaults(wandb, r.Scheme))
121-
desiredSpec.Merge(userInputSpec)
122122
desiredSpec.Merge(deployerSpec)
123+
desiredSpec.Merge(userInputSpec)
123124
desiredSpec.Merge(crdSpec)
124125

125126
log.Info("Desired spec", "spec", desiredSpec)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.19
44

55
require (
66
github.com/go-playground/validator/v10 v10.15.0
7-
github.com/imdario/mergo v0.3.15
87
github.com/onsi/ginkgo/v2 v2.9.1
98
github.com/onsi/gomega v1.27.4
109
github.com/pkg/errors v0.9.1
@@ -14,7 +13,6 @@ require (
1413
k8s.io/client-go v0.26.4
1514
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5
1615
sigs.k8s.io/controller-runtime v0.14.1
17-
sigs.k8s.io/yaml v1.3.0
1816
)
1917

2018
require (
@@ -73,6 +71,7 @@ require (
7371
github.com/gosuri/uitable v0.0.4 // indirect
7472
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
7573
github.com/huandu/xstrings v1.4.0 // indirect
74+
github.com/imdario/mergo v0.3.15 // indirect
7675
github.com/inconshreveable/mousetrap v1.0.1 // indirect
7776
github.com/jmoiron/sqlx v1.3.5 // indirect
7877
github.com/josharian/intern v1.0.0 // indirect
@@ -153,4 +152,5 @@ require (
153152
sigs.k8s.io/kustomize/api v0.12.1 // indirect
154153
sigs.k8s.io/kustomize/kyaml v0.13.9 // indirect
155154
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
155+
sigs.k8s.io/yaml v1.3.0 // indirect
156156
)

pkg/wandb/spec/channel/deployer/deployer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ func GetSpec(license string, activeState *spec.Spec) (*spec.Spec, error) {
6363
spec := new(spec.Spec)
6464
spec.Metadata = specUnknown.Metadata
6565
spec.Chart = charts.Get(specUnknown.Chart)
66-
if spec.Values != nil {
67-
spec.Values = *specUnknown.Values
66+
if specUnknown.Values != nil {
67+
spec.SetValues(*specUnknown.Values)
6868
}
6969

7070
return spec, nil

pkg/wandb/spec/config.go

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ package spec
22

33
import (
44
"fmt"
5-
"os"
65
"strings"
76

8-
"github.com/imdario/mergo"
97
"github.com/pkg/errors"
8+
"github.com/wandb/operator/pkg/utils"
109

1110
"helm.sh/helm/v3/pkg/chartutil"
1211
"helm.sh/helm/v3/pkg/strvals"
13-
"sigs.k8s.io/yaml"
1412
)
1513

1614
// Values holds an arbitrary tree-like data structure, such as parsed JSON or
@@ -172,18 +170,8 @@ func (v Values) SetValue(key string, value interface{}) error {
172170
// Merge uses deep copy to merge the content of another data structure. It
173171
// overrides the existing keys with their associated new values and copies the
174172
// missing keys.
175-
//
176-
// Merge can traverse nested values, it does not deep copy slices and treats
177-
// them as scalar values. It does not do any type checking and treats `nil`
178-
// values as valid values.
179-
//
180-
// It retruns an error if the underlying merge utility encounters an error.
181-
func (v Values) Merge(newValues Values) error {
182-
if err := mergo.Merge(&v, newValues, mergo.WithOverride); err != nil {
183-
return errors.Wrapf(err, "can not merge new values")
184-
}
185-
186-
return nil
173+
func (v Values) Merge(newValues Values) (Values, error) {
174+
return utils.MergeMapString(v.AsMap(), newValues.AsMap())
187175
}
188176

189177
// Coalesce uses Helm-style coalesce to merge the content of another data
@@ -209,38 +197,3 @@ func (v Values) AddHelmValue(key, value string) error {
209197

210198
return nil
211199
}
212-
213-
// AddFromYAML merges the values from the provided YAML.
214-
//
215-
// It will return an error if it fails to parse the YAML content or encounters
216-
// an error while merging. For more details see `Merge` function.
217-
func (v Values) AddFromYAML(content string) error {
218-
return v.AddFromYAMLBuffer([]byte(content))
219-
}
220-
221-
// AddFromYAMLBuffer merges the values from the provided YAML.
222-
//
223-
// It will return an error if it fails to parse the YAML content or encounters
224-
// an error while merging. For more details see `Merge` function.
225-
func (v Values) AddFromYAMLBuffer(content []byte) error {
226-
newValues := Values{}
227-
228-
if err := yaml.Unmarshal(content, &newValues); err != nil {
229-
return errors.Wrapf(err, "failed to parse yaml content")
230-
}
231-
232-
return v.Merge(newValues)
233-
}
234-
235-
// AddFromYAMLFile merges the values from the specified YAML file.
236-
//
237-
// It will return an error if it fails to read or parse the YAML file or
238-
// encounters an error while merging. For more details see `Merge` function.
239-
func (v Values) AddFromYAMLFile(filePath string) error {
240-
fileContent, err := os.ReadFile(filePath)
241-
if err != nil {
242-
return errors.Wrapf(err, "failed to read file: %s", filePath)
243-
}
244-
245-
return v.AddFromYAMLBuffer(fileContent)
246-
}

pkg/wandb/spec/spec.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ func (s *Spec) mergeConfig(values Values) (err error) {
8989
s.Values = values
9090
return nil
9191
}
92-
if err := s.Values.Merge(values); err != nil {
92+
mergedValues, err := s.Values.Merge(values)
93+
if err != nil {
9394
return err
9495
}
96+
s.Values = mergedValues
9597
return nil
9698
}
9799

pkg/wandb/spec/state/secrets/secrets.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ func write(
8787
Namespace: objKey.Namespace,
8888
},
8989
Data: map[string][]byte{
90-
"chart": chartJson,
91-
"values": valuesJson,
90+
"chart": chartJson,
91+
"values": valuesJson,
9292
},
9393
}
9494
if err := controllerutil.SetControllerReference(owner, secret, scheme); err != nil {

0 commit comments

Comments
 (0)