Skip to content

Commit

Permalink
Merge pull request #291 from kloudlite/cluster/status-update
Browse files Browse the repository at this point in the history
cluster status issue fix
  • Loading branch information
tulsiojha authored Sep 10, 2024
2 parents a1db742 + 807ce73 commit 12de338
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 24 deletions.
13 changes: 13 additions & 0 deletions gql-queries-generator/doc/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,19 @@ query consoleGetCluster($name: String!) {
}
}

query consoleListClusterStatus($pagination: CursorPaginationIn) {
infra_listBYOKClusters(pagination: $pagination) {
edges {
node {
lastOnlineAt
metadata {
name
}
}
}
}
}

query consoleGetKubeConfig($name: String!) {
infra_getCluster(name: $name) {
adminKubeconfig {
Expand Down
35 changes: 21 additions & 14 deletions src/apps/console/hooks/use-cluster-status-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import {
import { useSocketWatch } from '~/root/lib/client/helpers/socket/useWatch';
import useDebounce from '~/root/lib/client/hooks/use-debounce';
import { useConsoleApi } from '../server/gql/api-provider';
import { IByocClusters } from '../server/gql/queries/byok-cluster-queries';
import { ExtractNodeType, parseNodes } from '../server/r-utils/common';
import { IClustersStatus } from '../server/gql/queries/cluster-queries';

type IClusterMap = { [key: string]: ExtractNodeType<IByocClusters> };
type IClusterMap = { [key: string]: ExtractNodeType<IClustersStatus> };

const ClusterStatusContext = createContext<{
clusters: IClusterMap;
Expand All @@ -36,16 +36,17 @@ const ClusterStatusProvider = ({ children }: { children: ReactNode }) => {

const listCluster = useCallback(async () => {
try {
const cl = await api.listAllClusters();
const parsed = parseNodes(cl.data).reduce(
(acc, c) => {
acc[c.metadata.name] = c;
return acc;
const { data } = await api.listClusterStatus({
pagination: {
first: 500,
},
{} as { [key: string]: ExtractNodeType<IByocClusters> },
);
});
const parsed = parseNodes(data).reduce((acc, c) => {
acc[c.metadata.name] = c;
return acc;
}, {} as IClusterMap);
setClusters(parsed);
return clusters;
return parsed;
} catch (err) {
console.error(err);
return false;
Expand All @@ -56,8 +57,18 @@ const ClusterStatusProvider = ({ children }: { children: ReactNode }) => {
const interval = setInterval(() => {
listCluster();
}, 30 * 1000);

const onlineEvent = () => {
setTimeout(() => {
listCluster();
}, 3000);
};

window.addEventListener('online', onlineEvent);

return () => {
clearInterval(interval);
window.removeEventListener('online', onlineEvent);
};
}, []);

Expand All @@ -73,10 +84,6 @@ const ClusterStatusProvider = ({ children }: { children: ReactNode }) => {
setUpdate((p) => !p);
}, topic);

useEffect(() => {
console.log('helre', topic);
}, [topic]);

return (
<ClusterStatusContext.Provider
value={useMemo(
Expand Down
45 changes: 35 additions & 10 deletions src/apps/console/server/gql/queries/cluster-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ import {
ConsoleListDnsHostsQueryVariables,
ConsoleListAllClustersQuery,
ConsoleListAllClustersQueryVariables,
ConsoleListClusterStatusQuery,
ConsoleListClusterStatusQueryVariables,
} from '~/root/src/generated/gql/server';

export type ICluster = NN<ConsoleGetClusterQuery['infra_getCluster']>;
export type IClusters = NN<ConsoleListClustersQuery['infra_listClusters']>;
export type IClustersStatus = NN<
ConsoleListClusterStatusQuery['infra_listBYOKClusters']
>;

export type IDnsHosts = NN<ConsoleListDnsHostsQuery>['infra_listClusters'];

Expand Down Expand Up @@ -50,7 +55,7 @@ export const clusterQueries = (executor: IExecutor) => ({
return data.infra_listClusters;
},
vars(_: ConsoleListDnsHostsQueryVariables) {},
}
},
),

createCluster: executor(
Expand All @@ -65,7 +70,7 @@ export const clusterQueries = (executor: IExecutor) => ({
transformer: (data: ConsoleCreateClusterMutation) =>
data.infra_createCluster,
vars(_: ConsoleCreateClusterMutationVariables) {},
}
},
),
deleteCluster: executor(
gql`
Expand All @@ -77,7 +82,7 @@ export const clusterQueries = (executor: IExecutor) => ({
transformer: (data: ConsoleDeleteClusterMutation) =>
data.infra_deleteCluster,
vars(_: ConsoleDeleteClusterMutationVariables) {},
}
},
),
clustersCount: executor(
gql`
Expand All @@ -90,7 +95,7 @@ export const clusterQueries = (executor: IExecutor) => ({
{
transformer: (data: ConsoleClustersCountQuery) => data.infra_listClusters,
vars(_: ConsoleClustersCountQueryVariables) {},
}
},
),

listAllClusters: executor(
Expand Down Expand Up @@ -271,9 +276,8 @@ export const clusterQueries = (executor: IExecutor) => ({
{
transformer: (data: ConsoleListAllClustersQuery) => data.byok_clusters,
vars(_: ConsoleListAllClustersQueryVariables) {},
}
},
),

listClusters: executor(
gql`
query Infra_listClusterss(
Expand Down Expand Up @@ -396,7 +400,7 @@ export const clusterQueries = (executor: IExecutor) => ({
{
transformer: (data: ConsoleListClustersQuery) => data.infra_listClusters,
vars(_: ConsoleListClustersQueryVariables) {},
}
},
),
getCluster: executor(
gql`
Expand Down Expand Up @@ -502,7 +506,28 @@ export const clusterQueries = (executor: IExecutor) => ({
{
transformer: (data: ConsoleGetClusterQuery) => data.infra_getCluster,
vars(_: ConsoleGetClusterQueryVariables) {},
}
},
),
listClusterStatus: executor(
gql`
query listCluster($pagination: CursorPaginationIn) {
infra_listBYOKClusters(pagination: $pagination) {
edges {
node {
lastOnlineAt
metadata {
name
}
}
}
}
}
`,
{
transformer: (data: ConsoleListClusterStatusQuery) =>
data.infra_listBYOKClusters,
vars(_: ConsoleListClusterStatusQueryVariables) {},
},
),
getKubeConfig: executor(
gql`
Expand All @@ -518,7 +543,7 @@ export const clusterQueries = (executor: IExecutor) => ({
{
transformer: (data: ConsoleGetKubeConfigQuery) => data.infra_getCluster,
vars(_: ConsoleGetClusterQueryVariables) {},
}
},
),
updateCluster: executor(
gql`
Expand All @@ -532,6 +557,6 @@ export const clusterQueries = (executor: IExecutor) => ({
transformer: (data: ConsoleUpdateClusterMutation) =>
data.infra_updateCluster,
vars(_: ConsoleUpdateClusterMutationVariables) {},
}
},
),
});
10 changes: 10 additions & 0 deletions src/generated/gql/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,16 @@ export type ConsoleGetClusterQuery = {
};
};

export type ConsoleListClusterStatusQueryVariables = Exact<{
pagination?: InputMaybe<CursorPaginationIn>;
}>;

export type ConsoleListClusterStatusQuery = {
infra_listBYOKClusters?: {
edges: Array<{ node: { lastOnlineAt?: any; metadata: { name: string } } }>;
};
};

export type ConsoleGetKubeConfigQueryVariables = Exact<{
name: Scalars['String']['input'];
}>;
Expand Down

0 comments on commit 12de338

Please sign in to comment.