mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
remove hardcoded oci strings, add constant/util
Signed-off-by: Josh Dolitsky <josh@dolit.ski>
This commit is contained in:
parent
bfa5036a1a
commit
230e37ca52
14 changed files with 34 additions and 18 deletions
|
|
@ -20,6 +20,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"helm.sh/helm/v3/internal/experimental/pusher"
|
||||
"helm.sh/helm/v3/internal/experimental/registry"
|
||||
"helm.sh/helm/v3/internal/experimental/uploader"
|
||||
"helm.sh/helm/v3/pkg/action"
|
||||
"helm.sh/helm/v3/pkg/cli"
|
||||
|
|
@ -62,7 +63,7 @@ func (p *Push) Run(chartRef string, remote string) (string, error) {
|
|||
Options: []pusher.Option{},
|
||||
}
|
||||
|
||||
if strings.HasPrefix(remote, "oci://") {
|
||||
if registry.IsOCI(remote) {
|
||||
c.Options = append(c.Options, pusher.WithRegistryClient(p.cfg.RegistryClient))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ func (pusher *OCIPusher) push(chartRef, href string) error {
|
|||
}
|
||||
|
||||
ref := fmt.Sprintf("%s:%s",
|
||||
path.Join(strings.TrimPrefix(href, "oci://"), meta.Metadata.Name),
|
||||
path.Join(strings.TrimPrefix(href, fmt.Sprintf("%s://", registry.OCIScheme)), meta.Metadata.Name),
|
||||
meta.Metadata.Version)
|
||||
|
||||
_, err = client.Push(chartBytes, ref, pushOpts...)
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ func (p Providers) ByScheme(scheme string) (Pusher, error) {
|
|||
}
|
||||
|
||||
var ociProvider = Provider{
|
||||
Schemes: []string{"oci"},
|
||||
Schemes: []string{registry.OCIScheme},
|
||||
New: NewOCIPusher,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package pusher
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"helm.sh/helm/v3/internal/experimental/registry"
|
||||
"helm.sh/helm/v3/pkg/cli"
|
||||
)
|
||||
|
||||
|
|
@ -61,7 +62,7 @@ func TestAll(t *testing.T) {
|
|||
func TestByScheme(t *testing.T) {
|
||||
env := cli.New()
|
||||
g := All(env)
|
||||
if _, err := g.ByScheme("oci"); err != nil {
|
||||
if _, err := g.ByScheme(registry.OCIScheme); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ limitations under the License.
|
|||
package registry // import "helm.sh/helm/v3/internal/experimental/registry"
|
||||
|
||||
const (
|
||||
// OCIScheme is the URL scheme for OCI-based requests
|
||||
OCIScheme = "oci"
|
||||
|
||||
// CredentialsFileBasename is the filename for auth credentials file
|
||||
CredentialsFileBasename = "config.json"
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@ package registry // import "helm.sh/helm/v3/internal/experimental/registry"
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
orascontext "oras.land/oras-go/pkg/context"
|
||||
|
|
@ -28,6 +30,11 @@ import (
|
|||
"helm.sh/helm/v3/pkg/chart/loader"
|
||||
)
|
||||
|
||||
// IsOCI determines whether or not a URL is to be treated as an OCI URL
|
||||
func IsOCI(url string) bool {
|
||||
return strings.HasPrefix(url, fmt.Sprintf("%s://", OCIScheme))
|
||||
}
|
||||
|
||||
// extractChartMeta is used to extract a chart metadata from a byte array
|
||||
func extractChartMeta(chartData []byte) (*chart.Metadata, error) {
|
||||
ch, err := loader.LoadArchive(bytes.NewReader(chartData))
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
package uploader
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
|
||||
|
|
@ -45,7 +46,7 @@ func (c *ChartUploader) UploadTo(ref, remote string) error {
|
|||
}
|
||||
|
||||
if u.Scheme == "" {
|
||||
return errors.New("scheme prefix missing from remote (e.g. \"oci://\")")
|
||||
return errors.New(fmt.Sprintf("scheme prefix missing from remote (e.g. \"%s://\")", registry.OCIScheme))
|
||||
}
|
||||
|
||||
p, err := c.Pushers.ByScheme(u.Scheme)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/Masterminds/semver/v3"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"helm.sh/helm/v3/internal/experimental/registry"
|
||||
"helm.sh/helm/v3/pkg/chart"
|
||||
"helm.sh/helm/v3/pkg/chart/loader"
|
||||
"helm.sh/helm/v3/pkg/gates"
|
||||
|
|
@ -112,7 +113,7 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
|
|||
var version string
|
||||
var ok bool
|
||||
found := true
|
||||
if !strings.HasPrefix(d.Repository, "oci://") {
|
||||
if !registry.IsOCI(d.Repository) {
|
||||
repoIndex, err := repo.LoadIndexFile(filepath.Join(r.cachepath, helmpath.CacheIndexFile(repoName)))
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "no cached repository for %s found. (try 'helm repo update')", repoName)
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import (
|
|||
"k8s.io/cli-runtime/pkg/resource"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"helm.sh/helm/v3/internal/experimental/registry"
|
||||
"helm.sh/helm/v3/pkg/chart"
|
||||
"helm.sh/helm/v3/pkg/chartutil"
|
||||
"helm.sh/helm/v3/pkg/cli"
|
||||
|
|
@ -664,7 +665,7 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) (
|
|||
RepositoryCache: settings.RepositoryCache,
|
||||
}
|
||||
|
||||
if strings.HasPrefix(name, "oci://") {
|
||||
if registry.IsOCI(name) {
|
||||
if version == "" {
|
||||
return "", errors.New("version is explicitly required for OCI registries")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import (
|
|||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"helm.sh/helm/v3/internal/experimental/registry"
|
||||
"helm.sh/helm/v3/pkg/chartutil"
|
||||
"helm.sh/helm/v3/pkg/cli"
|
||||
"helm.sh/helm/v3/pkg/downloader"
|
||||
|
|
@ -90,7 +91,7 @@ func (p *Pull) Run(chartRef string) (string, error) {
|
|||
RepositoryCache: p.Settings.RepositoryCache,
|
||||
}
|
||||
|
||||
if strings.HasPrefix(chartRef, "oci://") {
|
||||
if registry.IsOCI(chartRef) {
|
||||
if p.Version == "" {
|
||||
return out.String(), errors.Errorf("--version flag is explicitly required for OCI registries")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *proven
|
|||
}
|
||||
|
||||
name := filepath.Base(u.Path)
|
||||
if u.Scheme == "oci" {
|
||||
if u.Scheme == registry.OCIScheme {
|
||||
name = fmt.Sprintf("%s-%s.tgz", name, version)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -342,7 +342,7 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error {
|
|||
}
|
||||
|
||||
version := ""
|
||||
if strings.HasPrefix(churl, "oci://") {
|
||||
if registry.IsOCI(churl) {
|
||||
if !resolver.FeatureGateOCI.IsEnabled() {
|
||||
return errors.Wrapf(resolver.FeatureGateOCI.Error(),
|
||||
"the repository %s is an OCI registry", churl)
|
||||
|
|
@ -402,7 +402,7 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error {
|
|||
}
|
||||
|
||||
func parseOCIRef(chartRef string) (string, string, error) {
|
||||
refTagRegexp := regexp.MustCompile(`^(oci://[^:]+(:[0-9]{1,5})?[^:]+):(.*)$`)
|
||||
refTagRegexp := regexp.MustCompile(fmt.Sprintf(`^(%s://[^:]+(:[0-9]{1,5})?[^:]+):(.*)$`, registry.OCIScheme))
|
||||
caps := refTagRegexp.FindStringSubmatch(chartRef)
|
||||
if len(caps) != 4 {
|
||||
return "", "", errors.Errorf("improperly formatted oci chart reference: %s", chartRef)
|
||||
|
|
@ -460,7 +460,7 @@ func (m *Manager) hasAllRepos(deps []*chart.Dependency) error {
|
|||
Loop:
|
||||
for _, dd := range deps {
|
||||
// If repo is from local path or OCI, continue
|
||||
if strings.HasPrefix(dd.Repository, "file://") || strings.HasPrefix(dd.Repository, "oci://") {
|
||||
if strings.HasPrefix(dd.Repository, "file://") || registry.IsOCI(dd.Repository) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -498,7 +498,7 @@ func (m *Manager) ensureMissingRepos(repoNames map[string]string, deps []*chart.
|
|||
}
|
||||
|
||||
// OCI-based dependencies do not have a local cache, so skip them
|
||||
if strings.HasPrefix(dd.Repository, "oci://") {
|
||||
if registry.IsOCI(dd.Repository) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -567,7 +567,7 @@ func (m *Manager) resolveRepoNames(deps []*chart.Dependency) (map[string]string,
|
|||
for _, dd := range deps {
|
||||
// Don't map the repository, we don't need to download chart from charts directory
|
||||
// When OCI is used there is no Helm repository
|
||||
if dd.Repository == "" || strings.HasPrefix(dd.Repository, "oci://") {
|
||||
if dd.Repository == "" || registry.IsOCI(dd.Repository) {
|
||||
continue
|
||||
}
|
||||
// if dep chart is from local path, verify the path is valid
|
||||
|
|
@ -583,7 +583,7 @@ func (m *Manager) resolveRepoNames(deps []*chart.Dependency) (map[string]string,
|
|||
continue
|
||||
}
|
||||
|
||||
if strings.HasPrefix(dd.Repository, "oci://") {
|
||||
if registry.IsOCI(dd.Repository) {
|
||||
reposMap[dd.Name] = dd.Repository
|
||||
continue
|
||||
}
|
||||
|
|
@ -697,7 +697,7 @@ func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) error {
|
|||
//
|
||||
// If it finds a URL that is "relative", it will prepend the repoURL.
|
||||
func (m *Manager) findChartURL(name, version, repoURL string, repos map[string]*repo.ChartRepository) (url, username, password string, insecureskiptlsverify, passcredentialsall bool, caFile, certFile, keyFile string, err error) {
|
||||
if strings.HasPrefix(repoURL, "oci://") {
|
||||
if registry.IsOCI(repoURL) {
|
||||
return fmt.Sprintf("%s/%s:%s", repoURL, name, version), "", "", false, false, "", "", "", nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ var httpProvider = Provider{
|
|||
}
|
||||
|
||||
var ociProvider = Provider{
|
||||
Schemes: []string{"oci"},
|
||||
Schemes: []string{registry.OCIScheme},
|
||||
New: NewOCIGetter,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ func (g *OCIGetter) Get(href string, options ...Option) (*bytes.Buffer, error) {
|
|||
func (g *OCIGetter) get(href string) (*bytes.Buffer, error) {
|
||||
client := g.opts.registryClient
|
||||
|
||||
ref := strings.TrimPrefix(href, "oci://")
|
||||
ref := strings.TrimPrefix(href, fmt.Sprintf("%s://", registry.OCIScheme))
|
||||
|
||||
var pullOpts []registry.PullOption
|
||||
requestingProv := strings.HasSuffix(ref, ".prov")
|
||||
|
|
|
|||
Loading…
Reference in a new issue