Skip to content

Commit 519cd1b

Browse files
committed
fix: Rename config -> values and release -> chart
1 parent dba6de7 commit 519cd1b

17 files changed

Lines changed: 93 additions & 250 deletions

File tree

api/v1/weightsandbiases_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ type WeightsAndBiasesSpec struct {
3737

3838
// +kubebuilder:validation:Optional
3939
// +kubebuilder:pruning:PreserveUnknownFields
40-
Release Object `json:"release,omitempty"`
40+
Chart Object `json:"chart,omitempty"`
4141

4242
// +kubebuilder:validation:Optional
4343
// +kubebuilder:pruning:PreserveUnknownFields
44-
Config Object `json:"config,omitempty"`
44+
Values Object `json:"values,omitempty"`
4545
}
4646

4747
// Unstructured values for rendering CDK8s Config.

api/v1/zz_generated.deepcopy.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/apps.wandb.com_weightsandbiases.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ spec:
3636
spec:
3737
description: WeightsAndBiasesSpec defines the desired state of WeightsAndBiases
3838
properties:
39-
config:
39+
chart:
4040
description: Unstructured values for rendering CDK8s Config.
4141
type: object
4242
x-kubernetes-preserve-unknown-fields: true
43-
release:
43+
values:
4444
description: Unstructured values for rendering CDK8s Config.
4545
type: object
4646
x-kubernetes-preserve-unknown-fields: true

