Skip to content

Commit

Permalink
labextension: Add input field to select access mode for volumes
Browse files Browse the repository at this point in the history
Signed-off-by: Ilias Katsakioris <[email protected]>
Reviewed-by: Stefano Fioravanzo <[email protected]>
  • Loading branch information
elikatsis authored and StefanoFioravanzo committed Nov 18, 2020
1 parent 3cb1135 commit 4c39895
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
54 changes: 54 additions & 0 deletions labextension/src/components/VolumeAccessModeSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2020 The Kale Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as React from 'react';
import { Select, ISelectOption } from './Select';

const VOLUME_ACCESS_MODE_ROM: ISelectOption = {
label: 'ReadOnlyMany',
value: 'rom',
};
const VOLUME_ACCESS_MODE_RWO: ISelectOption = {
label: 'ReadWriteOnce',
value: 'rwo',
};
const VOLUME_ACCESS_MODE_RWM: ISelectOption = {
label: 'ReadWriteMany',
value: 'rwm',
};
const VOLUME_ACCESS_MODES: ISelectOption[] = [
VOLUME_ACCESS_MODE_ROM,
VOLUME_ACCESS_MODE_RWO,
VOLUME_ACCESS_MODE_RWM,
];

interface VolumeAccessModeSelectProps {
value: string;
updateValue: Function;
}

export const VolumeAccessModeSelect: React.FunctionComponent<VolumeAccessModeSelectProps> = props => {
return (
<Select
variant="standard"
label="Volume access mode"
index={-1}
values={VOLUME_ACCESS_MODES}
value={props.value}
updateValue={props.updateValue}
/>
);
};
11 changes: 11 additions & 0 deletions labextension/src/widgets/LeftPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export interface IKaleNotebookMetadata {
katib_metadata?: IKatibMetadata;
steps_defaults?: string[];
storage_class_name?: string;
volume_access_mode?: string;
}

export interface IKatibExperiment {
Expand Down Expand Up @@ -192,6 +193,7 @@ export const DefaultState: IState = {
autosnapshot: false,
katib_run: false,
steps_defaults: [],
volume_access_mode: 'rwm',
},
runDeployment: false,
deploymentType: 'compile',
Expand Down Expand Up @@ -260,6 +262,7 @@ export class KubeflowKaleLeftPanel extends React.Component<IProps, IState> {
volumes: prevState.notebookVolumes,
snapshot_volumes: !prevState.metadata.snapshot_volumes,
storage_class_name: undefined,
volume_access_mode: undefined,
},
}));
};
Expand Down Expand Up @@ -299,6 +302,12 @@ export class KubeflowKaleLeftPanel extends React.Component<IProps, IState> {
metadata: { ...prevState.metadata, storage_class_name },
}));

updateVolumeAccessMode = (volume_access_mode: string) => {
this.setState((prevState, props) => ({
metadata: { ...prevState.metadata, volume_access_mode },
}));
};

updateKatibRun = () =>
this.setState((prevState, props) => ({
metadata: {
Expand Down Expand Up @@ -811,6 +820,8 @@ export class KubeflowKaleLeftPanel extends React.Component<IProps, IState> {
updateVolumes={this.updateVolumes}
storageClassName={this.state.metadata.storage_class_name}
updateStorageClassName={this.updateStorageClassName}
volumeAccessMode={this.state.metadata.volume_access_mode}
updateVolumeAccessMode={this.updateVolumeAccessMode}
/>
);

Expand Down
10 changes: 9 additions & 1 deletion labextension/src/widgets/VolumesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Select, ISelectOption } from '../components/Select';
import { LightTooltip } from '../components/LightTooltip';
import { AnnotationInput, IAnnotation } from '../components/AnnotationInput';
import { removeIdxFromArray, updateIdxInArray } from '../lib/Utils';
import { VolumeAccessModeSelect } from '../components/VolumeAccessModeSelect';

const DEFAULT_EMPTY_VOLUME: IVolumeMetadata = {
type: 'new_pvc',
Expand Down Expand Up @@ -97,6 +98,8 @@ interface VolumesPanelProps {
updateAutosnapshotSwitch: Function;
storageClassName: string;
updateStorageClassName: Function;
volumeAccessMode: string;
updateVolumeAccessMode: Function;
}

export const VolumesPanel: React.FunctionComponent<VolumesPanelProps> = props => {
Expand Down Expand Up @@ -576,14 +579,19 @@ export const VolumesPanel: React.FunctionComponent<VolumesPanelProps> = props =>
// FIXME: There is no separating bottom horizontal bar when there are no
// volumes
const volumesClassNameAndMode = (
<div className="input-container">
<div className="input-container volume-container">
<Input
label="Storage class name"
updateValue={props.updateStorageClassName}
value={props.storageClassName}
placeholder={'default'}
variant="standard"
/>

<VolumeAccessModeSelect
value={props.volumeAccessMode}
updateValue={props.updateVolumeAccessMode}
/>
</div>
);

Expand Down

0 comments on commit 4c39895

Please sign in to comment.