mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
plumb through changes on ReplicationController and Service
This commit is contained in:
parent
e1ca63f569
commit
5cbf89c060
@ -27,7 +27,7 @@ type Registry interface {
|
|||||||
ListControllers(ctx api.Context) (*api.ReplicationControllerList, error)
|
ListControllers(ctx api.Context) (*api.ReplicationControllerList, error)
|
||||||
WatchControllers(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error)
|
WatchControllers(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error)
|
||||||
GetController(ctx api.Context, controllerID string) (*api.ReplicationController, error)
|
GetController(ctx api.Context, controllerID string) (*api.ReplicationController, error)
|
||||||
CreateController(ctx api.Context, controller *api.ReplicationController) error
|
CreateController(ctx api.Context, controller *api.ReplicationController) (*api.ReplicationController, error)
|
||||||
UpdateController(ctx api.Context, controller *api.ReplicationController) error
|
UpdateController(ctx api.Context, controller *api.ReplicationController) (*api.ReplicationController, error)
|
||||||
DeleteController(ctx api.Context, controllerID string) error
|
DeleteController(ctx api.Context, controllerID string) error
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
|
||||||
rc "github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
|
rc "github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
@ -60,11 +59,11 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := rs.registry.CreateController(ctx, controller); err != nil {
|
out, err := rs.registry.CreateController(ctx, controller)
|
||||||
|
if err != nil {
|
||||||
err = rest.CheckGeneratedNameError(rest.ReplicationControllers, err, controller)
|
err = rest.CheckGeneratedNameError(rest.ReplicationControllers, err, controller)
|
||||||
return apiserver.RESTResult{}, err
|
|
||||||
}
|
}
|
||||||
return rs.registry.GetController(ctx, controller.Name)
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete asynchronously deletes the ReplicationController specified by its id.
|
// Delete asynchronously deletes the ReplicationController specified by its id.
|
||||||
@ -124,11 +123,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
|
|||||||
if errs := validation.ValidateReplicationController(controller); len(errs) > 0 {
|
if errs := validation.ValidateReplicationController(controller); len(errs) > 0 {
|
||||||
return nil, false, errors.NewInvalid("replicationController", controller.Name, errs)
|
return nil, false, errors.NewInvalid("replicationController", controller.Name, errs)
|
||||||
}
|
}
|
||||||
err := rs.registry.UpdateController(ctx, controller)
|
out, err := rs.registry.UpdateController(ctx, controller)
|
||||||
if err != nil {
|
|
||||||
return nil, false, err
|
|
||||||
}
|
|
||||||
out, err := rs.registry.GetController(ctx, controller.Name)
|
|
||||||
return out, false, err
|
return out, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,23 +152,25 @@ func (r *Registry) GetController(ctx api.Context, controllerID string) (*api.Rep
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateController creates a new ReplicationController.
|
// CreateController creates a new ReplicationController.
|
||||||
func (r *Registry) CreateController(ctx api.Context, controller *api.ReplicationController) error {
|
func (r *Registry) CreateController(ctx api.Context, controller *api.ReplicationController) (*api.ReplicationController, error) {
|
||||||
key, err := makeControllerKey(ctx, controller.Name)
|
key, err := makeControllerKey(ctx, controller.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = r.CreateObj(key, controller, nil, 0)
|
out := &api.ReplicationController{}
|
||||||
return etcderr.InterpretCreateError(err, "replicationController", controller.Name)
|
err = r.CreateObj(key, controller, out, 0)
|
||||||
|
return out, etcderr.InterpretCreateError(err, "replicationController", controller.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateController replaces an existing ReplicationController.
|
// UpdateController replaces an existing ReplicationController.
|
||||||
func (r *Registry) UpdateController(ctx api.Context, controller *api.ReplicationController) error {
|
func (r *Registry) UpdateController(ctx api.Context, controller *api.ReplicationController) (*api.ReplicationController, error) {
|
||||||
key, err := makeControllerKey(ctx, controller.Name)
|
key, err := makeControllerKey(ctx, controller.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = r.SetObj(key, controller, nil, 0)
|
out := &api.ReplicationController{}
|
||||||
return etcderr.InterpretUpdateError(err, "replicationController", controller.Name)
|
err = r.SetObj(key, controller, out, 0)
|
||||||
|
return out, etcderr.InterpretUpdateError(err, "replicationController", controller.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteController deletes a ReplicationController specified by its ID.
|
// DeleteController deletes a ReplicationController specified by its ID.
|
||||||
@ -199,13 +201,14 @@ func (r *Registry) ListServices(ctx api.Context) (*api.ServiceList, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateService creates a new Service.
|
// CreateService creates a new Service.
|
||||||
func (r *Registry) CreateService(ctx api.Context, svc *api.Service) error {
|
func (r *Registry) CreateService(ctx api.Context, svc *api.Service) (*api.Service, error) {
|
||||||
key, err := makeServiceKey(ctx, svc.Name)
|
key, err := makeServiceKey(ctx, svc.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = r.CreateObj(key, svc, nil, 0)
|
out := &api.Service{}
|
||||||
return etcderr.InterpretCreateError(err, "service", svc.Name)
|
err = r.CreateObj(key, svc, out, 0)
|
||||||
|
return out, etcderr.InterpretCreateError(err, "service", svc.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetService obtains a Service specified by its name.
|
// GetService obtains a Service specified by its name.
|
||||||
@ -270,13 +273,14 @@ func (r *Registry) DeleteService(ctx api.Context, name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateService replaces an existing Service.
|
// UpdateService replaces an existing Service.
|
||||||
func (r *Registry) UpdateService(ctx api.Context, svc *api.Service) error {
|
func (r *Registry) UpdateService(ctx api.Context, svc *api.Service) (*api.Service, error) {
|
||||||
key, err := makeServiceKey(ctx, svc.Name)
|
key, err := makeServiceKey(ctx, svc.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = r.SetObj(key, svc, nil, 0)
|
out := &api.Service{}
|
||||||
return etcderr.InterpretUpdateError(err, "service", svc.Name)
|
err = r.SetObj(key, svc, out, 0)
|
||||||
|
return out, etcderr.InterpretUpdateError(err, "service", svc.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WatchServices begins watching for new, changed, or deleted service configurations.
|
// WatchServices begins watching for new, changed, or deleted service configurations.
|
||||||
|
@ -212,7 +212,7 @@ func TestEtcdCreateController(t *testing.T) {
|
|||||||
fakeClient := tools.NewFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
registry := NewTestEtcdRegistry(fakeClient)
|
registry := NewTestEtcdRegistry(fakeClient)
|
||||||
key, _ := makeControllerKey(ctx, "foo")
|
key, _ := makeControllerKey(ctx, "foo")
|
||||||
err := registry.CreateController(ctx, &api.ReplicationController{
|
_, err := registry.CreateController(ctx, &api.ReplicationController{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
},
|
},
|
||||||
@ -242,7 +242,7 @@ func TestEtcdCreateControllerAlreadyExisting(t *testing.T) {
|
|||||||
fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{ObjectMeta: api.ObjectMeta{Name: "foo"}}), 0)
|
fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{ObjectMeta: api.ObjectMeta{Name: "foo"}}), 0)
|
||||||
|
|
||||||
registry := NewTestEtcdRegistry(fakeClient)
|
registry := NewTestEtcdRegistry(fakeClient)
|
||||||
err := registry.CreateController(ctx, &api.ReplicationController{
|
_, err := registry.CreateController(ctx, &api.ReplicationController{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
},
|
},
|
||||||
@ -259,7 +259,7 @@ func TestEtcdUpdateController(t *testing.T) {
|
|||||||
key, _ := makeControllerKey(ctx, "foo")
|
key, _ := makeControllerKey(ctx, "foo")
|
||||||
resp, _ := fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{ObjectMeta: api.ObjectMeta{Name: "foo"}}), 0)
|
resp, _ := fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{ObjectMeta: api.ObjectMeta{Name: "foo"}}), 0)
|
||||||
registry := NewTestEtcdRegistry(fakeClient)
|
registry := NewTestEtcdRegistry(fakeClient)
|
||||||
err := registry.UpdateController(ctx, &api.ReplicationController{
|
_, err := registry.UpdateController(ctx, &api.ReplicationController{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: strconv.FormatUint(resp.Node.ModifiedIndex, 10)},
|
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: strconv.FormatUint(resp.Node.ModifiedIndex, 10)},
|
||||||
Spec: api.ReplicationControllerSpec{
|
Spec: api.ReplicationControllerSpec{
|
||||||
Replicas: 2,
|
Replicas: 2,
|
||||||
@ -417,7 +417,7 @@ func TestEtcdCreateService(t *testing.T) {
|
|||||||
ctx := api.NewDefaultContext()
|
ctx := api.NewDefaultContext()
|
||||||
fakeClient := tools.NewFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
registry := NewTestEtcdRegistry(fakeClient)
|
registry := NewTestEtcdRegistry(fakeClient)
|
||||||
err := registry.CreateService(ctx, &api.Service{
|
_, err := registry.CreateService(ctx, &api.Service{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -447,7 +447,7 @@ func TestEtcdCreateServiceAlreadyExisting(t *testing.T) {
|
|||||||
key, _ := makeServiceKey(ctx, "foo")
|
key, _ := makeServiceKey(ctx, "foo")
|
||||||
fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Service{ObjectMeta: api.ObjectMeta{Name: "foo"}}), 0)
|
fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Service{ObjectMeta: api.ObjectMeta{Name: "foo"}}), 0)
|
||||||
registry := NewTestEtcdRegistry(fakeClient)
|
registry := NewTestEtcdRegistry(fakeClient)
|
||||||
err := registry.CreateService(ctx, &api.Service{
|
_, err := registry.CreateService(ctx, &api.Service{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||||
})
|
})
|
||||||
if !errors.IsAlreadyExists(err) {
|
if !errors.IsAlreadyExists(err) {
|
||||||
@ -572,7 +572,7 @@ func TestEtcdUpdateService(t *testing.T) {
|
|||||||
SessionAffinity: "None",
|
SessionAffinity: "None",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err := registry.UpdateService(ctx, &testService)
|
_, err := registry.UpdateService(ctx, &testService)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -49,16 +49,16 @@ func (r *ControllerRegistry) GetController(ctx api.Context, ID string) (*api.Rep
|
|||||||
return &api.ReplicationController{}, r.Err
|
return &api.ReplicationController{}, r.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ControllerRegistry) CreateController(ctx api.Context, controller *api.ReplicationController) error {
|
func (r *ControllerRegistry) CreateController(ctx api.Context, controller *api.ReplicationController) (*api.ReplicationController, error) {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
defer r.Unlock()
|
defer r.Unlock()
|
||||||
return r.Err
|
return controller, r.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ControllerRegistry) UpdateController(ctx api.Context, controller *api.ReplicationController) error {
|
func (r *ControllerRegistry) UpdateController(ctx api.Context, controller *api.ReplicationController) (*api.ReplicationController, error) {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
defer r.Unlock()
|
defer r.Unlock()
|
||||||
return r.Err
|
return controller, r.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ControllerRegistry) DeleteController(ctx api.Context, ID string) error {
|
func (r *ControllerRegistry) DeleteController(ctx api.Context, ID string) error {
|
||||||
|
@ -71,14 +71,14 @@ func (r *ServiceRegistry) ListServices(ctx api.Context) (*api.ServiceList, error
|
|||||||
return res, r.Err
|
return res, r.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ServiceRegistry) CreateService(ctx api.Context, svc *api.Service) error {
|
func (r *ServiceRegistry) CreateService(ctx api.Context, svc *api.Service) (*api.Service, error) {
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
|
|
||||||
r.Service = new(api.Service)
|
r.Service = new(api.Service)
|
||||||
*r.Service = *svc
|
*r.Service = *svc
|
||||||
r.List.Items = append(r.List.Items, *svc)
|
r.List.Items = append(r.List.Items, *svc)
|
||||||
return r.Err
|
return svc, r.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ServiceRegistry) GetService(ctx api.Context, id string) (*api.Service, error) {
|
func (r *ServiceRegistry) GetService(ctx api.Context, id string) (*api.Service, error) {
|
||||||
@ -98,13 +98,13 @@ func (r *ServiceRegistry) DeleteService(ctx api.Context, id string) error {
|
|||||||
return r.Err
|
return r.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ServiceRegistry) UpdateService(ctx api.Context, svc *api.Service) error {
|
func (r *ServiceRegistry) UpdateService(ctx api.Context, svc *api.Service) (*api.Service, error) {
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
|
|
||||||
r.UpdatedID = svc.Name
|
r.UpdatedID = svc.Name
|
||||||
*r.Service = *svc
|
*r.Service = *svc
|
||||||
return r.Err
|
return svc, r.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ServiceRegistry) WatchServices(ctx api.Context, label labels.Selector, field labels.Selector, resourceVersion string) (watch.Interface, error) {
|
func (r *ServiceRegistry) WatchServices(ctx api.Context, label labels.Selector, field labels.Selector, resourceVersion string) (watch.Interface, error) {
|
||||||
|
@ -26,10 +26,10 @@ import (
|
|||||||
// Registry is an interface for things that know how to store services.
|
// Registry is an interface for things that know how to store services.
|
||||||
type Registry interface {
|
type Registry interface {
|
||||||
ListServices(ctx api.Context) (*api.ServiceList, error)
|
ListServices(ctx api.Context) (*api.ServiceList, error)
|
||||||
CreateService(ctx api.Context, svc *api.Service) error
|
CreateService(ctx api.Context, svc *api.Service) (*api.Service, error)
|
||||||
GetService(ctx api.Context, name string) (*api.Service, error)
|
GetService(ctx api.Context, name string) (*api.Service, error)
|
||||||
DeleteService(ctx api.Context, name string) error
|
DeleteService(ctx api.Context, name string) error
|
||||||
UpdateService(ctx api.Context, svc *api.Service) error
|
UpdateService(ctx api.Context, svc *api.Service) (*api.Service, error)
|
||||||
WatchServices(ctx api.Context, labels, fields labels.Selector, resourceVersion string) (watch.Interface, error)
|
WatchServices(ctx api.Context, labels, fields labels.Selector, resourceVersion string) (watch.Interface, error)
|
||||||
|
|
||||||
// TODO: endpoints and their implementation should be separated, setting endpoints should be
|
// TODO: endpoints and their implementation should be separated, setting endpoints should be
|
||||||
|
@ -115,12 +115,12 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := rs.registry.CreateService(ctx, service); err != nil {
|
out, err := rs.registry.CreateService(ctx, service)
|
||||||
|
if err != nil {
|
||||||
rs.portalMgr.Release(net.ParseIP(service.Spec.PortalIP))
|
rs.portalMgr.Release(net.ParseIP(service.Spec.PortalIP))
|
||||||
err = rest.CheckGeneratedNameError(rest.Services, err, service)
|
err = rest.CheckGeneratedNameError(rest.Services, err, service)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
return rs.registry.GetService(ctx, service.Name)
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func hostsFromMinionList(list *api.NodeList) []string {
|
func hostsFromMinionList(list *api.NodeList) []string {
|
||||||
@ -213,11 +213,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = rs.registry.UpdateService(ctx, service)
|
out, err := rs.registry.UpdateService(ctx, service)
|
||||||
if err != nil {
|
|
||||||
return nil, false, err
|
|
||||||
}
|
|
||||||
out, err := rs.registry.GetService(ctx, service.Name)
|
|
||||||
return out, false, err
|
return out, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user