Skip to content

Commit

Permalink
Merge pull request #107 from kloudlite/impl/cluster-status
Browse files Browse the repository at this point in the history
Impl/cluster status
  • Loading branch information
abdheshnayak authored Mar 1, 2024
2 parents caf345f + e73ceb2 commit 56ce7d3
Show file tree
Hide file tree
Showing 11 changed files with 3,495 additions and 762 deletions.
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';
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(
(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>
),
})),
),
})),
]}
onChange={(_, v) => {
handleChange('clusterName')(dummyEvent(v));
onChange={(v) => {
if (parseStatus({ item: v.cluster }) === 'ready')
handleChange('clusterName')(dummyEvent(v.value));
}}
/>
<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';
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) {},
}
),
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

0 comments on commit 56ce7d3

Please sign in to comment.