Skip to content

Commit

Permalink
Merge pull request #4204 from kubeshop/olelensmar/fix/overlay-update-…
Browse files Browse the repository at this point in the history
…during-dryrun

Improves handling of overlays during dry-runs
  • Loading branch information
olensmar authored Dec 7, 2023
2 parents aa7f8b1 + e04ff9c commit f85c0c1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ const DryRunsPane: React.FC = () => {
return false;
});

rowVirtualizer.scrollToIndex(index);
if (index >= 0) {
rowVirtualizer.scrollToIndex(index);
}
}, [preview, list, rowVirtualizer]);

if (isLoading) {
Expand Down
2 changes: 1 addition & 1 deletion src/redux/selectors/dryRunsSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const dryRunLabelSelector = createSelector(

if (preview.type === 'kustomize') {
const resource = localResourceMetaMap[preview.kustomizationId];
return basename(resource.name);
return resource ? basename(resource.name) : 'Kustomize Overlay';
}

if (preview.type === 'helm') {
Expand Down
3 changes: 3 additions & 0 deletions src/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {Middleware, combineReducers, configureStore, createAction} from '@reduxj

import {createLogger} from 'redux-logger';

import {shouldStopKustomizeDryRunListener} from '@redux/thunks/listeners/shouldStopKustomizeDryRunListener';

import {editorSlice} from '@editor/editor.slice';
import {editorListeners} from '@editor/listeners';

Expand Down Expand Up @@ -55,6 +57,7 @@ combineListeners([
...appConfigListeners,
...clusterListeners,
imageListParserListener,
shouldStopKustomizeDryRunListener,
]);

const appReducer = combineReducers({
Expand Down
25 changes: 25 additions & 0 deletions src/redux/thunks/listeners/shouldStopKustomizeDryRunListener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {isAnyOf} from '@reduxjs/toolkit';

import {AppListenerFn} from '@redux/listeners/base';
import {multiplePathsChanged} from '@redux/thunks/multiplePathsChanged';
import {stopPreview} from '@redux/thunks/preview';
import {updateFileEntry} from '@redux/thunks/updateFileEntry';

export const shouldStopKustomizeDryRunListener: AppListenerFn = listen => {
listen({
matcher: isAnyOf(updateFileEntry.fulfilled, multiplePathsChanged.fulfilled),
effect: (action, listenerApi) => {
listenerApi.cancelActiveListeners();

const mainState = listenerApi.getState().main;

// check if the update resulted in the removal of the currently dry-run kustomize overlay
if (
mainState.preview?.type === 'kustomize' &&
!mainState.resourceMetaMapByStorage.local[mainState.preview.kustomizationId]
) {
listenerApi.dispatch(stopPreview());
}
},
});
};
11 changes: 8 additions & 3 deletions src/redux/thunks/updateFileEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,14 @@ export const updateFileEntry = createAsyncThunk<
});

const newHighlights: AppSelection[] = [];
Object.values(extractedResources).forEach(r => {
fileSideEffect.affectedResourceIds.push(r.id);
Object.values(extractedResources).forEach((r, ix) => {
// if we're just replacing one resource with another consider this an update
if (extractedResources.length === fileSideEffect.affectedResourceIds.length) {
r.id = fileSideEffect.affectedResourceIds[ix];
} else {
fileSideEffect.affectedResourceIds.push(r.id);
}

const {meta, content} = splitK8sResource(r);
mainState.resourceMetaMapByStorage.local[meta.id] = meta;
mainState.resourceContentMapByStorage.local[content.id] = content;
Expand All @@ -101,7 +107,6 @@ export const updateFileEntry = createAsyncThunk<
},
});
});
mainState.highlights = newHighlights;
}
}

Expand Down

0 comments on commit f85c0c1

Please sign in to comment.