From 253bce42fe0945614f8021874d409ecb5f20ad9a Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Tue, 23 Sep 2014 13:43:48 -0700 Subject: [PATCH] Extract the minion registry from the etcd implementation into the pod registry where it belongs. --- pkg/master/master.go | 14 +++++++++----- pkg/registry/etcd/etcd.go | 9 ++++----- pkg/registry/etcd/etcd_test.go | 9 +++++---- pkg/registry/{etcd => pod}/manifest_factory.go | 7 ++++--- .../{etcd => pod}/manifest_factory_test.go | 8 ++++---- 5 files changed, 26 insertions(+), 21 deletions(-) rename pkg/registry/{etcd => pod}/manifest_factory.go (88%) rename pkg/registry/{etcd => pod}/manifest_factory_test.go (97%) diff --git a/pkg/master/master.go b/pkg/master/master.go index 321572683d5..886cadbb6c4 100644 --- a/pkg/master/master.go +++ b/pkg/master/master.go @@ -83,12 +83,16 @@ func NewEtcdHelper(etcdServers []string, version string) (helper tools.EtcdHelpe // New returns a new instance of Master connected to the given etcd server. func New(c *Config) *Master { minionRegistry := makeMinionRegistry(c) + serviceRegistry := etcd.NewRegistry(c.EtcdHelper, nil) + manifestFactory := &pod.BasicManifestFactory{ + ServiceRegistry: serviceRegistry, + } m := &Master{ - podRegistry: etcd.NewRegistry(c.EtcdHelper), - controllerRegistry: etcd.NewRegistry(c.EtcdHelper), - serviceRegistry: etcd.NewRegistry(c.EtcdHelper), - endpointRegistry: etcd.NewRegistry(c.EtcdHelper), - bindingRegistry: etcd.NewRegistry(c.EtcdHelper), + podRegistry: etcd.NewRegistry(c.EtcdHelper, manifestFactory), + controllerRegistry: etcd.NewRegistry(c.EtcdHelper, nil), + serviceRegistry: serviceRegistry, + endpointRegistry: etcd.NewRegistry(c.EtcdHelper, nil), + bindingRegistry: etcd.NewRegistry(c.EtcdHelper, manifestFactory), minionRegistry: minionRegistry, client: c.Client, } diff --git a/pkg/registry/etcd/etcd.go b/pkg/registry/etcd/etcd.go index 88734a98cb3..58839a46f7a 100644 --- a/pkg/registry/etcd/etcd.go +++ b/pkg/registry/etcd/etcd.go @@ -23,6 +23,7 @@ import ( etcderr "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors/etcd" "github.com/GoogleCloudPlatform/kubernetes/pkg/constraint" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" + "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/tools" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" @@ -37,17 +38,15 @@ import ( // with backed by etcd. type Registry struct { tools.EtcdHelper - manifestFactory ManifestFactory + manifestFactory pod.ManifestFactory } // NewRegistry creates an etcd registry. -func NewRegistry(helper tools.EtcdHelper) *Registry { +func NewRegistry(helper tools.EtcdHelper, manifestFactory pod.ManifestFactory) *Registry { registry := &Registry{ EtcdHelper: helper, } - registry.manifestFactory = &BasicManifestFactory{ - serviceRegistry: registry, - } + registry.manifestFactory = manifestFactory return registry } diff --git a/pkg/registry/etcd/etcd_test.go b/pkg/registry/etcd/etcd_test.go index b9e5986cf71..c0de721a71b 100644 --- a/pkg/registry/etcd/etcd_test.go +++ b/pkg/registry/etcd/etcd_test.go @@ -24,6 +24,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" + "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/tools" @@ -32,10 +33,10 @@ import ( ) func NewTestEtcdRegistry(client tools.EtcdClient) *Registry { - registry := NewRegistry(tools.EtcdHelper{client, latest.Codec, latest.ResourceVersioner}) - registry.manifestFactory = &BasicManifestFactory{ - serviceRegistry: ®istrytest.ServiceRegistry{}, - } + registry := NewRegistry(tools.EtcdHelper{client, latest.Codec, latest.ResourceVersioner}, + &pod.BasicManifestFactory{ + ServiceRegistry: ®istrytest.ServiceRegistry{}, + }) return registry } diff --git a/pkg/registry/etcd/manifest_factory.go b/pkg/registry/pod/manifest_factory.go similarity index 88% rename from pkg/registry/etcd/manifest_factory.go rename to pkg/registry/pod/manifest_factory.go index fc724882b30..247ee9931be 100644 --- a/pkg/registry/etcd/manifest_factory.go +++ b/pkg/registry/pod/manifest_factory.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package etcd +package pod import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" @@ -27,11 +27,12 @@ type ManifestFactory interface { } type BasicManifestFactory struct { - serviceRegistry service.Registry + // TODO: this should really point at the API rather than a registry + ServiceRegistry service.Registry } func (b *BasicManifestFactory) MakeManifest(machine string, pod api.Pod) (api.ContainerManifest, error) { - envVars, err := service.GetServiceEnvironmentVariables(b.serviceRegistry, machine) + envVars, err := service.GetServiceEnvironmentVariables(b.ServiceRegistry, machine) if err != nil { return api.ContainerManifest{}, err } diff --git a/pkg/registry/etcd/manifest_factory_test.go b/pkg/registry/pod/manifest_factory_test.go similarity index 97% rename from pkg/registry/etcd/manifest_factory_test.go rename to pkg/registry/pod/manifest_factory_test.go index b51090be5cf..183702d52b4 100644 --- a/pkg/registry/etcd/manifest_factory_test.go +++ b/pkg/registry/pod/manifest_factory_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package etcd +package pod import ( "reflect" @@ -28,7 +28,7 @@ import ( func TestMakeManifestNoServices(t *testing.T) { registry := registrytest.ServiceRegistry{} factory := &BasicManifestFactory{ - serviceRegistry: ®istry, + ServiceRegistry: ®istry, } manifest, err := factory.MakeManifest("machine", api.Pod{ @@ -74,7 +74,7 @@ func TestMakeManifestServices(t *testing.T) { }, } factory := &BasicManifestFactory{ - serviceRegistry: ®istry, + ServiceRegistry: ®istry, } manifest, err := factory.MakeManifest("machine", api.Pod{ @@ -150,7 +150,7 @@ func TestMakeManifestServicesExistingEnvVar(t *testing.T) { }, } factory := &BasicManifestFactory{ - serviceRegistry: ®istry, + ServiceRegistry: ®istry, } manifest, err := factory.MakeManifest("machine", api.Pod{