Upgrade k8s package verison (#5358)
* upgrade k8s package version Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> * Script upgrade and code formatting. Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io>
This commit is contained in:
@@ -18,6 +18,7 @@ package resolver
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -28,25 +29,25 @@ import (
|
||||
|
||||
"helm.sh/helm/v3/pkg/chart"
|
||||
"helm.sh/helm/v3/pkg/chart/loader"
|
||||
"helm.sh/helm/v3/pkg/gates"
|
||||
"helm.sh/helm/v3/pkg/helmpath"
|
||||
"helm.sh/helm/v3/pkg/provenance"
|
||||
"helm.sh/helm/v3/pkg/registry"
|
||||
"helm.sh/helm/v3/pkg/repo"
|
||||
)
|
||||
|
||||
const FeatureGateOCI = gates.Gate("HELM_EXPERIMENTAL_OCI")
|
||||
|
||||
// Resolver resolves dependencies from semantic version ranges to a particular version.
|
||||
type Resolver struct {
|
||||
chartpath string
|
||||
cachepath string
|
||||
chartpath string
|
||||
cachepath string
|
||||
registryClient *registry.Client
|
||||
}
|
||||
|
||||
// New creates a new resolver for a given chart and a given helm home.
|
||||
func New(chartpath, cachepath string) *Resolver {
|
||||
// New creates a new resolver for a given chart, helm home and registry client.
|
||||
func New(chartpath, cachepath string, registryClient *registry.Client) *Resolver {
|
||||
return &Resolver{
|
||||
chartpath: chartpath,
|
||||
cachepath: cachepath,
|
||||
chartpath: chartpath,
|
||||
cachepath: cachepath,
|
||||
registryClient: registryClient,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +122,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)
|
||||
@@ -134,9 +135,36 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
|
||||
found = false
|
||||
} else {
|
||||
version = d.Version
|
||||
if !FeatureGateOCI.IsEnabled() {
|
||||
return nil, errors.Wrapf(FeatureGateOCI.Error(),
|
||||
"repository %s is an OCI registry", d.Repository)
|
||||
|
||||
// Check to see if an explicit version has been provided
|
||||
_, err := semver.NewVersion(version)
|
||||
|
||||
// Use an explicit version, otherwise search for tags
|
||||
if err == nil {
|
||||
vs = []*repo.ChartVersion{{
|
||||
Metadata: &chart.Metadata{
|
||||
Version: version,
|
||||
},
|
||||
}}
|
||||
|
||||
} else {
|
||||
// Retrieve list of tags for repository
|
||||
ref := fmt.Sprintf("%s/%s", strings.TrimPrefix(d.Repository, fmt.Sprintf("%s://", registry.OCIScheme)), d.Name)
|
||||
tags, err := r.registryClient.Tags(ref)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not retrieve list of tags for repository %s", d.Repository)
|
||||
}
|
||||
|
||||
vs = make(repo.ChartVersions, len(tags))
|
||||
for ti, t := range tags {
|
||||
// Mock chart version objects
|
||||
version := &repo.ChartVersion{
|
||||
Metadata: &chart.Metadata{
|
||||
Version: t,
|
||||
},
|
||||
}
|
||||
vs[ti] = version
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +176,8 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
|
||||
// The version are already sorted and hence the first one to satisfy the constraint is used
|
||||
for _, ver := range vs {
|
||||
v, err := semver.NewVersion(ver.Version)
|
||||
if err != nil || len(ver.URLs) == 0 {
|
||||
// OCI does not need URLs
|
||||
if err != nil || (!registry.IsOCI(d.Repository) && len(ver.URLs) == 0) {
|
||||
// Not a legit entry.
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user