Skip to content
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
4 changes: 2 additions & 2 deletions api/core/v1alpha6/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ type Chart struct {
// repository. Holos gets the username and password from the environment
// variables represented by the Auth field.
type Repository struct {
Name string `json:"name" yaml:"name"`
URL string `json:"url" yaml:"url"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
URL string `json:"url,omitempty" yaml:"url,omitempty"`
Auth Auth `json:"auth,omitempty" yaml:"auth,omitempty"`
}

Expand Down
16 changes: 16 additions & 0 deletions internal/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package helm
import (
"context"
"fmt"
"net/url"

"github.com/holos-run/holos/internal/errors"
"github.com/holos-run/holos/internal/logger"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/registry"
)

// PullChart downloads and caches a Helm chart locally. It handles both OCI and
Expand All @@ -32,6 +34,20 @@ func PullChart(ctx context.Context, settings *cli.EnvSettings, chartRef, chartVe
}
actionConfig.RegistryClient = registryClient

chartRefURL, err := url.Parse(chartRef)
if err != nil {
return errors.Format("Failed to parse the Chart: %w", err)
}

// If the chart been pulled is an OCI chart, the repo authentication has to be done ahead of the pull.
if chartRefURL.Scheme == "oci" && username != "" && password != "" {
loginOption := registry.LoginOptBasicAuth(username, password)
err = registryClient.Login(chartRefURL.Host, loginOption)
if err != nil {
return errors.Format("failed to login to registry: %w", err)
}
}

pullClient := action.NewPullWithOpts(action.WithConfig(actionConfig))
pullClient.Untar = true
pullClient.RepoURL = repoURL
Expand Down