@@ -26,7 +26,7 @@ import (
2626 log "github.com/sirupsen/logrus"
2727 appsv1 "k8s.io/api/apps/v1"
2828 v1 "k8s.io/api/core/v1"
29- policy "k8s.io/api/policy/v1beta1 "
29+ policy "k8s.io/api/policy/v1 "
3030 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131 "k8s.io/apimachinery/pkg/labels"
3232 "k8s.io/apimachinery/pkg/runtime"
@@ -69,9 +69,16 @@ func NewHandler(appContext *utils.AppContext) *Handler {
6969
7070// Run starts an eviction loop
7171func (h * Handler ) Run () error {
72+ // start measuring the loop duration
7273 loopTimer := prometheus .NewTimer (prometheus .ObserverFunc (func (v float64 ) {
7374 metrics .ShredderLoopsDurationSeconds .Observe (v * 10e6 )
7475 }))
76+
77+ // reset gauge metrics
78+ metrics .ShredderNodeForceToEvictTime .Reset ()
79+ metrics .ShredderPodForceToEvictTime .Reset ()
80+ metrics .ShredderPodErrorsTotal .Reset ()
81+
7582 h .logger .Infof ("Starting eviction loop" )
7683
7784 // sync all nodes goroutines
@@ -208,7 +215,14 @@ func (h *Handler) processNode(node v1.Node, rr chan *controllerObject) error {
208215 h .logger .WithFields (log.Fields {
209216 "namespace" : pod .Namespace ,
210217 "pod" : pod .Name ,
211- }).Warnf ("Failed to get pod controller object: %s" , err .Error ())
218+ }).Warnf ("Failed to get pod controller object: %s. Proceeding directly with pod eviction" , err .Error ())
219+ err := h .evictPod (pod , deleteOptions )
220+ if err != nil {
221+ h .logger .WithFields (log.Fields {
222+ "namespace" : pod .Namespace ,
223+ "pod" : pod .Name ,
224+ }).Warnf ("Failed to evict pod: %s" , err .Error ())
225+ }
212226 continue
213227 }
214228
@@ -296,8 +310,7 @@ func (h *Handler) GetPodsForNode(node v1.Node) ([]v1.Pod, error) {
296310// evictPod evict a pod using the eviction API
297311func (h * Handler ) evictPod (pod v1.Pod , deleteOptions * metav1.DeleteOptions ) error {
298312 h .logger .Infof ("Evicting pod %s from %s namespace" , pod .Name , pod .Namespace )
299- // TODO switch to stable V1 API version once we switch to k8s 1.22
300- err := h .appContext .K8sClient .PolicyV1beta1 ().Evictions (pod .Namespace ).Evict (h .appContext .Context , & policy.Eviction {
313+ err := h .appContext .K8sClient .PolicyV1 ().Evictions (pod .Namespace ).Evict (h .appContext .Context , & policy.Eviction {
301314 ObjectMeta : metav1.ObjectMeta {
302315 Name : pod .Name ,
303316 Namespace : pod .Namespace ,
@@ -367,9 +380,9 @@ func (h *Handler) getControllerObject(pod v1.Pod) (*controllerObject, error) {
367380 return co , err
368381 }
369382 return newControllerObject ("StatefulSet" , sts .Name , sts .Namespace , sts ), nil
383+ default :
384+ return co , errors .Errorf ("Controller object of type %s is not a standard controller" , pod .OwnerReferences [0 ].Kind )
370385 }
371-
372- return co , errors .Errorf ("could not find controller object for type %s\n " , pod .OwnerReferences [0 ].Kind )
373386}
374387
375388func (h * Handler ) isRolloutRestartInProgress (co * controllerObject ) (bool , error ) {
0 commit comments