| 40 | var previousListOfEvictedPods = strset.New() |
| 41 | |
| 42 | func DeleteEvictedPods() error { |
| 43 | failedPods, err := config.K8s.ListPods(&kmeta.ListOptions{ |
| 44 | FieldSelector: "status.phase=Failed", |
| 45 | }) |
| 46 | if err != nil { |
| 47 | return err |
| 48 | } |
| 49 | |
| 50 | var errs []error |
| 51 | currentEvictedPods := strset.New() |
| 52 | for _, pod := range failedPods { |
| 53 | if pod.Status.Reason != k8s.ReasonEvicted { |
| 54 | continue |
| 55 | } |
| 56 | if previousListOfEvictedPods.Has(pod.Name) { |
| 57 | _, err := config.K8s.DeletePod(pod.Name) |
| 58 | if err != nil { |
| 59 | errs = append(errs, err) |
| 60 | } |
| 61 | continue |
| 62 | } |
| 63 | currentEvictedPods.Add(pod.Name) |
| 64 | } |
| 65 | previousListOfEvictedPods = currentEvictedPods |
| 66 | |
| 67 | if errors.HasError(errs) { |
| 68 | return errors.FirstError(errs...) |
| 69 | } |
| 70 | return nil |
| 71 | } |
| 72 | |
| 73 | type instanceInfo struct { |
| 74 | InstanceType string `json:"instance_type" yaml:"instance_type"` |