Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deploy: enqueue configs on pod events #9953

Merged
merged 1 commit into from
Jul 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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