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
00ad7d1c
Commit
00ad7d1c
authored
Mar 28, 2016
by
Jack Greenfield
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #461 from jackgr/manager
Repo name routes, tests and cleanups
parents
e7119a92
73ff6768
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
201 additions
and
60 deletions
+201
-60
chartrepos.go
cmd/manager/chartrepos.go
+4
-4
chartrepos_test.go
cmd/manager/chartrepos_test.go
+143
-4
manager.go
cmd/manager/manager/manager.go
+36
-20
testutil.go
cmd/manager/testutil.go
+16
-30
gcs_repo.go
pkg/repo/gcs_repo.go
+2
-2
No files found.
cmd/manager/chartrepos.go
View file @
00ad7d1c
...
...
@@ -39,7 +39,7 @@ func registerChartRepoRoutes(c *router.Context, h *router.Handler) {
func
listChartReposHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
handler
:=
"manager: list chart repositories"
repos
,
err
:=
c
.
Manager
.
List
Chart
Repos
()
repos
,
err
:=
c
.
Manager
.
ListRepos
()
if
err
!=
nil
{
return
err
}
...
...
@@ -58,7 +58,7 @@ func addChartRepoHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.C
return
nil
}
if
err
:=
c
.
Manager
.
Add
Chart
Repo
(
cr
);
err
!=
nil
{
if
err
:=
c
.
Manager
.
AddRepo
(
cr
);
err
!=
nil
{
httputil
.
BadRequest
(
w
,
r
,
err
)
return
nil
}
...
...
@@ -77,7 +77,7 @@ func removeChartRepoHandlerFunc(w http.ResponseWriter, r *http.Request, c *route
return
err
}
err
=
c
.
Manager
.
Remove
Chart
Repo
(
name
)
err
=
c
.
Manager
.
RemoveRepo
(
name
)
if
err
!=
nil
{
return
err
}
...
...
@@ -95,7 +95,7 @@ func getChartRepoHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.C
return
err
}
cr
,
err
:=
c
.
Manager
.
Get
Chart
Repo
(
repoURL
)
cr
,
err
:=
c
.
Manager
.
GetRepo
(
repoURL
)
if
err
!=
nil
{
httputil
.
BadRequest
(
w
,
r
,
err
)
return
nil
...
...
cmd/manager/chartrepos_test.go
View file @
00ad7d1c
...
...
@@ -17,19 +17,158 @@ limitations under the License.
package
main
import
(
"github.com/kubernetes/helm/pkg/repo"
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"testing"
)
func
TestListChartRepositories
(
t
*
testing
.
T
)
{
var
(
TestRepoBucket
=
"kubernetes-charts-testing"
TestRepoURL
=
"gs://"
+
TestRepoBucket
TestChartName
=
"frobnitz-0.0.1.tgz"
TestRepoType
=
string
(
repo
.
GCSRepoType
)
TestRepoFormat
=
string
(
repo
.
GCSRepoFormat
)
TestRepoCredentialName
=
"default"
)
func
TestListChartRepos
(
t
*
testing
.
T
)
{
c
:=
stubContext
()
s
:=
httpHarness
(
c
,
"GET /repositories"
,
listChartReposHandlerFunc
)
defer
s
.
Close
()
res
,
err
:=
http
.
Get
(
s
.
URL
+
"/repositories"
)
URL
:=
getTestURL
(
t
,
s
.
URL
,
""
,
""
)
res
,
err
:=
http
.
Get
(
URL
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed GET: %s"
,
err
)
}
if
res
.
StatusCode
!=
http
.
StatusOK
{
t
.
Errorf
(
"Expected status %d, got %d"
,
http
.
StatusOK
,
res
.
StatusCode
)
}
}
func
TestGetChartRepo
(
t
*
testing
.
T
)
{
c
:=
stubContext
()
s
:=
httpHarness
(
c
,
"GET /repositories/*"
,
getChartRepoHandlerFunc
)
defer
s
.
Close
()
URL
:=
getTestURL
(
t
,
s
.
URL
,
TestRepoBucket
,
""
)
res
,
err
:=
http
.
Get
(
URL
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed GET: %s"
,
err
)
}
if
res
.
StatusCode
!=
http
.
StatusOK
{
t
.
Errorf
(
"Expected status %d, got %d"
,
http
.
StatusOK
,
res
.
StatusCode
)
}
}
func
TestListRepoCharts
(
t
*
testing
.
T
)
{
c
:=
stubContext
()
s
:=
httpHarness
(
c
,
"GET /repositories/*/charts"
,
listRepoChartsHandlerFunc
)
defer
s
.
Close
()
URL
:=
getTestURL
(
t
,
s
.
URL
,
TestRepoBucket
,
"charts"
)
res
,
err
:=
http
.
Get
(
URL
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed GET: %s"
,
err
)
}
else
if
res
.
StatusCode
!=
http
.
StatusOK
{
t
.
Fatalf
(
"Failed GET: %s"
,
err
)
}
if
res
.
StatusCode
!=
http
.
StatusOK
{
t
.
Errorf
(
"Expected status %d, got %d"
,
http
.
StatusOK
,
res
.
StatusCode
)
}
}
func
TestGetRepoChart
(
t
*
testing
.
T
)
{
c
:=
stubContext
()
s
:=
httpHarness
(
c
,
"GET /repositories/*/charts/*"
,
getRepoChartHandlerFunc
)
defer
s
.
Close
()
chartURL
:=
fmt
.
Sprintf
(
"charts/%s"
,
TestChartName
)
URL
:=
getTestURL
(
t
,
s
.
URL
,
TestRepoBucket
,
chartURL
)
res
,
err
:=
http
.
Get
(
URL
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed GET: %s"
,
err
)
}
if
res
.
StatusCode
!=
http
.
StatusOK
{
t
.
Errorf
(
"Expected status %d, got %d"
,
http
.
StatusOK
,
res
.
StatusCode
)
}
}
func
TestAddChartRepo
(
t
*
testing
.
T
)
{
c
:=
stubContext
()
s
:=
httpHarness
(
c
,
"POST /repositories"
,
addChartRepoHandlerFunc
)
defer
s
.
Close
()
URL
:=
getTestURL
(
t
,
s
.
URL
,
""
,
""
)
body
:=
getTestRepo
(
t
,
URL
)
res
,
err
:=
http
.
Post
(
URL
,
"application/json"
,
body
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed POST: %s"
,
err
)
}
if
res
.
StatusCode
!=
http
.
StatusCreated
{
t
.
Errorf
(
"Expected status %d, got %d"
,
http
.
StatusOK
,
res
.
StatusCode
)
}
}
func
TestRemoveChartRepo
(
t
*
testing
.
T
)
{
c
:=
stubContext
()
s
:=
httpHarness
(
c
,
"DELETE /repositories/*"
,
removeChartRepoHandlerFunc
)
defer
s
.
Close
()
URL
:=
getTestURL
(
t
,
s
.
URL
,
TestRepoBucket
,
""
)
req
,
err
:=
http
.
NewRequest
(
"DELETE"
,
URL
,
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"Cannot create DELETE request: %s"
,
err
)
}
res
,
err
:=
http
.
DefaultClient
.
Do
(
req
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed DELETE: %s"
,
err
)
}
defer
res
.
Body
.
Close
()
if
res
.
StatusCode
!=
http
.
StatusOK
{
t
.
Errorf
(
"Expected status %d, got %d"
,
http
.
StatusOK
,
res
.
StatusCode
)
}
}
func
getTestRepo
(
t
*
testing
.
T
,
URL
string
)
io
.
Reader
{
tr
,
err
:=
repo
.
NewRepo
(
URL
,
TestRepoCredentialName
,
TestRepoBucket
,
TestRepoFormat
,
TestRepoType
)
if
err
!=
nil
{
t
.
Fatalf
(
"Cannot create test repository: %s"
,
err
)
}
trb
,
err
:=
json
.
Marshal
(
&
tr
)
if
err
!=
nil
{
t
.
Fatalf
(
"Cannot marshal test repository: %s"
,
err
)
}
return
bytes
.
NewReader
(
trb
)
}
func
getTestURL
(
t
*
testing
.
T
,
baseURL
,
repoURL
,
chartURL
string
)
string
{
URL
:=
fmt
.
Sprintf
(
"%s/repositories"
,
baseURL
)
if
repoURL
!=
""
{
URL
=
fmt
.
Sprintf
(
"%s/%s"
,
URL
,
repoURL
)
}
if
chartURL
!=
""
{
URL
=
fmt
.
Sprintf
(
"%s/%s"
,
URL
,
chartURL
)
}
u
,
err
:=
url
.
Parse
(
URL
)
if
err
!=
nil
{
t
.
Fatalf
(
"cannot parse test URL %s: %s"
,
URL
,
err
)
}
return
u
.
String
()
}
cmd/manager/manager/manager.go
View file @
00ad7d1c
...
...
@@ -50,18 +50,18 @@ type Manager interface {
GetChart
(
chartName
string
)
(
*
chart
.
Chart
,
error
)
// Repo Charts
ListRepoCharts
(
repo
URL
string
,
regex
*
regexp
.
Regexp
)
([]
string
,
error
)
GetChartForRepo
(
repo
URL
,
chartName
string
)
(
*
chart
.
Chart
,
error
)
ListRepoCharts
(
repo
Name
string
,
regex
*
regexp
.
Regexp
)
([]
string
,
error
)
GetChartForRepo
(
repo
Name
,
chartName
string
)
(
*
chart
.
Chart
,
error
)
// Credentials
CreateCredential
(
name
string
,
c
*
repo
.
Credential
)
error
GetCredential
(
name
string
)
(
*
repo
.
Credential
,
error
)
// Chart Repositories
List
Chart
Repos
()
(
map
[
string
]
string
,
error
)
Add
Chart
Repo
(
addition
repo
.
IRepo
)
error
Remove
ChartRepo
(
n
ame
string
)
error
Get
ChartRepo
(
URL
string
)
(
repo
.
IRepo
,
error
)
ListRepos
()
(
map
[
string
]
string
,
error
)
AddRepo
(
addition
repo
.
IRepo
)
error
Remove
Repo
(
repoN
ame
string
)
error
Get
Repo
(
repoName
string
)
(
repo
.
IRepo
,
error
)
}
type
manager
struct
{
...
...
@@ -366,28 +366,34 @@ func (m *manager) GetChart(reference string) (*chart.Chart, error) {
return
c
,
nil
}
// List
ChartRepos returns the list of available chart
repository URLs
func
(
m
*
manager
)
List
Chart
Repos
()
(
map
[
string
]
string
,
error
)
{
// List
Repos returns the list of available
repository URLs
func
(
m
*
manager
)
ListRepos
()
(
map
[
string
]
string
,
error
)
{
return
m
.
service
.
ListRepos
()
}
// Add
ChartRepo adds a chart
repository to the list
func
(
m
*
manager
)
Add
Chart
Repo
(
addition
repo
.
IRepo
)
error
{
// Add
Repo adds a
repository to the list
func
(
m
*
manager
)
AddRepo
(
addition
repo
.
IRepo
)
error
{
return
m
.
service
.
CreateRepo
(
addition
)
}
// Remove
ChartRepo removes a chart
repository from the list by URL
func
(
m
*
manager
)
Remove
ChartRepo
(
n
ame
string
)
error
{
url
,
err
:=
m
.
service
.
GetRepoURLByName
(
n
ame
)
// Remove
Repo removes a
repository from the list by URL
func
(
m
*
manager
)
Remove
Repo
(
repoN
ame
string
)
error
{
repoURL
,
err
:=
m
.
service
.
GetRepoURLByName
(
repoN
ame
)
if
err
!=
nil
{
return
err
}
return
m
.
service
.
DeleteRepo
(
url
)
return
m
.
service
.
DeleteRepo
(
repoURL
)
}
// GetChartRepo returns the chart repository with the given URL
func
(
m
*
manager
)
GetChartRepo
(
URL
string
)
(
repo
.
IRepo
,
error
)
{
return
m
.
service
.
GetRepoByURL
(
URL
)
// GetRepo returns the repository with the given URL
func
(
m
*
manager
)
GetRepo
(
repoName
string
)
(
repo
.
IRepo
,
error
)
{
repoURL
,
err
:=
m
.
service
.
GetRepoURLByName
(
repoName
)
if
err
!=
nil
{
return
nil
,
err
}
return
m
.
service
.
GetRepoByURL
(
repoURL
)
}
func
generateManifestName
()
string
{
...
...
@@ -412,10 +418,15 @@ func getResourceErrors(c *common.Configuration) []string {
return
errs
}
// ListRepoCharts lists charts in a given repository whose
URL
s
// ListRepoCharts lists charts in a given repository whose
name
s
// conform to the supplied regular expression, or all charts, if the regular
// expression is nil.
func
(
m
*
manager
)
ListRepoCharts
(
repoURL
string
,
regex
*
regexp
.
Regexp
)
([]
string
,
error
)
{
func
(
m
*
manager
)
ListRepoCharts
(
repoName
string
,
regex
*
regexp
.
Regexp
)
([]
string
,
error
)
{
repoURL
,
err
:=
m
.
service
.
GetRepoURLByName
(
repoName
)
if
err
!=
nil
{
return
nil
,
err
}
r
,
err
:=
m
.
repoProvider
.
GetRepoByURL
(
repoURL
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -425,7 +436,12 @@ func (m *manager) ListRepoCharts(repoURL string, regex *regexp.Regexp) ([]string
}
// GetChartForRepo returns a chart by name from a given repository.
func
(
m
*
manager
)
GetChartForRepo
(
repoURL
,
chartName
string
)
(
*
chart
.
Chart
,
error
)
{
func
(
m
*
manager
)
GetChartForRepo
(
repoName
,
chartName
string
)
(
*
chart
.
Chart
,
error
)
{
repoURL
,
err
:=
m
.
service
.
GetRepoURLByName
(
repoName
)
if
err
!=
nil
{
return
nil
,
err
}
r
,
err
:=
m
.
repoProvider
.
GetRepoByURL
(
repoURL
)
if
err
!=
nil
{
return
nil
,
err
...
...
cmd/manager/testutil.go
View file @
00ad7d1c
...
...
@@ -112,54 +112,40 @@ func (m *mockManager) GetRepoForChart(chartName string) (string, error) {
}
func
(
m
*
mockManager
)
GetMetadataForChart
(
chartName
string
)
(
*
chart
.
Chartfile
,
error
)
{
return
nil
,
nil
return
&
chart
.
Chartfile
{}
,
nil
}
func
(
m
*
mockManager
)
GetChart
(
chartName
string
)
(
*
chart
.
Chart
,
error
)
{
return
nil
,
nil
return
&
chart
.
Chart
{}
,
nil
}
func
(
m
*
mockManager
)
AddChartRepo
(
addition
repo
.
IRepo
)
error
{
return
nil
func
(
m
*
mockManager
)
ListRepoCharts
(
repoName
string
,
regex
*
regexp
.
Regexp
)
([]
string
,
error
)
{
return
[]
string
{},
nil
}
func
(
m
*
mockManager
)
ListChartRepos
()
(
map
[
string
]
string
,
error
)
{
return
map
[
string
]
string
{},
nil
func
(
m
*
mockManager
)
GetChartForRepo
(
repoName
,
chartName
string
)
(
*
chart
.
Chart
,
error
)
{
return
&
chart
.
Chart
{},
nil
}
func
(
m
*
mockManager
)
RemoveChartRepo
(
name
string
)
error
{
func
(
m
*
mockManager
)
CreateCredential
(
name
string
,
c
*
repo
.
Credential
)
error
{
return
nil
}
func
(
m
*
mockManager
)
GetChartRepo
(
URL
string
)
(
repo
.
IRepo
,
error
)
{
return
nil
,
nil
func
(
m
*
mockManager
)
GetCredential
(
name
string
)
(
*
repo
.
Credential
,
error
)
{
return
&
repo
.
Credential
{},
nil
}
func
(
m
*
mockManager
)
ListRepos
()
(
[]
*
repo
.
Repo
,
error
)
{
return
[]
*
repo
.
Repo
{},
nil
func
(
m
*
mockManager
)
ListRepos
()
(
map
[
string
]
string
,
error
)
{
return
map
[
string
]
string
{},
nil
}
func
(
m
*
mockManager
)
CreateRepo
(
pr
*
repo
.
Repo
)
error
{
return
nil
}
func
(
m
*
mockManager
)
GetRepo
(
name
string
)
(
*
repo
.
Repo
,
error
)
{
return
&
repo
.
Repo
{},
nil
}
func
(
m
*
mockManager
)
DeleteRepo
(
name
string
)
error
{
func
(
m
*
mockManager
)
AddRepo
(
addition
repo
.
IRepo
)
error
{
return
nil
}
func
(
m
*
mockManager
)
ListRepoCharts
(
repoName
string
,
regex
*
regexp
.
Regexp
)
([]
string
,
error
)
{
return
[]
string
{},
nil
}
func
(
m
*
mockManager
)
GetChartForRepo
(
repoName
,
chartName
string
)
(
*
chart
.
Chart
,
error
)
{
return
nil
,
nil
}
func
(
m
*
mockManager
)
CreateCredential
(
name
string
,
c
*
repo
.
Credential
)
error
{
func
(
m
*
mockManager
)
RemoveRepo
(
name
string
)
error
{
return
nil
}
func
(
m
*
mockManager
)
GetCredential
(
name
string
)
(
*
repo
.
Credential
,
error
)
{
return
&
repo
.
Credential
{},
nil
func
(
m
*
mockManager
)
GetRepo
(
name
string
)
(
repo
.
IRepo
,
error
)
{
return
&
repo
.
Repo
{},
nil
}
pkg/repo/gcs_repo.go
View file @
00ad7d1c
...
...
@@ -59,12 +59,12 @@ type GCSRepo struct {
}
// NewPublicGCSRepo creates a new an IStorageRepo for the public GCS repository.
func
NewPublicGCSRepo
(
httpClient
*
http
.
Client
)
(
IStorage
Repo
,
error
)
{
func
NewPublicGCSRepo
(
httpClient
*
http
.
Client
)
(
*
GCS
Repo
,
error
)
{
return
NewGCSRepo
(
GCSPublicRepoURL
,
""
,
GCSPublicRepoBucket
,
nil
)
}
// NewGCSRepo creates a new IStorageRepo for a given GCS repository.
func
NewGCSRepo
(
URL
,
credentialName
,
repoName
string
,
httpClient
*
http
.
Client
)
(
IStorage
Repo
,
error
)
{
func
NewGCSRepo
(
URL
,
credentialName
,
repoName
string
,
httpClient
*
http
.
Client
)
(
*
GCS
Repo
,
error
)
{
r
,
err
:=
newRepo
(
URL
,
credentialName
,
repoName
,
GCSRepoFormat
,
GCSRepoType
)
if
err
!=
nil
{
return
nil
,
err
...
...
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