Search code examples
gokuberneteskubernetes-helm

Helm SDK download chart from extenanl repository


I need to download chart which is located external OCI repository, when I download it using click on the link of the chart and version and provide user and password it works but not with the following code, this is what I tried and get an error

failed to download "https://fdr.cdn.repositories.amp/artifactory/control-1.0.0.tgz" at version "1.0.0" (hint: running helm repo update may help) , if I click on the above link it asks for user and pass (in the browser) and when I provide it (the same in the code) the chart is downloaded, any idea why with the code its not working?

This is what I tried

    package main

import (
    "fmt"
    "os"

    "helm.sh/helm/v3/pkg/action"
    "helm.sh/helm/v3/pkg/cli"
    "helm.sh/helm/v3/pkg/repo"
)

var config *cli.EnvSettings

func main() {
    config = cli.New()
    re := repo.Entry{
        Name:     "control",
        URL:      "https://fdr.cdn.repositories.amp/artifactory/control",
        Username:              "myuser",
        Password:              "mypass",
    }
    file, err := repo.LoadFile(config.RepositoryConfig)
    if err != nil {
        fmt.Println(err.Error())
    }
    file.Update(&re)
    file.WriteFile(config.RepositoryConfig, os.ModeAppend)

    co := action.ChartPathOptions{
        InsecureSkipTLSverify: false,
        RepoURL:               "https://fdr.cdn.repositories.amp/artifactory/control",
        Username:              "myuser",
        Password:              "mypass",
        Version:               "1.0.0",
    }

    fp, err := co.LocateChart("control", config)
    if err != nil {
        fmt.Println(err.Error())
    }
    fmt.Println(fp)
}

While debug the code I found where the error is coming from https://github.com/helm/helm/blob/release-3.6/pkg/downloader/chart_downloader.go#L352 it trying to find some cache which doesn't exist in my laptop, how could I disable it or some other solution to make it work?


Solution

  • I think you need to update your repository before locating the chart.

    This is the code the CLI uses to update the repositories.

    And this is the function that performs the update on the repositories.