Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
SelectPicker,
ButtonVariantType,
ButtonStyleType,
ResourceListPayloadType,
} from '@devtron-labs/devtron-fe-common-lib'
import { K8S_EMPTY_GROUP } from '@Components/ResourceBrowser/Constants'
import {
Expand All @@ -44,7 +45,7 @@ import {
getResourceGroupList,
namespaceListByClusterId,
} from '../../../../../../components/ResourceBrowser/ResourceBrowser.service'
import { K8SObjectType, ResourceListPayloadType } from '../../../../../../components/ResourceBrowser/Types'
import { K8SObjectType } from '../../../../../../components/ResourceBrowser/Types'
import { formatOptionLabel } from '../../../../../../components/v2/common/ReactSelect.utils'
import { ReactComponent as Clone } from '../../../../../../assets/icons/ic-copy.svg'
import { ReactComponent as Delete } from '../../../../../../assets/icons/ic-delete-interactive.svg'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import {
InfoColourBar,
Progressing,
usePrompt,
DEFAULT_ROUTE_PROMPT_MESSAGE
} from '@devtron-labs/devtron-fe-common-lib'
import { Prompt } from 'react-router-dom'
import { HibernateStatusRow } from './HibernateStatusRow'
import { DEFAULT_ROUTE_PROMPT_MESSAGE } from '../../../../config'
import { ReactComponent as Close } from '../../../../assets/icons/ic-cross.svg'
import { ReactComponent as Error } from '../../../../assets/icons/ic-warning.svg'
import { ReactComponent as MechanicalOperation } from '../../../../assets/img/ic-mechanical-operation.svg'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
stopPropagation,
usePrompt,
useSearchString,
DEFAULT_ROUTE_PROMPT_MESSAGE,
ApiQueuingWithBatch,
} from '@devtron-labs/devtron-fe-common-lib'
import { Prompt, useHistory, useLocation } from 'react-router-dom'
Expand All @@ -51,7 +52,6 @@ import { RestartStatusListDrawer } from './RestartStatusListDrawer'
import { importComponentFromFELibrary } from '../../../common'
import { AllExpandableDropdown } from './AllExpandableDropdown'
import { ReactComponent as Warn } from '../../../../assets/icons/ic-warning.svg'
import { DEFAULT_ROUTE_PROMPT_MESSAGE } from '../../../../config'

