Skip to content

Commit

Permalink
feat: upgrade helm to v3
Browse files Browse the repository at this point in the history
  • Loading branch information
choujimmy committed May 8, 2020
1 parent 2c07393 commit 3ba8905
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ require (
github.com/brancz/gojsontoyaml v0.0.0-20190425155809-e8bd32d46b3d // indirect
github.com/casbin/casbin/v2 v2.1.2
github.com/chartmuseum/auth v0.4.1 // indirect
github.com/chartmuseum/storage v0.8.0
github.com/containerd/containerd v1.3.2 // indirect
github.com/containerd/continuity v0.0.0-20200107194136-26c1120b8d41 // indirect
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/coreos/prometheus-operator v0.29.0
github.com/cyphar/filepath-securejoin v0.2.2 // indirect
github.com/deislabs/oras v0.8.0 // indirect
github.com/dexidp/dex v0.0.0-20200408064242-83d8853fd969
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/docker/cli v0.0.0-20200130152716-5d0cf8839492 // indirect
Expand Down Expand Up @@ -124,15 +124,14 @@ require (
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
golang.org/x/tools v0.0.0-20200319210407-521f4a0cd458 // indirect
gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e // indirect
google.golang.org/api v0.15.1 // indirect
google.golang.org/grpc v1.26.0
google.golang.org/grpc v1.27.1
gopkg.in/go-playground/validator.v9 v9.29.1
gopkg.in/ldap.v2 v2.5.1
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/square/go-jose.v2 v2.4.1
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect
gopkg.in/yaml.v2 v2.2.8
helm.sh/chartmuseum v0.8.2
helm.sh/chartmuseum v0.12.0
honnef.co/go/tools v0.0.1-2020.1.3 // indirect
k8s.io/api v0.18.2
k8s.io/apiextensions-apiserver v0.18.2
Expand All @@ -141,7 +140,6 @@ require (
k8s.io/client-go v0.18.2
k8s.io/cluster-bootstrap v0.18.2
k8s.io/component-base v0.18.2
k8s.io/helm v2.16.1+incompatible
k8s.io/klog v1.0.0
k8s.io/kube-aggregator v0.18.2
k8s.io/kube-openapi v0.0.0-20200121204235-bf4fb3bd569c
Expand Down
47 changes: 25 additions & 22 deletions pkg/registry/chartmuseum/authorization/create_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ package authorization

import (
"fmt"
"io/ioutil"
"net/http"

"github.com/gorilla/mux"
"helm.sh/helm/v3/pkg/chart"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/proto/hapi/chart"
"net/http"
"sigs.k8s.io/yaml"
"tkestack.io/tke/api/registry"
"tkestack.io/tke/pkg/apiserver/authentication"
"tkestack.io/tke/pkg/registry/chartmuseum/model"
Expand Down Expand Up @@ -65,13 +67,14 @@ func (a *authorization) doAPICreateProvenance(w http.ResponseWriter, req *http.R
log.Error("Failed to retrieve chart file from request", log.Err(err))
return
}
ct, err := chartutil.LoadArchive(file)
bs, err := ioutil.ReadAll(file)
if err != nil {
log.Error("Failed to load chart from request body", log.Err(err))
log.Error("Failed to read all content from chart file", log.Err(err))
return
}
if ct.Metadata == nil {
log.Error("Chart metadata is nil after parsed", log.Any("chart", ct))
ct := new(chart.Metadata)
if err := yaml.Unmarshal(bs, ct); err != nil {
log.Error("Failed to unmarshal chart file", log.Err(err))
return
}
if err := a.afterAPICreateChart(chartGroup, ct, header.Size); err != nil {
Expand Down Expand Up @@ -133,9 +136,9 @@ func (a *authorization) validateAPICreateChart(w http.ResponseWriter, req *http.
return &chartGroup, nil
}

func (a *authorization) afterAPICreateChart(chartGroup *registry.ChartGroup, ct *chart.Chart, ctSize int64) error {
func (a *authorization) afterAPICreateChart(chartGroup *registry.ChartGroup, chartMeta *chart.Metadata, ctSize int64) error {
chartList, err := a.registryClient.Charts(chartGroup.ObjectMeta.Name).List(metav1.ListOptions{
FieldSelector: fmt.Sprintf("spec.tenantID=%s,spec.name=%s,spec.chartGroupName=%s", chartGroup.Spec.TenantID, ct.Metadata.Name, chartGroup.Spec.Name),
FieldSelector: fmt.Sprintf("spec.tenantID=%s,spec.name=%s,spec.chartGroupName=%s", chartGroup.Spec.TenantID, chartMeta.Name, chartGroup.Spec.Name),
})
if err != nil {
return err
Expand All @@ -149,7 +152,7 @@ func (a *authorization) afterAPICreateChart(chartGroup *registry.ChartGroup, ct
Namespace: chartGroup.ObjectMeta.Name,
},
Spec: registry.ChartSpec{
Name: ct.Metadata.Name,
Name: chartMeta.Name,
TenantID: chartGroup.Spec.TenantID,
ChartGroupName: chartGroup.Spec.Name,
Visibility: chartGroup.Spec.Visibility,
Expand All @@ -158,7 +161,7 @@ func (a *authorization) afterAPICreateChart(chartGroup *registry.ChartGroup, ct
PullCount: 0,
Versions: []registry.ChartVersion{
{
Version: ct.Metadata.Version,
Version: chartMeta.Version,
ChartSize: ctSize,
TimeCreated: metav1.Now(),
},
Expand All @@ -168,8 +171,8 @@ func (a *authorization) afterAPICreateChart(chartGroup *registry.ChartGroup, ct
log.Error("Failed to create chart while pushed chart",
log.String("tenantID", chartGroup.Spec.TenantID),
log.String("chartGroupName", chartGroup.Spec.Name),
log.String("chartName", ct.Metadata.Name),
log.String("version", ct.Metadata.Version),
log.String("chartName", chartMeta.Name),
log.String("version", chartMeta.Version),
log.Err(err))
return err
}
Expand All @@ -180,19 +183,19 @@ func (a *authorization) afterAPICreateChart(chartGroup *registry.ChartGroup, ct
needIncreaseChartCount = true
} else {
for k, v := range chartObject.Status.Versions {
if v.Version == ct.Metadata.Version {
if v.Version == chartMeta.Version {
existVersion = true
chartObject.Status.Versions[k] = registry.ChartVersion{
Version: ct.Metadata.Version,
Version: chartMeta.Version,
ChartSize: ctSize,
TimeCreated: metav1.Now(),
}
if _, err := a.registryClient.Charts(chartGroup.ObjectMeta.Name).UpdateStatus(&chartObject); err != nil {
log.Error("Failed to update chart version while chart pushed",
log.String("tenantID", chartGroup.Spec.TenantID),
log.String("chartGroupName", chartGroup.Spec.Name),
log.String("chartName", ct.Metadata.Name),
log.String("version", ct.Metadata.Version),
log.String("chartName", chartMeta.Name),
log.String("version", chartMeta.Version),
log.Err(err))
return err
}
Expand All @@ -203,16 +206,16 @@ func (a *authorization) afterAPICreateChart(chartGroup *registry.ChartGroup, ct

if !existVersion {
chartObject.Status.Versions = append(chartObject.Status.Versions, registry.ChartVersion{
Version: ct.Metadata.Version,
Version: chartMeta.Version,
ChartSize: ctSize,
TimeCreated: metav1.Now(),
})
if _, err := a.registryClient.Charts(chartGroup.ObjectMeta.Name).UpdateStatus(&chartObject); err != nil {
log.Error("Failed to create repository tag while received notification",
log.String("tenantID", chartGroup.Spec.TenantID),
log.String("chartGroupName", chartGroup.Spec.Name),
log.String("chartName", ct.Metadata.Name),
log.String("version", ct.Metadata.Version),
log.String("chartName", chartMeta.Name),
log.String("version", chartMeta.Version),
log.Err(err))
return err
}
Expand All @@ -226,8 +229,8 @@ func (a *authorization) afterAPICreateChart(chartGroup *registry.ChartGroup, ct
log.Error("Failed to update chart group's chart count while pushed",
log.String("tenantID", chartGroup.Spec.TenantID),
log.String("chartGroupName", chartGroup.Spec.Name),
log.String("chartName", ct.Metadata.Name),
log.String("version", ct.Metadata.Version),
log.String("chartName", chartMeta.Name),
log.String("version", chartMeta.Version),
log.Err(err))
return err
}
Expand Down

0 comments on commit 3ba8905

Please sign in to comment.