Skip to content

Commit 38e4e7f

Browse files
veophimingzhou.swx
authored andcommitted
[Fix] ResourceDistribution should watch unstructured object (#1464)
* fix resourcedistribution event watch Signed-off-by: mingzhou.swx <[email protected]> * fix image list pull job e2e Signed-off-by: mingzhou.swx <[email protected]> --------- Signed-off-by: mingzhou.swx <[email protected]> Co-authored-by: mingzhou.swx <[email protected]> Signed-off-by: pingjiang <[email protected]>
1 parent 15620f2 commit 38e4e7f

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

Diff for: pkg/controller/resourcedistribution/resourcedistribution_controller.go

+10-16
Original file line numberDiff line numberDiff line change
@@ -110,39 +110,33 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
110110
}
111111

112112
// Watch for changes to Secrets
113-
err = c.Watch(&source.Kind{Type: &corev1.Secret{}}, &handler.EnqueueRequestForOwner{
113+
secret := unstructured.Unstructured{}
114+
secret.SetGroupVersionKind(corev1.SchemeGroupVersion.WithKind("Secret"))
115+
err = c.Watch(&source.Kind{Type: &secret}, &handler.EnqueueRequestForOwner{
114116
IsController: true, OwnerType: &appsv1alpha1.ResourceDistribution{},
115117
}, predicate.Funcs{
116118
CreateFunc: func(createEvent event.CreateEvent) bool {
117119
return false
118120
},
119-
UpdateFunc: func(updateEvent event.UpdateEvent) bool {
120-
oldObject, oldOK := updateEvent.ObjectOld.(*corev1.Secret)
121-
newObject, newOK := updateEvent.ObjectNew.(*corev1.Secret)
122-
if !oldOK || !newOK {
123-
return false
124-
}
125-
return !reflect.DeepEqual(oldObject.Data, newObject.Data) || !reflect.DeepEqual(oldObject.StringData, newObject.StringData)
121+
GenericFunc: func(genericEvent event.GenericEvent) bool {
122+
return false
126123
},
127124
})
128125
if err != nil {
129126
return err
130127
}
131128

132129
// Watch for changes to ConfigMap
133-
err = c.Watch(&source.Kind{Type: &corev1.ConfigMap{}}, &handler.EnqueueRequestForOwner{
130+
configMap := unstructured.Unstructured{}
131+
configMap.SetGroupVersionKind(corev1.SchemeGroupVersion.WithKind("ConfigMap"))
132+
err = c.Watch(&source.Kind{Type: &configMap}, &handler.EnqueueRequestForOwner{
134133
IsController: true, OwnerType: &appsv1alpha1.ResourceDistribution{},
135134
}, predicate.Funcs{
136135
CreateFunc: func(createEvent event.CreateEvent) bool {
137136
return false
138137
},
139-
UpdateFunc: func(updateEvent event.UpdateEvent) bool {
140-
oldObject, oldOK := updateEvent.ObjectOld.(*corev1.ConfigMap)
141-
newObject, newOK := updateEvent.ObjectNew.(*corev1.ConfigMap)
142-
if !oldOK || !newOK {
143-
return false
144-
}
145-
return !reflect.DeepEqual(oldObject.Data, newObject.Data) || !reflect.DeepEqual(oldObject.BinaryData, newObject.BinaryData)
138+
GenericFunc: func(genericEvent event.GenericEvent) bool {
139+
return false
146140
},
147141
})
148142
if err != nil {

Diff for: test/e2e/apps/imagelistpulljobs.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,20 @@ var _ = SIGDescribe("PullImages", func() {
194194
gomega.Expect(err).NotTo(gomega.HaveOccurred())
195195

196196
ginkgo.By("Check imagepulljob should be cleaned")
197+
time.Sleep(3 * time.Second)
197198
gomega.Eventually(func() bool {
198-
imagePullJobs, err := testerForImagePullJob.ListJobs(job.Namespace)
199+
imagePullJobLister, err := testerForImagePullJob.ListJobs(job.Namespace)
199200
gomega.Expect(err).NotTo(gomega.HaveOccurred())
200-
return len(imagePullJobs.Items) > 0
201-
}, 3*time.Second, time.Second).Should(gomega.Equal(false))
201+
var imagePullJobs []*appsv1alpha1.ImagePullJob
202+
for i := range imagePullJobLister.Items {
203+
pullJob := &imagePullJobLister.Items[i]
204+
if metav1.IsControlledBy(pullJob, job) {
205+
imagePullJobs = append(imagePullJobs, pullJob)
206+
}
207+
fmt.Printf("waiting imagePullJob GC: %v", imagePullJobs)
208+
}
209+
return len(imagePullJobs) == 0
210+
}, time.Minute, time.Second).Should(gomega.BeTrue())
202211
})
203212

204213
framework.ConformanceIt("create an always job to pull an image on all nodes", func() {

0 commit comments

Comments
 (0)