MCPcopy Create free account
hub / github.com/devfile/devworkspace-operator / CheckPodEvents

Function CheckPodEvents

pkg/library/status/check.go:141–181  ·  view source on GitHub ↗
(pod *corev1.Pod, workspaceID string, ignoredEvents []string, clusterAPI sync.ClusterAPI)

Source from the content-addressed store, hash-verified

139}
140
141func CheckPodEvents(pod *corev1.Pod, workspaceID string, ignoredEvents []string, clusterAPI sync.ClusterAPI) (msg string, err error) {
142 evs := &corev1.EventList{}
143 selector, err := fields.ParseSelector(fmt.Sprintf("involvedObject.name=%s", pod.Name))
144 if err != nil {
145 return "", fmt.Errorf("failed to parse field selector: %s", err)
146 }
147 if err := clusterAPI.Client.List(clusterAPI.Ctx, evs, k8sclient.InNamespace(pod.Namespace), k8sclient.MatchingFieldsSelector{Selector: selector}); err != nil {
148 return "", fmt.Errorf("failed to list events in namespace %s: %w", pod.Namespace, err)
149 }
150 for _, ev := range evs.Items {
151 if ev.InvolvedObject.Kind != "Pod" {
152 continue
153 }
154
155 // On OpenShift, it's possible see "FailedMount" events when using a routingClass that depends on the service-ca
156 // operator. To avoid this, we always ignore FailedMount events if the message refers to the DWO-provisioned volume
157 if infrastructure.IsOpenShift() &&
158 ev.Reason == "FailedMount" &&
159 strings.Contains(ev.Message, common.ServingCertVolumeName(common.ServiceName(workspaceID))) {
160 continue
161 }
162
163 if maxCount, isUnrecoverableEvent := unrecoverablePodEventReasons[ev.Reason]; isUnrecoverableEvent {
164 if !checkIfUnrecoverableEventIgnored(ev.Reason, ignoredEvents) && getEventCount(ev) >= maxCount {
165 var msg string
166 eventMessage := ev.Message // Original Kubelet message from the event
167 if ev.Reason == "FailedPostStartHook" {
168 eventMessage = getConcisePostStartFailureMessage(ev.Message)
169 }
170
171 if getEventCount(ev) > 1 {
172 msg = fmt.Sprintf("Detected unrecoverable event %s %d times: %s", ev.Reason, getEventCount(ev), eventMessage)
173 } else {
174 msg = fmt.Sprintf("Detected unrecoverable event %s: %s", ev.Reason, eventMessage)
175 }
176 return msg, nil
177 }
178 }
179 }
180 return "", nil
181}
182
183// getConcisePostStartFailureMessage tries to parse the Kubelet's verbose message
184// for a PostStartHookError into a more user-friendly one.

Callers 1

CheckPodsStateFunction · 0.85

Calls 6

IsOpenShiftFunction · 0.92
ServingCertVolumeNameFunction · 0.92
ServiceNameFunction · 0.92
getEventCountFunction · 0.85

Tested by

no test coverage detected