Skip to content

Commit

Permalink
Allow Tolerations to have Seconds undefined (#2168)
Browse files Browse the repository at this point in the history
  • Loading branch information
cesnietor authored Jun 18, 2024
1 parent 6d8f680 commit da7bf70
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 33 deletions.
25 changes: 16 additions & 9 deletions api/tenant-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,22 +982,29 @@ func parseTenantPoolRequest(poolParams *models.Pool) (*miniov2.Pool, error) {
tolerations := []corev1.Toleration{}
for _, elem := range poolParams.Tolerations {
var tolerationSeconds *int64
if elem.TolerationSeconds != nil {
// elem.TolerationSeconds.Seconds is allowed to be nil
tolerationSeconds = elem.TolerationSeconds.Seconds
effect := corev1.TaintEffect(elem.Effect)
tolerationOperator := corev1.TolerationOperator(elem.Operator)

if tolerationSeconds != nil {
if corev1.TaintEffect(elem.Effect) != corev1.TaintEffectNoExecute {
return nil, fmt.Errorf(`Invalid value: "%s": effect must be 'NoExecute' when tolerationSeconds is set`, elem.Effect)
}
// We only allow empty key if operator is exists.
// An empty key with operator Exists matches all keys, values and effects which means this will tolerate everything.
if elem.Key == "" && tolerationOperator != corev1.TolerationOpExists {
// ignore
continue
}

if elem.TolerationSeconds != nil && elem.TolerationSeconds.Seconds != nil {
tolerationSeconds = elem.TolerationSeconds.Seconds
if effect != corev1.TaintEffectNoExecute {
return nil, fmt.Errorf(`Invalid value: "%s": effect must be 'NoExecute' when tolerationSeconds is set`, elem.Effect)
}

}

toleration := corev1.Toleration{
Key: elem.Key,
Operator: corev1.TolerationOperator(elem.Operator),
Operator: tolerationOperator,
Value: elem.Value,
Effect: corev1.TaintEffect(elem.Effect),
Effect: effect,
TolerationSeconds: tolerationSeconds,
}
tolerations = append(tolerations, toleration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,20 @@ const TolerationSelector = ({
<Grid item xs className={"fieldContainer"}>
<InputBox
id={`seconds-${index}`}
label={""}
name={`seconds-${index}`}
value={tolerationSeconds?.toString() || "0"}
value={
// treat the NaN cases
!isNaN(parseFloat(tolerationSeconds?.toString() || ""))
? tolerationSeconds?.toString()
: undefined
}
onChange={(e) => {
if (e.target.validity.valid) {
onSecondsChange(parseInt(e.target.value));
}
}}
index={index}
pattern={"[0-9]*"}
pattern={"[0-9]+"}
overlayObject={
<InputUnitMenu
id={`seconds-${index}`}
Expand Down
12 changes: 8 additions & 4 deletions web-app/src/screens/Console/Tenants/AddTenant/Steps/Affinity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,15 @@ const Affinity = () => {
onValueChange={(value) => {
updateToleration(i, "value", value);
}}
tolerationSeconds={tol.tolerationSeconds?.seconds || 0}
tolerationSeconds={tol.tolerationSeconds?.seconds}
onSecondsChange={(value) => {
updateToleration(i, "tolerationSeconds", {
seconds: value,
});
if (isNaN(value)) {
updateToleration(i, "tolerationSeconds", undefined);
} else {
updateToleration(i, "tolerationSeconds", {
seconds: value,
});
}
}}
index={i}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ const initialState: ICreateTenant = {
tolerations: [
{
key: "",
tolerationSeconds: { seconds: 0 },
value: "",
effect: ITolerationEffect.NoSchedule,
operator: ITolerationOperator.Equal,
Expand Down Expand Up @@ -658,7 +657,6 @@ export const createTenantSlice = createSlice({
...state.tolerations,
{
key: "",
tolerationSeconds: { seconds: 0 },
value: "",
effect: ITolerationEffect.NoSchedule,
operator: ITolerationOperator.Equal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,15 @@ const Affinity = () => {
onValueChange={(value) => {
updateToleration(i, "value", value);
}}
tolerationSeconds={tol.tolerationSeconds?.seconds || 0}
tolerationSeconds={tol.tolerationSeconds?.seconds}
onSecondsChange={(value) => {
updateToleration(i, "tolerationSeconds", {
seconds: value,
});
if (isNaN(value)) {
updateToleration(i, "tolerationSeconds", undefined);
} else {
updateToleration(i, "tolerationSeconds", {
seconds: value,
});
}
}}
index={i}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ const initialState: IAddPool = {
tolerations: [
{
key: "",
tolerationSeconds: { seconds: 0 },
value: "",
effect: ITolerationEffect.NoSchedule,
operator: ITolerationOperator.Equal,
Expand Down Expand Up @@ -150,7 +149,6 @@ export const addPoolSlice = createSlice({
addNewPoolToleration: (state) => {
state.tolerations.push({
key: "",
tolerationSeconds: { seconds: 0 },
value: "",
effect: ITolerationEffect.NoSchedule,
operator: ITolerationOperator.Equal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ const PoolDetails = () => {
<strong>{tolItem.value}</strong> then{" "}
<strong>{tolItem.effect}</strong> after{" "}
<strong>
{tolItem.tolerationSeconds?.seconds || 0}
{tolItem.tolerationSeconds?.seconds}
</strong>{" "}
seconds
</Fragment>
Expand All @@ -258,7 +258,7 @@ const PoolDetails = () => {
If <strong>{tolItem.key}</strong> exists then{" "}
<strong>{tolItem.effect}</strong> after{" "}
<strong>
{tolItem.tolerationSeconds?.seconds || 0}
{tolItem.tolerationSeconds?.seconds}
</strong>{" "}
seconds
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,15 @@ const Affinity = () => {
onValueChange={(value) => {
updateToleration(i, "value", value);
}}
tolerationSeconds={tol.tolerationSeconds?.seconds || 0}
tolerationSeconds={tol.tolerationSeconds?.seconds}
onSecondsChange={(value) => {
updateToleration(i, "tolerationSeconds", {
seconds: value,
});
if (isNaN(value)) {
updateToleration(i, "tolerationSeconds", undefined);
} else {
updateToleration(i, "tolerationSeconds", {
seconds: value,
});
}
}}
index={i}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ const initialState: IEditPool = {
tolerations: [
{
key: "",
tolerationSeconds: { seconds: 0 },
value: "",
effect: ITolerationEffect.NoSchedule,
operator: ITolerationOperator.Equal,
Expand All @@ -82,7 +81,6 @@ export const editPoolSlice = createSlice({
let tolerations: ITolerationModel[] = [
{
key: "",
tolerationSeconds: { seconds: 0 },
value: "",
effect: ITolerationEffect.NoSchedule,
operator: ITolerationOperator.Equal,
Expand Down Expand Up @@ -232,12 +230,12 @@ export const editPoolSlice = createSlice({

editPoolTolerationValue[action.payload.index] =
action.payload.tolerationValue;

state.fields.tolerations = editPoolTolerationValue;
},
addNewEditPoolToleration: (state) => {
state.fields.tolerations.push({
key: "",
tolerationSeconds: { seconds: 0 },
value: "",
effect: ITolerationEffect.NoSchedule,
operator: ITolerationOperator.Equal,
Expand Down

0 comments on commit da7bf70

Please sign in to comment.