Skip to content

Commit

Permalink
fix: resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
choujimmy committed May 12, 2020
1 parent d837b84 commit c740714
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/aws/aws-sdk-go v1.29.32
github.com/bitly/go-simplejson v0.5.0
github.com/blang/semver v3.5.1+incompatible
github.com/casbin/casbin/v2 v2.2.1
github.com/casbin/casbin/v2 v2.1.2
github.com/chartmuseum/storage v0.8.0
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/coreos/prometheus-operator v0.38.1-0.20200506070354-4231c1d4b313
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 c740714

Please sign in to comment.