-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Use shared caches in the deploymentconfig controller #9002
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package cache | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/golang/glog" | ||
|
||
kapi "k8s.io/kubernetes/pkg/api" | ||
"k8s.io/kubernetes/pkg/client/cache" | ||
"k8s.io/kubernetes/pkg/labels" | ||
|
||
deployapi "github.com/openshift/origin/pkg/deploy/api" | ||
deployutil "github.com/openshift/origin/pkg/deploy/util" | ||
) | ||
|
||
// StoreToDeploymentConfigLister gives a store List and Exists methods. The store must contain only deploymentconfigs. | ||
type StoreToDeploymentConfigLister struct { | ||
cache.Indexer | ||
} | ||
|
||
// Exists checks if the given deploymentconfig exists in the store. | ||
func (s *StoreToDeploymentConfigLister) Exists(dc *deployapi.DeploymentConfig) (bool, error) { | ||
_, exists, err := s.Indexer.Get(dc) | ||
return exists, err | ||
} | ||
|
||
// List all deploymentconfigs in the store. | ||
func (s *StoreToDeploymentConfigLister) List() ([]*deployapi.DeploymentConfig, error) { | ||
configs := []*deployapi.DeploymentConfig{} | ||
for _, c := range s.Indexer.List() { | ||
configs = append(configs, c.(*deployapi.DeploymentConfig)) | ||
} | ||
return configs, nil | ||
} | ||
|
||
// GetConfigForController returns the managing deployment config for the provided replication controller. | ||
func (s *StoreToDeploymentConfigLister) GetConfigForController(rc *kapi.ReplicationController) (*deployapi.DeploymentConfig, error) { | ||
dcName := deployutil.DeploymentConfigNameFor(rc) | ||
obj, exists, err := s.Indexer.GetByKey(rc.Namespace + "/" + dcName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !exists { | ||
return nil, fmt.Errorf("deployment config %q not found", dcName) | ||
} | ||
return obj.(*deployapi.DeploymentConfig), nil | ||
} | ||
|
||
func (s *StoreToDeploymentConfigLister) DeploymentConfigs(namespace string) storeDeploymentConfigsNamespacer { | ||
return storeDeploymentConfigsNamespacer{s.Indexer, namespace} | ||
} | ||
|
||
type storeDeploymentConfigsNamespacer struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lack of a I'm assuming its not critical for this PR, but I think exposing a basic List/Get from here is pretty reasonable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added Get |
||
indexer cache.Indexer | ||
namespace string | ||
} | ||
|
||
// Get the deployment config matching the name from the cache. | ||
func (s storeDeploymentConfigsNamespacer) Get(name string) (*deployapi.DeploymentConfig, error) { | ||
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !exists { | ||
return nil, fmt.Errorf("deployment config %q not found", name) | ||
} | ||
return obj.(*deployapi.DeploymentConfig), nil | ||
} | ||
|
||
// List all the deploymentconfigs that match the provided selector using a namespace index. | ||
// If the indexed list fails then we will fallback to listing from all namespaces and filter | ||
// by the namespace we want. | ||
func (s storeDeploymentConfigsNamespacer) List(selector labels.Selector) ([]*deployapi.DeploymentConfig, error) { | ||
configs := []*deployapi.DeploymentConfig{} | ||
|
||
if s.namespace == kapi.NamespaceAll { | ||
for _, obj := range s.indexer.List() { | ||
dc := obj.(*deployapi.DeploymentConfig) | ||
if selector.Matches(labels.Set(dc.Labels)) { | ||
configs = append(configs, dc) | ||
} | ||
} | ||
return configs, nil | ||
} | ||
|
||
key := &deployapi.DeploymentConfig{ObjectMeta: kapi.ObjectMeta{Namespace: s.namespace}} | ||
items, err := s.indexer.Index(cache.NamespaceIndex, key) | ||
if err != nil { | ||
// Ignore error; do slow search without index. | ||
glog.Warningf("can not retrieve list of objects using index : %v", err) | ||
for _, obj := range s.indexer.List() { | ||
dc := obj.(*deployapi.DeploymentConfig) | ||
if s.namespace == dc.Namespace && selector.Matches(labels.Set(dc.Labels)) { | ||
configs = append(configs, dc) | ||
} | ||
} | ||
return configs, nil | ||
} | ||
for _, obj := range items { | ||
dc := obj.(*deployapi.DeploymentConfig) | ||
if selector.Matches(labels.Set(dc.Labels)) { | ||
configs = append(configs, dc) | ||
} | ||
} | ||
return configs, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -576,9 +576,9 @@ func (c *MasterConfig) DeploymentControllerClients() (*osclient.Client, *kclient | |
return osClient, kClient | ||
} | ||
|
||
// DeployerPodControllerClients returns the deployer pod controller client objects | ||
func (c *MasterConfig) DeployerPodControllerClients() (*osclient.Client, *kclient.Client) { | ||
return c.PrivilegedLoopbackOpenShiftClient, c.PrivilegedLoopbackKubernetesClient | ||
// DeployerPodControllerClients returns the deployer pod controller client object | ||
func (c *MasterConfig) DeployerPodControllerClient() *kclient.Client { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're touching it, how about either converting to an SA or opening an issue where you promise to convert it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once we add a pod cache in the deployment controller, we can stop using the deployer pod controller. There is #9296 |
||
return c.PrivilegedLoopbackKubernetesClient | ||
} | ||
|
||
// DeploymentConfigClients returns deploymentConfig and deployment client objects | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smarterclayton I am using deployutil here. Should I not pull it here and just replicate what it does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok to use deployutil from client code I guess - I was initially hesitant. But let's make sure it's just deployutil. And deployutil is a terrible name.