mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Controller codebase refactoring
This commit is contained in:
parent
b73c53c37d
commit
d27ad5b714
@ -40,7 +40,8 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/nodecontroller"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/endpoint"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/node"
|
||||||
replicationControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/controller/replication"
|
replicationControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/controller/replication"
|
||||||
explatest "github.com/GoogleCloudPlatform/kubernetes/pkg/expapi/latest"
|
explatest "github.com/GoogleCloudPlatform/kubernetes/pkg/expapi/latest"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||||
@ -51,7 +52,6 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/probe"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/probe"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/service"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
|
||||||
@ -187,7 +187,7 @@ func startComponents(firstManifestURL, secondManifestURL, apiVersion string) (st
|
|||||||
eventBroadcaster.StartRecordingToSink(cl.Events(""))
|
eventBroadcaster.StartRecordingToSink(cl.Events(""))
|
||||||
scheduler.New(schedulerConfig).Run()
|
scheduler.New(schedulerConfig).Run()
|
||||||
|
|
||||||
endpoints := service.NewEndpointController(cl)
|
endpoints := endpointcontroller.NewEndpointController(cl)
|
||||||
// ensure the service endpoints are sync'd several times within the window that the integration tests wait
|
// ensure the service endpoints are sync'd several times within the window that the integration tests wait
|
||||||
go endpoints.Run(3, util.NeverStop)
|
go endpoints.Run(3, util.NeverStop)
|
||||||
|
|
||||||
|
@ -35,16 +35,16 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
|
||||||
clientcmdapi "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
|
clientcmdapi "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/nodecontroller"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/endpoint"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/routecontroller"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/namespace"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/servicecontroller"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/node"
|
||||||
replicationControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/controller/replication"
|
replicationControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/controller/replication"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/resourcequota"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/route"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/service"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/serviceaccount"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/namespace"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/resourcequota"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/service"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/serviceaccount"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/volumeclaimbinder"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/volumeclaimbinder"
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ func (s *CMServer) Run(_ []string) error {
|
|||||||
glog.Fatal(server.ListenAndServe())
|
glog.Fatal(server.ListenAndServe())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
endpoints := service.NewEndpointController(kubeClient)
|
endpoints := endpointcontroller.NewEndpointController(kubeClient)
|
||||||
go endpoints.Run(s.ConcurrentEndpointSyncs, util.NeverStop)
|
go endpoints.Run(s.ConcurrentEndpointSyncs, util.NeverStop)
|
||||||
|
|
||||||
controllerManager := replicationControllerPkg.NewReplicationManager(kubeClient, replicationControllerPkg.BurstReplicas)
|
controllerManager := replicationControllerPkg.NewReplicationManager(kubeClient, replicationControllerPkg.BurstReplicas)
|
||||||
@ -215,11 +215,11 @@ func (s *CMServer) Run(_ []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceQuotaManager := resourcequota.NewResourceQuotaManager(kubeClient)
|
resourceQuotaController := resourcequotacontroller.NewResourceQuotaController(kubeClient)
|
||||||
resourceQuotaManager.Run(s.ResourceQuotaSyncPeriod)
|
resourceQuotaController.Run(s.ResourceQuotaSyncPeriod)
|
||||||
|
|
||||||
namespaceManager := namespace.NewNamespaceManager(kubeClient, s.NamespaceSyncPeriod)
|
namespaceController := namespacecontroller.NewNamespaceController(kubeClient, s.NamespaceSyncPeriod)
|
||||||
namespaceManager.Run()
|
namespaceController.Run()
|
||||||
|
|
||||||
pvclaimBinder := volumeclaimbinder.NewPersistentVolumeClaimBinder(kubeClient, s.PVClaimBinderSyncPeriod)
|
pvclaimBinder := volumeclaimbinder.NewPersistentVolumeClaimBinder(kubeClient, s.PVClaimBinderSyncPeriod)
|
||||||
pvclaimBinder.Run()
|
pvclaimBinder.Run()
|
||||||
|
@ -34,15 +34,15 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/nodecontroller"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/endpoint"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/servicecontroller"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/node"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/replication"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/replication"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/service"
|
||||||
explatest "github.com/GoogleCloudPlatform/kubernetes/pkg/expapi/latest"
|
explatest "github.com/GoogleCloudPlatform/kubernetes/pkg/expapi/latest"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/cadvisor"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/cadvisor"
|
||||||
kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
|
kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/service"
|
|
||||||
etcdstorage "github.com/GoogleCloudPlatform/kubernetes/pkg/storage/etcd"
|
etcdstorage "github.com/GoogleCloudPlatform/kubernetes/pkg/storage/etcd"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
@ -140,10 +140,10 @@ func runControllerManager(cl *client.Client) {
|
|||||||
glog.Warningf("Running without a service controller: %v", err)
|
glog.Warningf("Running without a service controller: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoints := service.NewEndpointController(cl)
|
endpoints := endpointcontroller.NewEndpointController(cl)
|
||||||
go endpoints.Run(5, util.NeverStop)
|
go endpoints.Run(5, util.NeverStop)
|
||||||
|
|
||||||
controllerManager := replication.NewReplicationManager(cl, replication.BurstReplicas)
|
controllerManager := replicationcontroller.NewReplicationManager(cl, replicationcontroller.BurstReplicas)
|
||||||
go controllerManager.Run(5, util.NeverStop)
|
go controllerManager.Run(5, util.NeverStop)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,15 +29,15 @@ import (
|
|||||||
clientcmdapi "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
|
clientcmdapi "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/mesos"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/mesos"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/nodecontroller"
|
kendpoint "github.com/GoogleCloudPlatform/kubernetes/pkg/controller/endpoint"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/routecontroller"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/namespace"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/servicecontroller"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/node"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/replication"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/replication"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/resourcequota"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/route"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/service"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/serviceaccount"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/namespace"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/resourcequota"
|
|
||||||
kendpoint "github.com/GoogleCloudPlatform/kubernetes/pkg/service"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/serviceaccount"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/volumeclaimbinder"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/volumeclaimbinder"
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ func (s *CMServer) Run(_ []string) error {
|
|||||||
endpoints := s.createEndpointController(kubeClient)
|
endpoints := s.createEndpointController(kubeClient)
|
||||||
go endpoints.Run(s.ConcurrentEndpointSyncs, util.NeverStop)
|
go endpoints.Run(s.ConcurrentEndpointSyncs, util.NeverStop)
|
||||||
|
|
||||||
controllerManager := replication.NewReplicationManager(kubeClient, replication.BurstReplicas)
|
controllerManager := replicationcontroller.NewReplicationManager(kubeClient, replicationcontroller.BurstReplicas)
|
||||||
go controllerManager.Run(s.ConcurrentRCSyncs, util.NeverStop)
|
go controllerManager.Run(s.ConcurrentRCSyncs, util.NeverStop)
|
||||||
|
|
||||||
//TODO(jdef) should eventually support more cloud providers here
|
//TODO(jdef) should eventually support more cloud providers here
|
||||||
@ -141,11 +141,11 @@ func (s *CMServer) Run(_ []string) error {
|
|||||||
routeController.Run(s.NodeSyncPeriod)
|
routeController.Run(s.NodeSyncPeriod)
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceQuotaManager := resourcequota.NewResourceQuotaManager(kubeClient)
|
resourceQuotaController := resourcequotacontroller.NewResourceQuotaController(kubeClient)
|
||||||
resourceQuotaManager.Run(s.ResourceQuotaSyncPeriod)
|
resourceQuotaController.Run(s.ResourceQuotaSyncPeriod)
|
||||||
|
|
||||||
namespaceManager := namespace.NewNamespaceManager(kubeClient, s.NamespaceSyncPeriod)
|
namespaceController := namespacecontroller.NewNamespaceController(kubeClient, s.NamespaceSyncPeriod)
|
||||||
namespaceManager.Run()
|
namespaceController.Run()
|
||||||
|
|
||||||
pvclaimBinder := volumeclaimbinder.NewPersistentVolumeClaimBinder(kubeClient, s.PVClaimBinderSyncPeriod)
|
pvclaimBinder := volumeclaimbinder.NewPersistentVolumeClaimBinder(kubeClient, s.PVClaimBinderSyncPeriod)
|
||||||
pvclaimBinder.Run()
|
pvclaimBinder.Run()
|
||||||
|
@ -19,7 +19,7 @@ package resource
|
|||||||
import (
|
import (
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/resourcequota"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/resourcequota"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -30,14 +30,14 @@ const (
|
|||||||
// CPUFromPodSpec computes the cpu shares that the pod is admitted to use. Containers
|
// CPUFromPodSpec computes the cpu shares that the pod is admitted to use. Containers
|
||||||
// without CPU limit are NOT taken into account.
|
// without CPU limit are NOT taken into account.
|
||||||
func PodCPULimit(pod *api.Pod) CPUShares {
|
func PodCPULimit(pod *api.Pod) CPUShares {
|
||||||
cpuQuantity := resourcequota.PodCPU(pod)
|
cpuQuantity := resourcequotacontroller.PodCPU(pod)
|
||||||
return CPUShares(float64(cpuQuantity.MilliValue()) / 1000.0)
|
return CPUShares(float64(cpuQuantity.MilliValue()) / 1000.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MemFromPodSpec computes the amount of memory that the pod is admitted to use. Containers
|
// MemFromPodSpec computes the amount of memory that the pod is admitted to use. Containers
|
||||||
// without memory limit are NOT taken into account.
|
// without memory limit are NOT taken into account.
|
||||||
func PodMemLimit(pod *api.Pod) MegaBytes {
|
func PodMemLimit(pod *api.Pod) MegaBytes {
|
||||||
memQuantity := resourcequota.PodMemory(pod)
|
memQuantity := resourcequotacontroller.PodMemory(pod)
|
||||||
return MegaBytes(float64(memQuantity.Value()) / 1024.0 / 1024.0)
|
return MegaBytes(float64(memQuantity.Value()) / 1024.0 / 1024.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,11 +28,11 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache"
|
||||||
|
kservice "github.com/GoogleCloudPlatform/kubernetes/pkg/controller/endpoint"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/framework"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/framework"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
kservice "github.com/GoogleCloudPlatform/kubernetes/pkg/service"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/workqueue"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/workqueue"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/authenticator"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/authenticator"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/authenticator/bearertoken"
|
"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/storage"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/auth/authenticator/password/passwordfile"
|
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/auth/authenticator/password/passwordfile"
|
||||||
|
@ -16,4 +16,4 @@ limitations under the License.
|
|||||||
|
|
||||||
// Package service provides EndpointController implementation
|
// Package service provides EndpointController implementation
|
||||||
// to manage and sync service endpoints.
|
// 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
|
// CAUTION: If you update code in this file, you may need to also update code
|
||||||
// in contrib/mesos/pkg/service/endpoints_controller.go
|
// in contrib/mesos/pkg/service/endpoints_controller.go
|
||||||
package service
|
package endpointcontroller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package service
|
package endpointcontroller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -15,4 +15,4 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// namespace contains a controller that handles namespace lifecycle
|
// 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.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package namespace
|
package namespacecontroller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
@ -33,14 +33,14 @@ import (
|
|||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NamespaceManager is responsible for performing actions dependent upon a namespace phase
|
// NamespaceController is responsible for performing actions dependent upon a namespace phase
|
||||||
type NamespaceManager struct {
|
type NamespaceController struct {
|
||||||
controller *framework.Controller
|
controller *framework.Controller
|
||||||
StopEverything chan struct{}
|
StopEverything chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNamespaceManager creates a new NamespaceManager
|
// NewNamespaceController creates a new NamespaceController
|
||||||
func NewNamespaceManager(kubeClient client.Interface, resyncPeriod time.Duration) *NamespaceManager {
|
func NewNamespaceController(kubeClient client.Interface, resyncPeriod time.Duration) *NamespaceController {
|
||||||
_, controller := framework.NewInformer(
|
_, controller := framework.NewInformer(
|
||||||
&cache.ListWatch{
|
&cache.ListWatch{
|
||||||
ListFunc: func() (runtime.Object, error) {
|
ListFunc: func() (runtime.Object, error) {
|
||||||
@ -70,13 +70,13 @@ func NewNamespaceManager(kubeClient client.Interface, resyncPeriod time.Duration
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
return &NamespaceManager{
|
return &NamespaceController{
|
||||||
controller: controller,
|
controller: controller,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run begins observing the system. It starts a goroutine and returns immediately.
|
// Run begins observing the system. It starts a goroutine and returns immediately.
|
||||||
func (nm *NamespaceManager) Run() {
|
func (nm *NamespaceController) Run() {
|
||||||
if nm.StopEverything == nil {
|
if nm.StopEverything == nil {
|
||||||
nm.StopEverything = make(chan struct{})
|
nm.StopEverything = make(chan struct{})
|
||||||
go nm.controller.Run(nm.StopEverything)
|
go nm.controller.Run(nm.StopEverything)
|
||||||
@ -84,7 +84,7 @@ func (nm *NamespaceManager) Run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stop gracefully shutsdown this controller
|
// Stop gracefully shutsdown this controller
|
||||||
func (nm *NamespaceManager) Stop() {
|
func (nm *NamespaceController) Stop() {
|
||||||
if nm.StopEverything != nil {
|
if nm.StopEverything != nil {
|
||||||
close(nm.StopEverything)
|
close(nm.StopEverything)
|
||||||
nm.StopEverything = nil
|
nm.StopEverything = nil
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package namespace
|
package namespacecontroller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@ -138,21 +138,21 @@ func TestSyncNamespaceThatIsActive(t *testing.T) {
|
|||||||
func TestRunStop(t *testing.T) {
|
func TestRunStop(t *testing.T) {
|
||||||
o := testclient.NewObjects(api.Scheme, api.Scheme)
|
o := testclient.NewObjects(api.Scheme, api.Scheme)
|
||||||
client := &testclient.Fake{ReactFn: testclient.ObjectReaction(o, api.RESTMapper)}
|
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 {
|
if nsController.StopEverything != nil {
|
||||||
t.Errorf("Non-running manager should not have a stop channel. Got %v", nsMgr.StopEverything)
|
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")
|
t.Errorf("Running manager should have a stop channel. Got nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
nsMgr.Stop()
|
nsController.Stop()
|
||||||
|
|
||||||
if nsMgr.StopEverything != nil {
|
if nsController.StopEverything != nil {
|
||||||
t.Errorf("Non-running manager should not have a stop channel. Got %v", nsMgr.StopEverything)
|
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
|
// Package replication contains logic for watching and synchronizing
|
||||||
// replication controllers.
|
// replication controllers.
|
||||||
package replication
|
package replicationcontroller
|
||||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package replication
|
package replicationcontroller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -63,6 +63,8 @@ const (
|
|||||||
|
|
||||||
// ReplicationManager is responsible for synchronizing ReplicationController objects stored
|
// ReplicationManager is responsible for synchronizing ReplicationController objects stored
|
||||||
// in the system with actual running pods.
|
// 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 {
|
type ReplicationManager struct {
|
||||||
kubeClient client.Interface
|
kubeClient client.Interface
|
||||||
podControl controller.PodControlInterface
|
podControl controller.PodControlInterface
|
||||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package replication
|
package replicationcontroller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package replication
|
package replicationcontroller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
|
@ -15,4 +15,4 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// resourcequota contains a controller that makes resource quota usage observations
|
// 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.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package resourcequota
|
package resourcequotacontroller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
@ -28,8 +28,8 @@ import (
|
|||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ResourceQuotaManager is responsible for tracking quota usage status in the system
|
// ResourceQuotaController is responsible for tracking quota usage status in the system
|
||||||
type ResourceQuotaManager struct {
|
type ResourceQuotaController struct {
|
||||||
kubeClient client.Interface
|
kubeClient client.Interface
|
||||||
syncTime <-chan time.Time
|
syncTime <-chan time.Time
|
||||||
|
|
||||||
@ -37,10 +37,10 @@ type ResourceQuotaManager struct {
|
|||||||
syncHandler func(quota api.ResourceQuota) error
|
syncHandler func(quota api.ResourceQuota) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewResourceQuotaManager creates a new ResourceQuotaManager
|
// NewResourceQuotaController creates a new ResourceQuotaController
|
||||||
func NewResourceQuotaManager(kubeClient client.Interface) *ResourceQuotaManager {
|
func NewResourceQuotaController(kubeClient client.Interface) *ResourceQuotaController {
|
||||||
|
|
||||||
rm := &ResourceQuotaManager{
|
rm := &ResourceQuotaController{
|
||||||
kubeClient: kubeClient,
|
kubeClient: kubeClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,12 +50,12 @@ func NewResourceQuotaManager(kubeClient client.Interface) *ResourceQuotaManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run begins watching and syncing.
|
// Run begins watching and syncing.
|
||||||
func (rm *ResourceQuotaManager) Run(period time.Duration) {
|
func (rm *ResourceQuotaController) Run(period time.Duration) {
|
||||||
rm.syncTime = time.Tick(period)
|
rm.syncTime = time.Tick(period)
|
||||||
go util.Forever(func() { rm.synchronize() }, period)
|
go util.Forever(func() { rm.synchronize() }, period)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rm *ResourceQuotaManager) synchronize() {
|
func (rm *ResourceQuotaController) synchronize() {
|
||||||
var resourceQuotas []api.ResourceQuota
|
var resourceQuotas []api.ResourceQuota
|
||||||
list, err := rm.kubeClient.ResourceQuotas(api.NamespaceAll).List(labels.Everything())
|
list, err := rm.kubeClient.ResourceQuotas(api.NamespaceAll).List(labels.Everything())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -101,7 +101,7 @@ func FilterQuotaPods(pods []api.Pod) []*api.Pod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// syncResourceQuota runs a complete sync of current status
|
// 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
|
// 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)
|
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.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package resourcequota
|
package resourcequotacontroller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@ -152,8 +152,8 @@ func TestSyncResourceQuota(t *testing.T) {
|
|||||||
|
|
||||||
kubeClient := testclient.NewSimpleFake(&podList, "a)
|
kubeClient := testclient.NewSimpleFake(&podList, "a)
|
||||||
|
|
||||||
resourceQuotaManager := NewResourceQuotaManager(kubeClient)
|
ResourceQuotaController := NewResourceQuotaController(kubeClient)
|
||||||
err := resourceQuotaManager.syncResourceQuota(quota)
|
err := ResourceQuotaController.syncResourceQuota(quota)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error %v", err)
|
t.Fatalf("Unexpected error %v", err)
|
||||||
}
|
}
|
||||||
@ -210,8 +210,8 @@ func TestSyncResourceQuotaSpecChange(t *testing.T) {
|
|||||||
|
|
||||||
kubeClient := testclient.NewSimpleFake("a)
|
kubeClient := testclient.NewSimpleFake("a)
|
||||||
|
|
||||||
resourceQuotaManager := NewResourceQuotaManager(kubeClient)
|
ResourceQuotaController := NewResourceQuotaController(kubeClient)
|
||||||
err := resourceQuotaManager.syncResourceQuota(quota)
|
err := ResourceQuotaController.syncResourceQuota(quota)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error %v", err)
|
t.Fatalf("Unexpected error %v", err)
|
||||||
}
|
}
|
||||||
@ -257,8 +257,8 @@ func TestSyncResourceQuotaNoChange(t *testing.T) {
|
|||||||
|
|
||||||
kubeClient := testclient.NewSimpleFake(&api.PodList{}, "a)
|
kubeClient := testclient.NewSimpleFake(&api.PodList{}, "a)
|
||||||
|
|
||||||
resourceQuotaManager := NewResourceQuotaManager(kubeClient)
|
ResourceQuotaController := NewResourceQuotaController(kubeClient)
|
||||||
err := resourceQuotaManager.syncResourceQuota(quota)
|
err := ResourceQuotaController.syncResourceQuota(quota)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error %v", err)
|
t.Fatalf("Unexpected error %v", err)
|
||||||
}
|
}
|
@ -27,9 +27,9 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/resourcequota"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/resourcequota"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||||
)
|
)
|
||||||
@ -193,23 +193,23 @@ func IncrementUsage(a admission.Attributes, status *api.ResourceQuotaStatus, cli
|
|||||||
// handle memory/cpu constraints, and any diff of usage based on memory/cpu on updates
|
// handle memory/cpu constraints, and any diff of usage based on memory/cpu on updates
|
||||||
if a.GetResource() == "pods" && (set[api.ResourceMemory] || set[api.ResourceCPU]) {
|
if a.GetResource() == "pods" && (set[api.ResourceMemory] || set[api.ResourceCPU]) {
|
||||||
pod := obj.(*api.Pod)
|
pod := obj.(*api.Pod)
|
||||||
deltaCPU := resourcequota.PodCPU(pod)
|
deltaCPU := resourcequotacontroller.PodCPU(pod)
|
||||||
deltaMemory := resourcequota.PodMemory(pod)
|
deltaMemory := resourcequotacontroller.PodMemory(pod)
|
||||||
// if this is an update, we need to find the delta cpu/memory usage from previous state
|
// if this is an update, we need to find the delta cpu/memory usage from previous state
|
||||||
if a.GetOperation() == admission.Update {
|
if a.GetOperation() == admission.Update {
|
||||||
oldPod, err := client.Pods(a.GetNamespace()).Get(pod.Name)
|
oldPod, err := client.Pods(a.GetNamespace()).Get(pod.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
oldCPU := resourcequota.PodCPU(oldPod)
|
oldCPU := resourcequotacontroller.PodCPU(oldPod)
|
||||||
oldMemory := resourcequota.PodMemory(oldPod)
|
oldMemory := resourcequotacontroller.PodMemory(oldPod)
|
||||||
deltaCPU = resource.NewMilliQuantity(deltaCPU.MilliValue()-oldCPU.MilliValue(), resource.DecimalSI)
|
deltaCPU = resource.NewMilliQuantity(deltaCPU.MilliValue()-oldCPU.MilliValue(), resource.DecimalSI)
|
||||||
deltaMemory = resource.NewQuantity(deltaMemory.Value()-oldMemory.Value(), resource.DecimalSI)
|
deltaMemory = resource.NewQuantity(deltaMemory.Value()-oldMemory.Value(), resource.DecimalSI)
|
||||||
}
|
}
|
||||||
|
|
||||||
hardMem, hardMemFound := status.Hard[api.ResourceMemory]
|
hardMem, hardMemFound := status.Hard[api.ResourceMemory]
|
||||||
if hardMemFound {
|
if hardMemFound {
|
||||||
if set[api.ResourceMemory] && resourcequota.IsPodMemoryUnbounded(pod) {
|
if set[api.ResourceMemory] && resourcequotacontroller.IsPodMemoryUnbounded(pod) {
|
||||||
return false, fmt.Errorf("Limited to %s memory, but pod has no specified memory limit", hardMem.String())
|
return false, fmt.Errorf("Limited to %s memory, but pod has no specified memory limit", hardMem.String())
|
||||||
}
|
}
|
||||||
used, usedFound := status.Used[api.ResourceMemory]
|
used, usedFound := status.Used[api.ResourceMemory]
|
||||||
@ -225,7 +225,7 @@ func IncrementUsage(a admission.Attributes, status *api.ResourceQuotaStatus, cli
|
|||||||
}
|
}
|
||||||
hardCPU, hardCPUFound := status.Hard[api.ResourceCPU]
|
hardCPU, hardCPUFound := status.Hard[api.ResourceCPU]
|
||||||
if hardCPUFound {
|
if hardCPUFound {
|
||||||
if set[api.ResourceCPU] && resourcequota.IsPodCPUUnbounded(pod) {
|
if set[api.ResourceCPU] && resourcequotacontroller.IsPodCPUUnbounded(pod) {
|
||||||
return false, fmt.Errorf("Limited to %s CPU, but pod has no specified cpu limit", hardCPU.String())
|
return false, fmt.Errorf("Limited to %s CPU, but pod has no specified cpu limit", hardCPU.String())
|
||||||
}
|
}
|
||||||
used, usedFound := status.Used[api.ResourceCPU]
|
used, usedFound := status.Used[api.ResourceCPU]
|
||||||
|
@ -68,7 +68,7 @@ type MasterComponents struct {
|
|||||||
// Restclient used to talk to the kubernetes master
|
// Restclient used to talk to the kubernetes master
|
||||||
RestClient *client.Client
|
RestClient *client.Client
|
||||||
// Replication controller manager
|
// Replication controller manager
|
||||||
ControllerManager *replication.ReplicationManager
|
ControllerManager *replicationcontroller.ReplicationManager
|
||||||
// Channel for stop signals to rc manager
|
// Channel for stop signals to rc manager
|
||||||
rcStopCh chan struct{}
|
rcStopCh chan struct{}
|
||||||
// Used to stop master components individually, and via MasterComponents.Stop
|
// Used to stop master components individually, and via MasterComponents.Stop
|
||||||
@ -101,7 +101,7 @@ func NewMasterComponents(c *Config) *MasterComponents {
|
|||||||
}
|
}
|
||||||
restClient := client.NewOrDie(&client.Config{Host: s.URL, Version: testapi.Version(), QPS: c.QPS, Burst: c.Burst})
|
restClient := client.NewOrDie(&client.Config{Host: s.URL, Version: testapi.Version(), QPS: c.QPS, Burst: c.Burst})
|
||||||
rcStopCh := make(chan struct{})
|
rcStopCh := make(chan struct{})
|
||||||
controllerManager := replication.NewReplicationManager(restClient, c.Burst)
|
controllerManager := replicationcontroller.NewReplicationManager(restClient, c.Burst)
|
||||||
|
|
||||||
// TODO: Support events once we can cleanly shutdown an event recorder.
|
// TODO: Support events once we can cleanly shutdown an event recorder.
|
||||||
controllerManager.SetEventRecorder(&record.FakeRecorder{})
|
controllerManager.SetEventRecorder(&record.FakeRecorder{})
|
||||||
|
@ -40,10 +40,10 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/authorizer"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/authorizer"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/user"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/user"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller/serviceaccount"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/serviceaccount"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
|
||||||
|
Loading…
Reference in New Issue
Block a user