From 17ddb19ada67c933698ed934ecf128d43069b2b5 Mon Sep 17 00:00:00 2001 From: Matt Liggett Date: Tue, 16 Aug 2016 15:29:28 -0700 Subject: [PATCH 1/2] Add TODO comment. --- pkg/controller/disruption/disruption.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/controller/disruption/disruption.go b/pkg/controller/disruption/disruption.go index 8b80a9bcc69..5d81fbf28ba 100644 --- a/pkg/controller/disruption/disruption.go +++ b/pkg/controller/disruption/disruption.go @@ -462,6 +462,10 @@ func (dc *DisruptionController) trySync(pdb *policy.PodDisruptionBudget) error { func (dc *DisruptionController) getExpectedPodCount(pdb *policy.PodDisruptionBudget, pods []*api.Pod) (expectedCount, desiredHealthy int32, err error) { err = nil + // TODO(davidopp): consider making the way expectedCount and rules about + // permitted controller configurations (specifically, considering it an error + // if a pod covered by a PDB has 0 controllers or > 1 controller) should be + // handled the same way for integer and percentage minAvailable if pdb.Spec.MinAvailable.Type == intstr.Int { desiredHealthy = pdb.Spec.MinAvailable.IntVal expectedCount = int32(len(pods)) From 441bfb061478c00d0d1ce65a3d813b3d7dec5fe9 Mon Sep 17 00:00:00 2001 From: Matt Liggett Date: Tue, 16 Aug 2016 15:34:42 -0700 Subject: [PATCH 2/2] Record an event when a pod does not have exactly 1 controller. --- pkg/controller/disruption/disruption.go | 2 ++ pkg/controller/disruption/disruption_test.go | 16 ++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/controller/disruption/disruption.go b/pkg/controller/disruption/disruption.go index 5d81fbf28ba..ca01da20c41 100644 --- a/pkg/controller/disruption/disruption.go +++ b/pkg/controller/disruption/disruption.go @@ -502,9 +502,11 @@ func (dc *DisruptionController) getExpectedPodCount(pdb *policy.PodDisruptionBud } if controllerCount == 0 { err = fmt.Errorf("asked for percentage, but found no controllers for pod %q", pod.Name) + dc.recorder.Event(pdb, api.EventTypeWarning, "NoControllers", err.Error()) return } else if controllerCount > 1 { err = fmt.Errorf("pod %q has %v>1 controllers", pod.Name, controllerCount) + dc.recorder.Event(pdb, api.EventTypeWarning, "TooManyControllers", err.Error()) return } } diff --git a/pkg/controller/disruption/disruption_test.go b/pkg/controller/disruption/disruption_test.go index 3813af19d6d..b17189ab297 100644 --- a/pkg/controller/disruption/disruption_test.go +++ b/pkg/controller/disruption/disruption_test.go @@ -27,6 +27,7 @@ import ( "k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/apis/policy" "k8s.io/kubernetes/pkg/client/cache" + "k8s.io/kubernetes/pkg/client/record" "k8s.io/kubernetes/pkg/controller" "k8s.io/kubernetes/pkg/util/intstr" "k8s.io/kubernetes/pkg/util/uuid" @@ -76,14 +77,17 @@ func newFakeDisruptionController() (*DisruptionController, *pdbStates) { ps := &pdbStates{} dc := &DisruptionController{ - pdbLister: cache.StoreToPodDisruptionBudgetLister{Store: cache.NewStore(controller.KeyFunc)}, - podLister: cache.StoreToPodLister{Indexer: cache.NewIndexer(controller.KeyFunc, cache.Indexers{})}, - rcLister: cache.StoreToReplicationControllerLister{Indexer: cache.NewIndexer(controller.KeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})}, - rsLister: cache.StoreToReplicaSetLister{Store: cache.NewStore(controller.KeyFunc)}, - dLister: cache.StoreToDeploymentLister{Store: cache.NewStore(controller.KeyFunc)}, - getUpdater: func() updater { return ps.Set }, + pdbLister: cache.StoreToPodDisruptionBudgetLister{Store: cache.NewStore(controller.KeyFunc)}, + podLister: cache.StoreToPodLister{Indexer: cache.NewIndexer(controller.KeyFunc, cache.Indexers{})}, + rcLister: cache.StoreToReplicationControllerLister{Indexer: cache.NewIndexer(controller.KeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})}, + rsLister: cache.StoreToReplicaSetLister{Store: cache.NewStore(controller.KeyFunc)}, + dLister: cache.StoreToDeploymentLister{Store: cache.NewStore(controller.KeyFunc)}, + getUpdater: func() updater { return ps.Set }, + broadcaster: record.NewBroadcaster(), } + dc.recorder = dc.broadcaster.NewRecorder(api.EventSource{Component: "disruption_test"}) + return dc, ps }