From ca364363d6ee41bca42a1ce5a31a0ddb5cd316ad Mon Sep 17 00:00:00 2001 From: Alex Buchanan Date: Wed, 18 Sep 2024 08:15:18 -0700 Subject: [PATCH] feat: --chart flag --- internal/cmd/local/local/cmd.go | 2 +- internal/cmd/local/local/install.go | 5 ++++- internal/cmd/local/local/install_test.go | 3 +-- internal/cmd/local/local/locate.go | 7 ++++++- internal/cmd/local/local/locate_test.go | 11 +++++++++++ internal/cmd/local/local_install.go | 2 ++ 6 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 internal/cmd/local/local/locate_test.go diff --git a/internal/cmd/local/local/cmd.go b/internal/cmd/local/local/cmd.go index 507dfaf..608c052 100644 --- a/internal/cmd/local/local/cmd.go +++ b/internal/cmd/local/local/cmd.go @@ -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 { diff --git a/internal/cmd/local/local/install.go b/internal/cmd/local/local/install.go index b6c1ee8..1cefd4a 100644 --- a/internal/cmd/local/local/install.go +++ b/internal/cmd/local/local/install.go @@ -42,6 +42,7 @@ const ( ) type InstallOpts struct { + HelmChartFlag string HelmChartVersion string ValuesFile string Secrets []string @@ -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, @@ -524,6 +526,7 @@ type chartRequest struct { repoURL string chartName string chartRelease string + chartFlag string chartVersion string namespace string values []string @@ -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 { diff --git a/internal/cmd/local/local/install_test.go b/internal/cmd/local/local/install_test.go index a48343b..ca8c27d 100644 --- a/internal/cmd/local/local/install_test.go +++ b/internal/cmd/local/local/install_test.go @@ -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 } @@ -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) } - } diff --git a/internal/cmd/local/local/locate.go b/internal/cmd/local/local/locate.go index 8550db9..64fd8cd 100644 --- a/internal/cmd/local/local/locate.go +++ b/internal/cmd/local/local/locate.go @@ -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 diff --git a/internal/cmd/local/local/locate_test.go b/internal/cmd/local/local/locate_test.go new file mode 100644 index 0000000..405a13d --- /dev/null +++ b/internal/cmd/local/local/locate_test.go @@ -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) + } +} diff --git a/internal/cmd/local/local_install.go b/internal/cmd/local/local_install.go index e869b15..1f2b0e1 100644 --- a/internal/cmd/local/local_install.go +++ b/internal/cmd/local/local_install.go @@ -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"` @@ -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,