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
...@@ -6,7 +6,7 @@ you may not use this file except in compliance with the License. ...@@ -6,7 +6,7 @@ you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...@@ -31,9 +31,10 @@ import ( ...@@ -31,9 +31,10 @@ import (
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/kubernetes/deployment-manager/manager/manager"
"github.com/kubernetes/deployment-manager/common" "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/manager/repository"
"github.com/kubernetes/deployment-manager/registry"
"github.com/kubernetes/deployment-manager/util" "github.com/kubernetes/deployment-manager/util"
) )
...@@ -48,6 +49,7 @@ var deployments = []Route{ ...@@ -48,6 +49,7 @@ var deployments = []Route{
{"Expand", "/expand", "POST", expandHandlerFunc, ""}, {"Expand", "/expand", "POST", expandHandlerFunc, ""},
{"ListTypes", "/types", "GET", listTypesHandlerFunc, ""}, {"ListTypes", "/types", "GET", listTypesHandlerFunc, ""},
{"ListTypeInstances", "/types/{type}/instances", "GET", listTypeInstancesHandlerFunc, ""}, {"ListTypeInstances", "/types/{type}/instances", "GET", listTypeInstancesHandlerFunc, ""},
{"ListRegistries", "/registries", "GET", listRegistriesHandlerFunc, ""},
} }
var ( var (
...@@ -72,8 +74,9 @@ func init() { ...@@ -72,8 +74,9 @@ func init() {
func newManager() manager.Manager { func newManager() manager.Manager {
expander := manager.NewExpander(getServiceURL(*expanderURL, *expanderName), manager.NewTypeResolver()) expander := manager.NewExpander(getServiceURL(*expanderURL, *expanderName), manager.NewTypeResolver())
deployer := manager.NewDeployer(getServiceURL(*deployerURL, *deployerName)) deployer := manager.NewDeployer(getServiceURL(*deployerURL, *deployerName))
registryService := registry.NewInmemRepositoryService()
r := repository.NewMapBasedRepository() r := repository.NewMapBasedRepository()
return manager.NewManager(expander, deployer, r) return manager.NewManager(expander, deployer, r, registryService)
} }
func getServiceURL(serviceURL, serviceName string) string { func getServiceURL(serviceURL, serviceName string) string {
...@@ -329,3 +332,15 @@ func listTypeInstancesHandlerFunc(w http.ResponseWriter, r *http.Request) { ...@@ -329,3 +332,15 @@ func listTypeInstancesHandlerFunc(w http.ResponseWriter, r *http.Request) {
util.LogHandlerExitWithJSON(handler, w, backend.ListInstances(typeName), http.StatusOK) 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)
}
...@@ -6,7 +6,7 @@ you may not use this file except in compliance with the License. ...@@ -6,7 +6,7 @@ you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"github.com/kubernetes/deployment-manager/common" "github.com/kubernetes/deployment-manager/common"
"github.com/kubernetes/deployment-manager/manager/repository" "github.com/kubernetes/deployment-manager/manager/repository"
"github.com/kubernetes/deployment-manager/registry"
) )
// Manager manages a persistent set of Deployments. // Manager manages a persistent set of Deployments.
...@@ -37,17 +38,23 @@ type Manager interface { ...@@ -37,17 +38,23 @@ type Manager interface {
Expand(t *common.Template) (*common.Manifest, error) Expand(t *common.Template) (*common.Manifest, error)
ListTypes() []string ListTypes() []string
ListInstances(typeName string) []*common.TypeInstance 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 { type manager struct {
expander Expander expander Expander
deployer Deployer deployer Deployer
repository repository.Repository repository repository.Repository
registryService registry.RegistryService
} }
// NewManager returns a new initialized Manager. // NewManager returns a new initialized Manager.
func NewManager(expander Expander, deployer Deployer, repository repository.Repository) Manager { func NewManager(expander Expander, deployer Deployer, repository repository.Repository, registryService registry.RegistryService) Manager {
return &manager{expander, deployer, repository} return &manager{expander, deployer, repository, registryService}
} }
// ListDeployments returns the list of deployments // ListDeployments returns the list of deployments
...@@ -302,6 +309,22 @@ func (m *manager) ListInstances(typeName string) []*common.TypeInstance { ...@@ -302,6 +309,22 @@ func (m *manager) ListInstances(typeName string) []*common.TypeInstance {
return m.repository.GetTypeInstances(typeName) 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 { func generateManifestName() string {
return fmt.Sprintf("manifest-%d", time.Now().UTC().UnixNano()) return fmt.Sprintf("manifest-%d", time.Now().UTC().UnixNano())
} }
......
...@@ -28,13 +28,30 @@ type inmemRepositoryService struct { ...@@ -28,13 +28,30 @@ type inmemRepositoryService struct {
} }
func NewInmemRepositoryService() RegistryService { func NewInmemRepositoryService() RegistryService {
return &inmemRepositoryService{ rs := &inmemRepositoryService{
repositories: make(map[string]*common.Registry), 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) { 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 { func (rs *inmemRepositoryService) Create(repository *common.Registry) error {
......
...@@ -30,18 +30,6 @@ type RegistryProvider interface { ...@@ -30,18 +30,6 @@ type RegistryProvider interface {
func NewDefaultRegistryProvider() RegistryProvider { func NewDefaultRegistryProvider() RegistryProvider {
rs := NewInmemRepositoryService() 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} 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