const BulkDeployResistanceTippy = importComponentFromFELibrary('BulkDeployResistanceTippy')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ import {
getStageTitle,
TriggerBlockType,
RuntimePluginVariables,
DEFAULT_ROUTE_PROMPT_MESSAGE,
triggerCDNode,
} from '@devtron-labs/devtron-fe-common-lib'
import Tippy from '@tippyjs/react'
import {
BUILD_STATUS,
DEFAULT_GIT_BRANCH_VALUE,
DEFAULT_ROUTE_PROMPT_MESSAGE,
NO_COMMIT_SELECTED,
URLS,
ViewType,
Expand All @@ -73,7 +74,6 @@ import {
getCIMaterialList,
getGitMaterialByCommitHash,
refreshGitMaterial,
triggerCDNode,
triggerCINode,
triggerBranchChange,
} from '../../../app/service'
Expand Down Expand Up @@ -1492,11 +1492,15 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
if (ciArtifact) {
_CDTriggerPromiseFunctionList.push(() =>
triggerCDNode({
pipelineId: node.id,
ciArtifactId: ciArtifact.id,
appId: currentAppId,
pipelineId: Number(node.id),
ciArtifactId: Number(ciArtifact.id),
appId: Number(currentAppId),
stageType: bulkTriggerType,
runtimeParams: runtimeParams[currentAppId] || [],
...(
getRuntimeParamsPayload
? { runtimeParamsPayload: getRuntimeParamsPayload(runtimeParams[currentAppId] ?? [])}
: {}
),
}),
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,19 @@
* limitations under the License.
*/

import { useState } from 'react'
import { Progressing, useDownload } from '@devtron-labs/devtron-fe-common-lib'
import { useDownload } from '@devtron-labs/devtron-fe-common-lib'
import { ResponseRowType, TriggerModalRowType } from '../../AppGroup.types'
import { ReactComponent as Error } from '../../../../assets/icons/ic-error-exclamation.svg'
import { ReactComponent as Success } from '../../../../assets/icons/appstatus/healthy.svg'
import { ReactComponent as Download } from '../../../../assets/icons/ic-arrow-line-down.svg'
import { ReactComponent as UnAuthorized } from '../../../../assets/icons/ic-locked.svg'
import { ReactComponent as ICInfoFilled } from '../../../../assets/icons/ic-info-filled.svg'
import { BulkResponseStatus } from '../../Constants'
import { importComponentFromFELibrary } from '../../../common'

const getDownloadManifestUrl = importComponentFromFELibrary('getDownloadManifestUrl', null, 'function')
const DownloadManifestForVirtualEnvironmentButton = importComponentFromFELibrary('DownloadManifestForVirtualEnvironmentButton', null, 'function')

export const TriggerModalRow = ({ rowData, index, isVirtualEnv, envName }: TriggerModalRowType) => {
const { isDownloading, handleDownload } = useDownload()
const [isDownloaded, setIsDownloaded] = useState(false)
const params = {
appId: rowData.appId,
envId: rowData.envId,
appName: `${rowData.appName}-${envName}`,
}
const { handleDownload } = useDownload()

const renderStatusIcon = (rowData: ResponseRowType): JSX.Element => {
if (rowData.status === BulkResponseStatus.SKIP) {
Expand All @@ -49,21 +41,9 @@ export const TriggerModalRow = ({ rowData, index, isVirtualEnv, envName }: Trigg
return <Error className="mr-8 icon-dim-18" />
}

const downloadPackage = (e) => {
e.stopPropagation()
if (!getDownloadManifestUrl) {
return
}
const downloadUrl = getDownloadManifestUrl(params)
const downloadError = handleDownload({ downloadUrl, fileName: params.appName, showSuccessfulToast: false })
if (!downloadError) {
setIsDownloaded(true)
}
}

return (
<div
className={`response-row pt-8 pb-8 ${isVirtualEnv ? 'is-virtual' : ''}`}
className={`response-row py-8 ${isVirtualEnv ? 'is-virtual' : ''}`}
key={`response-${rowData.appId}`}
>
<div className="fs-13 fw-4 cn-9">{rowData.appName}</div>
Expand All @@ -73,23 +53,13 @@ export const TriggerModalRow = ({ rowData, index, isVirtualEnv, envName }: Trigg
</div>
<div className="fs-13 fw-4 cn-9">{rowData.message}</div>
{isVirtualEnv && rowData.status === BulkResponseStatus.PASS && (
<div
className="flex right cursor"
data-testid={`bulk-cd-manifest-download-button-${index}`}
onClick={downloadPackage}
>
{isDownloading ? (
<span className="flex">
<Progressing />
<span className="fs-13 flex fw-4 ml-6 cn-7">Downloading</span>
</span>
) : (
<span className={`flex ${isDownloaded ? 'cn-5 scn-5' : 'cb-5'} `}>
<Download className="icon-dim-16" />
<span className="ml-6 fw-6 fs-13">Download</span>
</span>
)}
</div>
<DownloadManifestForVirtualEnvironmentButton
appId={rowData.appId}
envId={rowData.envId}
appName={`${rowData.appName}-${envName}`}
handleDownload={handleDownload}
showSuccessfulToast={false}
/>
)}
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
*/

import { useState } from 'react'
import { showError, DeleteDialog, InfoColourBar, ToastVariantType, ToastManager } from '@devtron-labs/devtron-fe-common-lib'
import { showError, DeleteDialog, InfoColourBar, ToastVariantType, ToastManager, deleteNodeCapacity } from '@devtron-labs/devtron-fe-common-lib'
import { useParams } from 'react-router-dom'
import { ReactComponent as Help } from '../../../assets/icons/ic-help.svg'
import { NodeActionModalPropType } from '../types'
import { deleteNodeCapacity } from '../clusterNodes.service'
import { DELETE_NODE_MODAL_MESSAGING } from '../constants'

export default function DeleteNodeModal({ name, version, kind, closePopup }: NodeActionModalPropType) {
Expand Down
14 changes: 5 additions & 9 deletions src/components/ClusterNodes/clusterNodes.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
* limitations under the License.
*/

import { get, post, put, ResponseType, trash, APIOptions } from '@devtron-labs/devtron-fe-common-lib'
import { get, post, put, ResponseType, APIOptions, ROUTES } from '@devtron-labs/devtron-fe-common-lib'
import { Routes } from '../../config'
import {
ClusterCapacityResponse,
ClusterListResponse,
NodeCordonRequest,
NodeActionRequest,
NodeDetailResponse,
NodeDrainRequest,
UpdateNodeRequestBody,
Expand Down Expand Up @@ -55,22 +54,19 @@ export const updateClusterShortDescription = (
): Promise<ResponseType> => put(`${Routes.CLUSTER_DESCRIPTION}`, requestPayload)

export const getNodeCapacity = (clusterId: string, nodeName: string): Promise<NodeDetailResponse> =>
get(`${Routes.NODE_CAPACITY}?clusterId=${clusterId}&name=${nodeName}`)
get(`${ROUTES.NODE_CAPACITY}?clusterId=${clusterId}&name=${nodeName}`)

export const cordonNodeCapacity = (requestPayload: NodeCordonRequest): Promise<ResponseType> =>
put(`${Routes.NODE_CAPACITY}/cordon`, requestPayload)
put(`${ROUTES.NODE_CAPACITY}/cordon`, requestPayload)

export const drainNodeCapacity = (requestPayload: NodeDrainRequest): Promise<ResponseType> =>
put(`${Routes.NODE_CAPACITY}/drain`, requestPayload)

export const deleteNodeCapacity = (requestPayload: NodeActionRequest, signal?: AbortSignal): Promise<ResponseType> =>
trash(Routes.NODE_CAPACITY, requestPayload, signal ? { signal } : {})
put(`${ROUTES.NODE_CAPACITY}/drain`, requestPayload)

export const updateNodeManifest = (
clusterId: string,
nodeName: string,
nodeData: UpdateNodeRequestBody,
): Promise<ResponseType> => put(`${Routes.NODE_CAPACITY}?clusterId=${clusterId}&name=${nodeName}`, nodeData)
): Promise<ResponseType> => put(`${ROUTES.NODE_CAPACITY}?clusterId=${clusterId}&name=${nodeName}`, nodeData)

export const clusterTerminalStart = (data: TerminalDataType, option: APIOptions): Promise<ResponseType> =>
post(`${Routes.CLUSTER_TERMINAL}/${Routes.START}`, data, option)
Expand Down
7 changes: 1 addition & 6 deletions src/components/ClusterNodes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
ClusterCapacityType,
ClusterDetail,
NodeTaintType,
NodeActionRequest,
} from '@devtron-labs/devtron-fe-common-lib'
import { UpdateTabUrlParamsType } from '@Components/common/DynamicTabs/Types'
import { LabelTag, OptionType } from '../app/types'
Expand Down Expand Up @@ -172,12 +173,6 @@ export interface TaintErrorObj {
}[]
}

export interface NodeActionRequest {
clusterId?: number
name: string
version: string
kind: string
}
export interface NodeActionModalPropType extends NodeActionRequest {
closePopup: (refreshData?: boolean) => void
}
Expand Down
87 changes: 1 addition & 86 deletions src/components/ResourceBrowser/ResourceBrowser.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,18 @@
import {
ApiResourceType,
get,
post,
ResponseType,
convertJSONPointerToJSONPath,
getK8sResourceList,
getIsRequestAborted,
showError,
getUrlWithSearchParams,
getK8sResourceListPayload,
stringComparatorBySortOrder,
} from '@devtron-labs/devtron-fe-common-lib'
import {
getManifestResource,
updateManifestResourceHelmApps,
} from '@Components/v2/appDetails/k8Resource/nodeDetail/nodeDetail.api'
import { applyOperation, escapePathComponent } from 'fast-json-patch'
import { JSONPath } from 'jsonpath-plus'
import { SelectedResourceType } from '@Components/v2/appDetails/appDetails.type'
import { RefObject } from 'react'
import { Routes } from '../../config'
import { ClusterListResponse } from '../../services/service.types'
import { ResourceListPayloadType, ResourceType, GetResourceDataType, NodeRowDetail, URLParams } from './Types'
import { GetResourceDataType, NodeRowDetail, URLParams } from './Types'
import { SIDEBAR_KEYS } from './Constants'
import { parseNodeList } from './Utils'

Expand All @@ -64,82 +55,6 @@ export const getResourceGroupList = (clusterId: string, signal?: AbortSignal): P
signal,
})

export const deleteResource = (
resourceListPayload: ResourceListPayloadType,
signal?: AbortSignal,
): Promise<ResponseType<ResourceType[]>> => post(Routes.DELETE_RESOURCE, resourceListPayload, signal ? { signal } : {})

export const restartWorkload = async (resource: SelectedResourceType, signal: AbortSignal) => {
const {
result: {
manifestResponse: { manifest },
},
} = await getManifestResource(null, '', '', true, resource, signal)

if (!manifest) {
return
}

const metadataPath = '/spec/template/metadata'
const annotationsPath = `${metadataPath}/annotations`
const restartLabel = 'devtron/restart'

const jsonpathProps = {
json: manifest,
wrap: false,
resultType: 'value',
} as const

const dateString = new Date().toISOString()

if (!JSONPath({ path: convertJSONPointerToJSONPath(metadataPath), ...jsonpathProps })) {
applyOperation(
manifest,
{
op: 'add',
path: metadataPath,
value: {
annotations: {
[restartLabel]: dateString,
},
},
},
false,
true,
)
} else if (
!JSONPath({
path: convertJSONPointerToJSONPath(annotationsPath),
...jsonpathProps,
})
) {
applyOperation(
manifest,
{
op: 'add',
path: annotationsPath,
value: { [restartLabel]: dateString },
},
false,
true,
)
} else {
applyOperation(
manifest,
{
op: 'add',
// NOTE: we only need to escape / in restartLabel when making a path out of it
path: `${annotationsPath}/${escapePathComponent(restartLabel)}t`,
value: dateString,
},
false,
true,
)
}

await updateManifestResourceHelmApps(null, '', '', JSON.stringify(manifest), true, resource, signal)
}

export const getNodeList = (
clusterId: string,
abortControllerRef: RefObject<AbortController>,
Expand Down
Loading
Loading