Skip to content
Permalink
Browse files

fix the metainternalversion.List change error

  • Loading branch information...
liucimin authored and jpbetz committed May 7, 2019
1 parent 4023816 commit 381f1da79f7af89bf93fdd7012d6a7bac9a0c287
Showing with 35 additions and 22 deletions.
  1. +1 −0 pkg/controller/cronjob/BUILD
  2. +34 −22 pkg/controller/cronjob/cronjob_controller.go
@@ -21,6 +21,7 @@ go_library(
"//staging/src/k8s.io/api/batch/v1:go_default_library",
"//staging/src/k8s.io/api/batch/v1beta1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
@@ -39,6 +39,7 @@ import (
batchv1 "k8s.io/api/batch/v1"
batchv1beta1 "k8s.io/api/batch/v1beta1"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
@@ -107,41 +108,52 @@ func (jm *CronJobController) syncAll() {
jobListFunc := func(opts metav1.ListOptions) (runtime.Object, error) {
return jm.kubeClient.BatchV1().Jobs(metav1.NamespaceAll).List(opts)
}
jlTmp, err := pager.New(pager.SimplePageFunc(jobListFunc)).List(context.Background(), metav1.ListOptions{})

js := make([]batchv1.Job, 0)
jobs, err := pager.New(pager.SimplePageFunc(jobListFunc)).List(context.Background(), metav1.ListOptions{})
if err != nil {
utilruntime.HandleError(fmt.Errorf("can't list Jobs: %v", err))
utilruntime.HandleError(fmt.Errorf("Failed to list jobs: %v", err))
return
}
jl, ok := jlTmp.(*batchv1.JobList)
if !ok {
utilruntime.HandleError(fmt.Errorf("expected type *batchv1.JobList, got type %T", jlTmp))
err = meta.EachListItem(jobs, func(object runtime.Object) error {
jobTmp, ok := object.(*batchv1.Job)
if !ok {
return fmt.Errorf("expected type *batchv1.Job, got type %T", jobTmp)
}
js = append(js, *jobTmp)
return nil
})

if err != nil {
utilruntime.HandleError(fmt.Errorf("Failed to extract job list: %v", err))
return
}
js := jl.Items
klog.V(4).Infof("Found %d jobs", len(js))

klog.V(4).Infof("Found %d jobs", len(js))
cronJobListFunc := func(opts metav1.ListOptions) (runtime.Object, error) {
return jm.kubeClient.BatchV1beta1().CronJobs(metav1.NamespaceAll).List(opts)
}
sjlTmp, err := pager.New(pager.SimplePageFunc(cronJobListFunc)).List(context.Background(), metav1.ListOptions{})
if err != nil {
utilruntime.HandleError(fmt.Errorf("can't list CronJobs: %v", err))
return
}
sjl, ok := sjlTmp.(*batchv1beta1.CronJobList)
if !ok {
utilruntime.HandleError(fmt.Errorf("expected type *batchv1beta1.CronJobList, got type %T", sjlTmp))
return
}
sjs := sjl.Items
klog.V(4).Infof("Found %d cronjobs", len(sjs))

jobsBySj := groupJobsByParent(js)
klog.V(4).Infof("Found %d groups", len(jobsBySj))
cronJobs, err := pager.New(pager.SimplePageFunc(cronJobListFunc)).List(context.Background(), metav1.ListOptions{})
if err != nil {
utilruntime.HandleError(fmt.Errorf("Failed to list cronJobs: %v", err))
return
}
err = meta.EachListItem(cronJobs, func(object runtime.Object) error {
sj, ok := object.(*batchv1beta1.CronJob)
if !ok {
return fmt.Errorf("expected type *batchv1beta1.CronJob, got type %T", sj)
}
syncOne(sj, jobsBySj[sj.UID], time.Now(), jm.jobControl, jm.sjControl, jm.recorder)
cleanupFinishedJobs(sj, jobsBySj[sj.UID], jm.jobControl, jm.sjControl, jm.recorder)
return nil
})

for _, sj := range sjs {
syncOne(&sj, jobsBySj[sj.UID], time.Now(), jm.jobControl, jm.sjControl, jm.recorder)
cleanupFinishedJobs(&sj, jobsBySj[sj.UID], jm.jobControl, jm.sjControl, jm.recorder)
if err != nil {
utilruntime.HandleError(fmt.Errorf("Failed to extract cronJobs list: %v", err))
return
}
}

0 comments on commit 381f1da

Please sign in to comment.
You can’t perform that action at this time.