diff --git a/api/tenant-handlers.go b/api/tenant-handlers.go index a3626f9bd93..9381c349bac 100644 --- a/api/tenant-handlers.go +++ b/api/tenant-handlers.go @@ -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) diff --git a/web-app/src/screens/Console/Common/TolerationSelector/TolerationSelector.tsx b/web-app/src/screens/Console/Common/TolerationSelector/TolerationSelector.tsx index 0fe66546ed9..3ad22ed560e 100644 --- a/web-app/src/screens/Console/Common/TolerationSelector/TolerationSelector.tsx +++ b/web-app/src/screens/Console/Common/TolerationSelector/TolerationSelector.tsx @@ -181,16 +181,20 @@ const TolerationSelector = ({ { if (e.target.validity.valid) { onSecondsChange(parseInt(e.target.value)); } }} index={index} - pattern={"[0-9]*"} + pattern={"[0-9]+"} overlayObject={ { 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} /> diff --git a/web-app/src/screens/Console/Tenants/AddTenant/createTenantSlice.ts b/web-app/src/screens/Console/Tenants/AddTenant/createTenantSlice.ts index 241fb94560d..d46c95be3a8 100644 --- a/web-app/src/screens/Console/Tenants/AddTenant/createTenantSlice.ts +++ b/web-app/src/screens/Console/Tenants/AddTenant/createTenantSlice.ts @@ -324,7 +324,6 @@ const initialState: ICreateTenant = { tolerations: [ { key: "", - tolerationSeconds: { seconds: 0 }, value: "", effect: ITolerationEffect.NoSchedule, operator: ITolerationOperator.Equal, @@ -658,7 +657,6 @@ export const createTenantSlice = createSlice({ ...state.tolerations, { key: "", - tolerationSeconds: { seconds: 0 }, value: "", effect: ITolerationEffect.NoSchedule, operator: ITolerationOperator.Equal, diff --git a/web-app/src/screens/Console/Tenants/TenantDetails/Pools/AddPool/PoolPodPlacement.tsx b/web-app/src/screens/Console/Tenants/TenantDetails/Pools/AddPool/PoolPodPlacement.tsx index a8705eb0a12..bff97ec8578 100644 --- a/web-app/src/screens/Console/Tenants/TenantDetails/Pools/AddPool/PoolPodPlacement.tsx +++ b/web-app/src/screens/Console/Tenants/TenantDetails/Pools/AddPool/PoolPodPlacement.tsx @@ -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} /> diff --git a/web-app/src/screens/Console/Tenants/TenantDetails/Pools/AddPool/addPoolSlice.ts b/web-app/src/screens/Console/Tenants/TenantDetails/Pools/AddPool/addPoolSlice.ts index ecb125638d7..f3f5829884a 100644 --- a/web-app/src/screens/Console/Tenants/TenantDetails/Pools/AddPool/addPoolSlice.ts +++ b/web-app/src/screens/Console/Tenants/TenantDetails/Pools/AddPool/addPoolSlice.ts @@ -78,7 +78,6 @@ const initialState: IAddPool = { tolerations: [ { key: "", - tolerationSeconds: { seconds: 0 }, value: "", effect: ITolerationEffect.NoSchedule, operator: ITolerationOperator.Equal, @@ -150,7 +149,6 @@ export const addPoolSlice = createSlice({ addNewPoolToleration: (state) => { state.tolerations.push({ key: "", - tolerationSeconds: { seconds: 0 }, value: "", effect: ITolerationEffect.NoSchedule, operator: ITolerationOperator.Equal, diff --git a/web-app/src/screens/Console/Tenants/TenantDetails/Pools/Details/PoolDetails.tsx b/web-app/src/screens/Console/Tenants/TenantDetails/Pools/Details/PoolDetails.tsx index 1b38f254a4b..2645762e116 100644 --- a/web-app/src/screens/Console/Tenants/TenantDetails/Pools/Details/PoolDetails.tsx +++ b/web-app/src/screens/Console/Tenants/TenantDetails/Pools/Details/PoolDetails.tsx @@ -249,7 +249,7 @@ const PoolDetails = () => { {tolItem.value} then{" "} {tolItem.effect} after{" "} - {tolItem.tolerationSeconds?.seconds || 0} + {tolItem.tolerationSeconds?.seconds} {" "} seconds @@ -258,7 +258,7 @@ const PoolDetails = () => { If {tolItem.key} exists then{" "} {tolItem.effect} after{" "} - {tolItem.tolerationSeconds?.seconds || 0} + {tolItem.tolerationSeconds?.seconds} {" "} seconds diff --git a/web-app/src/screens/Console/Tenants/TenantDetails/Pools/EditPool/EditPoolPlacement.tsx b/web-app/src/screens/Console/Tenants/TenantDetails/Pools/EditPool/EditPoolPlacement.tsx index ee4cfd23ed9..b6d385f90d0 100644 --- a/web-app/src/screens/Console/Tenants/TenantDetails/Pools/EditPool/EditPoolPlacement.tsx +++ b/web-app/src/screens/Console/Tenants/TenantDetails/Pools/EditPool/EditPoolPlacement.tsx @@ -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} /> diff --git a/web-app/src/screens/Console/Tenants/TenantDetails/Pools/EditPool/editPoolSlice.ts b/web-app/src/screens/Console/Tenants/TenantDetails/Pools/EditPool/editPoolSlice.ts index 98b602290cd..10015f47fa8 100644 --- a/web-app/src/screens/Console/Tenants/TenantDetails/Pools/EditPool/editPoolSlice.ts +++ b/web-app/src/screens/Console/Tenants/TenantDetails/Pools/EditPool/editPoolSlice.ts @@ -60,7 +60,6 @@ const initialState: IEditPool = { tolerations: [ { key: "", - tolerationSeconds: { seconds: 0 }, value: "", effect: ITolerationEffect.NoSchedule, operator: ITolerationOperator.Equal, @@ -82,7 +81,6 @@ export const editPoolSlice = createSlice({ let tolerations: ITolerationModel[] = [ { key: "", - tolerationSeconds: { seconds: 0 }, value: "", effect: ITolerationEffect.NoSchedule, operator: ITolerationOperator.Equal, @@ -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,