controllers/weightsandbiases_controller.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (r *WeightsAndBiasesReconciler) Reconcile(ctx context.Context, req ctrl.Req
9999
userInputSpec, _ := specManager.GetUserInput()
100100
if userInputSpec == nil {
101101
log.Info("No user spec found, creating a new one")
102-
userInputSpec := &spec.Spec{Config: map[string]interface{}{}}
102+
userInputSpec := &spec.Spec{Values: map[string]interface{}{}}
103103
specManager.SetUserInput(userInputSpec)
104104
}
105105

@@ -127,17 +127,17 @@ func (r *WeightsAndBiasesReconciler) Reconcile(ctx context.Context, req ctrl.Req
127127
hasNotBeenFlaggedForDeletion := wandb.ObjectMeta.DeletionTimestamp.IsZero()
128128

129129
if hasNotBeenFlaggedForDeletion {
130-
if desiredSpec.Release == nil {
130+
if desiredSpec.Chart == nil {
131131
statusManager.Set(status.InvalidConfig)
132132
log.Error(err, "No release type was found in the spec")
133133
return ctrlqueue.DoNotRequeue()
134134
}
135-
t := reflect.TypeOf(desiredSpec.Release)
135+
t := reflect.TypeOf(desiredSpec.Chart)
136136
typ := t.Name()
137137
if t.Kind() == reflect.Ptr {
138138
typ = "*" + t.Elem().Name()
139139
}
140-
log.Info("Found release type "+typ, "release", reflect.TypeOf(desiredSpec.Release))
140+
log.Info("Found release type "+typ, "release", reflect.TypeOf(desiredSpec.Chart))
141141

142142
statusManager.Set(status.Loading)
143143

@@ -179,8 +179,8 @@ func (r *WeightsAndBiasesReconciler) Reconcile(ctx context.Context, req ctrl.Req
179179
}
180180

181181
if ctrlqueue.ContainsString(wandb.ObjectMeta.Finalizers, resFinalizer) {
182-
if desiredSpec.Release != nil {
183-
log.Info("Deprovisioning", "release", reflect.TypeOf(desiredSpec.Release))
182+
if desiredSpec.Chart != nil {
183+
log.Info("Deprovisioning", "release", reflect.TypeOf(desiredSpec.Chart))
184184
if err := desiredSpec.Prune(ctx, r.Client, wandb, r.Scheme); err != nil {
185185
log.Error(err, "Failed to cleanup deployment.")
186186
} else {

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package deployer
22

33
import (
4-
"bytes"
54
"encoding/json"
5+
"fmt"
66
"io"
77
"net/http"
88

@@ -18,25 +18,13 @@ func GetURL() string {
1818
return utils.Getenv("DEPLOYER_CHANNEL_URL", DeployerAPI)
1919
}
2020

21-
type Payload struct {
22-
Metadata map[string]string `json:"metadata"`
23-
}
24-
2521
// GetSpec returns the spec for the given license. If the license or an empty
2622
// string it will pull down the latest stable version.
2723
func GetSpec(license string, activeState *spec.Spec) (*spec.Spec, error) {
2824
url := GetURL()
2925
client := &http.Client{}
3026

31-
payload := new(Payload)
32-
if activeState != nil {
33-
// Config can hold secrets. We shouldn't submit it.
34-
payload.Metadata = activeState.Metadata
35-
}
36-
37-
payloadBytes, _ := json.Marshal(payload)
38-
body := bytes.NewReader(payloadBytes)
39-
req, err := http.NewRequest(http.MethodPost, url, body)
27+
req, err := http.NewRequest(http.MethodGet, url, nil)
4028
if err != nil {
4129
return nil, err
4230
}
@@ -54,6 +42,8 @@ func GetSpec(license string, activeState *spec.Spec) (*spec.Spec, error) {
5442
return nil, err
5543
}
5644

45+
fmt.Println("resBody: ", string(resBody))
46+
5747
var spec spec.Spec
5848
err = json.Unmarshal(resBody, &spec)
5949
if err != nil {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package release
1+
package charts
22

33
import (
44
"encoding/json"
55
"fmt"
66

77
"github.com/wandb/operator/pkg/wandb/spec"
8-
"github.com/wandb/operator/pkg/wandb/spec/release/helm"
8+
"github.com/wandb/operator/pkg/wandb/spec/charts/helm"
99
)
1010

1111
func Is(v spec.Validatable, data interface{}) error {
@@ -26,12 +26,12 @@ func Is(v spec.Validatable, data interface{}) error {
2626
}
2727

2828
type ValidatableRelease interface {
29-
spec.HelmRelease
29+
spec.Chart
3030
spec.Validatable
3131
}
3232

3333
// Get returns tries to match the spec of a given type to a release.
34-
func Get(maybeRelease interface{}) spec.HelmRelease {
34+
func Get(maybeRelease interface{}) spec.Chart {
3535
releases := []ValidatableRelease{
3636
new(helm.LocalRelease),
3737
new(helm.RepoRelease),
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (r LocalRelease) Apply(
4242
c client.Client,
4343
wandb *v1.WeightsAndBiases,
4444
scheme *runtime.Scheme,
45-
config spec.Config,
45+
values spec.Values,
4646
) error {
4747
actionableChart, err := r.getActionableChart(wandb)
4848
if err != nil {
@@ -54,7 +54,7 @@ func (r LocalRelease) Apply(
5454
return err
5555
}
5656

57-
_, err = actionableChart.Apply(chart, config)
57+
_, err = actionableChart.Apply(chart, values)
5858
return err
5959
}
6060

@@ -63,7 +63,7 @@ func (r LocalRelease) Prune(
6363
c client.Client,
6464
wandb *v1.WeightsAndBiases,
6565
scheme *runtime.Scheme,
66-
_ spec.Config,
66+
_ spec.Values,
6767
) error {
6868
actionableChart, err := r.getActionableChart(wandb)
6969
if err != nil {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (r RepoRelease) Apply(
5656
c client.Client,
5757
wandb *v1.WeightsAndBiases,
5858
scheme *runtime.Scheme,
59-
config spec.Config,
59+
config spec.Values,
6060
) error {
6161
local, err := r.ToLocalRelease()
6262
if err != nil {
@@ -70,7 +70,7 @@ func (r RepoRelease) Prune(
7070
c client.Client,
7171
wandb *v1.WeightsAndBiases,
7272
scheme *runtime.Scheme,
73-
config spec.Config,
73+
config spec.Values,
7474
) error {
7575
local, err := r.ToLocalRelease()
7676
if err != nil {

pkg/wandb/spec/config.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"sigs.k8s.io/yaml"
1414
)
1515

16-
// Config holds an arbitrary tree-like data structure, such as parsed JSON or
16+
// Values holds an arbitrary tree-like data structure, such as parsed JSON or
1717
// YAML. It can be used to represent Helm-like values.
1818
//
1919
// You can use convenient accessors to work with this data structure.
@@ -22,10 +22,10 @@ import (
2222
// type of the embedded lists and objects. To avoid any error or an unexpected
2323
// behavior use `[]interface{}` for lists and `map[string]interface{}` for
2424
// nested objects.
25-
type Config map[string]interface{}
25+
type Values map[string]interface{}
2626

2727
// AsMap returns the underlying map. This maybe be useful for external libraries.
28-
func (v Config) AsMap() map[string]interface{} {
28+
func (v Values) AsMap() map[string]interface{} {
2929
return v
3030
}
3131

@@ -34,7 +34,7 @@ func (v Config) AsMap() map[string]interface{} {
3434
//
3535
// It will return an error, if the key does not exist or can not be traversed,
3636
// for example nested keys of a leaf node of the tree.
37-
func (v Config) GetValue(key string) (interface{}, error) {
37+
func (v Values) GetValue(key string) (interface{}, error) {
3838
cursor := v
3939
keyElements := []string{}
4040

@@ -74,7 +74,7 @@ func (v Config) GetValue(key string) (interface{}, error) {
7474
// or an empty string.
7575
//
7676
// Use `HasKey` to check if the `key` exist.
77-
func (v Config) GetString(key string, defaultValue ...string) string {
77+
func (v Values) GetString(key string, defaultValue ...string) string {
7878
defaultValueToUse := ""
7979
if len(defaultValue) > 0 {
8080
defaultValueToUse = defaultValue[0]
@@ -102,7 +102,7 @@ func (v Config) GetString(key string, defaultValue ...string) string {
102102
// optional `defaultValue` or `false`.
103103
//
104104
// Use `HasKey` to check if the `key` exist.
105-
func (v Config) GetBool(key string, defaultValue ...bool) bool {
105+
func (v Values) GetBool(key string, defaultValue ...bool) bool {
106106
defaultValueToUse := false
107107
if len(defaultValue) > 0 {
108108
defaultValueToUse = defaultValue[0]
@@ -121,7 +121,7 @@ func (v Config) GetBool(key string, defaultValue ...bool) bool {
121121
// and it does not support array indexing. When it returns `true` the getter
122122
// methods, e.g. `GetValue`, can successfully retrieve the associated value of
123123
// the key.
124-
func (v Config) HasKey(key string) bool {
124+
func (v Values) HasKey(key string) bool {
125125
if _, err := v.GetValue(key); err == nil {
126126
return true
127127
}
@@ -136,7 +136,7 @@ func (v Config) HasKey(key string) bool {
136136
// the provided value. It will create any intermediate nested object that
137137
// doesn't exist. But it will return an error when the key can not be traversed,
138138
// for example nested keys of a leaf node of the tree.
139-
func (v Config) SetValue(key string, value interface{}) error {
139+
func (v Values) SetValue(key string, value interface{}) error {
140140
if key == "" {
141141
return errors.Errorf("can not set the root element")
142142
}
@@ -178,7 +178,7 @@ func (v Config) SetValue(key string, value interface{}) error {
178178
// values as valid values.
179179
//
180180
// It retruns an error if the underlying merge utility encounters an error.
181-
func (v Config) Merge(newValues Config) error {
181+
func (v Values) Merge(newValues Values) error {
182182
if err := mergo.Merge(&v, newValues, mergo.WithOverride); err != nil {
183183
return errors.Wrapf(err, "can not merge new values")
184184
}
@@ -194,15 +194,15 @@ func (v Config) Merge(newValues Config) error {
194194
//
195195
// It uses Helm SDK coalesce function and does not return an error when fails
196196
// to merge specific entries. Therefore it may lead to an incorrect output.
197-
func (v Config) Coalesce(newValues Config) {
197+
func (v Values) Coalesce(newValues Values) {
198198
chartutil.CoalesceTables(v, newValues)
199199
}
200200

201201
// AddHelmValue sets the specified value using Helm style key and value format.
202202
// This is similar to `--set key=value` command argument of Helm. It does not
203203
// support multiple keys and values. It returns an error if it can not parse
204204
// the key or assign the value.
205-
func (v Config) AddHelmValue(key, value string) error {
205+
func (v Values) AddHelmValue(key, value string) error {
206206
if err := strvals.ParseInto(fmt.Sprintf("%s=%s", key, value), v); err != nil {
207207
return errors.Wrapf(err, "failed to set value: %s=%s", key, value)
208208
}
@@ -214,16 +214,16 @@ func (v Config) AddHelmValue(key, value string) error {
214214
//
215215
// It will return an error if it fails to parse the YAML content or encounters
216216
// an error while merging. For more details see `Merge` function.
217-
func (v Config) AddFromYAML(content string) error {
217+
func (v Values) AddFromYAML(content string) error {
218218
return v.AddFromYAMLBuffer([]byte(content))
219219
}
220220

221221
// AddFromYAMLBuffer merges the values from the provided YAML.
222222
//
223223
// It will return an error if it fails to parse the YAML content or encounters
224224
// an error while merging. For more details see `Merge` function.
225-
func (v Config) AddFromYAMLBuffer(content []byte) error {
226-
newValues := Config{}
225+
func (v Values) AddFromYAMLBuffer(content []byte) error {
226+
newValues := Values{}
227227

228228
if err := yaml.Unmarshal(content, &newValues); err != nil {
229229
return errors.Wrapf(err, "failed to parse yaml content")
@@ -236,7 +236,7 @@ func (v Config) AddFromYAMLBuffer(content []byte) error {
236236
//
237237
// It will return an error if it fails to read or parse the YAML file or
238238
// encounters an error while merging. For more details see `Merge` function.
239-
func (v Config) AddFromYAMLFile(filePath string) error {
239+
func (v Values) AddFromYAMLFile(filePath string) error {
240240
fileContent, err := os.ReadFile(filePath)
241241
if err != nil {
242242
return errors.Wrapf(err, "failed to read file: %s", filePath)

pkg/wandb/spec/operator/operator.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
v1 "github.com/wandb/operator/api/v1"
77
"github.com/wandb/operator/pkg/wandb/spec"
8-
"github.com/wandb/operator/pkg/wandb/spec/release"
8+
"github.com/wandb/operator/pkg/wandb/spec/charts"
99
"k8s.io/apimachinery/pkg/runtime"
1010
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
1111
)
@@ -19,8 +19,8 @@ func Defaults(wandb *v1.WeightsAndBiases, scheme *runtime.Scheme) *spec.Spec {
1919
}
2020
gvk, _ := apiutil.GVKForObject(wandb, scheme)
2121
return &spec.Spec{
22-
Release: nil,
23-
Config: map[string]interface{}{
22+
Chart: nil,
23+
Values: map[string]interface{}{
2424
"global": map[string]interface{}{
2525
"operator": map[string]interface{}{
2626
"apiVersion": gvk.GroupVersion().String(),
@@ -34,7 +34,7 @@ func Defaults(wandb *v1.WeightsAndBiases, scheme *runtime.Scheme) *spec.Spec {
3434
// Spec returns the spec for the given CRD.
3535
func Spec(wandb *v1.WeightsAndBiases) *spec.Spec {
3636
return &spec.Spec{
37-
Release: release.Get(wandb.Spec.Release.Object),
38-
Config: wandb.Spec.Config.Object,
37+
Chart: charts.Get(wandb.Spec.Chart.Object),
38+
Values: wandb.Spec.Values.Object,
3939
}
4040
}

0 commit comments

Comments
 (0)