Skip to content

Commit

Permalink
PVC cluster settings update to restart juypter hub with changes. (ope…
Browse files Browse the repository at this point in the history
…ndatahub-io#135)

* Added PVC and Cluster Settings code

Added code for PVC, Cluster Settings, and updated to the latest version of patternfly.

update pvc settings

Fixed linting error.

* Fix to restart juypter hub notebook with cluster settings changes.
  • Loading branch information
dlabaj authored Mar 10, 2022
1 parent c5f98e7 commit f34a2bb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
11 changes: 9 additions & 2 deletions backend/src/routes/api/cluster-settings/clusterSettingsUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { FastifyRequest } from 'fastify';
import { scaleDeploymentConfig } from '../../../utils/deployment';
import { KubeFastifyInstance, ClusterSettings } from '../../../types';

const name = 'jupyterhub-cfg';

export const updateClusterSettings = async (
fastify: KubeFastifyInstance,
request: FastifyRequest,
Expand All @@ -9,9 +12,10 @@ export const updateClusterSettings = async (
const namespace = fastify.kube.namespace;
const query = request.query as { [key: string]: string };
try {
const jupyterhubCM = await coreV1Api.readNamespacedConfigMap(name, namespace);
if (query.pvcSize) {
await coreV1Api.patchNamespacedConfigMap(
'jupyterhub-cfg',
name,
namespace,
{
data: { singleuser_pvc_size: `${query.pvcSize}Gi` },
Expand All @@ -26,6 +30,9 @@ export const updateClusterSettings = async (
},
},
);
if (jupyterhubCM.body.data.singleuser_pvc_size.replace('Gi', '') !== query.pvcSize) {
await scaleDeploymentConfig(fastify, 'jupyterhub', 0);
}
}
return { success: true, error: null };
} catch (e) {
Expand All @@ -42,7 +49,7 @@ export const getClusterSettings = async (
const coreV1Api = fastify.kube.coreV1Api;
const namespace = fastify.kube.namespace;
try {
const clusterSettingsRes = await coreV1Api.readNamespacedConfigMap('jupyterhub-cfg', namespace);
const clusterSettingsRes = await coreV1Api.readNamespacedConfigMap(name, namespace);
return {
pvcSize: Number(clusterSettingsRes.body.data.singleuser_pvc_size.replace('Gi', '')),
};
Expand Down
4 changes: 4 additions & 0 deletions backend/src/routes/api/status/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ type groupObjResponse = {
users: string[];
};

type groupObjResponse = {
users: string[];
};

const status = async (
fastify: KubeFastifyInstance,
request: FastifyRequest,
Expand Down
36 changes: 36 additions & 0 deletions backend/src/utils/deployment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { KubeFastifyInstance } from '../types';

export const scaleDeploymentConfig = async (
fastify: KubeFastifyInstance,
name: string,
replicas: number,
): Promise<void> => {
const customObjectsApi = fastify.kube.customObjectsApi;
const group = 'apps.openshift.io';
const version = 'v1';
const plural = 'deploymentconfigs';
const namespace = fastify.kube.namespace;
try {
const res = await customObjectsApi.getNamespacedCustomObject(
group,
version,
namespace,
plural,
name,
);
const deployment: any = res.body;

deployment.spec.replicas = replicas;

await customObjectsApi.replaceNamespacedCustomObject(
group,
version,
namespace,
plural,
name,
deployment,
);
} catch (e) {
throw new Error('Error scale the deployment pods: ' + e.message);
}
};

0 comments on commit f34a2bb

Please sign in to comment.