Skip to content

Commit

Permalink
deploy: enqueue configs on pod events
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmichalis committed Jul 20, 2016
1 parent 4ecbe85 commit a227c50
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/client/cache/deploymentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ func (s *StoreToDeploymentConfigLister) GetConfigForController(rc *kapi.Replicat
return obj.(*deployapi.DeploymentConfig), nil
}

// GetConfigForPod returns the managing deployment config for the provided pod.
func (s *StoreToDeploymentConfigLister) GetConfigForPod(pod *kapi.Pod) (*deployapi.DeploymentConfig, error) {
dcName := deployutil.DeploymentConfigNameFor(pod)
obj, exists, err := s.Indexer.GetByKey(pod.Namespace + "/" + dcName)
if err != nil {
return nil, err
}
if !exists {
return nil, kapierrors.NewNotFound(deployapi.Resource("deploymentconfig"), dcName)
}
return obj.(*deployapi.DeploymentConfig), nil
}

func (s *StoreToDeploymentConfigLister) GetConfigsForImageStream(stream *imageapi.ImageStream) ([]*deployapi.DeploymentConfig, error) {
items, err := s.Indexer.ByIndex(ImageStreamReferenceIndex, stream.Namespace+"/"+stream.Name)
if err != nil {
Expand Down
36 changes: 36 additions & 0 deletions pkg/deploy/controller/deploymentconfig/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func NewDeploymentConfigController(dcInformer, rcInformer, podInformer framework
DeleteFunc: c.deleteReplicationController,
})
c.podStore.Indexer = podInformer.GetIndexer()
podInformer.AddEventHandler(framework.ResourceEventHandlerFuncs{
AddFunc: c.addPod,
UpdateFunc: c.updatePod,
DeleteFunc: c.deletePod,
})

c.dcStoreSynced = dcInformer.HasSynced
c.rcStoreSynced = rcInformer.HasSynced
Expand Down Expand Up @@ -189,6 +194,37 @@ func (c *DeploymentConfigController) deleteReplicationController(obj interface{}
}
}

func (c *DeploymentConfigController) addPod(obj interface{}) {
if dc, err := c.dcStore.GetConfigForPod(obj.(*kapi.Pod)); err == nil && dc != nil {
c.enqueueDeploymentConfig(dc)
}
}

func (c *DeploymentConfigController) updatePod(old, cur interface{}) {
if dc, err := c.dcStore.GetConfigForPod(cur.(*kapi.Pod)); err == nil && dc != nil {
c.enqueueDeploymentConfig(dc)
}
}

func (c *DeploymentConfigController) deletePod(obj interface{}) {
pod, ok := obj.(*kapi.Pod)
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
glog.Errorf("Couldn't get object from tombstone %+v", obj)
return
}
pod, ok = tombstone.Obj.(*kapi.Pod)
if !ok {
glog.Errorf("Tombstone contained object that is not a pod: %+v", obj)
return
}
}
if dc, err := c.dcStore.GetConfigForPod(pod); err == nil && dc != nil {
c.enqueueDeploymentConfig(dc)
}
}

func (c *DeploymentConfigController) enqueueDeploymentConfig(dc *deployapi.DeploymentConfig) {
key, err := kcontroller.KeyFunc(dc)
if err != nil {
Expand Down

0 comments on commit a227c50

Please sign in to comment.