Skip to content

Commit

Permalink
Add ability to modify chart in MongoDB and MysqlDB structs (#1637)
Browse files Browse the repository at this point in the history
* Add ability to configure MongoDB app via Options

* after review
added interface HelmApp and implemented in MongoDB and MysqlDB structs

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
alexvbg and mergify[bot] committed Sep 15, 2022
1 parent 6b63540 commit 5b28871
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
11 changes: 11 additions & 0 deletions pkg/app/helm_app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package app

import "github.com/kanisterio/kanister/pkg/helm"

type HelmApp interface {
App
// Chart returns the chart of this Helm app.
Chart() *helm.ChartInfo
// SetChart sets the chart of this Helm app.
SetChart(chart helm.ChartInfo)
}
12 changes: 11 additions & 1 deletion pkg/app/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type IsMasterOutput struct {
Ismaster bool `json:"ismaster"`
}

var _ HelmApp = &MongoDB{}

type MongoDB struct {
cli kubernetes.Interface
namespace string
Expand All @@ -50,7 +52,7 @@ type MongoDB struct {
}

// Last tested working version "9.0.0"
func NewMongoDB(name string) App {
func NewMongoDB(name string) HelmApp {
return &MongoDB{
username: "root",
name: name,
Expand All @@ -70,6 +72,14 @@ func NewMongoDB(name string) App {
}
}

func (mongo *MongoDB) Chart() *helm.ChartInfo {
return &mongo.chart
}

func (mongo *MongoDB) SetChart(chart helm.ChartInfo) {
mongo.chart = chart
}

func (mongo *MongoDB) Init(ctx context.Context) error {
// Instantiate Client SDKs
cfg, err := kube.LoadConfig()
Expand Down
26 changes: 11 additions & 15 deletions pkg/app/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,11 @@ type MysqlDB struct {
chart helm.ChartInfo
}

type MysqlDBOptions func(*MysqlDB)

func MysqlDBChartValues(values map[string]string) MysqlDBOptions {
return func(db *MysqlDB) {
for k, v := range values {
db.chart.Values[k] = v
}
}
}
var _ HelmApp = &MysqlDB{}

// Last tested working version "6.14.11"
func NewMysqlDB(name string, opts ...MysqlDBOptions) App {
m := MysqlDB{
func NewMysqlDB(name string) HelmApp {
return &MysqlDB{
name: name,
chart: helm.ChartInfo{
Release: appendRandString(name),
Expand All @@ -67,10 +59,14 @@ func NewMysqlDB(name string, opts ...MysqlDBOptions) App {
},
},
}
for _, opt := range opts {
opt(&m)
}
return &m
}

func (mdb *MysqlDB) Chart() *helm.ChartInfo {
return &mdb.chart
}

func (mdb *MysqlDB) SetChart(chart helm.ChartInfo) {
mdb.chart = chart
}

func (mdb *MysqlDB) Init(ctx context.Context) error {
Expand Down

0 comments on commit 5b28871

Please sign in to comment.