(client client.Client, kubeClient kubernetes.Interface, config *rest.Config, wp *worerkpool.WorkerPool, cloudshellImage string, nodeSelector map[string]string, resources *cloudshellv1alpha1.ResourceSetting, cloudshellInformer cloudshellinformers.CloudShellInformer, podInformer informercorev1.PodInformer, )
| 91 | } |
| 92 | |
| 93 | func New(client client.Client, kubeClient kubernetes.Interface, config *rest.Config, wp *worerkpool.WorkerPool, cloudshellImage string, |
| 94 | nodeSelector map[string]string, resources *cloudshellv1alpha1.ResourceSetting, |
| 95 | cloudshellInformer cloudshellinformers.CloudShellInformer, podInformer informercorev1.PodInformer, |
| 96 | ) *Controller { |
| 97 | controller := &Controller{ |
| 98 | Client: client, |
| 99 | kubeClient: kubeClient, |
| 100 | config: config, |
| 101 | Scheme: gclient.NewSchema(), |
| 102 | workerPool: wp, |
| 103 | queue: workqueue.NewRateLimitingQueue( |
| 104 | workqueue.NewItemExponentialFailureRateLimiter(DefaultCloudShellBackOff, MaxCloudShellBackOff), |
| 105 | ), |
| 106 | |
| 107 | cloudshellInformer: cloudshellInformer.Informer(), |
| 108 | lister: cloudshellInformer.Lister(), |
| 109 | podInformer: podInformer.Informer(), |
| 110 | podLister: podInformer.Lister(), |
| 111 | cloudshellImage: cloudshellImage, |
| 112 | nodeSelector: nodeSelector, |
| 113 | resources: resources, |
| 114 | } |
| 115 | |
| 116 | _, err := cloudshellInformer.Informer().AddEventHandler( |
| 117 | cache.ResourceEventHandlerFuncs{ |
| 118 | AddFunc: func(obj interface{}) { |
| 119 | controller.enqueue(obj) |
| 120 | }, |
| 121 | UpdateFunc: func(oldObj, newObj interface{}) { |
| 122 | older := oldObj.(*cloudshellv1alpha1.CloudShell) |
| 123 | newer := newObj.(*cloudshellv1alpha1.CloudShell) |
| 124 | if !reflect.DeepEqual(older.Spec, newer.Spec) || !newer.DeletionTimestamp.IsZero() { |
| 125 | controller.enqueue(newObj) |
| 126 | } |
| 127 | }, |
| 128 | DeleteFunc: func(obj interface{}) { |
| 129 | controller.enqueue(obj) |
| 130 | }, |
| 131 | }, |
| 132 | ) |
| 133 | if err != nil { |
| 134 | klog.ErrorS(err, "error when adding event handler to informer") |
| 135 | } |
| 136 | |
| 137 | _, err = podInformer.Informer().AddEventHandler( |
| 138 | cache.ResourceEventHandlerFuncs{ |
| 139 | AddFunc: func(obj interface{}) { |
| 140 | controller.enqueueCloudshellForPod(obj) |
| 141 | }, |
| 142 | UpdateFunc: func(_, newObj interface{}) { |
| 143 | controller.enqueueCloudshellForPod(newObj) |
| 144 | }, |
| 145 | DeleteFunc: func(obj interface{}) { |
| 146 | controller.enqueueCloudshellForPod(obj) |
| 147 | }, |
| 148 | }, |
| 149 | ) |
| 150 | if err != nil { |
no test coverage detected