Skip to content

Commit 7a4ee70

Browse files
committed
Merge branch 'master' of github.com:KubeOperator/kubepi
2 parents 2434e7e + 04e6e6c commit 7a4ee70

File tree

8 files changed

+130
-15
lines changed

8 files changed

+130
-15
lines changed

internal/api/v1/chart/chart.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@ func (h *Handler) DeleteRepo() iris.Handler {
3232

3333
func (h *Handler) GetChart() iris.Handler {
3434
return func(ctx *context.Context) {
35-
//name := ctx.Params().GetString("name")
36-
//c, err := h.chartService.GetByName(name, common.DBOptions{})
37-
//if err != nil {
38-
// ctx.StatusCode(iris.StatusInternalServerError)
39-
// ctx.Values().Set("message", err.Error())
40-
// return
41-
//}
42-
//ctx.Values().Set("data", &Chart{Chart: *c})
35+
name := ctx.Params().GetString("name")
36+
cluster := ctx.URLParam("cluster")
37+
repo := ctx.URLParam("repo")
38+
cs, err := h.chartService.GetCharts(cluster, repo, name)
39+
if err != nil {
40+
ctx.StatusCode(iris.StatusInternalServerError)
41+
ctx.Values().Set("message", err.Error())
42+
return
43+
}
44+
ctx.Values().Set("data", cs)
4345
}
4446
}
4547
func (h *Handler) UpdateChart() iris.Handler {

internal/api/v1/chart/types.go

+5
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ type Chart struct {
1919
Icon string `json:"icon"`
2020
Description string `json:"description"`
2121
}
22+
23+
type Detail struct {
24+
Name string `json:"name"`
25+
Versions string `json:"versions"`
26+
}

internal/model/v1/chart/chart.go

+7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
package chart
22

3+
import "helm.sh/helm/v3/pkg/chart"
4+
35
type RepoCreate struct {
46
Url string `json:"url"`
57
Name string `json:"name"`
68
UserName string `json:"userName"`
79
Password string `json:"password"`
810
}
11+
12+
type ChArrayResult struct {
13+
Versions []string `json:"versions"`
14+
Chart chart.Chart `json:"chart"`
15+
}

internal/service/v1/chart/chart.go

+30
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Service interface {
1616
AddRepo(cluster string, create *v1Chart.RepoCreate) error
1717
ListCharts(cluster, repo string, num, size int, pattern string) ([]*search.Result, int, error)
1818
RemoveRepo(cluster string, name string) error
19+
GetCharts(cluster, repo, name string) (*v1Chart.ChArrayResult, error)
1920
}
2021

2122
func NewService() Service {
@@ -126,3 +127,32 @@ func (c *service) ListCharts(cluster, repo string, num, size int, pattern string
126127
result := chartArray[(num-1)*size : end]
127128
return result, len(chartArray), nil
128129
}
130+
131+
func (c *service) GetCharts(cluster, repo, name string) (*v1Chart.ChArrayResult, error) {
132+
clu, err := c.clusterService.Get(cluster, common.DBOptions{})
133+
if err != nil {
134+
return nil, err
135+
}
136+
helmClient, err := helm.NewClient(&helm.Config{
137+
Host: clu.Spec.Connect.Forward.ApiServer,
138+
BearerToken: clu.Spec.Authentication.BearerToken,
139+
})
140+
if err != nil {
141+
return nil, err
142+
}
143+
allVersionCharts, err := helmClient.GetCharts(repo, name)
144+
if err != nil {
145+
return nil, err
146+
}
147+
var result v1Chart.ChArrayResult
148+
for _, chart := range allVersionCharts {
149+
result.Versions = append(result.Versions, chart.Chart.Version)
150+
}
151+
lastVersion := allVersionCharts[0].Chart.Metadata.Version
152+
chart, err := helmClient.GetChartDetail(repo, allVersionCharts[0].Chart.Name, lastVersion)
153+
if err != nil {
154+
return nil, err
155+
}
156+
result.Chart = *chart
157+
return &result, nil
158+
}

pkg/util/helm/helm.go

+45
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"gopkg.in/yaml.v3"
1010
"helm.sh/helm/v3/cmd/helm/search"
1111
"helm.sh/helm/v3/pkg/action"
12+
"helm.sh/helm/v3/pkg/chart"
1213
"helm.sh/helm/v3/pkg/chart/loader"
1314
"helm.sh/helm/v3/pkg/cli"
1415
"helm.sh/helm/v3/pkg/getter"
@@ -167,6 +168,50 @@ func (c Client) ListCharts(repoName, pattern string) ([]*search.Result, error) {
167168
return result, nil
168169
}
169170

171+
func (c Client) GetCharts(repoName, name string) ([]*search.Result, error) {
172+
charts, err := c.ListCharts(repoName, name)
173+
if err != nil {
174+
return nil, err
175+
}
176+
var result []*search.Result
177+
for _, chart := range charts {
178+
if chart.Chart.Name == name {
179+
result = append(result, chart)
180+
}
181+
}
182+
return result, nil
183+
}
184+
185+
func (c Client) GetChartDetail(repoName, name, version string) (*chart.Chart, error) {
186+
repos, err := c.ListRepo()
187+
if err != nil {
188+
return nil, err
189+
}
190+
var re *repo.Entry
191+
for _, r := range repos {
192+
if r.Name == repoName {
193+
re = r
194+
}
195+
}
196+
if re == nil {
197+
return nil, errors.New("get chart detail failed, repo not found")
198+
}
199+
client := action.NewShow(action.ShowAll)
200+
client.Version = version
201+
client.RepoURL = re.URL
202+
client.Username = re.Username
203+
client.Password = re.Password
204+
p, err := client.LocateChart(name, c.settings)
205+
if err != nil {
206+
return nil, err
207+
}
208+
ct, err := loader.Load(p)
209+
if err != nil {
210+
return nil, err
211+
}
212+
return ct, nil
213+
}
214+
170215
func (c Client) ListRepo() ([]*repo.Entry, error) {
171216
settings := GetSettings()
172217
var repos []*repo.Entry

web/dashboard/src/api/charts.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export function deleteChart (name) {
1111
return del(`${baseUrl}/${name}`)
1212
}
1313

14-
export function getChart (name) {
15-
return get(`${baseUrl}/${name}`)
14+
export function getChart (cluster,repo,name) {
15+
return get(`${baseUrl}/${name}?cluster=${cluster}&repo=${repo}`)
1616
}
1717

1818
export function updateChart (name, user) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<template>
2+
3+
</template>
4+
5+
<script>
6+
export default {
7+
name: "",
8+
components: {},
9+
props: {},
10+
data () {
11+
return {}
12+
},
13+
methods: {},
14+
created () {
15+
}
16+
}
17+
</script>
18+
19+
<style scoped>
20+
21+
</style>

web/dashboard/src/business/market-place/chart/index.vue

+10-5
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
</el-row>
1616
<el-row :gutter="20" v-infinite-scroll="load" :infinite-scroll-disabled="loading || moreLoading">
1717
<el-col v-for="(d,index) in shows" v-bind:key="index" :xs="8" :sm="8" :lg="6">
18-
<div>
19-
<el-card :body-style="{padding: '0px'}" class="d-card el-card">
18+
<div @click="getChartDetail(d)">
19+
<el-card :body-style="{padding: '0px'}" class="d-card el-card" >
2020
<el-row :gutter="24">
2121
<el-col :span="8">
22-
<div style="margin-top: 32px;margin-left: 25px;margin-bottom: 15px">
23-
<el-image :src="d.icon" fit="contain" style="height: 56px;width: 56px;position:relative">
22+
<div style="margin-top: 32px;margin-left: 30px;margin-bottom: 15px">
23+
<el-image :src="d.icon" fit="contain" style="height: 56px;width: 56px;position:relative" @click="getChartDetail(d)">
2424
<div slot="error" class="image-slot">
2525
<img :src="require('@/assets/apps.svg')"/>
2626
</div>
@@ -50,7 +50,7 @@
5050

5151
<script>
5252
import LayoutContent from "@/components/layout/LayoutContent"
53-
import {listRepos, searchCharts} from "@/api/charts"
53+
import {getChart, listRepos, searchCharts} from "@/api/charts"
5454
5555
export default {
5656
name: "Charts",
@@ -126,6 +126,11 @@ export default {
126126
total: 0,
127127
}
128128
this.currentSlice = 0
129+
},
130+
getChartDetail(row) {
131+
getChart(this.cluster,row.repo,row.name).then(res => {
132+
console.log(res.data)
133+
})
129134
}
130135
},
131136
created () {

0 commit comments

Comments
 (0)