Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
b61ff1a6
Commit
b61ff1a6
authored
Mar 24, 2016
by
jackgr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wire up routes to chart repo methods
parent
e065ebcc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
140 additions
and
173 deletions
+140
-173
chartrepos.go
cmd/manager/chartrepos.go
+102
-12
chartrepos_test.go
cmd/manager/chartrepos_test.go
+2
-2
deployments.go
cmd/manager/deployments.go
+0
-124
manager.go
cmd/manager/manager/manager.go
+31
-34
testutil.go
cmd/manager/testutil.go
+5
-1
No files found.
cmd/manager/chartrepos.go
View file @
b61ff1a6
...
...
@@ -2,50 +2,140 @@ package main
import
(
"github.com/kubernetes/helm/cmd/manager/router"
"github.com/kubernetes/helm/pkg/httputil"
"github.com/kubernetes/helm/pkg/repo"
"github.com/kubernetes/helm/pkg/util"
"net/http"
"net/url"
"regexp"
)
func
registerChartRepoRoutes
(
c
*
router
.
Context
,
h
*
router
.
Handler
)
{
h
.
Add
(
"GET /chart_repositories"
,
listChartRepositoriesHandlerFunc
)
h
.
Add
(
"POST /chart_repositories"
,
addChartRepoHandlerFunc
)
h
.
Add
(
"DELETE /chart_repositories"
,
removeChartRepoHandlerFunc
)
h
.
Add
(
"GET /repositories"
,
listChartReposHandlerFunc
)
h
.
Add
(
"GET /repositories/*"
,
getChartRepoHandlerFunc
)
h
.
Add
(
"GET /repositories/*/charts"
,
listRepoChartsHandlerFunc
)
h
.
Add
(
"GET /repositories/*/charts/*"
,
getRepoChartHandlerFunc
)
h
.
Add
(
"POST /repositories"
,
addChartRepoHandlerFunc
)
h
.
Add
(
"DELETE /repositories"
,
removeChartRepoHandlerFunc
)
}
func
listChartRepos
itories
HandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
func
listChartReposHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
handler
:=
"manager: list chart repositories"
repos
,
err
:=
c
.
Manager
.
ListChartRepos
()
if
err
!=
nil
{
return
err
}
util
.
LogHandlerExitWithJSON
(
handler
,
w
,
repos
,
http
.
StatusOK
)
return
nil
}
func
addChartRepoHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
handler
:=
"manager: add chart repository"
name
,
err
:=
pos
(
w
,
r
,
2
)
util
.
LogHandlerEntry
(
handler
,
r
)
defer
r
.
Body
.
Close
()
cr
:=
&
repo
.
Repo
{}
if
err
:=
httputil
.
Decode
(
w
,
r
,
cr
);
err
!=
nil
{
httputil
.
BadRequest
(
w
,
r
,
err
)
return
nil
}
if
err
:=
c
.
Manager
.
AddChartRepo
(
cr
);
err
!=
nil
{
httputil
.
BadRequest
(
w
,
r
,
err
)
return
nil
}
util
.
LogHandlerExitWithText
(
handler
,
w
,
"added"
,
http
.
StatusOK
)
return
nil
}
func
removeChartRepoHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
handler
:=
"manager: remove chart repository"
util
.
LogHandlerEntry
(
handler
,
r
)
URL
,
err
:=
pos
(
w
,
r
,
2
)
if
err
!=
nil
{
return
err
}
err
=
c
.
Manager
.
AddChartRepo
(
name
)
err
=
c
.
Manager
.
RemoveChartRepo
(
URL
)
if
err
!=
nil
{
return
err
}
util
.
LogHandlerExitWithJSON
(
handler
,
w
,
"added"
,
http
.
StatusOK
)
util
.
LogHandlerExitWithText
(
handler
,
w
,
"removed"
,
http
.
StatusOK
)
return
nil
}
func
removeChartRepoHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
handler
:=
"manager: remove chart repository"
name
,
err
:=
pos
(
w
,
r
,
2
)
func
getChartRepoHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
handler
:=
"manager: get repository"
util
.
LogHandlerEntry
(
handler
,
r
)
repoURL
,
err
:=
pos
(
w
,
r
,
2
)
if
err
!=
nil
{
return
err
}
err
=
c
.
Manager
.
RemoveChartRepo
(
name
)
cr
,
err
:=
c
.
Manager
.
GetChartRepo
(
repoURL
)
if
err
!=
nil
{
httputil
.
BadRequest
(
w
,
r
,
err
)
return
nil
}
util
.
LogHandlerExitWithJSON
(
handler
,
w
,
cr
,
http
.
StatusOK
)
return
nil
}
func
listRepoChartsHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
handler
:=
"manager: list repository charts"
util
.
LogHandlerEntry
(
handler
,
r
)
repoURL
,
err
:=
pos
(
w
,
r
,
2
)
if
err
!=
nil
{
return
err
}
util
.
LogHandlerExitWithJSON
(
handler
,
w
,
"removed"
,
http
.
StatusOK
)
values
,
err
:=
url
.
ParseQuery
(
r
.
URL
.
RawQuery
)
if
err
!=
nil
{
httputil
.
BadRequest
(
w
,
r
,
err
)
return
nil
}
var
regex
*
regexp
.
Regexp
regexString
:=
values
.
Get
(
"regex"
)
if
regexString
!=
""
{
regex
,
err
=
regexp
.
Compile
(
regexString
)
if
err
!=
nil
{
httputil
.
BadRequest
(
w
,
r
,
err
)
return
nil
}
}
repoCharts
,
err
:=
c
.
Manager
.
ListRepoCharts
(
repoURL
,
regex
)
if
err
!=
nil
{
return
err
}
util
.
LogHandlerExitWithJSON
(
handler
,
w
,
repoCharts
,
http
.
StatusOK
)
return
nil
}
func
getRepoChartHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
handler
:=
"manager: get repository charts"
util
.
LogHandlerEntry
(
handler
,
r
)
repoURL
,
err
:=
pos
(
w
,
r
,
2
)
if
err
!=
nil
{
return
err
}
chartName
,
err
:=
pos
(
w
,
r
,
4
)
if
err
!=
nil
{
return
err
}
repoChart
,
err
:=
c
.
Manager
.
GetChartForRepo
(
repoURL
,
chartName
)
if
err
!=
nil
{
return
err
}
util
.
LogHandlerExitWithJSON
(
handler
,
w
,
repoChart
,
http
.
StatusOK
)
return
nil
}
cmd/manager/chartrepos_test.go
View file @
b61ff1a6
...
...
@@ -7,10 +7,10 @@ import (
func
TestListChartRepositories
(
t
*
testing
.
T
)
{
c
:=
stubContext
()
s
:=
httpHarness
(
c
,
"GET /
chart_repositories"
,
listChartRepositorie
sHandlerFunc
)
s
:=
httpHarness
(
c
,
"GET /
repositories"
,
listChartRepo
sHandlerFunc
)
defer
s
.
Close
()
res
,
err
:=
http
.
Get
(
s
.
URL
+
"/
chart_
repositories"
)
res
,
err
:=
http
.
Get
(
s
.
URL
+
"/repositories"
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed GET: %s"
,
err
)
}
else
if
res
.
StatusCode
!=
http
.
StatusOK
{
...
...
cmd/manager/deployments.go
View file @
b61ff1a6
...
...
@@ -26,7 +26,6 @@ import (
"net/http"
"net/url"
"os"
"regexp"
"strings"
"github.com/ghodss/yaml"
...
...
@@ -71,13 +70,6 @@ func registerDeploymentRoutes(c *router.Context, h *router.Handler) {
h
.
Add
(
"GET /charts/*/repository"
,
getRepoForChartHandlerFunc
)
h
.
Add
(
"GET /charts/*/metadata"
,
getMetadataForChartHandlerFunc
)
h
.
Add
(
"GET /charts/*"
,
getChartHandlerFunc
)
// TODO: Refactor these commented out routes
// h.Add("GET /repositories/*", getRepoHandlerFunc)
// h.Add("POST /repositories/*", createRepoHandlerFunc)
h
.
Add
(
"GET /repositories/*/charts"
,
listRepositoryChartsHandlerFunc
)
h
.
Add
(
"GET /repositories/*/charts/*"
,
getRepositoryChartHandlerFunc
)
h
.
Add
(
"POST /credentials/*"
,
createCredentialHandlerFunc
)
h
.
Add
(
"GET /credentials/*"
,
getCredentialHandlerFunc
)
}
...
...
@@ -456,122 +448,6 @@ func getChartHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Conte
return
nil
}
// TODO: Refactor this commented out code.
/*
func getRepoHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
handler := "manager: get repository"
util.LogHandlerEntry(handler, r)
repoName, err := pos(w, r, 2)
if err != nil {
return err
}
cr, err := c.Manager.GetRepo(repoName)
if err != nil {
httputil.BadRequest(w, r, err)
return nil
}
util.LogHandlerExitWithJSON(handler, w, cr, http.StatusOK)
return nil
}
func getRepo(w http.ResponseWriter, r *http.Request, handler string) *repo.Repo {
util.LogHandlerEntry(handler, r)
t := &repo.Repo{}
if err := httputil.Decode(w, r, t); err != nil {
httputil.BadRequest(w, r, err)
return nil
}
return t
}
func createRepoHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
handler := "manager: create repository"
util.LogHandlerEntry(handler, r)
defer r.Body.Close()
repoName, err := pos(w, r, 2)
if err != nil {
return err
}
reg := getRepo(w, r, handler)
if reg.Name != repoName {
e := fmt.Errorf("Repo name does not match %s != %s", reg.Name, repoName)
httputil.BadRequest(w, r, e)
return nil
}
if reg != nil {
err = c.Manager.CreateRepo(reg)
if err != nil {
httputil.BadRequest(w, r, err)
return nil
}
}
util.LogHandlerExitWithJSON(handler, w, reg, http.StatusOK)
return nil
}
*/
func
listRepositoryChartsHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
handler
:=
"manager: list repository charts"
util
.
LogHandlerEntry
(
handler
,
r
)
repoName
,
err
:=
pos
(
w
,
r
,
2
)
if
err
!=
nil
{
return
err
}
values
,
err
:=
url
.
ParseQuery
(
r
.
URL
.
RawQuery
)
if
err
!=
nil
{
httputil
.
BadRequest
(
w
,
r
,
err
)
return
nil
}
var
regex
*
regexp
.
Regexp
regexString
:=
values
.
Get
(
"regex"
)
if
regexString
!=
""
{
regex
,
err
=
regexp
.
Compile
(
regexString
)
if
err
!=
nil
{
httputil
.
BadRequest
(
w
,
r
,
err
)
return
nil
}
}
repoCharts
,
err
:=
c
.
Manager
.
ListRepoCharts
(
repoName
,
regex
)
if
err
!=
nil
{
return
err
}
util
.
LogHandlerExitWithJSON
(
handler
,
w
,
repoCharts
,
http
.
StatusOK
)
return
nil
}
func
getRepositoryChartHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
handler
:=
"manager: get repository charts"
util
.
LogHandlerEntry
(
handler
,
r
)
repoName
,
err
:=
pos
(
w
,
r
,
2
)
if
err
!=
nil
{
return
err
}
chartName
,
err
:=
pos
(
w
,
r
,
4
)
if
err
!=
nil
{
return
err
}
repoChart
,
err
:=
c
.
Manager
.
GetChartForRepo
(
repoName
,
chartName
)
if
err
!=
nil
{
return
err
}
util
.
LogHandlerExitWithJSON
(
handler
,
w
,
repoChart
,
http
.
StatusOK
)
return
nil
}
func
getCredential
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
handler
string
)
*
repo
.
Credential
{
util
.
LogHandlerEntry
(
handler
,
r
)
t
:=
&
repo
.
Credential
{}
...
...
cmd/manager/manager/manager.go
View file @
b61ff1a6
...
...
@@ -50,8 +50,8 @@ type Manager interface {
GetChart
(
chartName
string
)
(
*
chart
.
Chart
,
error
)
// Repo Charts
ListRepoCharts
(
repo
Name
string
,
regex
*
regexp
.
Regexp
)
([]
string
,
error
)
GetChartForRepo
(
repo
Name
,
chartName
string
)
(
*
chart
.
Chart
,
error
)
ListRepoCharts
(
repo
URL
string
,
regex
*
regexp
.
Regexp
)
([]
string
,
error
)
GetChartForRepo
(
repo
URL
,
chartName
string
)
(
*
chart
.
Chart
,
error
)
// Credentials
CreateCredential
(
name
string
,
c
*
repo
.
Credential
)
error
...
...
@@ -59,8 +59,9 @@ type Manager interface {
// Chart Repositories
ListChartRepos
()
([]
string
,
error
)
AddChartRepo
(
name
string
)
error
AddChartRepo
(
addition
repo
.
IRepo
)
error
RemoveChartRepo
(
name
string
)
error
GetChartRepo
(
URL
string
)
(
repo
.
IRepo
,
error
)
}
type
manager
struct
{
...
...
@@ -335,19 +336,19 @@ func (m *manager) ListChartInstances(chartName string) ([]*common.ChartInstance,
return
m
.
repository
.
GetChartInstances
(
chartName
)
}
// GetRepoForChart returns the repository where
a
chart resides.
func
(
m
*
manager
)
GetRepoForChart
(
chartNam
e
string
)
(
string
,
error
)
{
_
,
r
,
err
:=
m
.
repoProvider
.
GetChartByReference
(
chartNam
e
)
// GetRepoForChart returns the repository where
the referenced
chart resides.
func
(
m
*
manager
)
GetRepoForChart
(
referenc
e
string
)
(
string
,
error
)
{
_
,
r
,
err
:=
m
.
repoProvider
.
GetChartByReference
(
referenc
e
)
if
err
!=
nil
{
return
""
,
err
}
return
r
.
Get
Name
(),
nil
return
r
.
Get
URL
(),
nil
}
// GetMetadataForChart returns the metadata for
a
chart.
func
(
m
*
manager
)
GetMetadataForChart
(
chartNam
e
string
)
(
*
chart
.
Chartfile
,
error
)
{
c
,
_
,
err
:=
m
.
repoProvider
.
GetChartByReference
(
chartNam
e
)
// GetMetadataForChart returns the metadata for
the referenced
chart.
func
(
m
*
manager
)
GetMetadataForChart
(
referenc
e
string
)
(
*
chart
.
Chartfile
,
error
)
{
c
,
_
,
err
:=
m
.
repoProvider
.
GetChartByReference
(
referenc
e
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -355,9 +356,9 @@ func (m *manager) GetMetadataForChart(chartName string) (*chart.Chartfile, error
return
c
.
Chartfile
(),
nil
}
// GetChart returns
a
chart.
func
(
m
*
manager
)
GetChart
(
chartNam
e
string
)
(
*
chart
.
Chart
,
error
)
{
c
,
_
,
err
:=
m
.
repoProvider
.
GetChartByReference
(
chartNam
e
)
// GetChart returns
the referenced
chart.
func
(
m
*
manager
)
GetChart
(
referenc
e
string
)
(
*
chart
.
Chart
,
error
)
{
c
,
_
,
err
:=
m
.
repoProvider
.
GetChartByReference
(
referenc
e
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -365,28 +366,24 @@ func (m *manager) GetChart(chartName string) (*chart.Chart, error) {
return
c
,
nil
}
// ListChartRepos returns the list of
chart repositorie
s
// ListChartRepos returns the list of
available chart repository URL
s
func
(
m
*
manager
)
ListChartRepos
()
([]
string
,
error
)
{
return
m
.
service
.
List
()
return
m
.
service
.
List
Repos
()
}
// AddChartRepo adds a chart repository to list of available chart repositories
func
(
m
*
manager
)
AddChartRepo
(
name
string
)
error
{
//TODO: implement
return
nil
// AddChartRepo adds a chart repository to the list
func
(
m
*
manager
)
AddChartRepo
(
addition
repo
.
IRepo
)
error
{
return
m
.
service
.
CreateRepo
(
addition
)
}
// RemoveChartRepo removes a chart repository
to list of available chart repositories
func
(
m
*
manager
)
RemoveChartRepo
(
name
string
)
error
{
return
m
.
service
.
Delete
(
name
)
// RemoveChartRepo removes a chart repository
from the list by URL
func
(
m
*
manager
)
RemoveChartRepo
(
URL
string
)
error
{
return
m
.
service
.
Delete
Repo
(
URL
)
}
func
(
m
*
manager
)
CreateRepo
(
pr
repo
.
IRepo
)
error
{
return
m
.
service
.
Create
(
pr
)
}
func
(
m
*
manager
)
GetRepo
(
name
string
)
(
repo
.
IRepo
,
error
)
{
return
m
.
service
.
Get
(
name
)
// GetChartRepo returns the chart repository with the given URL
func
(
m
*
manager
)
GetChartRepo
(
URL
string
)
(
repo
.
IRepo
,
error
)
{
return
m
.
service
.
GetRepoByURL
(
URL
)
}
func
generateManifestName
()
string
{
...
...
@@ -411,11 +408,11 @@ func getResourceErrors(c *common.Configuration) []string {
return
errs
}
// ListRepoCharts lists charts in a given repository whose
name
s
// ListRepoCharts lists charts in a given repository whose
URL
s
// conform to the supplied regular expression, or all charts, if the regular
// expression is nil.
func
(
m
*
manager
)
ListRepoCharts
(
repo
Name
string
,
regex
*
regexp
.
Regexp
)
([]
string
,
error
)
{
r
,
err
:=
m
.
repoProvider
.
GetRepoBy
Name
(
repoName
)
func
(
m
*
manager
)
ListRepoCharts
(
repo
URL
string
,
regex
*
regexp
.
Regexp
)
([]
string
,
error
)
{
r
,
err
:=
m
.
repoProvider
.
GetRepoBy
URL
(
repoURL
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -423,9 +420,9 @@ func (m *manager) ListRepoCharts(repoName string, regex *regexp.Regexp) ([]strin
return
r
.
ListCharts
(
regex
)
}
// GetChartForRepo returns a chart from a given repository.
func
(
m
*
manager
)
GetChartForRepo
(
repo
Name
,
chartName
string
)
(
*
chart
.
Chart
,
error
)
{
r
,
err
:=
m
.
repoProvider
.
GetRepoBy
Name
(
repoName
)
// GetChartForRepo returns a chart
by name
from a given repository.
func
(
m
*
manager
)
GetChartForRepo
(
repo
URL
,
chartName
string
)
(
*
chart
.
Chart
,
error
)
{
r
,
err
:=
m
.
repoProvider
.
GetRepoBy
URL
(
repoURL
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
cmd/manager/testutil.go
View file @
b61ff1a6
...
...
@@ -91,7 +91,7 @@ func (m *mockManager) GetChart(chartName string) (*chart.Chart, error) {
return
nil
,
nil
}
func
(
m
*
mockManager
)
AddChartRepo
(
name
string
)
error
{
func
(
m
*
mockManager
)
AddChartRepo
(
addition
repo
.
IRepo
)
error
{
return
nil
}
...
...
@@ -103,6 +103,10 @@ func (m *mockManager) RemoveChartRepo(name string) error {
return
nil
}
func
(
m
*
mockManager
)
GetChartRepo
(
URL
string
)
(
repo
.
IRepo
,
error
)
{
return
nil
,
nil
}
func
(
m
*
mockManager
)
ListRepos
()
([]
*
repo
.
Repo
,
error
)
{
return
[]
*
repo
.
Repo
{},
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment