mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-12 20:57:20 +00:00
Breakup the registry package into separate packages.
Currently all registry implementations live in a single package, which makes it bit harder to maintain. The different registry implementations do not follow the same coding style and naming conventions, which makes the code harder to read. Breakup the registry package into smaller packages based on the registry implementation. Refactor the registry packages to follow a similar coding style and naming convention. This patch does not introduce any changes in behavior.
This commit is contained in:
53
pkg/registry/registrytest/controller.go
Normal file
53
pkg/registry/registrytest/controller.go
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All rights reserved.
|
||||
|
||||
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 (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||
)
|
||||
|
||||
// TODO: Why do we have this AND MemoryRegistry?
|
||||
type ControllerRegistry struct {
|
||||
Err error
|
||||
Controllers []api.ReplicationController
|
||||
}
|
||||
|
||||
func (r *ControllerRegistry) ListControllers() ([]api.ReplicationController, error) {
|
||||
return r.Controllers, r.Err
|
||||
}
|
||||
|
||||
func (r *ControllerRegistry) GetController(ID string) (*api.ReplicationController, error) {
|
||||
return &api.ReplicationController{}, r.Err
|
||||
}
|
||||
|
||||
func (r *ControllerRegistry) CreateController(controller api.ReplicationController) error {
|
||||
return r.Err
|
||||
}
|
||||
|
||||
func (r *ControllerRegistry) UpdateController(controller api.ReplicationController) error {
|
||||
return r.Err
|
||||
}
|
||||
|
||||
func (r *ControllerRegistry) DeleteController(ID string) error {
|
||||
return r.Err
|
||||
}
|
||||
|
||||
func (r *ControllerRegistry) WatchControllers(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
|
||||
return nil, r.Err
|
||||
}
|
69
pkg/registry/registrytest/minion.go
Normal file
69
pkg/registry/registrytest/minion.go
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All rights reserved.
|
||||
|
||||
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 "sync"
|
||||
|
||||
type MinionRegistry struct {
|
||||
Err error
|
||||
Minion string
|
||||
Minions []string
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
func NewMinionRegistry(minions []string) *MinionRegistry {
|
||||
return &MinionRegistry{
|
||||
Minions: minions,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *MinionRegistry) List() ([]string, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
return r.Minions, r.Err
|
||||
}
|
||||
|
||||
func (r *MinionRegistry) Insert(minion string) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
r.Minion = minion
|
||||
return r.Err
|
||||
}
|
||||
|
||||
func (r *MinionRegistry) Contains(minion string) (bool, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
for _, name := range r.Minions {
|
||||
if name == minion {
|
||||
return true, r.Err
|
||||
}
|
||||
}
|
||||
return false, r.Err
|
||||
}
|
||||
|
||||
func (r *MinionRegistry) Delete(minion string) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
var newList []string
|
||||
for _, name := range r.Minions {
|
||||
if name != minion {
|
||||
newList = append(newList, name)
|
||||
}
|
||||
}
|
||||
r.Minions = newList
|
||||
return r.Err
|
||||
}
|
77
pkg/registry/registrytest/pod.go
Normal file
77
pkg/registry/registrytest/pod.go
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All rights reserved.
|
||||
|
||||
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 (
|
||||
"sync"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
)
|
||||
|
||||
type PodRegistry struct {
|
||||
Err error
|
||||
Pod *api.Pod
|
||||
Pods []api.Pod
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
func NewPodRegistry(pods []api.Pod) *PodRegistry {
|
||||
return &PodRegistry{
|
||||
Pods: pods,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *PodRegistry) ListPods(selector labels.Selector) ([]api.Pod, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
if r.Err != nil {
|
||||
return r.Pods, r.Err
|
||||
}
|
||||
var filtered []api.Pod
|
||||
for _, pod := range r.Pods {
|
||||
if selector.Matches(labels.Set(pod.Labels)) {
|
||||
filtered = append(filtered, pod)
|
||||
}
|
||||
}
|
||||
return filtered, nil
|
||||
}
|
||||
|
||||
func (r *PodRegistry) GetPod(podId string) (*api.Pod, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
return r.Pod, r.Err
|
||||
}
|
||||
|
||||
func (r *PodRegistry) CreatePod(machine string, pod api.Pod) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
return r.Err
|
||||
}
|
||||
|
||||
func (r *PodRegistry) UpdatePod(pod api.Pod) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
r.Pod = &pod
|
||||
return r.Err
|
||||
}
|
||||
|
||||
func (r *PodRegistry) DeletePod(podId string) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
return r.Err
|
||||
}
|
30
pkg/registry/registrytest/pod_storage.go
Normal file
30
pkg/registry/registrytest/pod_storage.go
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All rights reserved.
|
||||
|
||||
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 "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
|
||||
type PodRegistryStorage struct {
|
||||
PodRegistry
|
||||
machine string
|
||||
}
|
||||
|
||||
func (rs *PodRegistryStorage) CreatePod(machine string, pod api.Pod) error {
|
||||
rs.PodRegistry.Pod = &pod
|
||||
rs.machine = machine
|
||||
return rs.PodRegistry.Err
|
||||
}
|
33
pkg/registry/registrytest/schedular.go
Normal file
33
pkg/registry/registrytest/schedular.go
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All rights reserved.
|
||||
|
||||
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 (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/scheduler"
|
||||
)
|
||||
|
||||
type Scheduler struct {
|
||||
Err error
|
||||
Pod api.Pod
|
||||
Machine string
|
||||
}
|
||||
|
||||
func (s *Scheduler) Schedule(pod api.Pod, lister scheduler.MinionLister) (string, error) {
|
||||
s.Pod = pod
|
||||
return s.Machine, s.Err
|
||||
}
|
52
pkg/registry/registrytest/service.go
Normal file
52
pkg/registry/registrytest/service.go
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All rights reserved.
|
||||
|
||||
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 (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
)
|
||||
|
||||
type ServiceRegistry struct {
|
||||
List api.ServiceList
|
||||
Err error
|
||||
Endpoints api.Endpoints
|
||||
}
|
||||
|
||||
func (r *ServiceRegistry) ListServices() (api.ServiceList, error) {
|
||||
return r.List, r.Err
|
||||
}
|
||||
|
||||
func (r *ServiceRegistry) CreateService(svc api.Service) error {
|
||||
return r.Err
|
||||
}
|
||||
|
||||
func (r *ServiceRegistry) GetService(name string) (*api.Service, error) {
|
||||
return nil, r.Err
|
||||
}
|
||||
|
||||
func (r *ServiceRegistry) DeleteService(name string) error {
|
||||
return r.Err
|
||||
}
|
||||
|
||||
func (r *ServiceRegistry) UpdateService(svc api.Service) error {
|
||||
return r.Err
|
||||
}
|
||||
|
||||
func (r *ServiceRegistry) UpdateEndpoints(e api.Endpoints) error {
|
||||
r.Endpoints = e
|
||||
return r.Err
|
||||
}
|
Reference in New Issue
Block a user