Skip to content

Commit 623fb91

Browse files
authored
Merge pull request #2761 from devtron-labs/feat/online-connectivity-dev
feat: online connectivity dev
2 parents d7d9057 + 6f49026 commit 623fb91

File tree

13 files changed

+97
-53
lines changed

13 files changed

+97
-53
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ FEATURE_AI_INTEGRATION_ENABLE=false
7171
LOGIN_PAGE_IMAGE=
7272
FEATURE_MANAGE_TRAFFIC_ENABLE=false
7373
FEATURE_REDFISH_NODE_ENABLE=false
74+
FEATURE_INFRA_PROVISION_INFO_BLOCK_HIDE=false

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"homepage": "/dashboard",
66
"dependencies": {
7-
"@devtron-labs/devtron-fe-common-lib": "1.15.0-pre-6",
7+
"@devtron-labs/devtron-fe-common-lib": "1.15.0-pre-7",
88
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
99
"@rjsf/core": "^5.13.3",
1010
"@rjsf/utils": "^5.13.3",

src/Pages/GlobalConfigurations/ClustersAndEnvironments/CreateCluster/CreateCluster.component.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ const CreateClusterForm = importComponentFromFELibrary(
2828
'CreateClusterForm',
2929
() => (
3030
<EnterpriseTrialDialog
31-
featureTitle="EKS Cluster"
32-
featureDescription="With Devtron, you can effortlessly create an Amazon EKS cluster."
31+
featureTitle="Create Kubernetes Cluster"
32+
featureDescription="Use Devtron to easily create Kubernetes clusters on popular cloud providers. Simplify cluster
33+
provisioning and management with a guided, user-friendly interface."
3334
/>
3435
),
3536
'function',
@@ -74,7 +75,7 @@ const CreateCluster = ({ handleReloadClusterList, handleRedirectOnModalClose }:
7475
FooterComponent={FooterComponent}
7576
/>
7677
)
77-
case CreateClusterTypeEnum.CREATE_EKS_CLUSTER:
78+
case CreateClusterTypeEnum.CREATE_CLUSTER:
7879
return (
7980
<CreateClusterForm
8081
apiCallInProgress={apiCallInProgress}

src/Pages/GlobalConfigurations/ClustersAndEnvironments/CreateCluster/constants.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@ export const SIDEBAR_CONFIG: SidebarConfigType = {
1212
</p>
1313
),
1414
},
15-
[CreateClusterTypeEnum.CREATE_EKS_CLUSTER]: {
16-
title: 'Create EKS Cluster',
17-
iconName: 'ic-cluster',
18-
dataTestId: 'create-eks-cluster-tab',
15+
[CreateClusterTypeEnum.CREATE_CLUSTER]: {
16+
title: 'Create Kubernetes Cluster',
17+
iconName: 'ic-new',
18+
dataTestId: 'create-cluster-tab',
1919
body: (
20-
<>
21-
<p className="m-0">With Devtron, you can effortlessly create an Amazon EKS cluster.</p>
22-
<p className="m-0">
23-
Amazon Elastic Kubernetes Service (Amazon EKS) is a fully managed Kubernetes service that enables
24-
you to run Kubernetes seamlessly in both AWS Cloud and on-premises data centers.
25-
</p>
26-
</>
20+
<p className="m-0">
21+
Use Devtron to easily create Kubernetes clusters on popular cloud providers. Simplify cluster
22+
provisioning and management with a guided, user-friendly interface.
23+
</p>
2724
),
2825
isEnterprise: true,
2926
},

src/Pages/GlobalConfigurations/ClustersAndEnvironments/CreateCluster/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { IconName } from '@devtron-labs/devtron-fe-common-lib'
22

33
export enum CreateClusterTypeEnum {
44
CONNECT_CLUSTER = 'connect-cluster',
5-
CREATE_EKS_CLUSTER = 'create-eks-cluster',
5+
CREATE_CLUSTER = 'create-cluster',
66
ADD_ISOLATED_CLUSTER = 'add-isolated-cluster',
77
}
88

src/components/common/hooks/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ export const FILE_READING_FAILED_STATUS = {
3333
}
3434

3535
export const ONLINE_BANNER_TIMEOUT = 3000
36-
export const INTERNET_CONNECTIVITY_INTERVAL = 10000
36+
export const INTERNET_CONNECTIVITY_INTERVAL = 30000
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Routes } from '@Config/constants'
2+
3+
import { INTERNET_CONNECTIVITY_INTERVAL } from '../constants'
4+
import { CheckConnectivityParamsType, FetchConnectivityParamsType } from './types'
5+
6+
const fetchWithTimeout = ({ url, options, controller }: FetchConnectivityParamsType): Promise<any> => {
7+
const timeoutId = setTimeout(() => controller.abort(), INTERNET_CONNECTIVITY_INTERVAL)
8+
9+
return fetch(url, { ...options, signal: controller.signal }).finally(() => {
10+
clearTimeout(timeoutId)
11+
})
12+
}
13+
14+
export const getFallbackInternetConnectivity = ({ controller }: CheckConnectivityParamsType): Promise<any> =>
15+
fetchWithTimeout({
16+
url: 'https://www.google.com/favicon.ico',
17+
options: {
18+
method: 'HEAD',
19+
mode: 'no-cors',
20+
},
21+
controller,
22+
})
23+
24+
export const getInternetConnectivity = ({ controller }: CheckConnectivityParamsType): Promise<any> => {
25+
const baseUrl = window._env_?.CENTRAL_API_ENDPOINT ?? 'https://api.devtron.ai'
26+
const url = `${baseUrl}/${Routes.HEALTH}`
27+
28+
return fetchWithTimeout({ url, options: {}, controller })
29+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface FetchConnectivityParamsType {
2+
url: string
3+
options: RequestInit
4+
controller: AbortController
5+
}
6+
7+
export interface CheckConnectivityParamsType extends Pick<FetchConnectivityParamsType, 'controller'> {}

src/components/common/hooks/useOnline/useOnline.ts

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,69 @@
11
import { useEffect, useRef, useState } from 'react'
22

3-
import { getIsRequestAborted, noop, useMainContext } from '@devtron-labs/devtron-fe-common-lib'
4-
5-
import { getInternetConnectivity } from '@Services/service'
3+
import { noop, useMainContext } from '@devtron-labs/devtron-fe-common-lib'
64

75
import { INTERNET_CONNECTIVITY_INTERVAL } from '../constants'
6+
import { getFallbackInternetConnectivity, getInternetConnectivity } from './service'
87

98
export const useOnline = ({ onOnline = noop }: { onOnline?: () => void }) => {
109
const [online, setOnline] = useState(structuredClone(navigator.onLine))
1110
const abortControllerRef = useRef<AbortController>(new AbortController())
1211
const timeoutRef = useRef<NodeJS.Timeout>(null)
1312
const { isAirgapped } = useMainContext()
1413

14+
const hideInternetConnectivityBanner = isAirgapped || window._env_.FEATURE_INTERNET_CONNECTIVITY_ENABLE
15+
1516
const handleClearTimeout = () => {
1617
if (timeoutRef.current) {
1718
clearTimeout(timeoutRef.current)
1819
}
1920
abortControllerRef.current.abort()
2021
}
2122

23+
const onConnectivitySuccess = (checkConnectivity) => {
24+
setOnline((prev) => {
25+
if (!prev) onOnline()
26+
return true
27+
})
28+
timeoutRef.current = setTimeout(checkConnectivity, INTERNET_CONNECTIVITY_INTERVAL)
29+
}
30+
2231
const checkConnectivity = async () => {
23-
if (isAirgapped) return
32+
if (hideInternetConnectivityBanner) return
2433

2534
handleClearTimeout()
2635
const controller = new AbortController()
2736
abortControllerRef.current = controller
2837

2938
try {
30-
await getInternetConnectivity(abortControllerRef.current)
31-
setOnline((prev) => {
32-
if (!prev) {
33-
onOnline()
34-
}
35-
return true
39+
await getFallbackInternetConnectivity({
40+
controller: abortControllerRef.current,
3641
})
37-
timeoutRef.current = setTimeout(checkConnectivity, INTERNET_CONNECTIVITY_INTERVAL)
38-
} catch (error) {
39-
setOnline(false)
40-
if (!getIsRequestAborted(error)) {
41-
timeoutRef.current = setTimeout(checkConnectivity, INTERNET_CONNECTIVITY_INTERVAL)
42+
onConnectivitySuccess(checkConnectivity)
43+
} catch {
44+
if (abortControllerRef.current.signal.aborted) {
45+
if (timeoutRef.current) {
46+
timeoutRef.current = setTimeout(checkConnectivity, INTERNET_CONNECTIVITY_INTERVAL)
47+
}
48+
return
49+
}
50+
const fallbackController = new AbortController()
51+
abortControllerRef.current = fallbackController
52+
try {
53+
await getInternetConnectivity({
54+
controller: abortControllerRef.current,
55+
})
56+
onConnectivitySuccess(checkConnectivity)
57+
} catch {
58+
if (!abortControllerRef.current.signal.aborted) {
59+
setOnline(false)
60+
} else if (timeoutRef.current) {
61+
timeoutRef.current = setTimeout(checkConnectivity, INTERNET_CONNECTIVITY_INTERVAL)
62+
}
4263
}
4364
}
4465
}
66+
4567
const handleOffline = () => {
4668
handleClearTimeout()
4769
setOnline(false)
@@ -58,7 +80,7 @@ export const useOnline = ({ onOnline = noop }: { onOnline?: () => void }) => {
5880
}, [])
5981

6082
useEffect(() => {
61-
if (isAirgapped) return null
83+
if (hideInternetConnectivityBanner) return null
6284
window.addEventListener('online', handleOnline)
6385
window.addEventListener('offline', handleOffline)
6486

src/config/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { AppConfigProps, URLS as COMMON_URLS, EnvResourceType } from '@devtron-labs/devtron-fe-common-lib'
1818
import { generatePath } from 'react-router-dom'
1919

20-
const CREATE_CLUSTER_PATH = 'create/cluster/:type(connect-cluster|create-eks-cluster|add-isolated-cluster)'
20+
const CREATE_CLUSTER_PATH = 'create/cluster/:type(connect-cluster|create-cluster|add-isolated-cluster)'
2121

2222
export const URLS = {
2323
CHARTS: '/chart-store',

0 commit comments

Comments
 (0)