Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: --chart flag #121

Merged
merged 6 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Installs a local Airbyte instance or updates an existing installation which was

| Name | Default | Description |
|---------------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| --chart | "" | Path to chart. |
| --chart-version | latest | Which Airbyte helm-chart version to install. |
| --docker-email | "" | Docker email address to authenticate against `--docker-server`.<br />Can also be specified by the environment-variable `ABCTL_LOCAL_INSTALL_DOCKER_EMAIL`. |
| --docker-password | "" | Docker password to authenticate against `--docker-server`.<br />Can also be specified by the environment-variable `ABCTL_LOCAL_INSTALL_DOCKER_PASSWORD`. |
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/local/docker/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
func Secret(server, user, pass, email string) ([]byte, error) {
// map of the server to the credentials
return json.Marshal(map[string]any{
"auths": map[string]any {
server: map[string]any {
"auths": map[string]any{
server: map[string]any{
"username": user,
"password": pass,
"email": email,
"auth": base64.StdEncoding.EncodeToString([]byte(user + ":" + pass)),
},
},
})
}
}
2 changes: 1 addition & 1 deletion internal/cmd/local/k8s/k8stest/k8stest.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type MockClient struct {
FnEventsWatch func(ctx context.Context, namespace string) (watch.Interface, error)
FnLogsGet func(ctx context.Context, namespace string, name string) (string, error)
FnStreamPodLogs func(ctx context.Context, namespace, podName string, since time.Time) (io.ReadCloser, error)
FnPodList func(ctx context.Context, namespace string) (*corev1.PodList, error)
FnPodList func(ctx context.Context, namespace string) (*corev1.PodList, error)
}

func (m *MockClient) DeploymentList(ctx context.Context, namespace string) (*v1.DeploymentList, error) {
Expand Down
24 changes: 12 additions & 12 deletions internal/cmd/local/local/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import (

const (
airbyteBootloaderPodName = "airbyte-abctl-airbyte-bootloader"
airbyteChartName = "airbyte/airbyte"
airbyteChartRelease = "airbyte-abctl"
airbyteIngress = "ingress-abctl"
airbyteNamespace = "airbyte-abctl"
airbyteRepoName = "airbyte"
airbyteRepoURL = "https://airbytehq.github.io/helm-charts"
nginxChartName = "nginx/ingress-nginx"
nginxChartRelease = "ingress-nginx"
nginxNamespace = "ingress-nginx"
nginxRepoName = "nginx"
nginxRepoURL = "https://kubernetes.github.io/ingress-nginx"
airbyteChartName = "airbyte/airbyte"
airbyteChartRelease = "airbyte-abctl"
airbyteIngress = "ingress-abctl"
airbyteNamespace = "airbyte-abctl"
airbyteRepoName = "airbyte"
airbyteRepoURL = "https://airbytehq.github.io/helm-charts"
nginxChartName = "nginx/ingress-nginx"
nginxChartRelease = "ingress-nginx"
nginxNamespace = "ingress-nginx"
nginxRepoName = "nginx"
nginxRepoURL = "https://kubernetes.github.io/ingress-nginx"
)

// dockerAuthSecretName is the name of the secret which holds the docker authentication information.
Expand All @@ -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
7 changes: 5 additions & 2 deletions 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
HelmValues map[string]any
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 Expand Up @@ -746,7 +749,7 @@ func determineHelmChartAction(helm helm.Client, chart *chart.Chart, releaseName
// values provided were potentially overridden by the valuesYML file.
func mergeValuesWithValuesYAML(values []string, userValues map[string]any) (string, error) {
a := maps.FromSlice(values)

maps.Merge(a, userValues)

res, err := maps.ToYAML(a)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/local/local/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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
7 changes: 6 additions & 1 deletion internal/cmd/local/local/locate.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ var defaultNewChartRepo newChartRepo = func(cfg *repo.Entry, getters getter.Prov
// This variable should only be modified for testing purposes.
var defaultLoadIndexFile loadIndexFile = repo.LoadIndexFile

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
10 changes: 9 additions & 1 deletion internal/cmd/local/local/locate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import (
"helm.sh/helm/v3/pkg/repo"
)

func TestLocateChartFlag(t *testing.T) {
expect := "chartFlagValue"
c := locateLatestAirbyteChart("airbyte", "", expect)
if c != expect {
t.Errorf("expected %q but got %q", expect, c)
}
}

func TestLocate(t *testing.T) {
origNewChartRepo := defaultNewChartRepo
origLoadIndexFile := defaultLoadIndexFile
Expand Down Expand Up @@ -90,7 +98,7 @@ func TestLocate(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defaultLoadIndexFile = mockLoadIndexFile(repo.IndexFile{Entries: tt.entries})
act := locateLatestAirbyteChart(airbyteChartName, "")
act := locateLatestAirbyteChart(airbyteChartName, "", "")
if d := cmp.Diff(tt.exp, act); d != "" {
t.Errorf("mismatch (-want +got):\n%s", d)
}
Expand Down
4 changes: 1 addition & 3 deletions internal/cmd/local/local/log_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestJavaLogScanner(t *testing.T) {

expectLogLine := func(level, msg string) {
s.Scan()

if s.line.level != level {
t.Errorf("expected level %q but got %q", level, s.line.level)
}
Expand Down Expand Up @@ -58,5 +58,3 @@ func TestLastErrorLog(t *testing.T) {
t.Errorf("expected %q but got %q", expect, l)
}
}


2 changes: 1 addition & 1 deletion internal/cmd/local/local/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ func (c *Command) Status(_ context.Context) error {
pterm.Info.Println(fmt.Sprintf("Airbyte should be accessible via http://localhost:%d", c.portHTTP))

return nil
}
}
4 changes: 3 additions & 1 deletion internal/cmd/local/local_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
)

type InstallCmd struct {
ChartVersion string `default:"latest" help:"Version to install."`
Chart string `help:"Path to chart." xor:"chartver"`
ChartVersion string `default:"latest" help:"Version to install." xor:"chartver"`
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"`
DockerServer string `group:"docker" default:"https://index.docker.io/v1/" help:"Docker server." env:"ABCTL_LOCAL_INSTALL_DOCKER_SERVER"`
Expand Down Expand Up @@ -114,6 +115,7 @@ func (i *InstallCmd) Run(ctx context.Context, provider k8s.Provider, telClient t
}

opts := local.InstallOpts{
HelmChartFlag: i.Chart,
HelmChartVersion: i.ChartVersion,
HelmValues: helmValues,
Secrets: i.Secret,
Expand Down
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func main() {

func run(ctx context.Context) error {


var root cmd.Cmd
parser, err := kong.New(
&root,
Expand Down