2014-08-11 07:34:59 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
2014-08-11 07:34:59 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package registrytest
|
|
|
|
|
|
|
|
import (
|
2015-01-29 04:11:29 +00:00
|
|
|
"sync"
|
|
|
|
|
2014-08-11 07:34:59 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
2015-03-06 23:29:03 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
2014-11-28 22:28:42 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
2014-08-11 07:34:59 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TODO: Why do we have this AND MemoryRegistry?
|
|
|
|
type ControllerRegistry struct {
|
|
|
|
Err error
|
2014-08-29 00:48:07 +00:00
|
|
|
Controllers *api.ReplicationControllerList
|
2015-01-29 04:11:29 +00:00
|
|
|
sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ControllerRegistry) SetError(err error) {
|
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
r.Err = err
|
2014-08-11 07:34:59 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 19:19:22 +00:00
|
|
|
func (r *ControllerRegistry) ListControllers(ctx api.Context) (*api.ReplicationControllerList, error) {
|
2015-02-06 01:27:58 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
2014-08-11 07:34:59 +00:00
|
|
|
return r.Controllers, r.Err
|
|
|
|
}
|
|
|
|
|
2014-09-26 19:19:22 +00:00
|
|
|
func (r *ControllerRegistry) GetController(ctx api.Context, ID string) (*api.ReplicationController, error) {
|
2015-02-06 01:27:58 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
2015-03-06 06:12:52 +00:00
|
|
|
if r.Controllers != nil {
|
|
|
|
for _, rc := range r.Controllers.Items {
|
|
|
|
if ID == rc.Name {
|
|
|
|
return &r.Controllers.Items[0], r.Err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-11 07:34:59 +00:00
|
|
|
return &api.ReplicationController{}, r.Err
|
|
|
|
}
|
|
|
|
|
2015-02-28 00:37:04 +00:00
|
|
|
func (r *ControllerRegistry) CreateController(ctx api.Context, controller *api.ReplicationController) (*api.ReplicationController, error) {
|
2015-01-29 04:11:29 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
2015-03-06 06:12:52 +00:00
|
|
|
if r.Controllers != nil {
|
|
|
|
r.Controllers.Items = append(r.Controllers.Items, *controller)
|
|
|
|
}
|
2015-02-28 00:37:04 +00:00
|
|
|
return controller, r.Err
|
2014-08-11 07:34:59 +00:00
|
|
|
}
|
|
|
|
|
2015-02-28 00:37:04 +00:00
|
|
|
func (r *ControllerRegistry) UpdateController(ctx api.Context, controller *api.ReplicationController) (*api.ReplicationController, error) {
|
2015-02-06 01:27:58 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
2015-02-28 00:37:04 +00:00
|
|
|
return controller, r.Err
|
2014-08-11 07:34:59 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 19:19:22 +00:00
|
|
|
func (r *ControllerRegistry) DeleteController(ctx api.Context, ID string) error {
|
2015-02-06 01:27:58 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
2014-08-11 07:34:59 +00:00
|
|
|
return r.Err
|
|
|
|
}
|
|
|
|
|
2015-03-06 23:29:03 +00:00
|
|
|
func (r *ControllerRegistry) WatchControllers(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
|
2015-02-06 01:27:58 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
2014-08-11 07:34:59 +00:00
|
|
|
return nil, r.Err
|
|
|
|
}
|