@@ -15,6 +15,7 @@ import (
1515 "github.com/pubg/kube-image-deployer/remoteRegistry/docker"
1616 "github.com/pubg/kube-image-deployer/watcher"
1717 appV1 "k8s.io/api/apps/v1"
18+ batchV1 "k8s.io/api/batch/v1"
1819 batchV1beta1 "k8s.io/api/batch/v1beta1"
1920 metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2021 "k8s.io/apimachinery/pkg/types"
3132 offStatefulsets = * flag .Bool ("off-statefulsets" , false , "disable statefulsets" )
3233 offDaemonsets = * flag .Bool ("off-daemonsets" , false , "disable daemonsets" )
3334 offCronjobs = * flag .Bool ("off-cronjobs" , false , "disable cronjobs" )
35+ useCronJobV1 = * flag .Bool ("use-cronjob-v1" , false , "use cronjob version v1 instead of v1beta1" )
3436 imageStringCacheTTLSec = * flag .Uint ("image-hash-cache-ttl-sec" , 60 , "image hash cache TTL in seconds" )
3537 imageCheckIntervalSec = * flag .Uint ("image-check-interval-sec" , 10 , "image check interval in seconds" )
3638 controllerWatchKey = * flag .String ("controller-watch-key" , "kube-image-deployer" , "controller watch key" )
@@ -68,6 +70,9 @@ func init() {
6870 if os .Getenv ("OFF_CRONJOBS" ) != "" {
6971 offCronjobs = true
7072 }
73+ if os .Getenv ("USE_CRONJOB_V1" ) != "" {
74+ useCronJobV1 = true
75+ }
7176 if os .Getenv ("IMAGE_HASH_CACHE_TTL_SEC" ) != "" {
7277 if v , err := strconv .ParseUint (os .Getenv ("IMAGE_HASH_CACHE_TTL_SEC" ), 10 , 32 ); err == nil {
7378 imageStringCacheTTLSec = uint (v )
@@ -100,6 +105,7 @@ func init() {
100105 "offStatefulsets" : offStatefulsets ,
101106 "offDaemonsets" : offDaemonsets ,
102107 "offCronjobs" : offCronjobs ,
108+ "useCronJobV1" : useCronJobV1 ,
103109 "imageStringCacheTTLSec" : imageStringCacheTTLSec ,
104110 "imageCheckIntervalSec" : imageCheckIntervalSec ,
105111 "controllerWatchKey" : controllerWatchKey ,
@@ -181,11 +187,19 @@ func runWatchers(stopCh chan struct{}) {
181187 }
182188
183189 if ! offCronjobs { // cronjobs watcher
184- applyStrategicMergePatch := func (namespace string , name string , data []byte ) error {
185- _ , err := clientset .BatchV1beta1 ().CronJobs (namespace ).Patch (context .TODO (), name , types .StrategicMergePatchType , data , metaV1.PatchOptions {})
186- return err
190+ if useCronJobV1 {
191+ applyStrategicMergePatch := func (namespace string , name string , data []byte ) error {
192+ _ , err := clientset .BatchV1 ().CronJobs (namespace ).Patch (context .TODO (), name , types .StrategicMergePatchType , data , metaV1.PatchOptions {})
193+ return err
194+ }
195+ go watcher .NewWatcher ("cronjobs" , stopCh , logger , cache .NewFilteredListWatchFromClient (clientset .BatchV1 ().RESTClient (), "cronjobs" , controllerWatchNamespace , optionsModifier ), & batchV1.CronJob {}, imageNotifier , controllerWatchKey , applyStrategicMergePatch )
196+ } else {
197+ applyStrategicMergePatch := func (namespace string , name string , data []byte ) error {
198+ _ , err := clientset .BatchV1beta1 ().CronJobs (namespace ).Patch (context .TODO (), name , types .StrategicMergePatchType , data , metaV1.PatchOptions {})
199+ return err
200+ }
201+ go watcher .NewWatcher ("cronjobs" , stopCh , logger , cache .NewFilteredListWatchFromClient (clientset .BatchV1beta1 ().RESTClient (), "cronjobs" , controllerWatchNamespace , optionsModifier ), & batchV1beta1.CronJob {}, imageNotifier , controllerWatchKey , applyStrategicMergePatch )
187202 }
188- go watcher .NewWatcher ("cronjobs" , stopCh , logger , cache .NewFilteredListWatchFromClient (clientset .BatchV1beta1 ().RESTClient (), "cronjobs" , controllerWatchNamespace , optionsModifier ), & batchV1beta1.CronJob {}, imageNotifier , controllerWatchKey , applyStrategicMergePatch )
189203 }
190204}
191205
0 commit comments