Pod analyzes the pod for potential problems
(client kubectl.Client, pod *v1.Pod, ignoreContainerRestarts bool)
| 133 | |
| 134 | // Pod analyzes the pod for potential problems |
| 135 | func checkPod(client kubectl.Client, pod *v1.Pod, ignoreContainerRestarts bool) *podProblem { |
| 136 | hasProblem := false |
| 137 | podProblem := &podProblem{ |
| 138 | Name: pod.Name, |
| 139 | Status: kubectl.GetPodStatus(pod), |
| 140 | Age: time.Since(pod.CreationTimestamp.Time).Round(time.Second).String(), |
| 141 | ContainerProblems: []*containerProblem{}, |
| 142 | InitContainerProblems: []*containerProblem{}, |
| 143 | } |
| 144 | |
| 145 | // Check for unusual status |
| 146 | if _, ok := kubectl.OkayStatus[podProblem.Status]; !ok { |
| 147 | if !strings.HasPrefix(podProblem.Status, "Init") { |
| 148 | hasProblem = true |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // Analyze container status |
| 153 | if pod.Status.ContainerStatuses != nil { |
| 154 | podProblem.ContainerTotal = len(pod.Status.ContainerStatuses) |
| 155 | |
| 156 | for _, containerStatus := range pod.Status.ContainerStatuses { |
| 157 | containerProblem := getContainerProblem(client, pod, &containerStatus, ignoreContainerRestarts) |
| 158 | if containerProblem != nil { |
| 159 | hasProblem = true |
| 160 | |
| 161 | podProblem.ContainerProblems = append(podProblem.ContainerProblems, containerProblem) |
| 162 | } |
| 163 | |
| 164 | if containerStatus.Ready { |
| 165 | podProblem.ContainerReady++ |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | // Analyze init container status |
| 171 | if pod.Status.InitContainerStatuses != nil { |
| 172 | podProblem.InitContainerTotal = len(pod.Status.ContainerStatuses) |
| 173 | |
| 174 | for _, containerStatus := range pod.Status.InitContainerStatuses { |
| 175 | containerProblem := getContainerProblem(client, pod, &containerStatus, ignoreContainerRestarts) |
| 176 | if containerProblem != nil { |
| 177 | hasProblem = true |
| 178 | |
| 179 | podProblem.InitContainerProblems = append(podProblem.InitContainerProblems, containerProblem) |
| 180 | } |
| 181 | |
| 182 | if containerStatus.Ready { |
| 183 | podProblem.InitContainerReady++ |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | if hasProblem { |
| 189 | return podProblem |
| 190 | } |
| 191 | |
| 192 | return nil |
no test coverage detected