Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl/cluster status #107

Merged
merged 4 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ tasks:

"vision")
URL_SUFFIX="-vision"
;;

;;
"nxtcoder17")
URL_SUFFIX="-mohit"
;;

"piyush")
URL_SUFFIX="-piyush"
;;
Expand Down
4 changes: 0 additions & 4 deletions gql-queries-generator/doc/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,6 @@ query consoleGetCluster($name: String!) {
aws {
k3sMasters {
iamInstanceProfileRole
imageId
imageSSHUsername
instanceType
nodes
nvidiaGpuEnabled
Expand Down Expand Up @@ -590,8 +588,6 @@ query consoleGetNodePool($clusterName: String!, $poolName: String!) {
nodes
}
iamInstanceProfileRole
imageId
imageSSHUsername
nvidiaGpuEnabled
poolType
rootVolumeSize
Expand Down
4 changes: 2 additions & 2 deletions src/apps/console/components/sync-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const SyncStatus = ({ item }: { item: IStatusMeta }) => {
return null;
};

export type IStatus = 'deleting' | 'notready' | 'syncing' | 'none';
export type IStatus = 'deleting' | 'notready' | 'syncing' | 'ready';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (llm): The modification to the IStatus type to include 'ready' is a significant change. It's important to ensure that all components consuming IStatus properly handle the new 'ready' status. This might include rendering logic, styling, or even business logic changes. If not already covered, adding tests to verify these components react appropriately to the 'ready' status would mitigate potential issues.

type IResourceType = 'nodepool';

export const parseStatus = ({
Expand All @@ -173,7 +173,7 @@ export const parseStatus = ({
item: IStatusMeta;
type?: IResourceType;
}) => {
let status: IStatus = 'none';
let status: IStatus = 'ready';

if (item.markedForDeletion) {
status = 'deleting';
Expand Down
71 changes: 56 additions & 15 deletions src/apps/console/page-components/new-project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import useForm, { dummyEvent } from '~/root/lib/client/hooks/use-form';
import Yup from '~/root/lib/server/helpers/yup';
import { handleError } from '~/root/lib/utils/common';
import Select from '~/components/atoms/select';
import { parseName, parseNodes } from '../server/r-utils/common';
import { listStatus, parseStatus } from '~/console/components/sync-status';
import { IClusters } from '~/console/server/gql/queries/cluster-queries';
import {
ExtractNodeType,
parseName,
parseNodes,
} from '../server/r-utils/common';
import { ensureAccountClientSide } from '../server/utils/auth-utils';
import { INewProjectFromAccountLoader } from '../routes/_a+/$a+/new-project';
import { useConsoleApi } from '../server/gql/api-provider';
Expand All @@ -19,6 +25,14 @@ import MultiStepProgress, {
import MultiStepProgressWrapper from '../components/multi-step-progress-wrapper';
import { TitleBox } from '../components/raw-wrapper';

const statusRender = (item: ExtractNodeType<IClusters>) => {
return listStatus({
key: parseName(item),
item,
className: 'text-center',
});
};

const NewProject = () => {
const { clustersData } = useLoaderData<INewProjectFromAccountLoader>();
const clusters = parseNodes(clustersData);
Expand Down Expand Up @@ -125,22 +139,49 @@ const NewProject = () => {
placeholder="Select a cluster"
value={values.clusterName}
options={async () => [
...clusters.map((clster) => ({
label: clster.displayName,
value: parseName(clster),
cluster: clster,
render: () => (
<div className="flex flex-col">
<div>{clster.displayName}</div>
<div className="bodySm text-text-soft">
{parseName(clster)}
...clusters
.filter(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (llm): It seems like the filtering logic for clusters based on their status ('deleting') has been introduced. I recommend adding unit tests to verify that clusters with a status of 'deleting' are indeed filtered out and not displayed as options. This is crucial to ensure the UI behaves as expected and only presents valid clusters to the user.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (llm): Considering the addition of conditional rendering based on the cluster status ('ready', 'syncing', 'notready'), it would be beneficial to include integration or end-to-end tests. These tests should verify that the UI correctly displays the cluster information and status indicators according to the cluster's current state. This ensures that users receive accurate feedback on the cluster status.

(clster) => parseStatus({ item: clster }) !== 'deleting'
)
.map((clster) => ({
label: clster.displayName,
value: parseName(clster),
cluster: clster,
render: () => (
<div>
{parseStatus({ item: clster }) === 'ready' ? (
<div className="flex flex-col">
<div>{clster.displayName}</div>
<div className="bodySm text-text-soft">
{parseName(clster)}
</div>
</div>
) : (
// parseStatus({ item: clster }) === 'syncing' ||
// parseStatus({ item: clster }) === 'notready' ?
<div className="flex text-text-disabled">
<div className="flex-grow">
<div className="flex flex-col">
<div>{clster.displayName}</div>
<div className="bodySm">
{parseName(clster)}
</div>
</div>
</div>
<div className="flex flex-grow-0 items-center">
{statusRender(
clster as ExtractNodeType<IClusters>
).render()}
</div>
</div>
)}
</div>
</div>
),
})),
),
})),
Comment on lines +143 to +180
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (llm): The filtering and mapping logic for clusters based on their status introduces a significant amount of complexity within the JSX. Consider abstracting this logic into a separate function or utilizing useMemo to avoid recalculating this on every render, especially since this operation depends on the clusters' data which might not change on every render. This could improve readability and performance.

]}
onChange={(_, v) => {
handleChange('clusterName')(dummyEvent(v));
onChange={(v) => {
if (parseStatus({ item: v.cluster }) === 'ready')
handleChange('clusterName')(dummyEvent(v.value));
Comment on lines +183 to +184
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (rule): Sourcery has identified the following issue:

  • Use block braces for ifs, whiles, etc. (use-braces)
Suggested change
if (parseStatus({ item: v.cluster }) === 'ready')
handleChange('clusterName')(dummyEvent(v.value));
if (parseStatus({ item: v.cluster }) === 'ready') {
handleChange('clusterName')(dummyEvent(v.value));
}


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

}}
/>
<div className="flex flex-row justify-start">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
parseUpdateOrCreatedBy,
parseUpdateOrCreatedOn,
} from '~/console/server/r-utils/common';
import { memo, useState } from 'react';
import { useState } from 'react';
import Popup from '~/components/molecule/popup';
import { HighlightJsLogs } from 'react-highlightjs-logs';
import { yamlDump } from '~/console/components/diff-viewer';
Expand All @@ -32,13 +32,13 @@ import AnimateHide from '~/components/atoms/animate-hide';
import { ISetState } from '~/console/page-components/app-states';
import { Button } from '~/components/atoms/button';
import { dayjs } from '~/components/molecule/dayjs';
import LogComp from '~/root/lib/client/components/logger';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (llm): The introduction of a new logging component (LogComp) in the nodepool resources file suggests changes in logging behavior or additional logging functionality. It would be beneficial to have tests that verify the logging behavior, especially in error scenarios or critical execution paths. This ensures that the system's operational aspects are observable and debuggable.

import HandleNodePool from './handle-nodepool';
import {
findNodePlanWithCategory,
findNodePlanWithSpec,
} from './nodepool-utils';
import { IAccountContext } from '../../../_layout';
import LogComp from '~/root/lib/client/components/logger';

const RESOURCE_NAME = 'nodepool';
type BaseType = ExtractNodeType<INodepools>;
Expand Down Expand Up @@ -186,7 +186,6 @@ const ListDetail = (
</div>
);
case 'azure':
case 'do':
case 'gcp':
default:
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const getProvider = (item: ExtractNodeType<IClusters>) => {
<span>({item.spec.aws?.region})</span>
</div>
);
case 'do':
case 'gcp':
case 'azure':
return (
Expand Down
16 changes: 7 additions & 9 deletions src/apps/console/server/gql/queries/cluster-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const clusterQueries = (executor: IExecutor) => ({
{
transformer: (data: ConsoleCreateClusterMutation) =>
data.infra_createCluster,
vars(_: ConsoleCreateClusterMutationVariables) { },
vars(_: ConsoleCreateClusterMutationVariables) {},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (llm): Given the changes in GraphQL queries and mutations, it's crucial to ensure that the corresponding tests are updated or added to cover these changes. This includes verifying that the queries and mutations behave as expected with the new or modified variables, and that error handling is properly implemented. This is important for maintaining the reliability of the API interactions.

}
),
deleteCluster: executor(
Expand All @@ -44,7 +44,7 @@ export const clusterQueries = (executor: IExecutor) => ({
{
transformer: (data: ConsoleDeleteClusterMutation) =>
data.infra_deleteCluster,
vars(_: ConsoleDeleteClusterMutationVariables) { },
vars(_: ConsoleDeleteClusterMutationVariables) {},
}
),
clustersCount: executor(
Expand All @@ -57,7 +57,7 @@ export const clusterQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: ConsoleClustersCountQuery) => data.infra_listClusters,
vars(_: ConsoleClustersCountQueryVariables) { },
vars(_: ConsoleClustersCountQueryVariables) {},
}
),

Expand Down Expand Up @@ -171,7 +171,7 @@ export const clusterQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: ConsoleListClustersQuery) => data.infra_listClusters,
vars(_: ConsoleListClustersQueryVariables) { },
vars(_: ConsoleListClustersQueryVariables) {},
}
),
getCluster: executor(
Expand Down Expand Up @@ -212,8 +212,6 @@ export const clusterQueries = (executor: IExecutor) => ({
aws {
k3sMasters {
iamInstanceProfileRole
imageId
imageSSHUsername
instanceType
nodes
nvidiaGpuEnabled
Expand Down Expand Up @@ -283,7 +281,7 @@ export const clusterQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: ConsoleGetClusterQuery) => data.infra_getCluster,
vars(_: ConsoleGetClusterQueryVariables) { },
vars(_: ConsoleGetClusterQueryVariables) {},
}
),
getKubeConfig: executor(
Expand All @@ -299,7 +297,7 @@ export const clusterQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: ConsoleGetKubeConfigQuery) => data.infra_getCluster,
vars(_: ConsoleGetClusterQueryVariables) { },
vars(_: ConsoleGetClusterQueryVariables) {},
}
),
updateCluster: executor(
Expand All @@ -313,7 +311,7 @@ export const clusterQueries = (executor: IExecutor) => ({
{
transformer: (data: ConsoleUpdateClusterMutation) =>
data.infra_updateCluster,
vars(_: ConsoleUpdateClusterMutationVariables) { },
vars(_: ConsoleUpdateClusterMutationVariables) {},
}
),
});
2 changes: 0 additions & 2 deletions src/apps/console/server/gql/queries/nodepool-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ export const nodepoolQueries = (executor: IExecutor) => ({
nodes
}
iamInstanceProfileRole
imageId
imageSSHUsername
nvidiaGpuEnabled
poolType
rootVolumeSize
Expand Down
2 changes: 0 additions & 2 deletions src/apps/console/server/r-utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export const parseFromAnn = (resource: parseFromAnnResource, key: string) =>

export const validateClusterCloudProvider = (v: string): CloudProvider => {
switch (v as CloudProvider) {
case 'do':
case 'aws':
case 'azure':
case 'gcp':
Expand All @@ -128,7 +127,6 @@ export const validateClusterCloudProvider = (v: string): CloudProvider => {

export const validateCloudProvider = (v: string): CloudProvider => {
switch (v as CloudProvider) {
case 'do':
case 'aws':
case 'azure':
case 'gcp':
Expand Down
34 changes: 18 additions & 16 deletions src/generated/gql/sdl.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ type Github__com___kloudlite___operator___apis___clusters___v1__AWSClusterConfig
nodePools: Map
region: String!
spotNodePools: Map
vpc: Github__com___kloudlite___operator___apis___clusters___v1__AwsVPCParams
}

input Github__com___kloudlite___operator___apis___clusters___v1__AWSClusterConfigIn {
Expand All @@ -833,8 +834,6 @@ input Github__com___kloudlite___operator___apis___clusters___v1__AwsEC2PoolConfi

type Github__com___kloudlite___operator___apis___clusters___v1__AWSK3sMastersConfig {
iamInstanceProfileRole: String
imageId: String!
imageSSHUsername: String!
instanceType: String!
nodes: Map
nvidiaGpuEnabled: Boolean!
Expand All @@ -851,13 +850,13 @@ type Github__com___kloudlite___operator___apis___clusters___v1__AWSNodePoolConfi
availabilityZone: String!
ec2Pool: Github__com___kloudlite___operator___apis___clusters___v1__AwsEC2PoolConfig
iamInstanceProfileRole: String
imageId: String!
imageSSHUsername: String!
nvidiaGpuEnabled: Boolean!
poolType: Github__com___kloudlite___operator___apis___clusters___v1__AWSPoolType!
rootVolumeSize: Int!
rootVolumeType: String!
spotPool: Github__com___kloudlite___operator___apis___clusters___v1__AwsSpotPoolConfig
vpcId: String!
vpcSubnetId: String!
}

input Github__com___kloudlite___operator___apis___clusters___v1__AWSNodePoolConfigIn {
Expand Down Expand Up @@ -904,6 +903,16 @@ input Github__com___kloudlite___operator___apis___clusters___v1__AwsSpotPoolConf
nodes: Map
}

type Github__com___kloudlite___operator___apis___clusters___v1__AwsSubnetWithID {
availabilityZone: String!
id: String!
}

type Github__com___kloudlite___operator___apis___clusters___v1__AwsVPCParams {
id: String!
publicSubnets: [Github__com___kloudlite___operator___apis___clusters___v1__AwsSubnetWithID!]!
}

type Github__com___kloudlite___operator___apis___clusters___v1__CloudProviderCredentialKeys {
keyAccessKey: String!
keyAWSAccountId: String!
Expand All @@ -916,6 +925,8 @@ type Github__com___kloudlite___operator___apis___clusters___v1__CloudProviderCre
type Github__com___kloudlite___operator___apis___clusters___v1__ClusterOutput {
jobName: String!
jobNamespace: String!
keyAWSVPCId: String
keyAWSVPCPublicSubnets: String
keyK3sAgentJoinToken: String!
keyK3sServerJoinToken: String!
keyKubeconfig: String!
Expand Down Expand Up @@ -954,26 +965,16 @@ input Github__com___kloudlite___operator___apis___clusters___v1__ClusterSpecIn {
credentialsRef: Github__com___kloudlite___operator___apis___common____types__SecretRefIn!
}

type Github__com___kloudlite___operator___apis___clusters___v1__InfrastuctureAsCode {
cloudProviderAccessKey: Github__com___kloudlite___operator___apis___common____types__SecretKeyRef!
cloudProviderSecretKey: Github__com___kloudlite___operator___apis___common____types__SecretKeyRef!
jobName: String
jobNamespace: String
stateS3BucketFilePath: String!
stateS3BucketName: String!
stateS3BucketRegion: String!
}

type Github__com___kloudlite___operator___apis___clusters___v1__MasterNodeProps {
availabilityZone: String!
kloudliteRelease: String!
lastRecreatedAt: Date
role: String!
}

type Github__com___kloudlite___operator___apis___clusters___v1__NodePoolSpec {
aws: Github__com___kloudlite___operator___apis___clusters___v1__AWSNodePoolConfig
cloudProvider: Github__com___kloudlite___operator___apis___common____types__CloudProvider!
iac: Github__com___kloudlite___operator___apis___clusters___v1__InfrastuctureAsCode!
maxCount: Int!
minCount: Int!
nodeLabels: Map
Expand Down Expand Up @@ -1008,7 +1009,7 @@ input Github__com___kloudlite___operator___apis___clusters___v1__NodeSpecIn {
enum Github__com___kloudlite___operator___apis___common____types__CloudProvider {
aws
azure
do
digitalocean
gcp
}

Expand Down Expand Up @@ -1247,6 +1248,7 @@ type Github__com___kloudlite___operator___apis___crds___v1__HelmChartSpec {
postUninstall: String
preInstall: String
preUninstall: String
releaseName: String
values: Map!
}

Expand Down
Loading
Loading