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
cc97c522
Commit
cc97c522
authored
Mar 21, 2016
by
Michelle Noorali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(repo): add new chart repo routes
parent
bc90e18b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
202 additions
and
110 deletions
+202
-110
chartrepos.go
cmd/manager/chartrepos.go
+23
-3
chartrepos_test.go
cmd/manager/chartrepos_test.go
+19
-0
deployments_test.go
cmd/manager/deployments_test.go
+0
-102
manager.go
cmd/manager/manager/manager.go
+30
-5
testutil.go
cmd/manager/testutil.go
+130
-0
No files found.
cmd/manager/chartrepos.go
View file @
cc97c522
...
@@ -14,18 +14,38 @@ func registerChartRepoRoutes(c *router.Context, h *router.Handler) {
...
@@ -14,18 +14,38 @@ func registerChartRepoRoutes(c *router.Context, h *router.Handler) {
func
listChartRepositoriesHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
func
listChartRepositoriesHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
handler
:=
"manager: list chart repositories"
handler
:=
"manager: list chart repositories"
util
.
LogHandlerExitWithJSON
(
handler
,
w
,
"a repo here"
,
http
.
StatusOK
)
repos
,
err
:=
c
.
Manager
.
ListChartRepos
()
if
err
!=
nil
{
return
err
}
util
.
LogHandlerExitWithJSON
(
handler
,
w
,
repos
,
http
.
StatusOK
)
return
nil
return
nil
}
}
func
addChartRepoHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
func
addChartRepoHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
handler
:=
"manager: add chart repository"
handler
:=
"manager: add chart repository"
util
.
LogHandlerExitWithJSON
(
handler
,
w
,
"add a repo"
,
http
.
StatusOK
)
name
,
err
:=
pos
(
w
,
r
,
2
)
if
err
!=
nil
{
return
err
}
err
=
c
.
Manager
.
AddChartRepo
(
name
)
if
err
!=
nil
{
return
err
}
util
.
LogHandlerExitWithJSON
(
handler
,
w
,
"added"
,
http
.
StatusOK
)
return
nil
return
nil
}
}
func
removeChartRepoHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
func
removeChartRepoHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
handler
:=
"manager: remove chart repository"
handler
:=
"manager: remove chart repository"
util
.
LogHandlerExitWithJSON
(
handler
,
w
,
"remove a repo"
,
http
.
StatusOK
)
name
,
err
:=
pos
(
w
,
r
,
2
)
if
err
!=
nil
{
return
err
}
err
=
c
.
Manager
.
RemoveChartRepo
(
name
)
if
err
!=
nil
{
return
err
}
util
.
LogHandlerExitWithJSON
(
handler
,
w
,
"removed"
,
http
.
StatusOK
)
return
nil
return
nil
}
}
cmd/manager/chartrepos_test.go
0 → 100644
View file @
cc97c522
package
main
import
(
"net/http"
"testing"
)
func
TestListChartRepositories
(
t
*
testing
.
T
)
{
c
:=
stubContext
()
s
:=
httpHarness
(
c
,
"GET /chart_repositories"
,
listChartRepositoriesHandlerFunc
)
defer
s
.
Close
()
res
,
err
:=
http
.
Get
(
s
.
URL
+
"/chart_repositories"
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed GET: %s"
,
err
)
}
else
if
res
.
StatusCode
!=
http
.
StatusOK
{
t
.
Errorf
(
"Expected status %d, got %d"
,
http
.
StatusOK
,
res
.
StatusCode
)
}
}
cmd/manager/deployments_test.go
View file @
cc97c522
...
@@ -4,15 +4,9 @@ import (
...
@@ -4,15 +4,9 @@ import (
"bytes"
"bytes"
"encoding/json"
"encoding/json"
"net/http"
"net/http"
"net/http/httptest"
"net/url"
"regexp"
"testing"
"testing"
"github.com/kubernetes/helm/cmd/manager/router"
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/httputil"
"github.com/kubernetes/helm/pkg/registry"
)
)
func
TestHealthz
(
t
*
testing
.
T
)
{
func
TestHealthz
(
t
*
testing
.
T
)
{
...
@@ -48,99 +42,3 @@ func TestCreateDeployments(t *testing.T) {
...
@@ -48,99 +42,3 @@ func TestCreateDeployments(t *testing.T) {
t
.
Errorf
(
"Expected status %d, got %d"
,
http
.
StatusCreated
,
res
.
StatusCode
)
t
.
Errorf
(
"Expected status %d, got %d"
,
http
.
StatusCreated
,
res
.
StatusCode
)
}
}
}
}
// httpHarness is a simple test server fixture.
// Simple fixture for standing up a test server with a single route.
//
// You must Close() the returned server.
func
httpHarness
(
c
*
router
.
Context
,
route
string
,
fn
router
.
HandlerFunc
)
*
httptest
.
Server
{
h
:=
router
.
NewHandler
(
c
)
h
.
Add
(
route
,
fn
)
return
httptest
.
NewServer
(
h
)
}
// stubContext creates a stub of a Context object.
//
// This creates a stub context with the following properties:
// - Config is initialized to empty values
// - Encoder is initialized to httputil.DefaultEncoder
// - CredentialProvider is initialized to registry.InmemCredentialProvider
// - Manager is initialized to mockManager.
func
stubContext
()
*
router
.
Context
{
return
&
router
.
Context
{
Config
:
&
router
.
Config
{},
Manager
:
&
mockManager
{},
CredentialProvider
:
registry
.
NewInmemCredentialProvider
(),
Encoder
:
httputil
.
DefaultEncoder
,
}
}
type
mockManager
struct
{}
func
(
m
*
mockManager
)
ListDeployments
()
([]
common
.
Deployment
,
error
)
{
return
[]
common
.
Deployment
{},
nil
}
func
(
m
*
mockManager
)
GetDeployment
(
name
string
)
(
*
common
.
Deployment
,
error
)
{
return
&
common
.
Deployment
{},
nil
}
func
(
m
*
mockManager
)
CreateDeployment
(
t
*
common
.
Template
)
(
*
common
.
Deployment
,
error
)
{
return
&
common
.
Deployment
{},
nil
}
func
(
m
*
mockManager
)
DeleteDeployment
(
name
string
,
forget
bool
)
(
*
common
.
Deployment
,
error
)
{
return
&
common
.
Deployment
{},
nil
}
func
(
m
*
mockManager
)
PutDeployment
(
name
string
,
t
*
common
.
Template
)
(
*
common
.
Deployment
,
error
)
{
return
&
common
.
Deployment
{},
nil
}
func
(
m
*
mockManager
)
ListManifests
(
deploymentName
string
)
(
map
[
string
]
*
common
.
Manifest
,
error
)
{
return
map
[
string
]
*
common
.
Manifest
{},
nil
}
func
(
m
*
mockManager
)
GetManifest
(
deploymentName
string
,
manifest
string
)
(
*
common
.
Manifest
,
error
)
{
return
&
common
.
Manifest
{},
nil
}
func
(
m
*
mockManager
)
Expand
(
t
*
common
.
Template
)
(
*
common
.
Manifest
,
error
)
{
return
&
common
.
Manifest
{},
nil
}
func
(
m
*
mockManager
)
ListTypes
()
([]
string
,
error
)
{
return
[]
string
{},
nil
}
func
(
m
*
mockManager
)
ListInstances
(
typeName
string
)
([]
*
common
.
TypeInstance
,
error
)
{
return
[]
*
common
.
TypeInstance
{},
nil
}
func
(
m
*
mockManager
)
GetRegistryForType
(
typeName
string
)
(
string
,
error
)
{
return
""
,
nil
}
func
(
m
*
mockManager
)
GetMetadataForType
(
typeName
string
)
(
string
,
error
)
{
return
""
,
nil
}
func
(
m
*
mockManager
)
ListRegistries
()
([]
*
common
.
Registry
,
error
)
{
return
[]
*
common
.
Registry
{},
nil
}
func
(
m
*
mockManager
)
CreateRegistry
(
pr
*
common
.
Registry
)
error
{
return
nil
}
func
(
m
*
mockManager
)
GetRegistry
(
name
string
)
(
*
common
.
Registry
,
error
)
{
return
&
common
.
Registry
{},
nil
}
func
(
m
*
mockManager
)
DeleteRegistry
(
name
string
)
error
{
return
nil
}
func
(
m
*
mockManager
)
ListRegistryTypes
(
registryName
string
,
regex
*
regexp
.
Regexp
)
([]
registry
.
Type
,
error
)
{
return
[]
registry
.
Type
{},
nil
}
func
(
m
*
mockManager
)
GetDownloadURLs
(
registryName
string
,
t
registry
.
Type
)
([]
*
url
.
URL
,
error
)
{
return
[]
*
url
.
URL
{},
nil
}
func
(
m
*
mockManager
)
GetFile
(
registryName
string
,
url
string
)
(
string
,
error
)
{
return
""
,
nil
}
func
(
m
*
mockManager
)
CreateCredential
(
name
string
,
c
*
common
.
RegistryCredential
)
error
{
return
nil
}
func
(
m
*
mockManager
)
GetCredential
(
name
string
)
(
*
common
.
RegistryCredential
,
error
)
{
return
&
common
.
RegistryCredential
{},
nil
}
cmd/manager/manager/manager.go
View file @
cc97c522
...
@@ -64,14 +64,20 @@ type Manager interface {
...
@@ -64,14 +64,20 @@ type Manager interface {
// Credentials
// Credentials
CreateCredential
(
name
string
,
c
*
common
.
RegistryCredential
)
error
CreateCredential
(
name
string
,
c
*
common
.
RegistryCredential
)
error
GetCredential
(
name
string
)
(
*
common
.
RegistryCredential
,
error
)
GetCredential
(
name
string
)
(
*
common
.
RegistryCredential
,
error
)
// Chart Repositories
ListChartRepos
()
([]
string
,
error
)
AddChartRepo
(
name
string
)
error
RemoveChartRepo
(
name
string
)
error
}
}
type
manager
struct
{
type
manager
struct
{
expander
Expander
expander
Expander
deployer
Deployer
deployer
Deployer
repository
repository
.
Repository
repository
repository
.
Repository
registryProvider
registry
.
RegistryProvider
registryProvider
registry
.
RegistryProvider
service
common
.
RegistryService
service
common
.
RegistryService
//TODO: add chart repo service
credentialProvider
common
.
CredentialProvider
credentialProvider
common
.
CredentialProvider
}
}
...
@@ -81,6 +87,7 @@ func NewManager(expander Expander,
...
@@ -81,6 +87,7 @@ func NewManager(expander Expander,
repository
repository
.
Repository
,
repository
repository
.
Repository
,
registryProvider
registry
.
RegistryProvider
,
registryProvider
registry
.
RegistryProvider
,
service
common
.
RegistryService
,
service
common
.
RegistryService
,
//TODO: add chart repo service
credentialProvider
common
.
CredentialProvider
)
Manager
{
credentialProvider
common
.
CredentialProvider
)
Manager
{
return
&
manager
{
expander
,
deployer
,
repository
,
registryProvider
,
service
,
credentialProvider
}
return
&
manager
{
expander
,
deployer
,
repository
,
registryProvider
,
service
,
credentialProvider
}
}
}
...
@@ -378,6 +385,24 @@ func (m *manager) ListRegistries() ([]*common.Registry, error) {
...
@@ -378,6 +385,24 @@ func (m *manager) ListRegistries() ([]*common.Registry, error) {
return
m
.
service
.
List
()
return
m
.
service
.
List
()
}
}
// ListChartRepos returns the list of chart repositories
func
(
m
*
manager
)
ListChartRepos
()
([]
string
,
error
)
{
//TODO: implement
return
nil
,
nil
}
// AddChartRepo adds a chart repository to list of available chart repositories
func
(
m
*
manager
)
AddChartRepo
(
name
string
)
error
{
//TODO: implement
return
nil
}
// RemoveChartRepo removes a chart repository to list of available chart repositories
func
(
m
*
manager
)
RemoveChartRepo
(
name
string
)
error
{
//TODO: implement
return
nil
}
func
(
m
*
manager
)
CreateRegistry
(
pr
*
common
.
Registry
)
error
{
func
(
m
*
manager
)
CreateRegistry
(
pr
*
common
.
Registry
)
error
{
return
m
.
service
.
Create
(
pr
)
return
m
.
service
.
Create
(
pr
)
}
}
...
...
cmd/manager/testutil.go
0 → 100644
View file @
cc97c522
package
main
import
(
"net/http/httptest"
"net/url"
"regexp"
"github.com/kubernetes/helm/cmd/manager/router"
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/httputil"
"github.com/kubernetes/helm/pkg/registry"
)
// httpHarness is a simple test server fixture.
// Simple fixture for standing up a test server with a single route.
//
// You must Close() the returned server.
func
httpHarness
(
c
*
router
.
Context
,
route
string
,
fn
router
.
HandlerFunc
)
*
httptest
.
Server
{
h
:=
router
.
NewHandler
(
c
)
h
.
Add
(
route
,
fn
)
return
httptest
.
NewServer
(
h
)
}
// stubContext creates a stub of a Context object.
//
// This creates a stub context with the following properties:
// - Config is initialized to empty values
// - Encoder is initialized to httputil.DefaultEncoder
// - CredentialProvider is initialized to registry.InmemCredentialProvider
// - Manager is initialized to mockManager.
func
stubContext
()
*
router
.
Context
{
return
&
router
.
Context
{
Config
:
&
router
.
Config
{},
Manager
:
&
mockManager
{},
CredentialProvider
:
registry
.
NewInmemCredentialProvider
(),
Encoder
:
httputil
.
DefaultEncoder
,
}
}
type
mockManager
struct
{}
func
(
m
*
mockManager
)
ListDeployments
()
([]
common
.
Deployment
,
error
)
{
return
[]
common
.
Deployment
{},
nil
}
func
(
m
*
mockManager
)
GetDeployment
(
name
string
)
(
*
common
.
Deployment
,
error
)
{
return
&
common
.
Deployment
{},
nil
}
func
(
m
*
mockManager
)
CreateDeployment
(
t
*
common
.
Template
)
(
*
common
.
Deployment
,
error
)
{
return
&
common
.
Deployment
{},
nil
}
func
(
m
*
mockManager
)
DeleteDeployment
(
name
string
,
forget
bool
)
(
*
common
.
Deployment
,
error
)
{
return
&
common
.
Deployment
{},
nil
}
func
(
m
*
mockManager
)
PutDeployment
(
name
string
,
t
*
common
.
Template
)
(
*
common
.
Deployment
,
error
)
{
return
&
common
.
Deployment
{},
nil
}
func
(
m
*
mockManager
)
ListManifests
(
deploymentName
string
)
(
map
[
string
]
*
common
.
Manifest
,
error
)
{
return
map
[
string
]
*
common
.
Manifest
{},
nil
}
func
(
m
*
mockManager
)
GetManifest
(
deploymentName
string
,
manifest
string
)
(
*
common
.
Manifest
,
error
)
{
return
&
common
.
Manifest
{},
nil
}
func
(
m
*
mockManager
)
Expand
(
t
*
common
.
Template
)
(
*
common
.
Manifest
,
error
)
{
return
&
common
.
Manifest
{},
nil
}
func
(
m
*
mockManager
)
ListTypes
()
([]
string
,
error
)
{
return
[]
string
{},
nil
}
func
(
m
*
mockManager
)
ListInstances
(
typeName
string
)
([]
*
common
.
TypeInstance
,
error
)
{
return
[]
*
common
.
TypeInstance
{},
nil
}
func
(
m
*
mockManager
)
GetRegistryForType
(
typeName
string
)
(
string
,
error
)
{
return
""
,
nil
}
func
(
m
*
mockManager
)
GetMetadataForType
(
typeName
string
)
(
string
,
error
)
{
return
""
,
nil
}
func
(
m
*
mockManager
)
AddChartRepo
(
name
string
)
error
{
return
nil
}
func
(
m
*
mockManager
)
ListChartRepos
()
([]
string
,
error
)
{
return
[]
string
{},
nil
}
func
(
m
*
mockManager
)
RemoveChartRepo
(
name
string
)
error
{
return
nil
}
func
(
m
*
mockManager
)
ListRegistries
()
([]
*
common
.
Registry
,
error
)
{
return
[]
*
common
.
Registry
{},
nil
}
func
(
m
*
mockManager
)
CreateRegistry
(
pr
*
common
.
Registry
)
error
{
return
nil
}
func
(
m
*
mockManager
)
GetRegistry
(
name
string
)
(
*
common
.
Registry
,
error
)
{
return
&
common
.
Registry
{},
nil
}
func
(
m
*
mockManager
)
DeleteRegistry
(
name
string
)
error
{
return
nil
}
func
(
m
*
mockManager
)
ListRegistryTypes
(
registryName
string
,
regex
*
regexp
.
Regexp
)
([]
registry
.
Type
,
error
)
{
return
[]
registry
.
Type
{},
nil
}
func
(
m
*
mockManager
)
GetDownloadURLs
(
registryName
string
,
t
registry
.
Type
)
([]
*
url
.
URL
,
error
)
{
return
[]
*
url
.
URL
{},
nil
}
func
(
m
*
mockManager
)
GetFile
(
registryName
string
,
url
string
)
(
string
,
error
)
{
return
""
,
nil
}
func
(
m
*
mockManager
)
CreateCredential
(
name
string
,
c
*
common
.
RegistryCredential
)
error
{
return
nil
}
func
(
m
*
mockManager
)
GetCredential
(
name
string
)
(
*
common
.
RegistryCredential
,
error
)
{
return
&
common
.
RegistryCredential
{},
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