Skip to content

Commit

Permalink
fix: update resource in cluster mode
Browse files Browse the repository at this point in the history
  • Loading branch information
topliceanurazvan committed Mar 31, 2023
1 parent fb8d58b commit a391f2f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const Drawer = styled(RawDrawer)`
& .ant-drawer-content {
background: ${Colors.grey1};
}
z-index: 10000;
z-index: 1000;
& .ant-drawer-close {
position: absolute;
Expand Down
7 changes: 6 additions & 1 deletion src/components/organisms/Dashboard/Tableview/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const Drawer = () => {
const selectedResourceId = useAppSelector(state => state.dashboard.tableDrawer.selectedResourceId);
const clusterResourceMetaMap = useResourceMetaMap('cluster');
const activeTab = useAppSelector(state => state.dashboard.ui.activeTab);
const isApplyingResource = useAppSelector(state => state.main.isApplyingResource);

const selectedResource = useResource(selectedResourceId ? {id: selectedResourceId, storage: 'cluster'} : undefined);

Expand Down Expand Up @@ -115,7 +116,11 @@ export const Drawer = () => {
<S.TabsFooter>
<S.ActionButtons>
{activeTab === 'Manifest' && (
<S.ActionButton disabled={!selectedResource} onClick={() => handleApplyResource()}>
<S.ActionButton
loading={isApplyingResource}
disabled={!selectedResource}
onClick={() => handleApplyResource()}
>
Update
</S.ActionButton>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/LazyDrawer/LazyDrawer.styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Drawer as RawDrawer} from 'antd';
import styled from 'styled-components';

export const Drawer = styled(RawDrawer)`
z-index: 100;
z-index: 1000;
& .ant-drawer-close {
position: absolute;
Expand Down
1 change: 1 addition & 0 deletions src/components/organisms/MessageBox/MessageBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const MessageBox: React.FC = () => {
/>
),
duration: alert.duration || 4,
style: {zIndex: '10000'},
});
}

Expand Down
14 changes: 12 additions & 2 deletions src/redux/thunks/applyResource.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createAsyncThunk} from '@reduxjs/toolkit';

import _ from 'lodash';
import _, {cloneDeep} from 'lodash';
import log from 'loglevel';
import {stringify} from 'yaml';

Expand Down Expand Up @@ -99,7 +99,16 @@ export async function applyResource(
) {
const showAlert = options?.quiet !== true;
const resourceMeta = resourceMetaMapByStorage[resourceIdentifeir.storage][resourceIdentifeir.id];
const resourceContent = resourceContentMapByStorage[resourceIdentifeir.storage][resourceIdentifeir.id];

const resourceContent = cloneDeep(resourceContentMapByStorage[resourceIdentifeir.storage][resourceIdentifeir.id]);

// Related to this https://stackoverflow.com/questions/51297136/kubectl-error-the-object-has-been-modified-please-apply-your-changes-to-the-la
// We need to remove certain properties before updating the resource in cluster mode
if (options?.isInClusterMode) {
delete resourceContent.object.metadata.creationTimestamp;
delete resourceContent.object.metadata.resourceVersion;
}

try {
if (resourceMeta) {
dispatch(setApplyingResource(true));
Expand Down Expand Up @@ -167,6 +176,7 @@ export async function applyResource(
}

const alert = errorAlert(`Applying ${resourceMeta.name} to cluster ${context} failed`, result.stderr);

if (showAlert) dispatch(setAlert(alert));
dispatch(setApplyingResource(false));
}
Expand Down

0 comments on commit a391f2f

Please sign in to comment.