Skip to content

Commit

Permalink
Parse display name from chart annotation
Browse files Browse the repository at this point in the history
Signed-off-by: LiHui <andrewli@yunify.com>
  • Loading branch information
LiHui committed Jun 29, 2021
1 parent 29f28bf commit f35f2c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
27 changes: 14 additions & 13 deletions cmd/import-app/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,22 @@ func (wf *ImportWorkFlow) CreateApp(ctx context.Context, chrt *chart.Chart) (app

for ind := range appList.Items {
item := &appList.Items[ind]
if item.GetTrueName() == wf.importConfig.ReplaceAppName(chrt.Name()) {
if item.GetTrueName() == wf.importConfig.ReplaceAppName(chrt) {
klog.Infof("helm application exists, name: %s, version: %s", chrt.Name(), chrt.Metadata.Version)
err = wf.UpdateAppNameInStore(ctx, item, wf.importConfig.ReplaceAppName(chrt.Name()))
err = wf.UpdateAppNameInStore(ctx, item, wf.importConfig.ReplaceAppName(chrt))
if err != nil {
return nil, err
}
return item, nil
} else if item.GetTrueName() == chrt.Name() {
// we need update app name
klog.Infof("chart name: %s, replace name: %s", chrt.Name(), wf.importConfig.ReplaceAppName(chrt.Name()))
app, err := wf.UpdateAppName(ctx, item, wf.importConfig.ReplaceAppName(chrt.Name()))
klog.Infof("chart name: %s, replace name: %s", chrt.Name(), wf.importConfig.ReplaceAppName(chrt))
app, err := wf.UpdateAppName(ctx, item, wf.importConfig.ReplaceAppName(chrt))
if err != nil {
return nil, err
}
// update app name in store
err = wf.UpdateAppNameInStore(ctx, item, wf.importConfig.ReplaceAppName(chrt.Name()))
err = wf.UpdateAppNameInStore(ctx, item, wf.importConfig.ReplaceAppName(chrt))
if err == nil {
return app, err
} else {
Expand Down Expand Up @@ -229,7 +229,7 @@ func (wf *ImportWorkFlow) CreateApp(ctx context.Context, chrt *chart.Chart) (app
},
},
Spec: v1alpha1.HelmApplicationSpec{
Name: wf.importConfig.ReplaceAppName(chrt.Name()),
Name: wf.importConfig.ReplaceAppName(chrt),
Description: chrt.Metadata.Description,
Icon: chrt.Metadata.Icon,
},
Expand Down Expand Up @@ -420,15 +420,16 @@ type ImportConfig struct {
AppNameReplace map[string]string `yaml:"appNameReplace"`
}

func (ic *ImportConfig) ReplaceAppName(oldName string) string {
if len(ic.AppNameReplace) == 0 {
return oldName
}

if newName, exists := ic.AppNameReplace[oldName]; exists {
func (ic *ImportConfig) ReplaceAppName(chrt *chart.Chart) string {
// import-config.yaml comes first
if newName, exists := ic.AppNameReplace[chrt.Name()]; exists {
return newName
} else {
return oldName
// If app.kubesphere.io/display-name exists in chart's annotation, use this value.
if chrt.Metadata.Annotations != nil && chrt.Metadata.Annotations[constants.ChartDisplayName] != "" {
return strings.TrimSpace(chrt.Metadata.Annotations[constants.ChartDisplayName])
}
return chrt.Name()
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package constants

const (
CategoryKeyInChart = "app.kubesphere.io/category"
ChartDisplayName = "app.kubesphere.io/display-name"
ClusterNameLabelKey = "kubesphere.io/cluster"
WorkspaceLabelKey = "kubesphere.io/workspace"
NamespaceLabelKey = "kubesphere.io/namespace"
Expand Down
2 changes: 1 addition & 1 deletion urls.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ https://charts.kubesphere.io/test/postgresql-0.4.2.tgz
https://charts.kubesphere.io/test/rabbitmq-0.3.2.tgz
https://charts.kubesphere.io/test/redis-0.3.5.tgz
https://charts.kubesphere.io/test/radondb-mysql-1.0.0.tgz
https://charts.kubesphere.io/test/radondb-postgresql-1.0.0.tgz
https://charts.kubesphere.io/test/radondb-postgresql-1.0.1.tgz

0 comments on commit f35f2c6

Please sign in to comment.