Commit f3fd7b14 authored by vaikas-google's avatar vaikas-google

wire in the in memory registry provider so that we can show how it works

parent 616a8c38
......@@ -31,9 +31,10 @@ import (
"github.com/ghodss/yaml"
"github.com/gorilla/mux"
"github.com/kubernetes/deployment-manager/manager/manager"
"github.com/kubernetes/deployment-manager/common"
"github.com/kubernetes/deployment-manager/manager/manager"
"github.com/kubernetes/deployment-manager/manager/repository"
"github.com/kubernetes/deployment-manager/registry"
"github.com/kubernetes/deployment-manager/util"
)
......@@ -48,6 +49,7 @@ var deployments = []Route{
{"Expand", "/expand", "POST", expandHandlerFunc, ""},
{"ListTypes", "/types", "GET", listTypesHandlerFunc, ""},
{"ListTypeInstances", "/types/{type}/instances", "GET", listTypeInstancesHandlerFunc, ""},
{"ListRegistries", "/registries", "GET", listRegistriesHandlerFunc, ""},
}
var (
......@@ -72,8 +74,9 @@ func init() {
func newManager() manager.Manager {
expander := manager.NewExpander(getServiceURL(*expanderURL, *expanderName), manager.NewTypeResolver())
deployer := manager.NewDeployer(getServiceURL(*deployerURL, *deployerName))
registryService := registry.NewInmemRepositoryService()
r := repository.NewMapBasedRepository()
return manager.NewManager(expander, deployer, r)
return manager.NewManager(expander, deployer, r, registryService)
}
func getServiceURL(serviceURL, serviceName string) string {
......@@ -329,3 +332,15 @@ func listTypeInstancesHandlerFunc(w http.ResponseWriter, r *http.Request) {
util.LogHandlerExitWithJSON(handler, w, backend.ListInstances(typeName), http.StatusOK)
}
// Putting Registry handlers here for now because deployments.go
// currently owns its own Manager backend and doesn't like to share.
func listRegistriesHandlerFunc(w http.ResponseWriter, r *http.Request) {
handler := "manager: list registries"
util.LogHandlerEntry(handler, r)
registries, err := backend.ListRegistries()
if err != nil {
return
}
util.LogHandlerExitWithJSON(handler, w, registries, http.StatusOK)
}
......@@ -23,6 +23,7 @@ import (
"github.com/kubernetes/deployment-manager/common"
"github.com/kubernetes/deployment-manager/manager/repository"
"github.com/kubernetes/deployment-manager/registry"
)
// Manager manages a persistent set of Deployments.
......@@ -37,17 +38,23 @@ type Manager interface {
Expand(t *common.Template) (*common.Manifest, error)
ListTypes() []string
ListInstances(typeName string) []*common.TypeInstance
// Registry related functions
ListRegistries() ([]*common.Registry, error)
CreateRegistry(pr *common.Registry) error
GetRegistry(name string) (*common.Registry, error)
DeleteRegistry(name string) error
}
type manager struct {
expander Expander
deployer Deployer
repository repository.Repository
registryService registry.RegistryService
}
// NewManager returns a new initialized Manager.
func NewManager(expander Expander, deployer Deployer, repository repository.Repository) Manager {
return &manager{expander, deployer, repository}
func NewManager(expander Expander, deployer Deployer, repository repository.Repository, registryService registry.RegistryService) Manager {
return &manager{expander, deployer, repository, registryService}
}
// ListDeployments returns the list of deployments
......@@ -302,6 +309,22 @@ func (m *manager) ListInstances(typeName string) []*common.TypeInstance {
return m.repository.GetTypeInstances(typeName)
}
func (m *manager) ListRegistries() ([]*common.Registry, error) {
return m.registryService.List()
}
func (m *manager) CreateRegistry(pr *common.Registry) error {
return m.registryService.Create(pr)
}
func (m *manager) GetRegistry(name string) (*common.Registry, error) {
return m.registryService.Get(name)
}
func (m *manager) DeleteRegistry(name string) error {
return m.registryService.Delete(name)
}
func generateManifestName() string {
return fmt.Sprintf("manifest-%d", time.Now().UTC().UnixNano())
}
......
......@@ -28,13 +28,30 @@ type inmemRepositoryService struct {
}
func NewInmemRepositoryService() RegistryService {
return &inmemRepositoryService{
rs := &inmemRepositoryService{
repositories: make(map[string]*common.Registry),
}
rs.Create(&common.Registry{
Name: "charts",
Type: common.Github,
URL: "github.com/helm/charts",
Format: common.UnversionedRegistry,
})
rs.Create(&common.Registry{
Name: "application-dm-templates",
Type: common.Github,
URL: "github.com/kubernetes/application-dm-templates",
Format: common.VersionedRegistry,
})
return rs
}
func (rs *inmemRepositoryService) List() ([]*common.Registry, error) {
return nil, nil
ret := []*common.Registry{}
for _, r := range rs.repositories {
ret = append(ret, r)
}
return ret, nil
}
func (rs *inmemRepositoryService) Create(repository *common.Registry) error {
......
......@@ -30,18 +30,6 @@ type RegistryProvider interface {
func NewDefaultRegistryProvider() RegistryProvider {
rs := NewInmemRepositoryService()
rs.Create(&common.Registry{
Name: "charts",
Type: common.Github,
URL: "github.com/helm/charts",
Format: common.UnversionedRegistry,
})
rs.Create(&common.Registry{
Name: "application-dm-templates",
Type: common.Github,
URL: "github.com/kubernetes/application-dm-templates",
Format: common.VersionedRegistry,
})
return &DefaultRegistryProvider{rs: rs}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment