Skip to content

Commit 6cf967b

Browse files
Move deployments to use versioned Kubernetes informers
Removes the need for an additional cache for these. Also all controllers are moving in this direction anyway.
1 parent 37f5963 commit 6cf967b

File tree

16 files changed

+408
-311
lines changed

16 files changed

+408
-311
lines changed

pkg/client/cache/deploymentconfig.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
66
"k8s.io/apimachinery/pkg/labels"
77
"k8s.io/client-go/tools/cache"
8-
kapi "k8s.io/kubernetes/pkg/api"
8+
"k8s.io/kubernetes/pkg/api/v1"
99

1010
deployapi "github.com/openshift/origin/pkg/deploy/api"
1111
deployutil "github.com/openshift/origin/pkg/deploy/util"
@@ -27,7 +27,7 @@ func (s *StoreToDeploymentConfigLister) List() ([]*deployapi.DeploymentConfig, e
2727
}
2828

2929
// GetConfigForController returns the managing deployment config for the provided replication controller.
30-
func (s *StoreToDeploymentConfigLister) GetConfigForController(rc *kapi.ReplicationController) (*deployapi.DeploymentConfig, error) {
30+
func (s *StoreToDeploymentConfigLister) GetConfigForController(rc *v1.ReplicationController) (*deployapi.DeploymentConfig, error) {
3131
dcName := deployutil.DeploymentConfigNameFor(rc)
3232
obj, exists, err := s.Indexer.GetByKey(rc.Namespace + "/" + dcName)
3333
if err != nil {
@@ -40,7 +40,7 @@ func (s *StoreToDeploymentConfigLister) GetConfigForController(rc *kapi.Replicat
4040
}
4141

4242
// GetConfigForPod returns the managing deployment config for the provided pod.
43-
func (s *StoreToDeploymentConfigLister) GetConfigForPod(pod *kapi.Pod) (*deployapi.DeploymentConfig, error) {
43+
func (s *StoreToDeploymentConfigLister) GetConfigForPod(pod *v1.Pod) (*deployapi.DeploymentConfig, error) {
4444
dcName := deployutil.DeploymentConfigNameFor(pod)
4545
obj, exists, err := s.Indexer.GetByKey(pod.Namespace + "/" + dcName)
4646
if err != nil {

pkg/cmd/server/origin/controller/apps.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@ type DeploymentTriggerControllerConfig struct {
2626
}
2727

2828
func (c *DeployerControllerConfig) RunController(ctx ControllerContext) (bool, error) {
29-
internalDeployerKubeClient, err := ctx.ClientBuilder.KubeInternalClient(bootstrappolicy.InfraDeployerControllerServiceAccountName)
29+
kubeClient, err := ctx.ClientBuilder.Client(bootstrappolicy.InfraDeployerControllerServiceAccountName)
3030
if err != nil {
3131
return true, err
3232
}
3333

3434
go deployercontroller.NewDeployerController(
35-
ctx.InternalKubeInformers.Core().InternalVersion().ReplicationControllers(),
36-
ctx.InternalKubeInformers.Core().InternalVersion().Pods(),
37-
internalDeployerKubeClient,
38-
ctx.ClientBuilder.ClientOrDie(bootstrappolicy.InfraDeployerControllerServiceAccountName),
35+
ctx.ExternalKubeInformers.Core().V1().ReplicationControllers(),
36+
ctx.ExternalKubeInformers.Core().V1().Pods(),
37+
kubeClient,
3938
bootstrappolicy.DeployerServiceAccountName,
4039
c.ImageName,
4140
c.ClientEnvVars,
@@ -48,7 +47,7 @@ func (c *DeployerControllerConfig) RunController(ctx ControllerContext) (bool, e
4847
func (c *DeploymentConfigControllerConfig) RunController(ctx ControllerContext) (bool, error) {
4948
saName := bootstrappolicy.InfraDeploymentConfigControllerServiceAccountName
5049

51-
internalDcKubeClient, err := ctx.ClientBuilder.KubeInternalClient(saName)
50+
kubeClient, err := ctx.ClientBuilder.Client(saName)
5251
if err != nil {
5352
return true, err
5453
}
@@ -59,10 +58,9 @@ func (c *DeploymentConfigControllerConfig) RunController(ctx ControllerContext)
5958

6059
go deployconfigcontroller.NewDeploymentConfigController(
6160
ctx.AppInformers.Apps().InternalVersion().DeploymentConfigs().Informer(),
62-
ctx.InternalKubeInformers.Core().InternalVersion().ReplicationControllers(),
61+
ctx.ExternalKubeInformers.Core().V1().ReplicationControllers(),
6362
deprecatedOcDcClient,
64-
internalDcKubeClient,
65-
ctx.ClientBuilder.ClientOrDie(saName),
63+
kubeClient,
6664
c.Codec,
6765
).Run(5, ctx.Stop)
6866

@@ -79,7 +77,7 @@ func (c *DeploymentTriggerControllerConfig) RunController(ctx ControllerContext)
7977

8078
go triggercontroller.NewDeploymentTriggerController(
8179
ctx.AppInformers.Apps().InternalVersion().DeploymentConfigs().Informer(),
82-
ctx.InternalKubeInformers.Core().InternalVersion().ReplicationControllers().Informer(),
80+
ctx.ExternalKubeInformers.Core().V1().ReplicationControllers().Informer(),
8381
ctx.ImageInformers.Image().InternalVersion().ImageStreams().Informer(),
8482
deprecatedOcTriggerClient,
8583
c.Codec,

pkg/controller/controller_ref_manager.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"k8s.io/apimachinery/pkg/types"
1212
kutilerrors "k8s.io/apimachinery/pkg/util/errors"
1313
"k8s.io/client-go/tools/record"
14-
kapi "k8s.io/kubernetes/pkg/api"
15-
kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
14+
"k8s.io/kubernetes/pkg/api/v1"
15+
kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
1616
kcontroller "k8s.io/kubernetes/pkg/controller"
1717
)
1818

@@ -86,15 +86,15 @@ func NewRCControllerRefManager(
8686
// If the error is nil, either the reconciliation succeeded, or no
8787
// reconciliation was necessary. The returned boolean indicates whether you now
8888
// own the object.
89-
func (m *RCControllerRefManager) ClaimReplicationController(rc *kapi.ReplicationController) (bool, error) {
89+
func (m *RCControllerRefManager) ClaimReplicationController(rc *v1.ReplicationController) (bool, error) {
9090
match := func(obj kmetav1.Object) bool {
9191
return m.Selector.Matches(klabels.Set(obj.GetLabels()))
9292
}
9393
adopt := func(obj kmetav1.Object) error {
94-
return m.AdoptReplicationController(obj.(*kapi.ReplicationController))
94+
return m.AdoptReplicationController(obj.(*v1.ReplicationController))
9595
}
9696
release := func(obj kmetav1.Object) error {
97-
return m.ReleaseReplicationController(obj.(*kapi.ReplicationController))
97+
return m.ReleaseReplicationController(obj.(*v1.ReplicationController))
9898
}
9999

100100
return m.ClaimObject(rc, match, adopt, release)
@@ -113,8 +113,8 @@ func (m *RCControllerRefManager) ClaimReplicationController(rc *kapi.Replication
113113
// If the error is nil, either the reconciliation succeeded, or no
114114
// reconciliation was necessary. The list of ReplicationControllers that you now own is
115115
// returned.
116-
func (m *RCControllerRefManager) ClaimReplicationControllers(rcs []*kapi.ReplicationController) ([]*kapi.ReplicationController, error) {
117-
var claimed []*kapi.ReplicationController
116+
func (m *RCControllerRefManager) ClaimReplicationControllers(rcs []*v1.ReplicationController) ([]*v1.ReplicationController, error) {
117+
var claimed []*v1.ReplicationController
118118
var errlist []error
119119

120120
for _, rc := range rcs {
@@ -132,7 +132,7 @@ func (m *RCControllerRefManager) ClaimReplicationControllers(rcs []*kapi.Replica
132132

133133
// AdoptReplicationController sends a patch to take control of the ReplicationController. It returns the error if
134134
// the patching fails.
135-
func (m *RCControllerRefManager) AdoptReplicationController(rs *kapi.ReplicationController) error {
135+
func (m *RCControllerRefManager) AdoptReplicationController(rs *v1.ReplicationController) error {
136136
if err := m.CanAdopt(); err != nil {
137137
return fmt.Errorf("can't adopt ReplicationController %s/%s (%s): %v", rs.Namespace, rs.Name, rs.UID, err)
138138
}
@@ -153,7 +153,7 @@ func (m *RCControllerRefManager) AdoptReplicationController(rs *kapi.Replication
153153

154154
// ReleaseReplicationController sends a patch to free the ReplicationController from the control of the Deployment controller.
155155
// It returns the error if the patching fails. 404 and 422 errors are ignored.
156-
func (m *RCControllerRefManager) ReleaseReplicationController(rc *kapi.ReplicationController) error {
156+
func (m *RCControllerRefManager) ReleaseReplicationController(rc *v1.ReplicationController) error {
157157
glog.V(4).Infof("patching ReplicationController %s/%s to remove its controllerRef to %s/%s:%s",
158158
rc.Namespace, rc.Name, m.controllerKind.GroupVersion(), m.controllerKind.Kind, m.Controller.GetName())
159159
deleteOwnerRefPatch := fmt.Sprintf(`{"metadata":{"ownerReferences":[{"$patch":"delete","uid":"%s"}],"uid":"%s"}}`, m.Controller.GetUID(), rc.UID)

0 commit comments

Comments
 (0)