Skip to content

Commit

Permalink
Added tolerations selector to Add Tenant wizard (#1747)
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
  • Loading branch information
bexsoft committed Mar 23, 2022
1 parent 842c3de commit bef3897
Show file tree
Hide file tree
Showing 7 changed files with 470 additions and 8 deletions.
17 changes: 15 additions & 2 deletions portal-ui/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,21 @@ export interface IMatchExpressionItem {
values: string[];
}

export enum ITolerationEffect {
"NoSchedule" = "NoSchedule",
"PreferNoSchedule" = "PreferNoSchedule",
"NoExecute" = "NoExecute",
}

export enum ITolerationOperator {
"Equal" = "Equal",
"Exists" = "Exists",
}

export interface ITolerationModel {
effect: string;
effect: ITolerationEffect;
key: string;
operator: string;
operator: ITolerationOperator;
value?: string;
tolerationSeconds?: ITolerationSeconds;
}
Expand Down Expand Up @@ -194,6 +205,7 @@ export interface IGCPSecretManager {
endpoint?: string;
credentials?: IGCPCredentials;
}

export interface IGCPConfig {
secretmanager: IGCPSecretManager;
}
Expand All @@ -203,6 +215,7 @@ export interface IAzureCredentials {
client_id: string;
client_secret: string;
}

export interface IAzureKeyVault {
endpoint: string;
credentials?: IAzureCredentials;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
// This file is part of MinIO Console Server
// Copyright (c) 2022 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import React from "react";
import {
ITolerationEffect,
ITolerationOperator,
} from "../../../../common/types";
import SelectWrapper, {
selectorTypes,
} from "../FormComponents/SelectWrapper/SelectWrapper";
import { Grid, SelectChangeEvent } from "@mui/material";
import InputBoxWrapper from "../FormComponents/InputBoxWrapper/InputBoxWrapper";
import InputUnitMenu from "../FormComponents/InputUnitMenu/InputUnitMenu";
import withStyles from "@mui/styles/withStyles";
import { Theme } from "@mui/material/styles";
import createStyles from "@mui/styles/createStyles";

interface ITolerationSelector {
effect: ITolerationEffect;
onEffectChange: (value: ITolerationEffect) => void;
tolerationKey: string;
onTolerationKeyChange: (value: string) => void;
operator: ITolerationOperator;
onOperatorChange: (value: ITolerationOperator) => void;
value?: string;
onValueChange: (value: string) => void;
tolerationSeconds?: number;
onSecondsChange: (value: number) => void;
index: number;
classes: any;
}

const styles = (theme: Theme) =>
createStyles({
labelsStyle: {
fontSize: 18,
fontWeight: "bold",
color: "#AEAEAE",
display: "flex",
alignItems: "center",
justifyContent: "center",
maxWidth: 45,
marginRight: 10,
},
fieldsetStyle: {
border: "1px solid #EAEAEA",
borderRadius: 2,
padding: 10,
marginBottom: 15,
},
firstLevel: {
marginBottom: 10,
},
fieldContainer: {
marginRight: 10,
},
legendStyle: {
fontSize: 12,
color: "#696969",
fontWeight: "bold",
},
});

const TolerationSelector = ({
effect,
onEffectChange,
tolerationKey,
onTolerationKeyChange,
operator,
onOperatorChange,
value,
onValueChange,
tolerationSeconds,
onSecondsChange,
index,
classes,
}: ITolerationSelector) => {
const operatorOptions: selectorTypes[] = [];
const effectOptions: selectorTypes[] = [];

for (let operator in ITolerationOperator) {
operatorOptions.push({
value: operator,
label: operator,
});
}

for (let effect in ITolerationEffect) {
effectOptions.push({
value: effect,
label: effect,
});
}

return (
<Grid item xs={12}>
<fieldset className={classes.fieldsetStyle}>
<legend className={classes.legendStyle}>Toleration {index + 1}</legend>
<Grid container>
<Grid container className={classes.firstLevel}>
<Grid item xs className={classes.labelsStyle}>
If
</Grid>
<Grid item xs className={classes.fieldContainer}>
<InputBoxWrapper
id={`keyField-${index}`}
label={""}
name={`keyField-${index}`}
value={tolerationKey}
onChange={(e) => {
onTolerationKeyChange(e.target.value);
}}
index={index}
placeholder={"Toleration Key"}
/>
</Grid>
{ITolerationOperator[operator] === ITolerationOperator.Equal && (
<Grid item xs className={classes.labelsStyle}>
is
</Grid>
)}
<Grid item xs={1} className={classes.fieldContainer}>
<SelectWrapper
onChange={(e: SelectChangeEvent<string>) => {
onOperatorChange(
ITolerationOperator[e.target.value as ITolerationOperator]
);
}}
id={`operator-${index}`}
name="operator"
label={""}
value={ITolerationOperator[operator]}
options={operatorOptions}
/>
</Grid>
{ITolerationOperator[operator] === ITolerationOperator.Equal && (
<Grid item xs className={classes.labelsStyle}>
to
</Grid>
)}
{ITolerationOperator[operator] === ITolerationOperator.Equal && (
<Grid item xs className={classes.fieldContainer}>
<InputBoxWrapper
id={`valueField-${index}`}
label={""}
name={`valueField-${index}`}
value={value || ""}
onChange={(e) => {
onValueChange(e.target.value);
}}
index={index}
placeholder={"Toleration Value"}
/>
</Grid>
)}
</Grid>
<Grid container>
<Grid item xs className={classes.labelsStyle}>
then
</Grid>
<Grid item xs className={classes.fieldContainer}>
<SelectWrapper
onChange={(e: SelectChangeEvent<string>) => {
onEffectChange(
ITolerationEffect[e.target.value as ITolerationEffect]
);
}}
id={`effects-${index}`}
name="effects"
label={""}
value={ITolerationEffect[effect]}
options={effectOptions}
/>
</Grid>
<Grid item xs className={classes.labelsStyle}>
after
</Grid>
<Grid item xs className={classes.fieldContainer}>
<InputBoxWrapper
id={`seconds-${index}`}
label={""}
name={`seconds-${index}`}
value={tolerationSeconds?.toString() || "0"}
onChange={(e) => {
if (e.target.validity.valid) {
onSecondsChange(parseInt(e.target.value));
}
}}
index={index}
pattern={"[0-9]*"}
overlayObject={
<InputUnitMenu
id={`seconds-${index}`}
unitSelected={"seconds"}
unitsList={[{ label: "Seconds", value: "seconds" }]}
disabled={true}
/>
}
/>
</Grid>
</Grid>
</Grid>
</fieldset>
</Grid>
);
};

export default withStyles(styles)(TolerationSelector);
14 changes: 13 additions & 1 deletion portal-ui/src/screens/Console/Tenants/AddTenant/AddTenant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ import { generatePoolName, getBytes } from "../../../../common/utils";
import GenericWizard from "../../Common/GenericWizard/GenericWizard";
import { IWizardElement } from "../../Common/GenericWizard/types";
import { NewServiceAccount } from "../../Common/CredentialsPrompt/types";
import { ErrorResponseHandler, ITenantCreator } from "../../../../common/types";
import {
ErrorResponseHandler,
ITenantCreator,
ITolerationModel,
} from "../../../../common/types";
import { KeyPair } from "../ListTenants/utils";

import { setErrorSnackMessage } from "../../../../actions";
Expand Down Expand Up @@ -73,6 +77,7 @@ interface IAddTenantProps {
validPages: string[];
classes: any;
features?: string[];
tolerations: ITolerationModel[];
}

const styles = (theme: Theme) =>
Expand All @@ -95,6 +100,7 @@ const AddTenant = ({
setErrorSnackMessage,
resetAddTenantForm,
features,
tolerations,
}: IAddTenantProps) => {
// Modals
const [showNewCredentials, setShowNewCredentials] = useState<boolean>(false);
Expand Down Expand Up @@ -232,6 +238,10 @@ const AddTenant = ({
const kesReplicas = fields.encryption.replicas;

if (addSending) {
const tolerationValues = tolerations.filter(
(toleration) => toleration.key.trim() !== ""
);

const poolName = generatePoolName([]);

let affinityObject = {};
Expand Down Expand Up @@ -281,6 +291,7 @@ const AddTenant = ({
},
securityContext: tenantCustom ? tenantSecurityContext : null,
...affinityObject,
tolerations: tolerationValues,
},
],
erasureCodingParity: parseInt(erasureCode, 10),
Expand Down Expand Up @@ -847,6 +858,7 @@ const mapState = (state: AppState) => ({
selectedStorageClass:
state.tenants.createTenant.fields.nameTenant.selectedStorageClass,
features: state.console.session.features,
tolerations: state.tenants.createTenant.tolerations,
});

const connector = connect(mapState, {
Expand Down

0 comments on commit bef3897

Please sign in to comment.