Skip to content

Commit

Permalink
feat: --chart flag
Browse files Browse the repository at this point in the history
  • Loading branch information
abuchanan-airbyte committed Sep 18, 2024
1 parent d70ad70 commit ca36436
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/local/local/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type HTTPClient interface {
type BrowserLauncher func(url string) error

// ChartLocator primarily for testing purposes.
type ChartLocator func(repoName, repoUrl string) string
type ChartLocator func(repoName, repoUrl, chartFlag string) string

// Command is the local command, responsible for installing, uninstalling, or other local actions.
type Command struct {
Expand Down
5 changes: 4 additions & 1 deletion internal/cmd/local/local/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
)

type InstallOpts struct {
HelmChartFlag string
HelmChartVersion string
ValuesFile string
Secrets []string
Expand Down Expand Up @@ -252,6 +253,7 @@ func (c *Command) Install(ctx context.Context, opts InstallOpts) error {
repoURL: airbyteRepoURL,
chartName: airbyteChartName,
chartRelease: airbyteChartRelease,
chartFlag: opts.HelmChartFlag,
chartVersion: opts.HelmChartVersion,
namespace: airbyteNamespace,
valuesYAML: valuesYAML,
Expand Down Expand Up @@ -524,6 +526,7 @@ type chartRequest struct {
repoURL string
chartName string
chartRelease string
chartFlag string
chartVersion string
namespace string
values []string
Expand All @@ -548,7 +551,7 @@ func (c *Command) handleChart(

c.spinner.UpdateText(fmt.Sprintf("Fetching %s Helm Chart with version", req.chartName))

chartLoc := c.locateChart(req.chartName, req.chartVersion)
chartLoc := c.locateChart(req.chartName, req.chartVersion, req.chartFlag)

helmChart, _, err := c.helm.GetChart(chartLoc, &action.ChartPathOptions{Version: req.chartVersion})
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions internal/cmd/local/local/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
const portTest = 9999
const testAirbyteChartLoc = "https://airbytehq.github.io/helm-charts/airbyte-1.2.3.tgz"

func testChartLocator(chartName, chartVersion string) string {
func testChartLocator(chartName, chartVersion, chartFlag string) string {
if chartName == airbyteChartName && chartVersion == "" {
return testAirbyteChartLoc
}
Expand Down Expand Up @@ -396,5 +396,4 @@ func TestCommand_Install_InvalidValuesFile(t *testing.T) {
if !strings.Contains(err.Error(), fmt.Sprintf("unable to read values from yaml file '%s'", valuesFile)) {
t.Error("unexpected error:", err)
}

}
7 changes: 6 additions & 1 deletion internal/cmd/local/local/locate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ import (
"helm.sh/helm/v3/pkg/repo"
)

func locateLatestAirbyteChart(chartName, chartVersion string) string {
func locateLatestAirbyteChart(chartName, chartVersion, chartFlag string) string {
pterm.Debug.Printf("getting helm chart %q with version %q\n", chartName, chartVersion)

// If the --chart flag was given, use that.
if chartFlag != "" {
return chartFlag
}

// Helm will consider a local directory path named "airbyte/airbyte" to be a chart repo,
// but it might not be, which causes errors like "Chart.yaml file is missing".
// This trips up plenty of people, see: https://github.com/helm/helm/issues/7862
Expand Down
11 changes: 11 additions & 0 deletions internal/cmd/local/local/locate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package local

import "testing"

func TestLocateChartFlag(t *testing.T) {
expect := "chartFlagValue"
c := locateLatestAirbyteChart("airbyte", "", expect)
if c != expect {
t.Errorf("expected %q but got %q", expect, c)
}
}
2 changes: 2 additions & 0 deletions internal/cmd/local/local_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

type InstallCmd struct {
Chart string `help:"Path to chart."`
ChartVersion string `default:"latest" help:"Version to install."`
DockerEmail string `group:"docker" help:"Docker email." env:"ABCTL_LOCAL_INSTALL_DOCKER_EMAIL"`
DockerPassword string `group:"docker" help:"Docker password." env:"ABCTL_LOCAL_INSTALL_DOCKER_PASSWORD"`
Expand Down Expand Up @@ -101,6 +102,7 @@ func (i *InstallCmd) Run(ctx context.Context, provider k8s.Provider, telClient t
}

opts := local.InstallOpts{
HelmChartFlag: i.Chart,
HelmChartVersion: i.ChartVersion,
ValuesFile: i.Values,
Secrets: i.Secret,
Expand Down

0 comments on commit ca36436

Please sign in to comment.