Skip to content

Commit

Permalink
fix(nodepool): adds stateful field in nodepool
Browse files Browse the repository at this point in the history
  • Loading branch information
nxtCoder19 committed Mar 2, 2024
1 parent b75c8d6 commit 8da3775
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 63 deletions.
2 changes: 2 additions & 0 deletions gql-queries-generator/doc/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ query consoleGetNodePool($clusterName: String!, $poolName: String!) {
}
creationTime
displayName
stateful
kind
lastUpdatedBy {
userEmail
Expand Down Expand Up @@ -663,6 +664,7 @@ query consoleListNodePools($clusterName: String!, $search: SearchNodepool, $pagi
}
creationTime
displayName
stateful
lastUpdatedBy {
userEmail
userId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable react/destructuring-assignment */
import { useMemo } from 'react';
import { toast } from 'react-toastify';
import { NumberInput } from '~/components/atoms/input';
import {NumberInput, TextInput} from '~/components/atoms/input';
import Select from '~/components/atoms/select';
import Popup from '~/components/molecule/popup';
import { useConsoleApi } from '~/console/server/gql/api-provider';
Expand Down Expand Up @@ -53,6 +53,7 @@ const Root = (props: IDialog) => {
taints: [],
autoScale: props.data.spec.minCount !== props.data.spec.maxCount,
isNameError: false,
stateful: props.data.stateful || false
}
: {
nvidiaGpuEnabled: false,
Expand All @@ -72,6 +73,7 @@ const Root = (props: IDialog) => {
labels: [],
taints: [],
isNameError: false,
stateful: false
},
validationSchema: Yup.object({
name: Yup.string().required('id is required'),
Expand Down Expand Up @@ -155,6 +157,7 @@ const Root = (props: IDialog) => {
cloudProvider: 'aws',
...getNodeConf(),
},
stateful: val.stateful || false
},
});
if (e) {
Expand All @@ -174,6 +177,7 @@ const Root = (props: IDialog) => {
minCount: Number.parseInt(val.minimum, 10),
...getNodeConf(),
},
stateful: val.stateful || false
},
});
if (e) {
Expand Down Expand Up @@ -217,79 +221,98 @@ const Root = (props: IDialog) => {
/>

{cloudProvider === 'aws' && (
<>
<Select
label="Provision Mode"
// eslint-disable-next-line react-hooks/rules-of-hooks
value={values.poolType}
options={async () => provisionTypes}
onChange={(_, value) => {
handleChange('poolType')(dummyEvent(value));
}}
/>
<>
<Select
label="Provision Mode"
// eslint-disable-next-line react-hooks/rules-of-hooks
value={values.poolType}
options={async () => provisionTypes}
onChange={(_, value) => {
handleChange('poolType')(dummyEvent(value));
}}
/>

<Select
label="Availability Zone"
value={values.awsAvailabilityZone}
options={async () =>
mapper(
awsRegions.find((v) => v.Name === clusterRegion)?.Zones ||
[],
(v) => ({
value: v,
label: v,
})
)
}
onChange={(_, v) => {
handleChange('awsAvailabilityZone')(dummyEvent(v));
}}
/>

<Select
label="Availability Zone"
value={values.awsAvailabilityZone}
options={async () =>
mapper(
awsRegions.find((v) => v.Name === clusterRegion)?.Zones ||
[],
(v) => ({
value: v,
label: v,
})
)
}
onChange={(_, v) => {
handleChange('awsAvailabilityZone')(dummyEvent(v));
}}
/>
<div className="flex flex-row gap-xl items-end">
<div className="flex flex-row gap-xl items-end flex-1">
<div className="flex-1">
<Select
// eslint-disable-next-line react-hooks/rules-of-hooks
value={useMemo(() => {
const plan = findNodePlan(values.instanceType);
return plan?.value;
}, [values.instanceType])}
label="Node plan"
options={async () => nodePlans}
onChange={(value) => {
handleChange('instanceType')(dummyEvent(value.value));
handleChange('nvidiaGpuEnabled')(
dummyEvent(!!value.gpuEnabled)
);
}}
/>
</div>
</div>

<Select
// eslint-disable-next-line react-hooks/rules-of-hooks
value={useMemo(() => {
const plan = findNodePlan(values.instanceType);
return plan?.value;
}, [values.instanceType])}
label="Node plan"
options={async () => nodePlans}
onChange={(value) => {
handleChange('instanceType')(dummyEvent(value.value));
handleChange('nvidiaGpuEnabled')(
dummyEvent(!!value.gpuEnabled)
);
}}
/>
</>
<div className="flex flex-col gap-md ">
<div className="bodyMd-medium text-text-default">Stateful</div>
<div className="flex items-center h-6xl">
<Switch
label=""
checked={values.stateful}
onChange={(val) => {
handleChange('stateful')(dummyEvent(val));
}}
/>
</div>
</div>
</div>
</>
)}

<div className="flex flex-row gap-xl items-end">
<div className="flex flex-row gap-xl items-end flex-1 ">
<div className="flex-1">
<NumberInput
label={values.autoScale ? 'Min Node Count' : `Node Count`}
placeholder="Minimum"
value={values.minimum}
error={!!errors.minimum}
message={errors.minimum}
onChange={(e) => {
handleChange('minimum')(e);
if (!values.autoScale) {
handleChange('maximum')(e);
}
}}
label={values.autoScale ? 'Min Node Count' : `Node Count`}
placeholder="Minimum"
value={values.minimum}
error={!!errors.minimum}
message={errors.minimum}
onChange={(e) => {
handleChange('minimum')(e);
if (!values.autoScale) {
handleChange('maximum')(e);
}
}}
/>
</div>
{values.autoScale && (
<div className="flex-1">
<NumberInput
error={!!errors.maximum}
message={errors.maximum}
label="Max Node Count"
placeholder="Maximum"
value={values.maximum}
onChange={handleChange('maximum')}
<div className="flex-1">
<NumberInput
error={!!errors.maximum}
message={errors.maximum}
label="Max Node Count"
placeholder="Maximum"
value={values.maximum}
onChange={handleChange('maximum')}
/>
</div>
)}
Expand Down
2 changes: 2 additions & 0 deletions src/apps/console/server/gql/queries/nodepool-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const nodepoolQueries = (executor: IExecutor) => ({
}
creationTime
displayName
stateful
kind
lastUpdatedBy {
userEmail
Expand Down Expand Up @@ -157,6 +158,7 @@ export const nodepoolQueries = (executor: IExecutor) => ({
}
creationTime
displayName
stateful
lastUpdatedBy {
userEmail
userId
Expand Down
3 changes: 3 additions & 0 deletions src/generated/gql/sdl.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3020,6 +3020,7 @@ type NodePool {
metadata: Metadata
recordVersion: Int!
spec: Github__com___kloudlite___operator___apis___clusters___v1__NodePoolSpec!
stateful: Boolean!
status: Github__com___kloudlite___operator___pkg___operator__Status
syncStatus: Github__com___kloudlite___api___pkg___types__SyncStatus!
updateTime: Date!
Expand All @@ -3036,6 +3037,7 @@ input NodePoolIn {
kind: String
metadata: MetadataIn
spec: Github__com___kloudlite___operator___apis___clusters___v1__NodePoolSpecIn!
stateful: Boolean!
}

type NodePoolPaginatedRecords {
Expand Down Expand Up @@ -3475,6 +3477,7 @@ input SearchNamespaces {
}

input SearchNodepool {
isStateful: MatchFilterIn
text: MatchFilterIn
}

Expand Down
4 changes: 4 additions & 0 deletions src/generated/gql/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ export type SearchNamespaces = {
};

export type SearchNodepool = {
isStateful?: InputMaybe<MatchFilterIn>;
text?: InputMaybe<MatchFilterIn>;
};

Expand Down Expand Up @@ -961,6 +962,7 @@ export type NodePoolIn = {
kind?: InputMaybe<Scalars['String']['input']>;
metadata?: InputMaybe<MetadataIn>;
spec: Github__Com___Kloudlite___Operator___Apis___Clusters___V1__NodePoolSpecIn;
stateful: Scalars['Boolean']['input'];
};

export type Github__Com___Kloudlite___Operator___Apis___Clusters___V1__NodePoolSpecIn =
Expand Down Expand Up @@ -2014,6 +2016,7 @@ export type ConsoleGetNodePoolQuery = {
clusterName: string;
creationTime: any;
displayName: string;
stateful: boolean;
kind?: string;
markedForDeletion?: boolean;
updateTime: any;
Expand Down Expand Up @@ -2101,6 +2104,7 @@ export type ConsoleListNodePoolsQuery = {
clusterName: string;
creationTime: any;
displayName: string;
stateful: boolean;
markedForDeletion?: boolean;
recordVersion: number;
updateTime: any;
Expand Down

0 comments on commit 8da3775

Please sign in to comment.