Skip to content

Commit

Permalink
Fixes chart overrides (smartcontractkit#195)
Browse files Browse the repository at this point in the history
* Fixes chart overrides
* Updates helmenv
  • Loading branch information
kalverra authored Jan 24, 2022
1 parent ffa9a24 commit fd305d2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 61 deletions.
28 changes: 17 additions & 11 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,30 +145,36 @@ func (l *LocalStore) Fetch() ([]string, error) {
// chart values. It returns a JSON block that can be set to the `CHARTS` environment variable that the helmenv library
// will read from. This will merge the override values with the default values for the appropriate charts.
func (cfg *FrameworkConfig) CreateChartOverrrides() (string, error) {
chartOverrides := ChartOverrides{
ChainlinkChartOverrride: ChainlinkChart{
Values: ChainlinkValuesWrapper{
ChainlinkVals: ChainlinkValues{
Image: ChainlinkImage{
chartOverrides := ChartOverrides{}
// Don't marshall chainlink if there's no chainlink values provided
if cfg.ChainlinkImage != "" || cfg.ChainlinkVersion != "" || len(cfg.ChainlinkEnvValues) != 0 {
chartOverrides.ChainlinkChartOverrride = &ChainlinkChart{
Values: &ChainlinkValuesWrapper{
ChainlinkVals: &ChainlinkValues{
Image: &ChainlinkImage{
Image: cfg.ChainlinkImage,
Version: cfg.ChainlinkVersion,
},
},
EnvironmentVariables: cfg.ChainlinkEnvValues,
},
},
GethChartOverride: GethChart{
Values: GethValuesWrapper{
GethVals: GethValues{
Image: GethImage{
}
}
// Don't marshall geth if there's no geth values provided
if cfg.GethImage != "" || cfg.GethVersion != "" || len(cfg.GethArgs) != 0 {
chartOverrides.GethChartOverride = &GethChart{
Values: &GethValuesWrapper{
GethVals: &GethValues{
Image: &GethImage{
Image: cfg.GethImage,
Version: cfg.GethVersion,
},
},
Args: cfg.GethArgs,
},
},
}
}

jsonChartOverrides, err := json.Marshal(chartOverrides)
return string(jsonChartOverrides), err
}
16 changes: 8 additions & 8 deletions config/config_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@ type LoggingConfig struct {

// ChartOverrides enables building json styled chart overrides for the deployed chart values and environment variables
type ChartOverrides struct {
GethChartOverride GethChart `json:"geth,omitempty"`
ChainlinkChartOverrride ChainlinkChart `json:"chainlink,omitempty"`
GethChartOverride *GethChart `json:"geth,omitempty"`
ChainlinkChartOverrride *ChainlinkChart `json:"chainlink,omitempty"`
}

// GethChart holds the overall geth chart values
type GethChart struct {
Values GethValuesWrapper `json:"values,omitempty"`
Values *GethValuesWrapper `json:"values,omitempty"`
}

// GethValuesWrapper geth values wrapper
type GethValuesWrapper struct {
GethVals GethValues `json:"geth,omitempty"`
GethVals *GethValues `json:"geth,omitempty"`
Args []interface{} `json:"args,omitempty"`
}

type GethValues struct {
Image GethImage `json:"image,omitempty"`
Image *GethImage `json:"image,omitempty"`
}

type GethImage struct {
Expand All @@ -85,17 +85,17 @@ type GethImage struct {

// ChainlinkChart holds the overall geth chart values
type ChainlinkChart struct {
Values ChainlinkValuesWrapper `json:"values,omitempty"`
Values *ChainlinkValuesWrapper `json:"values,omitempty"`
}

// ChainlinkValuesWrapper Chainlink values wrapper
type ChainlinkValuesWrapper struct {
ChainlinkVals ChainlinkValues `json:"chainlink,omitempty"`
ChainlinkVals *ChainlinkValues `json:"chainlink,omitempty"`
EnvironmentVariables map[string]string `json:"env,omitempty" yaml:"chainlink_env_values"`
}

type ChainlinkValues struct {
Image ChainlinkImage `json:"image,omitempty"`
Image *ChainlinkImage `json:"image,omitempty"`
}

type ChainlinkImage struct {
Expand Down
38 changes: 1 addition & 37 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,7 @@ func TestChartCreation(t *testing.T) {
t.Parallel()

emptyConfig := config.FrameworkConfig{}
emptyChartString := `{
"geth": {
"values": {
"geth": {
"image": {}
}
}
},
"chainlink": {
"values": {
"chainlink": {
"image": {}
}
}
}
}`
emptyChartString := `{}`
chart, err := emptyConfig.CreateChartOverrrides()
require.NoError(t, err)
require.JSONEq(t, emptyChartString, chart, "Expected an empty config to produce an empty object for chart overrides")
Expand Down Expand Up @@ -86,13 +71,6 @@ func TestChartCreation(t *testing.T) {
"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
]
}
},
"chainlink": {
"values": {
"chainlink": {
"image": {}
}
}
}
}`
chart, err = gethOnlyConfig.CreateChartOverrrides()
Expand All @@ -104,13 +82,6 @@ func TestChartCreation(t *testing.T) {
ChainlinkVersion: "testChainlinkVersion",
}
chainlinkOnlyChartString := `{
"geth": {
"values": {
"geth": {
"image": {}
}
}
},
"chainlink":{
"values":{
"chainlink":{
Expand All @@ -131,13 +102,6 @@ func TestChartCreation(t *testing.T) {
"test_int_val": "420",
}
chainlinkOnlyChartString = `{
"geth": {
"values": {
"geth": {
"image": {}
}
}
},
"chainlink":{
"values":{
"chainlink":{
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.17

require (
github.com/ethereum/go-ethereum v1.10.11
github.com/ghodss/yaml v1.0.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/onsi/ginkgo/v2 v2.0.0
github.com/onsi/gomega v1.17.0
Expand All @@ -13,11 +12,10 @@ require (
github.com/prometheus/common v0.32.1
github.com/rs/zerolog v1.26.1
github.com/satori/go.uuid v1.2.0
github.com/smartcontractkit/helmenv v1.0.23
github.com/smartcontractkit/helmenv v1.0.25
github.com/smartcontractkit/libocr v0.0.0-20210826183649-d12971936c12
github.com/spf13/viper v1.10.1
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
k8s.io/client-go v0.23.1
)

require (
Expand All @@ -33,10 +31,12 @@ require (
github.com/fatih/camelcase v1.0.0 // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/fvbommel/sortorder v1.0.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
helm.sh/helm/v3 v3.7.2 // indirect
k8s.io/api v0.23.1 // indirect
k8s.io/apimachinery v0.23.1 // indirect
k8s.io/client-go v0.23.1 // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1792,8 +1792,8 @@ github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartcontractkit/chainlink v0.8.10-0.20200825114219-81dd2fc95bac/go.mod h1:j7qIYHGCN4QqMXdO8g8A9dmUT5vKFmkxPSbjAIfrfNU=
github.com/smartcontractkit/chainlink v0.9.5-0.20201207211610-6c7fee37d5b7/go.mod h1:kmdLJbVZRCnBLiL6gG+U+1+0ofT3bB48DOF8tjQvcoI=
github.com/smartcontractkit/helmenv v1.0.23 h1:i6fXppyr8CCSwuat05J/NRpc75bncCDfWemnDjymqBo=
github.com/smartcontractkit/helmenv v1.0.23/go.mod h1:ef0doolSZf8ckqaWMIK2M+EPXdIKYVzttd6EXaCgCK4=
github.com/smartcontractkit/helmenv v1.0.25 h1:FxVzDyMa5GjIHAsK9puHbraoSM1Z7IThN6oqEz8cukU=
github.com/smartcontractkit/helmenv v1.0.25/go.mod h1:ef0doolSZf8ckqaWMIK2M+EPXdIKYVzttd6EXaCgCK4=
github.com/smartcontractkit/libocr v0.0.0-20201203233047-5d9b24f0cbb5/go.mod h1:bfdSuLnBWCkafDvPGsQ1V6nrXhg046gh227MKi4zkpc=
github.com/smartcontractkit/libocr v0.0.0-20210826183649-d12971936c12 h1:3yXjCJgj91ZRRqq4cV++y2EkKefEJpiWxhvnI14rclw=
github.com/smartcontractkit/libocr v0.0.0-20210826183649-d12971936c12/go.mod h1:AQktwBooI+Y/8NWdvIzU+EgGoLzpe3mo+o+jluMonTw=
Expand Down

0 comments on commit fd305d2

Please sign in to comment.