Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix User Data Collection checkbox #404

Merged
merged 4 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 22 additions & 15 deletions backend/src/routes/api/cluster-settings/clusterSettingsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const DEFAULT_IDLENESS_CHECK_PERIOD = '1'; // 1 minute
const DEFAULT_CLUSTER_SETTINGS: ClusterSettings = {
pvcSize: DEFAULT_PVC_SIZE,
cullerTimeout: DEFAULT_CULLER_TIMEOUT,
userTrackingEnabled: null,
userTrackingEnabled: false,
};

export const updateClusterSettings = async (
andrewballantyne marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -26,11 +26,11 @@ export const updateClusterSettings = async (
const query = request.query as { [key: string]: string };
const dashConfig = getDashboardConfig();
try {
if (query.userTrackingEnabled !== 'null') {
await patchCM(fastify, segmentKeyCfg, {
data: { segmentKeyEnabled: query.userTrackingEnabled },
});
}
await patchCM(fastify, segmentKeyCfg, {
data: { segmentKeyEnabled: query.userTrackingEnabled },
}).catch((e) => {
fastify.log.error('Failed to update segment key enabled: ' + e.message);
});
if (query.pvcSize && query.cullerTimeout) {
if (dashConfig.spec?.notebookController?.enabled) {
await setDashboardConfig(fastify, {
Expand All @@ -48,13 +48,13 @@ export const updateClusterSettings = async (
isEnabled = false;
}
if (!isEnabled) {
await coreV1Api.deleteNamespacedConfigMap(nbcCfg, fastify.kube.namespace);
await coreV1Api.deleteNamespacedConfigMap(nbcCfg, fastify.kube.namespace).catch((e) => {
fastify.log.error('Failed to delete culler config: ') + e.message;
});
} else {
try {
await patchCM(fastify, nbcCfg, {
data: { ENABLE_CULLING: String(isEnabled), CULL_IDLE_TIME: String(cullingTimeMin) },
});
} catch (e) {
await patchCM(fastify, nbcCfg, {
data: { ENABLE_CULLING: String(isEnabled), CULL_IDLE_TIME: String(cullingTimeMin) },
}).catch(async (e) => {
if (e.statusCode === 404) {
const cm: V1ConfigMap = {
apiVersion: 'v1',
Expand All @@ -69,19 +69,23 @@ export const updateClusterSettings = async (
},
};
await fastify.kube.coreV1Api.createNamespacedConfigMap(fastify.kube.namespace, cm);
} else {
fastify.log.error('Failed to patch culler config: ' + e.message);
}
}
});
}
} else {
patchCM(fastify, jupyterhubCfg, {
data: {
singleuser_pvc_size: `${query.pvcSize}Gi`,
culler_timeout: query.cullerTimeout,
},
}).catch((e) => {
fastify.log.error('Unable to patch JupyterHub config' + e.message);
});
}
}
if (dashConfig.spec.notebookController.enabled) {
if (dashConfig.spec.notebookController?.enabled) {
await rolloutDeployment(fastify, namespace, 'notebook-controller-deployment');
} else {
const jupyterhubCM = await coreV1Api.readNamespacedConfigMap(jupyterhubCfg, namespace);
Expand All @@ -94,10 +98,13 @@ export const updateClusterSettings = async (
}
return { success: true, error: null };
} catch (e) {
fastify.log.error(
'Setting cluster settings error: ' + e.toString() + e.response?.body?.message,
);
if (e.response?.statusCode !== 404) {
fastify.log.error('Setting cluster settings error: ' + e.toString() + e.respose.body.message);
return { success: false, error: 'Unable to update cluster settings. ' + e.message };
}
throw e;
}
};

Expand Down
2 changes: 1 addition & 1 deletion backend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export type NotebookSize = {
export type ClusterSettings = {
pvcSize: number;
cullerTimeout: number;
userTrackingEnabled: boolean | null;
userTrackingEnabled: boolean;
};

// Add a minimal QuickStart type here as there is no way to get types without pulling in frontend (React) modules
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/clusterSettings/ClusterSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const ClusterSettings: React.FC = () => {
const [loadError, setLoadError] = React.useState<Error>();
const [clusterSettings, setClusterSettings] = React.useState(DEFAULT_CONFIG);
const [pvcSize, setPvcSize] = React.useState<number | string>(DEFAULT_PVC_SIZE);
const [userTrackingEnabled, setUserTrackingEnabled] = React.useState<boolean | null>(null);
const [userTrackingEnabled, setUserTrackingEnabled] = React.useState<boolean>(false);
const [cullerTimeoutChecked, setCullerTimeoutChecked] =
React.useState<string>(CULLER_TIMEOUT_UNLIMITED);
const [cullerTimeout, setCullerTimeout] = React.useState<number>(DEFAULT_CULLER_TIMEOUT);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/clusterSettings/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export const DEFAULT_CULLER_TIMEOUT = 31536000; // 1 year as no culling
export const DEFAULT_CONFIG: ClusterSettings = {
pvcSize: DEFAULT_PVC_SIZE,
cullerTimeout: DEFAULT_CULLER_TIMEOUT,
userTrackingEnabled: null,
userTrackingEnabled: false,
};
2 changes: 1 addition & 1 deletion frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export type NotebookSize = {
};

export type ClusterSettings = {
userTrackingEnabled: boolean | null;
userTrackingEnabled: boolean;
pvcSize: number | string;
cullerTimeout: number;
};
Expand Down