Skip to content

Commit

Permalink
Merge pull request #328 from opendatahub-io/v2.22.0-fixes
Browse files Browse the repository at this point in the history
V2.22.0 fixes
  • Loading branch information
riprasad authored Apr 29, 2024
2 parents 883c004 + bc33d07 commit 709fbd3
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 130 deletions.
4 changes: 2 additions & 2 deletions backend/src/routes/api/notebooks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export const enableNotebook = async (
const url = request.headers.origin;

try {
await getNotebook(fastify, notebookNamespace, name);
return await updateNotebook(fastify, username, url, notebookData);
const notebook = await getNotebook(fastify, notebookNamespace, name);
return await updateNotebook(fastify, username, url, notebookData, notebook);
} catch (e) {
if (e.response?.statusCode === 404) {
return await createNotebook(fastify, username, url, notebookData);
Expand Down
26 changes: 25 additions & 1 deletion backend/src/utils/notebookUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getDashboardConfig } from './resourceUtils';
import { merge } from 'lodash';
import {
ContainerResourceAttributes,
EnvironmentVariable,
Expand Down Expand Up @@ -510,6 +511,7 @@ export const updateNotebook = async (
username: string,
url: string,
notebookData: NotebookData,
oldNotebook: Notebook,
): Promise<Notebook> => {
if (!notebookData) {
const error = createCustomError(
Expand All @@ -521,7 +523,29 @@ export const updateNotebook = async (
throw error;
}
try {
const notebookAssembled = await generateNotebookResources(fastify, username, url, notebookData);
const serverNotebook = await generateNotebookResources(fastify, username, url, notebookData);

// Fix for Workbench Certs that get overridden
// We are intentionally applying on some details as to avoid implementing logic to properly
// manage the notebook the same way as workbench
const importantOldNotebookDetails: RecursivePartial<Notebook> = {
spec: {
template: {
spec: {
containers: [
{
env: oldNotebook.spec.template.spec.containers[0].env,
volumeMounts: oldNotebook.spec.template.spec.containers[0].volumeMounts,
},
],
volumes: oldNotebook.spec.template.spec.volumes,
},
},
},
};

const notebookAssembled = merge({}, importantOldNotebookDetails, serverNotebook);

const response = await fastify.kube.customObjectsApi.patchNamespacedCustomObject(
'kubeflow.org',
'v1',
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/__mocks__/mockDWUsageByOwnerPrometheusResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { WorkloadMetricIndexedByOwner, WorkloadMetricPromQueryResponse } from '~/api';
import { WorkloadOwnerType } from '~/k8sTypes';
import { mockPrometheusQueryVectorResponse } from './mockPrometheusQueryVectorResponse';

export const mockDWUsageByOwnerPrometheusResponse = (
usageByOwner: WorkloadMetricIndexedByOwner,
): WorkloadMetricPromQueryResponse =>
mockPrometheusQueryVectorResponse({
result: Object.values(WorkloadOwnerType).flatMap((ownerKind) =>
Object.keys(usageByOwner[ownerKind]).map((ownerName) => ({
// eslint-disable-next-line camelcase
metric: { owner_kind: ownerKind, owner_name: ownerName },
value: [0, String(usageByOwner[ownerKind][ownerName])],
})),
),
});
16 changes: 9 additions & 7 deletions frontend/src/__mocks__/mockWorkloadK8sResource.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { genUID } from '~/__mocks__/mockUtils';
import { WorkloadStatusType } from '~/concepts/distributedWorkloads/utils';
import { WorkloadCondition, WorkloadKind, WorkloadPodSet } from '~/k8sTypes';
import { WorkloadCondition, WorkloadKind, WorkloadOwnerType, WorkloadPodSet } from '~/k8sTypes';

const mockWorkloadStatusConditions: Record<WorkloadStatusType, WorkloadCondition[]> = {
Pending: [
Expand Down Expand Up @@ -127,14 +127,16 @@ const mockWorkloadStatusConditions: Record<WorkloadStatusType, WorkloadCondition
type MockResourceConfigType = {
k8sName?: string;
namespace?: string;
ownerJobName?: string;
ownerKind?: WorkloadOwnerType;
ownerName?: string;
mockStatus?: WorkloadStatusType | null;
podSets?: WorkloadPodSet[];
};
export const mockWorkloadK8sResource = ({
k8sName = 'test-workload',
namespace = 'test-project',
ownerJobName,
ownerKind = WorkloadOwnerType.Job,
ownerName,
mockStatus = WorkloadStatusType.Succeeded,
podSets = [],
}: MockResourceConfigType): WorkloadKind => ({
Expand All @@ -150,16 +152,16 @@ export const mockWorkloadK8sResource = ({
namespace,
resourceVersion: '9279356',
uid: genUID('workload'),
...(ownerJobName
...(ownerName
? {
ownerReferences: [
{
apiVersion: 'batch/v1',
blockOwnerDeletion: true,
controller: true,
kind: 'Job',
name: ownerJobName,
uid: genUID('job'),
kind: ownerKind,
name: ownerName,
uid: genUID(ownerKind.toLowerCase()),
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { mockK8sResourceList } from '~/__mocks__/mockK8sResourceList';
import { mockProjectK8sResource } from '~/__mocks__/mockProjectK8sResource';
import { mockPrometheusQueryVectorResponse } from '~/__mocks__/mockPrometheusQueryVectorResponse';
import { mockWorkloadK8sResource } from '~/__mocks__/mockWorkloadK8sResource';
import { ClusterQueueKind, LocalQueueKind, WorkloadKind } from '~/k8sTypes';
import { ClusterQueueKind, LocalQueueKind, WorkloadKind, WorkloadOwnerType } from '~/k8sTypes';
import { WorkloadStatusType } from '~/concepts/distributedWorkloads/utils';
import { mockClusterQueueK8sResource } from '~/__mocks__/mockClusterQueueK8sResource';
import { mockLocalQueueK8sResource } from '~/__mocks__/mockLocalQueueK8sResource';
Expand Down Expand Up @@ -35,9 +35,16 @@ const initIntercepts = ({
mockLocalQueueK8sResource({ name: 'test-local-queue', namespace: 'test-project' }),
],
workloads = [
mockWorkloadK8sResource({ k8sName: 'test-workload', mockStatus: WorkloadStatusType.Succeeded }),
mockWorkloadK8sResource({
k8sName: 'test-workload',
ownerKind: WorkloadOwnerType.Job,
ownerName: 'test-workload-job',
mockStatus: WorkloadStatusType.Succeeded,
}),
mockWorkloadK8sResource({
k8sName: 'test-workload-2',
ownerKind: WorkloadOwnerType.RayCluster,
ownerName: 'test-workload-2-rc',
mockStatus: WorkloadStatusType.Succeeded,
}),
],
Expand Down
Loading

0 comments on commit 709fbd3

Please sign in to comment.