-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
display stateful set errors when notebook pod fails to create
- Loading branch information
1 parent
dfb659f
commit 38ff7a6
Showing
11 changed files
with
167 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
import { k8sListResource } from '@openshift/dynamic-plugin-sdk-utils'; | ||
import { k8sListResourceItems } from '@openshift/dynamic-plugin-sdk-utils'; | ||
import { EventKind } from '~/k8sTypes'; | ||
import { EventModel } from '~/api/models'; | ||
|
||
export const getNotebookEvents = async (namespace: string, podUid: string): Promise<EventKind[]> => | ||
k8sListResource<EventKind>({ | ||
export const getNotebookEvents = async ( | ||
namespace: string, | ||
notebookName: string, | ||
podUid: string | undefined, | ||
): Promise<EventKind[]> => | ||
k8sListResourceItems<EventKind>({ | ||
model: EventModel, | ||
queryOptions: { | ||
ns: namespace, | ||
queryParams: { | ||
fieldSelector: `involvedObject.kind=Pod,involvedObject.uid=${podUid}`, | ||
fieldSelector: podUid | ||
? `involvedObject.kind=Pod,involvedObject.uid=${podUid}` | ||
: `involvedObject.kind=StatefulSet,involvedObject.name=${notebookName}`, | ||
}, | ||
}, | ||
}).then( | ||
// Filter the events by pods that have the same name as the notebook | ||
(r) => r.items, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 42 additions & 28 deletions
70
frontend/src/pages/projects/notebook/useWatchNotebookEvents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,61 @@ | ||
import * as React from 'react'; | ||
import { EventKind } from '~/k8sTypes'; | ||
import { EventKind, NotebookKind } from '~/k8sTypes'; | ||
import { getNotebookEvents } from '~/api'; | ||
import { FAST_POLL_INTERVAL } from '~/utilities/const'; | ||
|
||
export const useWatchNotebookEvents = ( | ||
projectName: string, | ||
notebook: NotebookKind, | ||
podUid: string, | ||
activeFetch: boolean, | ||
): EventKind[] => { | ||
const [notebookEvents, setNoteBookEvents] = React.useState<EventKind[]>([]); | ||
const notebookName = notebook.metadata.name; | ||
const namespace = notebook.metadata.namespace; | ||
const [notebookEvents, setNotebookEvents] = React.useState<EventKind[]>([]); | ||
|
||
// Cached events are returned when activeFetch is false. | ||
// This allows us to reset notebookEvents state when activeFetch becomes | ||
// false to prevent UI blips when activeFetch goes true again. | ||
const notebookEventsCache = React.useRef<EventKind[]>(notebookEvents); | ||
|
||
// when activeFetch switches to false, reset events state | ||
React.useEffect(() => { | ||
if (!activeFetch) { | ||
setNotebookEvents([]); | ||
} | ||
}, [activeFetch]); | ||
|
||
React.useEffect(() => { | ||
let watchHandle: ReturnType<typeof setTimeout>; | ||
let cancelled = false; | ||
|
||
const clear = () => { | ||
cancelled = true; | ||
clearTimeout(watchHandle); | ||
}; | ||
|
||
if (activeFetch) { | ||
if (activeFetch && namespace && notebookName) { | ||
const watchNotebookEvents = () => { | ||
if (projectName && podUid) { | ||
getNotebookEvents(projectName, podUid) | ||
.then((data: EventKind[]) => { | ||
if (cancelled) { | ||
return; | ||
} | ||
setNoteBookEvents(data); | ||
}) | ||
.catch((e) => { | ||
/* eslint-disable-next-line no-console */ | ||
console.error('Error fetching notebook events', e); | ||
clear(); | ||
}); | ||
watchHandle = setTimeout(watchNotebookEvents, FAST_POLL_INTERVAL); | ||
} | ||
getNotebookEvents(namespace, notebookName, podUid) | ||
.then((data: EventKind[]) => { | ||
if (!cancelled) { | ||
notebookEventsCache.current = data; | ||
setNotebookEvents(data); | ||
} | ||
}) | ||
.catch((e) => { | ||
/* eslint-disable-next-line no-console */ | ||
console.error('Error fetching notebook events', e); | ||
}); | ||
watchHandle = setTimeout(watchNotebookEvents, FAST_POLL_INTERVAL); | ||
}; | ||
|
||
watchNotebookEvents(); | ||
if (!podUid) { | ||
// delay the initial fetch to avoid older StatefulSet event errors from blipping on screen during notebook startup | ||
watchHandle = setTimeout(watchNotebookEvents, Math.max(FAST_POLL_INTERVAL, 3000)); | ||
} else { | ||
watchNotebookEvents(); | ||
} | ||
} | ||
return clear; | ||
}, [projectName, podUid, activeFetch]); | ||
return () => { | ||
cancelled = true; | ||
clearTimeout(watchHandle); | ||
}; | ||
}, [namespace, notebookName, podUid, activeFetch]); | ||
|
||
return notebookEvents; | ||
return activeFetch ? notebookEvents : notebookEventsCache.current; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import axios from 'axios'; | ||
import { K8sEvent } from '~/types'; | ||
|
||
export const getNotebookEvents = (projectName: string, podUID: string): Promise<K8sEvent[]> => { | ||
const url = `/api/nb-events/${projectName}/${podUID}`; | ||
export const getNotebookEvents = ( | ||
projectName: string, | ||
notebookName: string, | ||
podUID?: string, | ||
): Promise<K8sEvent[]> => { | ||
const url = `/api/nb-events/${projectName}/${notebookName}${podUID ? `/${podUID}` : ''}`; | ||
return axios.get(url).then((response) => response.data); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.