Skip to content

Commit

Permalink
[Fix] ResourceDistribution should watch unstructured object (#1464)
Browse files Browse the repository at this point in the history
* fix resourcedistribution event watch

Signed-off-by: mingzhou.swx <mingzhou.swx@alibaba-inc.com>

* fix image list pull job e2e

Signed-off-by: mingzhou.swx <mingzhou.swx@alibaba-inc.com>

---------

Signed-off-by: mingzhou.swx <mingzhou.swx@alibaba-inc.com>
Co-authored-by: mingzhou.swx <mingzhou.swx@alibaba-inc.com>
  • Loading branch information
veophi and mingzhou.swx committed Dec 8, 2023
1 parent 6a62320 commit 28c0a72
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,39 +110,33 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
}

// Watch for changes to Secrets
err = c.Watch(&source.Kind{Type: &corev1.Secret{}}, &handler.EnqueueRequestForOwner{
secret := unstructured.Unstructured{}
secret.SetGroupVersionKind(corev1.SchemeGroupVersion.WithKind("Secret"))
err = c.Watch(&source.Kind{Type: &secret}, &handler.EnqueueRequestForOwner{
IsController: true, OwnerType: &appsv1alpha1.ResourceDistribution{},
}, predicate.Funcs{
CreateFunc: func(createEvent event.CreateEvent) bool {
return false
},
UpdateFunc: func(updateEvent event.UpdateEvent) bool {
oldObject, oldOK := updateEvent.ObjectOld.(*corev1.Secret)
newObject, newOK := updateEvent.ObjectNew.(*corev1.Secret)
if !oldOK || !newOK {
return false
}
return !reflect.DeepEqual(oldObject.Data, newObject.Data) || !reflect.DeepEqual(oldObject.StringData, newObject.StringData)
GenericFunc: func(genericEvent event.GenericEvent) bool {
return false
},
})
if err != nil {
return err
}

// Watch for changes to ConfigMap
err = c.Watch(&source.Kind{Type: &corev1.ConfigMap{}}, &handler.EnqueueRequestForOwner{
configMap := unstructured.Unstructured{}
configMap.SetGroupVersionKind(corev1.SchemeGroupVersion.WithKind("ConfigMap"))
err = c.Watch(&source.Kind{Type: &configMap}, &handler.EnqueueRequestForOwner{
IsController: true, OwnerType: &appsv1alpha1.ResourceDistribution{},
}, predicate.Funcs{
CreateFunc: func(createEvent event.CreateEvent) bool {
return false
},
UpdateFunc: func(updateEvent event.UpdateEvent) bool {
oldObject, oldOK := updateEvent.ObjectOld.(*corev1.ConfigMap)
newObject, newOK := updateEvent.ObjectNew.(*corev1.ConfigMap)
if !oldOK || !newOK {
return false
}
return !reflect.DeepEqual(oldObject.Data, newObject.Data) || !reflect.DeepEqual(oldObject.BinaryData, newObject.BinaryData)
GenericFunc: func(genericEvent event.GenericEvent) bool {
return false
},
})
if err != nil {
Expand Down
15 changes: 12 additions & 3 deletions test/e2e/apps/imagelistpulljobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,20 @@ var _ = SIGDescribe("PullImages", func() {
gomega.Expect(err).NotTo(gomega.HaveOccurred())

ginkgo.By("Check imagepulljob should be cleaned")
time.Sleep(3 * time.Second)
gomega.Eventually(func() bool {
imagePullJobs, err := testerForImagePullJob.ListJobs(job.Namespace)
imagePullJobLister, err := testerForImagePullJob.ListJobs(job.Namespace)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return len(imagePullJobs.Items) > 0
}, 3*time.Second, time.Second).Should(gomega.Equal(false))
var imagePullJobs []*appsv1alpha1.ImagePullJob
for i := range imagePullJobLister.Items {
pullJob := &imagePullJobLister.Items[i]
if metav1.IsControlledBy(pullJob, job) {
imagePullJobs = append(imagePullJobs, pullJob)
}
fmt.Printf("waiting imagePullJob GC: %v", imagePullJobs)
}
return len(imagePullJobs) == 0
}, time.Minute, time.Second).Should(gomega.BeTrue())
})

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

0 comments on commit 28c0a72

Please sign in to comment.