Skip to content

Commit 851f2f5

Browse files
Merge pull request #395 from devtron-labs/feat/rb-sync-cluster
feat: rb sync cluster
2 parents b1b8a16 + b990093 commit 851f2f5

File tree

16 files changed

+163
-7
lines changed

16 files changed

+163
-7
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.2.14",
3+
"version": "1.2.15",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Assets/Icon/ic-tilde.svg

Lines changed: 3 additions & 0 deletions
Loading

src/Common/Constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const URLS = {
6969
NETWORK_STATUS_INTERFACE: '/network-status-interface',
7070
CONFIG_DRIFT: 'config-drift',
7171
RESOURCE_BROWSER: '/resource-browser',
72+
COMPARE_CLUSTERS: '/compare-clusters',
7273
}
7374

7475
export const ROUTES = {
@@ -78,6 +79,8 @@ export const ROUTES = {
7879
PROJECT_LIST_MIN: 'team/autocomplete',
7980
USER_CHECK_ROLE: 'user/check/roles',
8081
IMAGE_TAGGING: 'app/image-tagging',
82+
CREATE_RESOURCE: 'k8s/resource/create',
83+
K8S_RESOURCE_CREATE: 'k8s/resources/apply',
8184
CI_CONFIG_GET: 'app/ci-pipeline',
8285
CD_MATERIAL_GET: 'app/cd-pipeline',
8386
DEPLOYMENT_TEMPLATE_LIST: 'app/template/list',
@@ -116,6 +119,7 @@ export const ROUTES = {
116119
DEPLOYMENT_CHARTS_LIST: 'deployment/template/fetch',
117120
USER_LIST_MIN: 'user/list/min',
118121
CONFIG_DATA: 'config/data',
122+
K8S_RESOURCE: 'k8s/resource',
119123
K8S_RESOURCE_LIST: 'k8s/resource/list',
120124
CONFIG_COMPARE_SECRET: 'config/compare/secret',
121125
}

src/Pages/ResourceBrowser/Helper.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
*/
1616

1717
import { AggregationKeys, NodeType, Nodes } from '../../Shared'
18+
import { ALL_NAMESPACE_OPTION } from './constants'
19+
import {
20+
ApiResourceGroupType,
21+
CreateResourceRequestBodyParamsType,
22+
CreateResourceRequestBodyType,
23+
} from './ResourceBrowser.Types'
1824

1925
export function getAggregator(nodeType: NodeType, defaultAsOtherResources?: boolean): AggregationKeys {
2026
switch (nodeType) {
@@ -65,3 +71,46 @@ export function getAggregator(nodeType: NodeType, defaultAsOtherResources?: bool
6571
return defaultAsOtherResources ? AggregationKeys['Other Resources'] : AggregationKeys['Custom Resource']
6672
}
6773
}
74+
75+
export const getK8sResourceListPayload = (
76+
clusterId: string,
77+
namespace: string,
78+
selectedResource: ApiResourceGroupType,
79+
filters: object,
80+
) => ({
81+
clusterId: +clusterId,
82+
k8sRequest: {
83+
resourceIdentifier: {
84+
groupVersionKind: selectedResource.gvk,
85+
...(selectedResource.namespaced && {
86+
namespace: namespace === ALL_NAMESPACE_OPTION.value ? '' : namespace,
87+
}),
88+
},
89+
},
90+
...filters,
91+
})
92+
93+
export const createResourceRequestBody = ({
94+
clusterId,
95+
group,
96+
version,
97+
kind,
98+
name,
99+
namespace,
100+
updatedManifest,
101+
}: CreateResourceRequestBodyParamsType): CreateResourceRequestBodyType => ({
102+
appId: '',
103+
clusterId,
104+
k8sRequest: {
105+
resourceIdentifier: {
106+
groupVersionKind: {
107+
Group: group || '',
108+
Version: version || 'v1',
109+
Kind: kind,
110+
},
111+
namespace,
112+
name,
113+
},
114+
...(updatedManifest && { patch: updatedManifest }),
115+
},
116+
})

src/Pages/ResourceBrowser/ResourceBrowser.Types.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,27 @@ export interface BulkSelectionActionWidgetProps {
7676
showBulkRestartOption: boolean
7777
}
7878

79+
interface BulkOperationAdditionalKeysType {
80+
label: string
81+
value: string
82+
isSortable: boolean
83+
/**
84+
* width to be given in gridTemplateColumns
85+
*/
86+
width: string
87+
}
88+
7989
export interface BulkOperation {
8090
name: string
91+
/**
92+
* Would these keys beside the name
93+
*/
94+
additionalKeys?: BulkOperationAdditionalKeysType[]
8195
operation: (signal: AbortSignal, data?: unknown) => Promise<void>
8296
}
8397

8498
export type BulkOperationModalProps = {
85-
operationType: 'restart' | 'delete'
99+
operationType: 'restart' | 'delete' | 'creation'
86100
clusterName: string
87101
operations: NonNullable<BulkOperation[]>
88102
handleModalClose: () => void
@@ -93,3 +107,40 @@ export type BulkOperationModalProps = {
93107
}
94108

95109
export type BulkOperationModalState = BulkOperationModalProps['operationType'] | 'closed'
110+
111+
export interface CreateResourceRequestBodyType {
112+
appId: string
113+
clusterId: number
114+
k8sRequest: {
115+
resourceIdentifier: Required<K8sRequestResourceIdentifierType>
116+
patch?: string
117+
}
118+
}
119+
120+
export interface ResourceManifestDTO {
121+
manifestResponse: {
122+
manifest: Record<string, unknown>
123+
}
124+
secretViewAccess: boolean
125+
}
126+
127+
export interface CreateResourceRequestBodyParamsType
128+
extends Pick<CreateResourceRequestBodyType, 'clusterId'>,
129+
Required<Pick<K8sRequestResourceIdentifierType, 'name' | 'namespace'>> {
130+
updatedManifest?: string
131+
group: GVKType['Group']
132+
version: GVKType['Version']
133+
kind: GVKType['Kind']
134+
}
135+
136+
export interface CreateResourcePayload {
137+
clusterId: number
138+
manifest: string
139+
}
140+
141+
export interface CreateResourceDTO {
142+
kind: string
143+
name: string
144+
isUpdate: boolean
145+
error: string
146+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { SelectPickerOptionType } from '@Shared/Components'
2+
3+
export const ALL_NAMESPACE_OPTION: Readonly<Pick<SelectPickerOptionType, 'value' | 'label'>> = {
4+
value: 'all',
5+
label: 'All namespaces',
6+
}

src/Pages/ResourceBrowser/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616

1717
export * from './ResourceBrowser.Types'
1818
export * from './Helper'
19+
export * from './constants'
1920
export * from './types'
2021
export * from './service'

src/Pages/ResourceBrowser/service.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { post } from '@Common/Api'
22
import { ROUTES } from '@Common/Constants'
33
import { ResponseType } from '@Common/Types'
4-
import { K8sResourceDetailType, K8sResourceListPayloadType } from './ResourceBrowser.Types'
4+
import {
5+
CreateResourceDTO,
6+
CreateResourcePayload,
7+
K8sResourceDetailType,
8+
K8sResourceListPayloadType,
9+
} from './ResourceBrowser.Types'
510

611
export const getK8sResourceList = (
712
resourceListPayload: K8sResourceListPayloadType,
@@ -10,3 +15,7 @@ export const getK8sResourceList = (
1015
post(ROUTES.K8S_RESOURCE_LIST, resourceListPayload, {
1116
signal,
1217
})
18+
19+
export const createNewResource = (
20+
resourceListPayload: CreateResourcePayload,
21+
): Promise<ResponseType<CreateResourceDTO[]>> => post(ROUTES.K8S_RESOURCE_CREATE, resourceListPayload)

src/Shared/Components/BulkSelection/BulkSelection.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { ReactComponent as ICCheckSquare } from '../../../Assets/Icon/ic-check-s
2424
import { ReactComponent as ICCheckAll } from '../../../Assets/Icon/ic-check-all.svg'
2525
import { ReactComponent as ICClose } from '../../../Assets/Icon/ic-close.svg'
2626

27-
const BulkSelection = <T,>({ showPagination, disabled = false }: BulkSelectionProps) => {
27+
const BulkSelection = <T,>({ showPagination, disabled = false, showChevronDownIcon = true }: BulkSelectionProps) => {
2828
const { handleBulkSelection, isChecked, checkboxValue, getSelectedIdentifiersCount } = useBulkSelection<T>()
2929
const areOptionsSelected = getSelectedIdentifiersCount() > 0
3030
const BulkSelectionItems: BulkSelectionDropdownItemsType[] = [
@@ -74,7 +74,7 @@ const BulkSelection = <T,>({ showPagination, disabled = false }: BulkSelectionPr
7474
// Ideally should be disabled but was giving issue with cursor
7575
/>
7676

77-
<ICChevronDown className="icon-dim-20 fcn-6 dc__no-shrink" />
77+
{showChevronDownIcon && <ICChevronDown className="icon-dim-20 fcn-6 dc__no-shrink" />}
7878
</PopupMenu.Button>
7979

8080
<PopupMenu.Body rootClassName="dc__top-22 w-150 dc__right-0 pt-4 pb-4 pl-0 pr-0 bcn-0 flex column dc__content-start dc__align-start dc__position-abs bcn-0 dc__border dc__border-radius-4-imp">

0 commit comments

Comments
 (0)