Controller codebase refactoring
This commit is contained in:
@@ -21,7 +21,7 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/authenticator"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/authenticator/bearertoken"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/serviceaccount"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/serviceaccount"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/storage"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/auth/authenticator/password/passwordfile"
|
||||
|
@@ -16,4 +16,4 @@ limitations under the License.
|
||||
|
||||
// Package service provides EndpointController implementation
|
||||
// to manage and sync service endpoints.
|
||||
package service
|
||||
package endpointcontroller
|
@@ -16,7 +16,7 @@ limitations under the License.
|
||||
|
||||
// CAUTION: If you update code in this file, you may need to also update code
|
||||
// in contrib/mesos/pkg/service/endpoints_controller.go
|
||||
package service
|
||||
package endpointcontroller
|
||||
|
||||
import (
|
||||
"fmt"
|
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package service
|
||||
package endpointcontroller
|
||||
|
||||
import (
|
||||
"fmt"
|
@@ -15,4 +15,4 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
// namespace contains a controller that handles namespace lifecycle
|
||||
package namespace
|
||||
package namespacecontroller
|
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package namespace
|
||||
package namespacecontroller
|
||||
|
||||
import (
|
||||
"time"
|
||||
@@ -33,14 +33,14 @@ import (
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
// NamespaceManager is responsible for performing actions dependent upon a namespace phase
|
||||
type NamespaceManager struct {
|
||||
// NamespaceController is responsible for performing actions dependent upon a namespace phase
|
||||
type NamespaceController struct {
|
||||
controller *framework.Controller
|
||||
StopEverything chan struct{}
|
||||
}
|
||||
|
||||
// NewNamespaceManager creates a new NamespaceManager
|
||||
func NewNamespaceManager(kubeClient client.Interface, resyncPeriod time.Duration) *NamespaceManager {
|
||||
// NewNamespaceController creates a new NamespaceController
|
||||
func NewNamespaceController(kubeClient client.Interface, resyncPeriod time.Duration) *NamespaceController {
|
||||
_, controller := framework.NewInformer(
|
||||
&cache.ListWatch{
|
||||
ListFunc: func() (runtime.Object, error) {
|
||||
@@ -70,13 +70,13 @@ func NewNamespaceManager(kubeClient client.Interface, resyncPeriod time.Duration
|
||||
},
|
||||
)
|
||||
|
||||
return &NamespaceManager{
|
||||
return &NamespaceController{
|
||||
controller: controller,
|
||||
}
|
||||
}
|
||||
|
||||
// Run begins observing the system. It starts a goroutine and returns immediately.
|
||||
func (nm *NamespaceManager) Run() {
|
||||
func (nm *NamespaceController) Run() {
|
||||
if nm.StopEverything == nil {
|
||||
nm.StopEverything = make(chan struct{})
|
||||
go nm.controller.Run(nm.StopEverything)
|
||||
@@ -84,7 +84,7 @@ func (nm *NamespaceManager) Run() {
|
||||
}
|
||||
|
||||
// Stop gracefully shutsdown this controller
|
||||
func (nm *NamespaceManager) Stop() {
|
||||
func (nm *NamespaceController) Stop() {
|
||||
if nm.StopEverything != nil {
|
||||
close(nm.StopEverything)
|
||||
nm.StopEverything = nil
|
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package namespace
|
||||
package namespacecontroller
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -138,21 +138,21 @@ func TestSyncNamespaceThatIsActive(t *testing.T) {
|
||||
func TestRunStop(t *testing.T) {
|
||||
o := testclient.NewObjects(api.Scheme, api.Scheme)
|
||||
client := &testclient.Fake{ReactFn: testclient.ObjectReaction(o, api.RESTMapper)}
|
||||
nsMgr := NewNamespaceManager(client, 1*time.Second)
|
||||
nsController := NewNamespaceController(client, 1*time.Second)
|
||||
|
||||
if nsMgr.StopEverything != nil {
|
||||
t.Errorf("Non-running manager should not have a stop channel. Got %v", nsMgr.StopEverything)
|
||||
if nsController.StopEverything != nil {
|
||||
t.Errorf("Non-running manager should not have a stop channel. Got %v", nsController.StopEverything)
|
||||
}
|
||||
|
||||
nsMgr.Run()
|
||||
nsController.Run()
|
||||
|
||||
if nsMgr.StopEverything == nil {
|
||||
if nsController.StopEverything == nil {
|
||||
t.Errorf("Running manager should have a stop channel. Got nil")
|
||||
}
|
||||
|
||||
nsMgr.Stop()
|
||||
nsController.Stop()
|
||||
|
||||
if nsMgr.StopEverything != nil {
|
||||
t.Errorf("Non-running manager should not have a stop channel. Got %v", nsMgr.StopEverything)
|
||||
if nsController.StopEverything != nil {
|
||||
t.Errorf("Non-running manager should not have a stop channel. Got %v", nsController.StopEverything)
|
||||
}
|
||||
}
|
@@ -16,4 +16,4 @@ limitations under the License.
|
||||
|
||||
// Package replication contains logic for watching and synchronizing
|
||||
// replication controllers.
|
||||
package replication
|
||||
package replicationcontroller
|
||||
|
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package replication
|
||||
package replicationcontroller
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
@@ -63,6 +63,8 @@ const (
|
||||
|
||||
// ReplicationManager is responsible for synchronizing ReplicationController objects stored
|
||||
// in the system with actual running pods.
|
||||
// TODO: this really should be called ReplicationController. The only reason why it's a Manager
|
||||
// is to distinguish this type from API object "ReplicationController". We should fix this.
|
||||
type ReplicationManager struct {
|
||||
kubeClient client.Interface
|
||||
podControl controller.PodControlInterface
|
||||
|
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package replication
|
||||
package replicationcontroller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package replication
|
||||
package replicationcontroller
|
||||
|
||||
import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
|
@@ -15,4 +15,4 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
// resourcequota contains a controller that makes resource quota usage observations
|
||||
package resourcequota
|
||||
package resourcequotacontroller
|
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package resourcequota
|
||||
package resourcequotacontroller
|
||||
|
||||
import (
|
||||
"time"
|
||||
@@ -28,8 +28,8 @@ import (
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
// ResourceQuotaManager is responsible for tracking quota usage status in the system
|
||||
type ResourceQuotaManager struct {
|
||||
// ResourceQuotaController is responsible for tracking quota usage status in the system
|
||||
type ResourceQuotaController struct {
|
||||
kubeClient client.Interface
|
||||
syncTime <-chan time.Time
|
||||
|
||||
@@ -37,10 +37,10 @@ type ResourceQuotaManager struct {
|
||||
syncHandler func(quota api.ResourceQuota) error
|
||||
}
|
||||
|
||||
// NewResourceQuotaManager creates a new ResourceQuotaManager
|
||||
func NewResourceQuotaManager(kubeClient client.Interface) *ResourceQuotaManager {
|
||||
// NewResourceQuotaController creates a new ResourceQuotaController
|
||||
func NewResourceQuotaController(kubeClient client.Interface) *ResourceQuotaController {
|
||||
|
||||
rm := &ResourceQuotaManager{
|
||||
rm := &ResourceQuotaController{
|
||||
kubeClient: kubeClient,
|
||||
}
|
||||
|
||||
@@ -50,12 +50,12 @@ func NewResourceQuotaManager(kubeClient client.Interface) *ResourceQuotaManager
|
||||
}
|
||||
|
||||
// Run begins watching and syncing.
|
||||
func (rm *ResourceQuotaManager) Run(period time.Duration) {
|
||||
func (rm *ResourceQuotaController) Run(period time.Duration) {
|
||||
rm.syncTime = time.Tick(period)
|
||||
go util.Forever(func() { rm.synchronize() }, period)
|
||||
}
|
||||
|
||||
func (rm *ResourceQuotaManager) synchronize() {
|
||||
func (rm *ResourceQuotaController) synchronize() {
|
||||
var resourceQuotas []api.ResourceQuota
|
||||
list, err := rm.kubeClient.ResourceQuotas(api.NamespaceAll).List(labels.Everything())
|
||||
if err != nil {
|
||||
@@ -101,7 +101,7 @@ func FilterQuotaPods(pods []api.Pod) []*api.Pod {
|
||||
}
|
||||
|
||||
// syncResourceQuota runs a complete sync of current status
|
||||
func (rm *ResourceQuotaManager) syncResourceQuota(quota api.ResourceQuota) (err error) {
|
||||
func (rm *ResourceQuotaController) syncResourceQuota(quota api.ResourceQuota) (err error) {
|
||||
|
||||
// quota is dirty if any part of spec hard limits differs from the status hard limits
|
||||
dirty := !api.Semantic.DeepEqual(quota.Spec.Hard, quota.Status.Hard)
|
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package resourcequota
|
||||
package resourcequotacontroller
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -152,8 +152,8 @@ func TestSyncResourceQuota(t *testing.T) {
|
||||
|
||||
kubeClient := testclient.NewSimpleFake(&podList, "a)
|
||||
|
||||
resourceQuotaManager := NewResourceQuotaManager(kubeClient)
|
||||
err := resourceQuotaManager.syncResourceQuota(quota)
|
||||
ResourceQuotaController := NewResourceQuotaController(kubeClient)
|
||||
err := ResourceQuotaController.syncResourceQuota(quota)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
||||
@@ -210,8 +210,8 @@ func TestSyncResourceQuotaSpecChange(t *testing.T) {
|
||||
|
||||
kubeClient := testclient.NewSimpleFake("a)
|
||||
|
||||
resourceQuotaManager := NewResourceQuotaManager(kubeClient)
|
||||
err := resourceQuotaManager.syncResourceQuota(quota)
|
||||
ResourceQuotaController := NewResourceQuotaController(kubeClient)
|
||||
err := ResourceQuotaController.syncResourceQuota(quota)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
||||
@@ -257,8 +257,8 @@ func TestSyncResourceQuotaNoChange(t *testing.T) {
|
||||
|
||||
kubeClient := testclient.NewSimpleFake(&api.PodList{}, "a)
|
||||
|
||||
resourceQuotaManager := NewResourceQuotaManager(kubeClient)
|
||||
err := resourceQuotaManager.syncResourceQuota(quota)
|
||||
ResourceQuotaController := NewResourceQuotaController(kubeClient)
|
||||
err := ResourceQuotaController.syncResourceQuota(quota)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
Reference in New Issue
Block a user