Skip to content

Commit d485992

Browse files
committed
interesting: switch image change reactor to use runtime.Object
1 parent 4f70f5d commit d485992

File tree

8 files changed

+26
-25
lines changed

8 files changed

+26
-25
lines changed

pkg/build/controller/build/build_controller_test.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,7 @@ func TestHandleBuild(t *testing.T) {
371371
t.Errorf("%s: did not get an update. Expected: %v", tc.name, tc.expectUpdate)
372372
return
373373
}
374-
expectedBuild, err := buildutil.BuildDeepCopy(tc.build)
375-
if err != nil {
376-
t.Fatalf("unexpected: %v", err)
377-
}
374+
expectedBuild := tc.build.DeepCopy()
378375
tc.expectUpdate.apply(expectedBuild)
379376

380377
// For start/completion/duration fields, simply validate that they are set/not set

pkg/image/controller/imagestream_controller_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func TestHandleImageStream(t *testing.T) {
233233

234234
for i, test := range testCases {
235235
fake := imageclient.NewSimpleClientset()
236-
other = test.stream.DeepCopy()
236+
other := test.stream.DeepCopy()
237237

238238
if err := handleImageStream(test.stream, fake.Image(), nil); err != nil {
239239
t.Errorf("%d: unexpected error: %v", i, err)

pkg/image/controller/trigger/image_trigger_controller.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/golang/glog"
1111

1212
"k8s.io/api/core/v1"
13+
"k8s.io/apimachinery/pkg/runtime"
1314
"k8s.io/apimachinery/pkg/runtime/schema"
1415
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
1516
"k8s.io/apimachinery/pkg/util/wait"
@@ -373,5 +374,5 @@ func (c *TriggerController) syncResource(key string) error {
373374
return nil
374375
}
375376

376-
return source.Reactor.ImageChanged(obj, c.tagRetriever)
377+
return source.Reactor.ImageChanged(obj.(runtime.Object), c.tagRetriever)
377378
}

pkg/image/controller/trigger/image_trigger_controller_test.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -811,13 +811,13 @@ type fakeImageReactor struct {
811811
err error
812812
}
813813

814-
type imageReactorFunc func(obj interface{}, tagRetriever trigger.TagRetriever) error
814+
type imageReactorFunc func(obj runtime.Object, tagRetriever trigger.TagRetriever) error
815815

816-
func (fn imageReactorFunc) ImageChanged(obj interface{}, tagRetriever trigger.TagRetriever) error {
816+
func (fn imageReactorFunc) ImageChanged(obj runtime.Object, tagRetriever trigger.TagRetriever) error {
817817
return fn(obj, tagRetriever)
818818
}
819819

820-
func (r *fakeImageReactor) ImageChanged(obj interface{}, tagRetriever trigger.TagRetriever) error {
820+
func (r *fakeImageReactor) ImageChanged(obj runtime.Object, tagRetriever trigger.TagRetriever) error {
821821
r.lock.Lock()
822822
defer r.lock.Unlock()
823823
err := r.err
@@ -972,10 +972,9 @@ func updateBuildConfigImages(bc *buildapi.BuildConfig, tagRetriever trigger.TagR
972972
// alterBuildConfigFromTriggers will alter the incoming build config based on the trigger
973973
// changes passed to it and send it back on the watch as a modification.
974974
func alterBuildConfigFromTriggers(bcWatch *consistentWatch) imageReactorFunc {
975-
return imageReactorFunc(func(obj interface{}, tagRetriever trigger.TagRetriever) error {
976-
bc := obj.DeepCopy()
977-
978-
updated, err := updateBuildConfigImages(bc, tagRetriever)
975+
return imageReactorFunc(func(obj runtime.Object, tagRetriever trigger.TagRetriever) error {
976+
bc := obj.DeepCopyObject()
977+
updated, err := updateBuildConfigImages(bc.(*buildapi.BuildConfig), tagRetriever)
979978
if err != nil {
980979
return err
981980
}
@@ -987,9 +986,9 @@ func alterBuildConfigFromTriggers(bcWatch *consistentWatch) imageReactorFunc {
987986
}
988987

989988
func alterDeploymentConfigFromTriggers(dcWatch *consistentWatch) imageReactorFunc {
990-
return imageReactorFunc(func(obj interface{}, tagRetriever trigger.TagRetriever) error {
991-
dc := obj.DeepCopy()
992-
updated, resolvable, err := deploymentconfigs.UpdateDeploymentConfigImages(dc, tagRetriever)
989+
return imageReactorFunc(func(obj runtime.Object, tagRetriever trigger.TagRetriever) error {
990+
dc := obj.DeepCopyObject()
991+
updated, resolvable, err := deploymentconfigs.UpdateDeploymentConfigImages(dc.(*deployapi.DeploymentConfig), tagRetriever)
993992
if err != nil {
994993
return err
995994
}
@@ -1004,10 +1003,10 @@ func alterDeploymentConfigFromTriggers(dcWatch *consistentWatch) imageReactorFun
10041003
// changes passed to it and send it back on the watch as a modification.
10051004
func alterPodFromTriggers(podWatch *watch.RaceFreeFakeWatcher) imageReactorFunc {
10061005
count := 2
1007-
return imageReactorFunc(func(obj interface{}, tagRetriever trigger.TagRetriever) error {
1008-
pod := obj.DeepCopy()
1006+
return imageReactorFunc(func(obj runtime.Object, tagRetriever trigger.TagRetriever) error {
1007+
pod := obj.DeepCopyObject()
10091008

1010-
updated, err := annotations.UpdateObjectFromImages(pod, kapi.Scheme, tagRetriever)
1009+
updated, err := annotations.UpdateObjectFromImages(pod.(*kapi.Pod), kapi.Scheme, tagRetriever)
10111010
if err != nil {
10121011
return err
10131012
}
@@ -1224,7 +1223,8 @@ func TestTriggerController(t *testing.T) {
12241223
if len(items) == 0 {
12251224
continue
12261225
}
1227-
bc := items[rnd.Int31n(int32(len(items)))].DeepCopy()
1226+
originalBc := items[rnd.Int31n(int32(len(items)))].(*buildapi.BuildConfig)
1227+
bc := originalBc.DeepCopy()
12281228
if len(bc.Spec.Triggers) > 0 {
12291229
index := rnd.Int31n(int32(len(bc.Spec.Triggers)))
12301230
trigger := &bc.Spec.Triggers[index]

pkg/image/trigger/annotations/annotations.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ type AnnotationReactor struct {
261261
Copier runtime.ObjectCopier
262262
}
263263

264-
func (r *AnnotationReactor) ImageChanged(obj interface{}, tagRetriever trigger.TagRetriever) error {
265-
changed, err := UpdateObjectFromImages(obj.(runtime.Object), r.Copier, tagRetriever)
264+
func (r *AnnotationReactor) ImageChanged(obj runtime.Object, tagRetriever trigger.TagRetriever) error {
265+
changed, err := UpdateObjectFromImages(obj, r.Copier, tagRetriever)
266266
if err != nil {
267267
return err
268268
}

pkg/image/trigger/buildconfigs/buildconfigs.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
clientv1 "k8s.io/api/core/v1"
88
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
"k8s.io/apimachinery/pkg/runtime"
910
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
1011
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
1112
"k8s.io/client-go/rest"
@@ -131,7 +132,7 @@ func NewBuildConfigReactor(instantiator BuildConfigInstantiator, restclient rest
131132

132133
// ImageChanged is passed a build config and a set of changes and updates the object if
133134
// necessary.
134-
func (r *buildConfigReactor) ImageChanged(obj interface{}, tagRetriever trigger.TagRetriever) error {
135+
func (r *buildConfigReactor) ImageChanged(obj runtime.Object, tagRetriever trigger.TagRetriever) error {
135136
bc := obj.(*buildapi.BuildConfig)
136137

137138
var request *buildapi.BuildRequest

pkg/image/trigger/deploymentconfigs/deploymentconfigs.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/golang/glog"
99

10+
"k8s.io/apimachinery/pkg/runtime"
1011
"k8s.io/client-go/tools/cache"
1112
kapi "k8s.io/kubernetes/pkg/api"
1213

@@ -226,7 +227,7 @@ func UpdateDeploymentConfigImages(dc *appsapi.DeploymentConfig, tagRetriever tri
226227
}
227228

228229
// ImageChanged is passed a deployment config and a set of changes.
229-
func (r *DeploymentConfigReactor) ImageChanged(obj interface{}, tagRetriever trigger.TagRetriever) error {
230+
func (r *DeploymentConfigReactor) ImageChanged(obj runtime.Object, tagRetriever trigger.TagRetriever) error {
230231
dc := obj.(*appsapi.DeploymentConfig)
231232
newDC := dc.DeepCopy()
232233

pkg/image/trigger/interfaces.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package trigger
22

33
import (
4+
"k8s.io/apimachinery/pkg/runtime"
45
"k8s.io/client-go/tools/cache"
56

67
"github.com/openshift/origin/pkg/image/apis/image/v1/trigger"
@@ -27,5 +28,5 @@ type TagRetriever interface {
2728
}
2829

2930
type ImageReactor interface {
30-
ImageChanged(obj interface{}, tagRetriever TagRetriever) error
31+
ImageChanged(obj runtime.Object, tagRetriever TagRetriever) error
3132
}

0 commit comments

Comments
 (0)