Skip to content

Commit

Permalink
[UPSTREAM]: Add culler timeout feature and save button
Browse files Browse the repository at this point in the history
  • Loading branch information
DaoDaoNoCode authored and Chad Roberts committed Apr 14, 2022
1 parent cf6e7d6 commit b12ff21
Show file tree
Hide file tree
Showing 9 changed files with 331 additions and 156 deletions.
20 changes: 12 additions & 8 deletions backend/src/routes/api/cluster-settings/clusterSettingsUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FastifyRequest } from 'fastify';
import { scaleDeploymentConfig } from '../../../utils/deployment';
import { rolloutDeployment } from '../../../utils/deployment';
import { KubeFastifyInstance, ClusterSettings } from '../../../types';

const juypterhubCfg = 'jupyterhub-cfg';
Expand Down Expand Up @@ -32,12 +32,18 @@ export const updateClusterSettings = async (
);
}
const jupyterhubCM = await coreV1Api.readNamespacedConfigMap(juypterhubCfg, namespace);
if (query.pvcSize) {
if (query.pvcSize && query.cullerTimeout) {
if (jupyterhubCM.body.data.singleuser_pvc_size.replace('Gi', '') !== query.pvcSize) {
await rolloutDeployment(fastify, namespace, 'jupyterhub');
}
if (jupyterhubCM.body.data['culler_timeout'] !== query.cullerTimeout) {
await rolloutDeployment(fastify, namespace, 'jupyterhub-idle-culler');
}
await coreV1Api.patchNamespacedConfigMap(
juypterhubCfg,
namespace,
{
data: { singleuser_pvc_size: `${query.pvcSize}Gi` },
data: { singleuser_pvc_size: `${query.pvcSize}Gi`, culler_timeout: query.cullerTimeout },
},
undefined,
undefined,
Expand All @@ -49,9 +55,6 @@ 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 @@ -69,10 +72,11 @@ export const getClusterSettings = async (
const namespace = fastify.kube.namespace;
try {
const segmentEnabledRes = await coreV1Api.readNamespacedConfigMap(segmentKeyCfg, namespace);
const pvcResponse = await coreV1Api.readNamespacedConfigMap(juypterhubCfg, namespace);
const jupyterhubCfgResponse = await coreV1Api.readNamespacedConfigMap(juypterhubCfg, namespace);

return {
pvcSize: Number(pvcResponse.body.data.singleuser_pvc_size.replace('Gi', '')),
pvcSize: Number(jupyterhubCfgResponse.body.data.singleuser_pvc_size.replace('Gi', '')),
cullerTimeout: Number(jupyterhubCfgResponse.body.data.culler_timeout),
userTrackingEnabled: segmentEnabledRes.body.data.segmentKeyEnabled === 'true',
};
} catch (e) {
Expand Down
3 changes: 2 additions & 1 deletion backend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export type DashboardConfig = {

export type ClusterSettings = {
pvcSize: number;
userTrackingEnabled: boolean
cullerTimeout: number;
userTrackingEnabled: boolean;
}

// Add a minimal QuickStart type here as there is no way to get types without pulling in frontend (React) modules
Expand Down
36 changes: 12 additions & 24 deletions backend/src/utils/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,24 @@
import { KubeFastifyInstance } from '../types';

export const scaleDeploymentConfig = async (
export const rolloutDeployment = async (
fastify: KubeFastifyInstance,
namespace: string,
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;
const plural = `deploymentconfigs/${name}/instantiate`;
const body = {
kind: 'DeploymentRequest',
apiVersion: 'apps.openshift.io/v1',
name,
latest: true,
force: true,
};
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,
);
await customObjectsApi.createNamespacedCustomObject(group, version, namespace, plural, body);
} catch (e) {
throw new Error('Error scale the deployment pods: ' + e.message);
throw new Error('Error rollout the deployment: ' + e.message);
}
};
32 changes: 30 additions & 2 deletions frontend/src/pages/clusterSettings/ClusterSettings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,46 @@
border: var(--pf-global--BorderWidth--sm) solid var(--pf-global--BorderColor--100);
padding: var(--pf-global--spacer--md);
margin: 0;
&.pf-m-action {
border: none;
padding: 0;
}
}

.odh-number-input {
.odh-number-input {
max-width: 100px;
}

.pf-c-input-group {
padding-top: var(--pf-global--spacer--md);
padding-bottom: var(--pf-global--spacer--md);
&__text {
font-size: var(--pf-global--FontSize--sm);
color: var(--pf-global--Color--100);
}
}
.pf-c-helper-text {
margin-top: var(--pf-global--spacer--sm);
}
.pf-c-radio {
margin: var(--pf-global--spacer--sm) 0;
padding-left: var(--pf-global--spacer--sm);
&__label {
font-size: var(--pf-global--FontSize--sm);
}
}

&__form {
margin: 0 var(--pf-global--spacer--lg);
}
&__culler-input-group {
&.pf-c-input-group {
padding: var(--pf-global--spacer--xs) var(--pf-global--spacer--lg) 0;
}
.odh-number-input {
max-width: 40px;
&__hour {
max-width: 60px;
}
}
}
}
Loading

0 comments on commit b12ff21

Please sign in to comment.