Files
41536738c8 refactor(cd): hard-fork - rename CRD API group argoproj.io -> deploy.hanzo.ai (#1)
* feat(api): hard-fork CRD API group argoproj.io -> deploy.hanzo.ai

Hanzo CD hard-fork, phase 1.1. Single source of truth is
pkg/apis/application/register.go's Group constant (Application/AppProject/
ApplicationSet all derive their FullName from it); every other Go call-site
that hardcoded the literal group string is updated to match: the 3 generated
informer GVRs, the app-of-apps nested-Application detector in types.go, the
resource-tree Application-kind cache populator, the 3 NotFound error
constructors in server/application, and the applicationset-controller's
leader-election Lease name/ID (kept in lockstep across Go source + RBAC
resourceNames, or leader election would get RBAC-denied on startup).

CRD YAMLs (application/appproject/applicationset) and every RBAC apiGroups
rule that actually governs our 3 CRDs are repointed to deploy.hanzo.ai, across
both manifests/base/* (namespaced Roles) and manifests/cluster-rbac/* (cluster
scope). Two adjacent things that share the "argoproj.io" string but are NOT
ours are deliberately left untouched: gitops-engine's health-check dispatch
for Argo Workflows' `Workflow` kind, and argocd-server-clusterrole's second
apiGroups block granting read on Argo Workflows' `workflows` resource — both
belong to a separate, unrelated Argoproj-family project we are not forking.

Also untouched, per explicit scope: annotation/label keys (argocd.argoproj.io/*)
and finalizers (*.argoproj.io) that track already-applied live resources, and
argocd-cm.yaml's resource.customizations.ignoreResourceUpdates keys (a narrow
app-of-apps diffing nicety, not build- or RBAC-relevant).

CGO_ENABLED=0 go build ./... verified green.

* ci: wire canonical hanzo.yml + cicd.yml (Hanzo CD image build)

Phase 1.3. Follows the same one-way pattern every hanzo/lux/zoo repo uses:
hanzo.yml declares the image (root Dockerfile -> ghcr.io/hanzoai/deploy) and a
fast go-build sanity test (the multi-stage Dockerfile build is the slow, real
gate); cicd.yml is the ~10-line trigger shim importing hanzoai/ci's reusable
build workflow on the arc pool, secrets from KMS only.

No `deploy:` block yet, matching the hanzoai/cms build-only-first-cutover
pattern: this repo's own live hanzo-cd namespace runs the whole Hanzo fleet's
GitOps, so the prod image/CRD swap is a deliberate separate action (see the
[HELD] universe PR), never an automatic rollout on merge. Every PR/push still
builds and pushes an immutable ghcr.io/hanzoai/deploy:sha-<7>-amd64 image.

* feat(ui): rebrand Argo CD -> Hanzo CD (title, favicon, logo, sidebar)

Phase 1.2. User-facing "Argo CD"/"ArgoCD" text replaced with "Hanzo CD"
across the login page, help modal, settings screens, version-info panel,
sync-options warning, fullscreen-logs title, app.tsx page titles, and
index.html's <title>/noscript text (dropped the now-wrong upstream CLI
doc link rather than invent a hanzo.ai URL that doesn't exist).

Logo/favicon assets replaced with the canonical Hanzo mark (never
hand-drawn, copied from ~/work/hanzo/logo/dist): the two real usages of
Argo's logo collapse onto one Hanzo glyph (mono + white variants) at the
same 5 call sites (login icon + footer, login.scss $logoPath/
$logoNegativePath, sidebar text-logo), preserving the existing CSS
invert() filters so both the light login panel and dark sidebar still
render correctly. Old argologo.svg/argo_o.svg/argo.png deleted (no
longer referenced). favicon-{16x16,32x32}.png added at
ui/src/assets/favicon/ (index.html's links to that path were previously
dead - the directory didn't exist in this checkout). package.json name
argo-cd-ui -> hanzo-cd-ui.

Left alone, deliberately: the two Kubernetes resource-kind icon sets
under ui/src/assets/images/resources/ (unrelated to branding), and
upstream doc/project links (argoproj.io, argo-cd.readthedocs.io) since
we have no equivalent hanzo.ai docs to point to yet - except the login
footer logo's outbound link, which now points to hanzo.ai instead of
argoproj.io (a Hanzo-branded mark linking to the upstream project it
was forked from read as an obvious leftover).

* feat(module): rename Go module github.com/argoproj/argo-cd/v3 -> github.com/hanzoai/deploy

Phase 2. No version suffix on the new path (org policy: never publish our
own Go modules above v1.x.x / with a v2+ suffix) — this fork starts a fresh
v0/v1 module identity rather than carrying the v3 the upstream fork point
had reached.

Mechanical, symmetric rewrite: 704 .go files (import statements only; two
disjoint substitutions applied specific-first so the nested gitops-engine
module path never double-matches), plus go.mod (module line, the
gitops-engine require+replace pair, version reset to v0.0.0-... since a
suffix-less path can't carry a v3 semver), gitops-engine/go.mod, Makefile
(ldflags PACKAGE + 2 TEST_MODULE filters), .golangci.yaml, .goreleaser.yaml,
.mockery.yaml (+ gitops-engine's), Procfile, the codegen/proto generation
scripts (hack/generate-proto.sh, update-codegen.sh, update-openapi.sh), and
20 .proto files' go_package options. Also one OpenTelemetry tracer name
string in gitops-engine/pkg/sync/sync_context.go (a cosmestic label, not an
import, but worth keeping consistent).

CGO_ENABLED=0 go build ./... verified green for both the root module and
the nested gitops-engine module; go vet clean on both; go mod tidy run
(network available) to reconcile go.sum, dependency set unchanged.

Left alone, deliberately: doc-only mentions (docs/snyk/*.html scan reports,
gitops-engine/README.md), a comment-only reference in
.github/workflows/release.yaml, and one Renovate bot config line — none are
build- or codegen-load-bearing. Also left alone: comments citing upstream
GitHub issue URLs (github.com/argoproj/argo-cd/issues/NNNNN) and a handful
of test fixtures using "https://github.com/argoproj/argo-cd.git" as a
representative example repo URL — both are accurate historical/test-data
references, not stale self-references.

---------

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-29 18:27:58 -07:00

604 lines
19 KiB
Go

package helm
import (
"bytes"
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"time"
executil "github.com/hanzoai/deploy/util/exec"
"github.com/argoproj/pkg/v2/sync"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
"oras.land/oras-go/v2/registry/remote"
"oras.land/oras-go/v2/registry/remote/auth"
"oras.land/oras-go/v2/registry/remote/credentials"
"github.com/hanzoai/deploy/common"
"github.com/hanzoai/deploy/util/cache"
utilio "github.com/hanzoai/deploy/util/io"
"github.com/hanzoai/deploy/util/io/files"
"github.com/hanzoai/deploy/util/proxy"
)
var (
globalLock = sync.NewKeyLock()
indexLock = sync.NewKeyLock()
ErrOCINotEnabled = errors.New("could not perform the action when oci is not enabled")
)
// userAgentTransport wraps an http.RoundTripper to add User-Agent header to all requests
type userAgentTransport struct {
Transport http.RoundTripper
UserAgent string
}
// RoundTrip implements the http.RoundTripper interface
func (t *userAgentTransport) RoundTrip(req *http.Request) (*http.Response, error) {
req.Header.Set("User-Agent", t.UserAgent)
return t.Transport.RoundTrip(req)
}
type indexCache interface {
SetHelmIndex(repo string, indexData []byte) error
GetHelmIndex(repo string, indexData *[]byte) error
}
type Client interface {
CleanChartCache(chart string, version string) error
ExtractChart(ctx context.Context, chart string, version string, passCredentials bool, manifestMaxExtractedSize int64, disableManifestMaxExtractedSize bool) (string, utilio.Closer, error)
GetIndex(ctx context.Context, noCache bool, maxIndexSize int64) (*Index, error)
GetTags(ctx context.Context, chart string, noCache bool) ([]string, error)
TestHelmOCI() (bool, error)
}
type ClientOpts func(c *nativeHelmChart)
func WithIndexCache(indexCache indexCache) ClientOpts {
return func(c *nativeHelmChart) {
c.indexCache = indexCache
}
}
func WithChartPaths(chartPaths utilio.TempPaths) ClientOpts {
return func(c *nativeHelmChart) {
c.chartCachePaths = chartPaths
}
}
// WithUserAgent sets a custom User-Agent string for HTTP requests.
// If not set, a default User-Agent will be generated automatically.
func WithUserAgent(userAgent string) ClientOpts {
return func(c *nativeHelmChart) {
c.customUserAgent = userAgent
}
}
// WithPlainHTTP configures the client to use plain HTTP instead of HTTPS for OCI registry operations.
func WithPlainHTTP() ClientOpts {
return func(c *nativeHelmChart) {
c.plainHTTP = true
}
}
func NewClient(repoURL string, creds Creds, enableOci bool, proxy string, noProxy string, opts ...ClientOpts) Client {
return NewClientWithLock(repoURL, creds, globalLock, enableOci, proxy, noProxy, opts...)
}
func NewClientWithLock(repoURL string, creds Creds, repoLock sync.KeyLock, enableOci bool, proxy string, noProxy string, opts ...ClientOpts) Client {
c := &nativeHelmChart{
repoURL: repoURL,
creds: creds,
repoLock: repoLock,
enableOci: enableOci,
proxy: proxy,
noProxy: noProxy,
chartCachePaths: utilio.NewRandomizedTempPaths(os.TempDir()),
}
for i := range opts {
opts[i](c)
}
return c
}
// WithHelmChartCacheExpiration sets the cache expiration duration for chart cache.
func WithHelmChartCacheExpiration(helmChartCacheExpiration time.Duration) ClientOpts {
return func(c *nativeHelmChart) {
c.helmChartCacheExpiration = helmChartCacheExpiration
}
}
var _ Client = &nativeHelmChart{}
type nativeHelmChart struct {
chartCachePaths utilio.TempPaths
repoURL string
creds Creds
repoLock sync.KeyLock
enableOci bool
plainHTTP bool
indexCache indexCache
proxy string
noProxy string
customUserAgent string // Custom User-Agent string (optional)
helmChartCacheExpiration time.Duration // Cache expiration for chart cache
}
// getUserAgent returns the User-Agent string to use for HTTP requests.
// If a custom User-Agent is set, it will be used; otherwise, a default will be generated.
func (c *nativeHelmChart) getUserAgent() string {
if c.customUserAgent != "" {
return c.customUserAgent
}
// Default User-Agent with version and platform info
version := common.GetVersion()
return fmt.Sprintf("argocd-repo-server/%s (%s)", version.Version, version.Platform)
}
func fileExist(filePath string) (bool, error) {
if _, err := os.Stat(filePath); err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, fmt.Errorf("error checking file existence for %s: %w", filePath, err)
}
return true, nil
}
func (c *nativeHelmChart) CleanChartCache(chart string, version string) error {
cachePath, err := c.getCachedChartPath(chart, version)
if err != nil {
return fmt.Errorf("error getting cached chart path: %w", err)
}
if err := os.RemoveAll(cachePath); err != nil {
return fmt.Errorf("error removing chart cache at %s: %w", cachePath, err)
}
return nil
}
func untarChart(ctx context.Context, tempDir string, cachedChartPath string, manifestMaxExtractedSize int64, disableManifestMaxExtractedSize bool) error {
if disableManifestMaxExtractedSize {
cmd := exec.CommandContext(ctx, "tar", "-zxvf", cachedChartPath)
cmd.Dir = tempDir
_, err := executil.Run(cmd)
if err != nil {
return fmt.Errorf("error executing tar command: %w", err)
}
return nil
}
reader, err := os.Open(cachedChartPath)
if err != nil {
return fmt.Errorf("error opening cached chart path %s: %w", cachedChartPath, err)
}
return files.Untgz(tempDir, reader, manifestMaxExtractedSize, false)
}
func (c *nativeHelmChart) ExtractChart(ctx context.Context, chart string, version string, passCredentials bool, manifestMaxExtractedSize int64, disableManifestMaxExtractedSize bool) (string, utilio.Closer, error) {
// always use Helm V3 since we don't have chart content to determine correct Helm version
helmCmd, err := NewCmdWithVersion("", c.enableOci, c.proxy, c.noProxy)
if err != nil {
return "", nil, fmt.Errorf("error creating Helm command: %w", err)
}
defer helmCmd.Close()
// throw away temp directory that stores extracted chart and should be deleted as soon as no longer needed by returned closer
tempDir, err := files.CreateTempDir(os.TempDir())
if err != nil {
return "", nil, fmt.Errorf("error creating temporary directory: %w", err)
}
cachedChartPath, err := c.getCachedChartPath(chart, version)
if err != nil {
_ = os.RemoveAll(tempDir)
return "", nil, fmt.Errorf("error getting cached chart path: %w", err)
}
c.repoLock.Lock(cachedChartPath)
defer c.repoLock.Unlock(cachedChartPath)
// check if chart tar is already downloaded
exists, err := fileExist(cachedChartPath)
if err != nil {
_ = os.RemoveAll(tempDir)
return "", nil, fmt.Errorf("error checking existence of cached chart path: %w", err)
}
// if chart tar exists, check if it is expired based on cache expiration duration configuration.
if exists && c.helmChartCacheExpiration > 0 {
info, err := os.Stat(cachedChartPath)
if err != nil {
log.WithFields(log.Fields{
"path": cachedChartPath,
"err": err,
}).Warn("error checking cached Helm chart; removing cached archive")
_ = os.RemoveAll(cachedChartPath)
exists = false
} else if time.Since(info.ModTime()) > c.helmChartCacheExpiration {
if err := os.RemoveAll(cachedChartPath); err != nil {
_ = os.RemoveAll(tempDir)
return "", nil, fmt.Errorf(
"error removing expired cached chart: %w",
err,
)
}
exists = false
}
}
if !exists {
// create empty temp directory to extract chart from the registry
tempDest, err := files.CreateTempDir(os.TempDir())
if err != nil {
_ = os.RemoveAll(tempDir)
return "", nil, fmt.Errorf("error creating temporary destination directory: %w", err)
}
defer func() { _ = os.RemoveAll(tempDest) }()
if c.enableOci {
helmPassword, err := c.creds.GetPassword()
if err != nil {
return "", nil, fmt.Errorf("failed to get password for helm registry: %w", err)
}
if helmPassword != "" && c.creds.GetUsername() != "" {
_, err = helmCmd.RegistryLogin(c.repoURL, c.creds, c.plainHTTP)
if err != nil {
_ = os.RemoveAll(tempDir)
return "", nil, fmt.Errorf("error logging into OCI registry: %w", err)
}
defer func() {
_, _ = helmCmd.RegistryLogout(c.repoURL, c.creds)
}()
}
// 'helm pull' ensures that chart is downloaded into temp directory
_, err = helmCmd.PullOCI(c.repoURL, chart, version, tempDest, c.creds, c.plainHTTP)
if err != nil {
_ = os.RemoveAll(tempDir)
return "", nil, fmt.Errorf("error pulling OCI chart: %w", err)
}
} else {
_, err = helmCmd.Fetch(c.repoURL, chart, version, tempDest, c.creds, passCredentials)
if err != nil {
_ = os.RemoveAll(tempDir)
return "", nil, fmt.Errorf("error fetching chart: %w", err)
}
}
// 'helm pull/fetch' file downloads chart into the tgz file and we move that to where we want it
infos, err := os.ReadDir(tempDest)
if err != nil {
return "", nil, fmt.Errorf("error reading directory %s: %w", tempDest, err)
}
if len(infos) != 1 {
return "", nil, fmt.Errorf("expected 1 file, found %v", len(infos))
}
chartFilePath := filepath.Join(tempDest, infos[0].Name())
err = os.Rename(chartFilePath, cachedChartPath)
if err != nil {
return "", nil, fmt.Errorf("error renaming file from %s to %s: %w", chartFilePath, cachedChartPath, err)
}
}
err = untarChart(ctx, tempDir, cachedChartPath, manifestMaxExtractedSize, disableManifestMaxExtractedSize)
if err != nil {
_ = os.RemoveAll(tempDir)
return "", nil, fmt.Errorf("error untarring chart: %w", err)
}
return path.Join(tempDir, normalizeChartName(chart)), utilio.NewCloser(func() error {
return os.RemoveAll(tempDir)
}), nil
}
func (c *nativeHelmChart) GetIndex(ctx context.Context, noCache bool, maxIndexSize int64) (*Index, error) {
indexLock.Lock(c.repoURL)
defer indexLock.Unlock(c.repoURL)
var data []byte
if !noCache && c.indexCache != nil {
if err := c.indexCache.GetHelmIndex(c.repoURL, &data); err != nil && !errors.Is(err, cache.ErrCacheMiss) {
log.Warnf("Failed to load index cache for repo: %s: %v", c.repoURL, err)
}
}
if len(data) == 0 {
start := time.Now()
var err error
data, err = c.loadRepoIndex(ctx, maxIndexSize)
if err != nil {
return nil, fmt.Errorf("error loading repo index: %w", err)
}
log.WithFields(log.Fields{"seconds": time.Since(start).Seconds()}).Info("took to get index")
if c.indexCache != nil {
if err := c.indexCache.SetHelmIndex(c.repoURL, data); err != nil {
log.Warnf("Failed to store index cache for repo: %s: %v", c.repoURL, err)
}
}
}
index := &Index{}
err := yaml.NewDecoder(bytes.NewBuffer(data)).Decode(index)
if err != nil {
return nil, fmt.Errorf("error decoding index: %w", err)
}
return index, nil
}
func (c *nativeHelmChart) TestHelmOCI() (bool, error) {
start := time.Now()
tmpDir, err := os.MkdirTemp("", "helm")
if err != nil {
return false, fmt.Errorf("error creating temporary directory: %w", err)
}
defer func() { _ = os.RemoveAll(tmpDir) }()
helmCmd, err := NewCmdWithVersion(tmpDir, c.enableOci, c.proxy, c.noProxy)
if err != nil {
return false, fmt.Errorf("error creating Helm command: %w", err)
}
defer helmCmd.Close()
// Looks like there is no good way to test access to OCI repo if credentials are not provided
// just assume it is accessible
helmPassword, err := c.creds.GetPassword()
if err != nil {
return false, fmt.Errorf("failed to get password for helm registry: %w", err)
}
if c.creds.GetUsername() != "" && helmPassword != "" {
_, err = helmCmd.RegistryLogin(c.repoURL, c.creds, c.plainHTTP)
if err != nil {
return false, fmt.Errorf("error logging into OCI registry: %w", err)
}
defer func() {
_, _ = helmCmd.RegistryLogout(c.repoURL, c.creds)
}()
log.WithFields(log.Fields{"seconds": time.Since(start).Seconds()}).Info("took to test helm oci repository")
}
return true, nil
}
func (c *nativeHelmChart) loadRepoIndex(ctx context.Context, maxIndexSize int64) ([]byte, error) {
indexURL, err := getIndexURL(c.repoURL)
if err != nil {
return nil, fmt.Errorf("error getting index URL: %w", err)
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, indexURL, http.NoBody)
if err != nil {
return nil, fmt.Errorf("error creating HTTP request: %w", err)
}
// Set User-Agent header to comply with robot policies
req.Header.Set("User-Agent", c.getUserAgent())
helmPassword, err := c.creds.GetPassword()
if err != nil {
return nil, fmt.Errorf("failed to get password for helm registry: %w", err)
}
if c.creds.GetUsername() != "" || helmPassword != "" {
// only basic supported
req.SetBasicAuth(c.creds.GetUsername(), helmPassword)
}
tlsConf, err := newTLSConfig(c.creds)
if err != nil {
return nil, fmt.Errorf("error creating TLS config: %w", err)
}
tr := &http.Transport{
Proxy: proxy.GetCallback(c.proxy, c.noProxy),
TLSClientConfig: tlsConf,
DisableKeepAlives: true,
ForceAttemptHTTP2: true,
}
client := http.Client{Transport: tr}
resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("error making HTTP request: %w", err)
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK {
return nil, errors.New("failed to get index: " + resp.Status)
}
return io.ReadAll(io.LimitReader(resp.Body, maxIndexSize))
}
func newTLSConfig(creds Creds) (*tls.Config, error) {
tlsConfig := &tls.Config{InsecureSkipVerify: creds.GetInsecureSkipVerify()}
if creds.GetCAPath() != "" {
caData, err := os.ReadFile(creds.GetCAPath())
if err != nil {
return nil, fmt.Errorf("error reading CA file %s: %w", creds.GetCAPath(), err)
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caData)
tlsConfig.RootCAs = caCertPool
}
// If a client cert & key is provided then configure TLS config accordingly.
if len(creds.GetCertData()) > 0 && len(creds.GetKeyData()) > 0 {
cert, err := tls.X509KeyPair(creds.GetCertData(), creds.GetKeyData())
if err != nil {
return nil, fmt.Errorf("error creating X509 key pair: %w", err)
}
tlsConfig.Certificates = []tls.Certificate{cert}
}
//nolint:staticcheck
tlsConfig.BuildNameToCertificate()
return tlsConfig, nil
}
// Normalize a chart name for file system use, that is, if chart name is foo/bar/baz, returns the last component as chart name.
func normalizeChartName(chart string) string {
strings.Join(strings.Split(chart, "/"), "_")
_, nc := path.Split(chart)
// We do not want to return the empty string or something else related to filesystem access
// Instead, return original string
if nc == "" || nc == "." || nc == ".." {
return chart
}
return nc
}
func (c *nativeHelmChart) getCachedChartPath(chart string, version string) (string, error) {
keyData, err := json.Marshal(map[string]string{"url": c.repoURL, "chart": chart, "version": version})
if err != nil {
return "", fmt.Errorf("error marshaling cache key data: %w", err)
}
return c.chartCachePaths.GetPath(string(keyData))
}
// Ensures that given OCI registries URL does not have protocol
func IsHelmOciRepo(repoURL string) bool {
if repoURL == "" {
return false
}
parsed, err := url.Parse(repoURL)
// the URL parser treat hostname as either path or opaque if scheme is not specified, so hostname must be empty
return err == nil && parsed.Host == ""
}
func getIndexURL(rawURL string) (string, error) {
indexFile := "index.yaml"
repoURL, err := url.Parse(rawURL)
if err != nil {
return "", fmt.Errorf("error parsing repository URL: %w", err)
}
repoURL.Path = path.Join(repoURL.Path, indexFile)
repoURL.RawPath = path.Join(repoURL.RawPath, indexFile)
return repoURL.String(), nil
}
func (c *nativeHelmChart) GetTags(ctx context.Context, chart string, noCache bool) ([]string, error) {
if !c.enableOci {
return nil, ErrOCINotEnabled
}
tagsURL := strings.Replace(fmt.Sprintf("%s/%s", c.repoURL, chart), "https://", "", 1)
indexLock.Lock(tagsURL)
defer indexLock.Unlock(tagsURL)
var data []byte
if !noCache && c.indexCache != nil {
if err := c.indexCache.GetHelmIndex(tagsURL, &data); err != nil && !errors.Is(err, cache.ErrCacheMiss) {
log.Warnf("Failed to load index cache for repo: %s: %v", tagsURL, err)
}
}
type entriesStruct struct {
Tags []string
}
entries := &entriesStruct{}
if len(data) == 0 {
start := time.Now()
repo, err := remote.NewRepository(tagsURL)
if err != nil {
return nil, fmt.Errorf("failed to initialize repository: %w", err)
}
repo.PlainHTTP = c.plainHTTP
tlsConf, err := newTLSConfig(c.creds)
if err != nil {
return nil, fmt.Errorf("failed setup tlsConfig: %w", err)
}
// Create base transport with TLS config and proxy
baseTransport := &http.Transport{
Proxy: proxy.GetCallback(c.proxy, c.noProxy),
TLSClientConfig: tlsConf,
DisableKeepAlives: true,
ForceAttemptHTTP2: true,
}
// Wrap transport to add User-Agent header to all requests
client := &http.Client{
Transport: &userAgentTransport{
Transport: baseTransport,
UserAgent: c.getUserAgent(),
},
}
repoHost, _, _ := strings.Cut(tagsURL, "/")
helmPassword, err := c.creds.GetPassword()
if err != nil {
return nil, fmt.Errorf("failed to get password for helm registry: %w", err)
}
credential := auth.StaticCredential(repoHost, auth.Credential{
Username: c.creds.GetUsername(),
Password: helmPassword,
})
// Try to fallback to the environment config, but we shouldn't error if the file is not set
if c.creds.GetUsername() == "" && helmPassword == "" {
store, _ := credentials.NewStoreFromDocker(credentials.StoreOptions{})
if store != nil {
credential = credentials.Credential(store)
}
}
repo.Client = &auth.Client{
Client: client,
Cache: nil,
Credential: credential,
}
err = repo.Tags(ctx, "", func(tagsResult []string) error {
for _, tag := range tagsResult {
// By convention: Change underscore (_) back to plus (+) to get valid SemVer
convertedTag := strings.ReplaceAll(tag, "_", "+")
entries.Tags = append(entries.Tags, convertedTag)
}
return nil
})
if err != nil {
return nil, fmt.Errorf("failed to get tags: %w", err)
}
log.WithFields(
log.Fields{"seconds": time.Since(start).Seconds(), "chart": chart, "repo": c.repoURL},
).Info("took to get tags")
if c.indexCache != nil {
cacheData, err := json.Marshal(entries)
if err != nil {
return nil, fmt.Errorf("failed to encode tags: %w", err)
}
if err := c.indexCache.SetHelmIndex(tagsURL, cacheData); err != nil {
log.Warnf("Failed to store tags list cache for repo: %s: %v", tagsURL, err)
}
}
} else {
err := json.Unmarshal(data, entries)
if err != nil {
return nil, fmt.Errorf("failed to decode tags: %w", err)
}
}
return entries.Tags, nil
}