Skip to content
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

[Fix] ResourceDistribution should watch unstructured object #1464

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading