Skip to content

Commit

Permalink
fix: reload kubeConfig when changing config path
Browse files Browse the repository at this point in the history
  • Loading branch information
mortada-codes committed Feb 21, 2023
1 parent e35e1e1 commit de4974d
Show file tree
Hide file tree
Showing 33 changed files with 70 additions and 34 deletions.
2 changes: 1 addition & 1 deletion electron/app/createWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export const createWindow = (givenPath?: string) => {
await checkNewVersion(dispatch, true);
}, NEW_VERSION_CHECK_INTERVAL);

initKubeconfig(dispatch, userHomeDir);
initKubeconfig(dispatch, userHomeDir, utilsElectronStore.get('appConfig.kubeConfig'));
dispatch({type: 'main/setAppRehydrating', payload: false});

const missingDependencies = checkMissingDependencies(APP_DEPENDENCIES);
Expand Down
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import semver from 'semver';

import {TelemetryDocumentationUrl} from '@constants/tooltips';

import {setCreateProject, setDeleteProject, setLoadingProject, setOpenProject} from '@redux/appConfig';
import {toggleForm} from '@redux/forms';
import {setIsGitInstalled} from '@redux/git';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {setAlert} from '@redux/reducers/alert';
import {setCreateProject, setDeleteProject, setLoadingProject, setOpenProject} from '@redux/reducers/appConfig';
import {clearNotifications, closePreviewConfigurationEditor} from '@redux/reducers/main';
import {closeFolderExplorer, closeReleaseNotesDrawer, openWelcomePopup, toggleNotifications} from '@redux/reducers/ui';
import {isInClusterModeSelector} from '@redux/selectors';
Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules/CommandPreview/CommandLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {Modal} from 'antd';

import {cloneDeep} from 'lodash';

import {updateProjectConfig} from '@redux/appConfig';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {setAlert} from '@redux/reducers/alert';
import {updateProjectConfig} from '@redux/reducers/appConfig';
import {openSaveEditCommandModal} from '@redux/reducers/ui';

import {AlertEnum} from '@shared/models/alert';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {toggleEditorPlaceholderVisiblity} from '@redux/appConfig';
import {useAppDispatch} from '@redux/hooks';
import {toggleEditorPlaceholderVisiblity} from '@redux/reducers/appConfig';

import MonacoPlaceholderImage from '@assets/MonacoPlaceholderImage.svg';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {notification} from 'antd';

import {toggleErrorReporting, toggleEventTracking, updateTelemetry} from '@redux/appConfig';
import {setAlert} from '@redux/reducers/alert';
import {toggleErrorReporting, toggleEventTracking, updateTelemetry} from '@redux/reducers/appConfig';
import {setActiveSettingsPanel, toggleNotifications} from '@redux/reducers/ui';
import store from '@redux/store';

Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules_new/ProjectCard/ProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {DeleteOutlined, ExclamationCircleOutlined, PushpinFilled, PushpinOutline

import {TOOLTIP_DELAY} from '@constants/constants';

import {setDeleteProject, setOpenProject, toggleProjectPin} from '@redux/appConfig';
import {useAppDispatch} from '@redux/hooks';
import {setDeleteProject, setOpenProject, toggleProjectPin} from '@redux/reducers/appConfig';
import {toggleStartProjectPane} from '@redux/reducers/ui';

import {getRelativeDate} from '@utils/index';
Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules_new/ProjectsList/ProjectsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {PlusOutlined} from '@ant-design/icons';

import {orderBy, size} from 'lodash';

import {sortProjects} from '@redux/appConfig';
import {useAppSelector} from '@redux/hooks';
import {sortProjects} from '@redux/reducers/appConfig';

import {ProjectCard} from '@components/molecules_new';

Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/GitCloneModal/GitCloneModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {sep} from 'path';

import {DEFAULT_GIT_REPO_PLACEHOLDER, VALID_URL_REGEX} from '@constants/constants';

import {setCreateProject} from '@redux/appConfig';
import {closeGitCloneModal} from '@redux/git';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {setCreateProject} from '@redux/reducers/appConfig';

import {FileExplorer} from '@atoms';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {v4 as uuid} from 'uuid';

import {CLUSTER_AVAILABLE_COLORS, TOOLTIP_DELAY} from '@constants/constants';

import {setCurrentContext, setKubeConfigContextColor, updateClusterNamespaces} from '@redux/appConfig';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {setAlert} from '@redux/reducers/alert';
import {setCurrentContext, setKubeConfigContextColor, updateClusterNamespaces} from '@redux/reducers/appConfig';
import {kubeConfigContextsSelector} from '@redux/selectors';

import {FilePatternList} from '@atoms';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Dropdown, Typography} from 'antd';

import {updateK8sVersion, updateProjectK8sVersion} from '@redux/appConfig';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {updateK8sVersion, updateProjectK8sVersion} from '@redux/reducers/appConfig';
import {currentConfigSelector} from '@redux/selectors';
import {downloadK8sSchema} from '@redux/thunks/downloadK8sSchema';
import {setConfigK8sSchemaVersion} from '@redux/validation/validation.slice';
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/PageHeader/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import newGithubIssueUrl from 'new-github-issue-url';
import {TOOLTIP_DELAY} from '@constants/constants';
import {InitializeGitTooltip, InstallGitTooltip, NotificationsTooltip} from '@constants/tooltips';

import {updateProjectsGitRepo} from '@redux/appConfig';
import {setCurrentBranch, setRepo} from '@redux/git';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {updateProjectsGitRepo} from '@redux/reducers/appConfig';
import {setAutosavingError} from '@redux/reducers/main';
import {setIsInQuickClusterMode, setLayoutSize, toggleNotifications, toggleStartProjectPane} from '@redux/reducers/ui';
import {isInClusterModeSelector, isInPreviewModeSelectorNew, kubeConfigContextColorSelector} from '@redux/selectors';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {v4 as uuidv4} from 'uuid';
import {HELM_INSTALL_OPTIONS_DOCS_URL, HELM_TEMPLATE_OPTIONS_DOCS_URL} from '@constants/constants';
import {helmInstallOptions, helmTemplateOptions} from '@constants/helmOptions';

import {updateProjectConfig} from '@redux/appConfig';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {updateProjectConfig} from '@redux/reducers/appConfig';
import {closePreviewConfigurationEditor} from '@redux/reducers/main';
import {startPreview} from '@redux/services/preview';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {useForm} from 'antd/lib/form/Form';
import {cloneDeep} from 'lodash';
import {v4 as uuid} from 'uuid';

import {updateProjectConfig} from '@redux/appConfig';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {setAlert} from '@redux/reducers/alert';
import {updateProjectConfig} from '@redux/reducers/appConfig';
import {closeSaveEditCommandModal} from '@redux/reducers/ui';

import {ROOT_FILE_ENTRY} from '@shared/constants/fileEntry';
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/UpdateNotice/UpdateNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {Button} from 'antd';

import {CloseOutlined} from '@ant-design/icons';

import {updateNewVersion} from '@redux/appConfig';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {updateNewVersion} from '@redux/reducers/appConfig';

import NewUpdate from '@assets/NewUpdate.svg';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {existsSync} from 'fs';
import {includes, isEmpty} from 'lodash';
import path from 'path';

import {setCreateProject} from '@redux/appConfig';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {setCreateProject} from '@redux/reducers/appConfig';
import {closeCreateProjectModal, openTemplateExplorer, setTemplateProjectCreate} from '@redux/reducers/ui';

import {FileExplorer} from '@atoms';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {ExclamationCircleOutlined} from '@ant-design/icons';

import {basename, dirname, join} from 'path';

import {updateProjectConfig} from '@redux/appConfig';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {setAlert} from '@redux/reducers/alert';
import {updateProjectConfig} from '@redux/reducers/appConfig';
import {openCreateFileFolderModal, openNewResourceWizard, openRenameEntityModal} from '@redux/reducers/ui';
import {scanExcludesSelector} from '@redux/selectors';
import {useResourceMetaMapRef} from '@redux/selectors/resourceMapSelectors';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {changeCurrentProjectName, updateProjectConfig} from '@redux/appConfig';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {changeCurrentProjectName, updateProjectConfig} from '@redux/reducers/appConfig';
import {currentConfigSelector} from '@redux/selectors';

import {Project, ProjectConfig} from '@shared/models/config';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import _ from 'lodash';

import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {
setKubeConfig,
updateApplicationSettings,
updateFileIncludes,
updateFolderReadsMaxDepth,
updateK8sVersion,
updateScanExcludes,
} from '@redux/reducers/appConfig';
} from '@redux/appConfig';
import {useAppDispatch, useAppSelector} from '@redux/hooks';

import {PREDEFINED_K8S_VERSION} from '@shared/constants/k8s';
import {ProjectConfig} from '@shared/models/config';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import _ from 'lodash';
import {DEFAULT_KUBECONFIG_DEBOUNCE, TOOLTIP_DELAY} from '@constants/constants';
import {AutoLoadLastProjectTooltip, TelemetryDocumentationUrl} from '@constants/tooltips';

import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {
changeProjectsRootPath,
toggleErrorReporting,
toggleEventTracking,
updateClusterSelectorVisibilty,
updateFileExplorerSortOrder,
updateLoadLastProjectOnStartup,
} from '@redux/reducers/appConfig';
} from '@redux/appConfig';
import {useAppDispatch, useAppSelector} from '@redux/hooks';

import {FileExplorer} from '@components/atoms';

Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms_new/StartPage/StartPageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import _ from 'lodash';
import {TOOLTIP_DELAY} from '@constants/constants';
import {NotificationsTooltip} from '@constants/tooltips';

import {setOpenProject} from '@redux/appConfig';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {setOpenProject} from '@redux/reducers/appConfig';
import {setShowStartPageLearn, toggleNotifications} from '@redux/reducers/ui';

import {WelcomePopupContent} from '@molecules';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {Skeleton} from 'antd';

import {Primitive} from 'type-fest';

import {setCreateProject} from '@redux/appConfig';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {setCreateProject} from '@redux/reducers/appConfig';
import {kubeConfigPathSelector} from '@redux/selectors';
import {createTransientResourcesFromVanillaTemplate} from '@redux/services/templates';
import {previewReferencedHelmChart} from '@redux/thunks/previewReferencedHelmChart';
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/fileTreeHooks/useProcessing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {Modal} from 'antd';

import {ExclamationCircleOutlined} from '@ant-design/icons';

import {updateProjectConfig} from '@redux/appConfig';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {updateProjectConfig} from '@redux/reducers/appConfig';
import {scanExcludesSelector} from '@redux/selectors';

import {useSelectorWithRef} from '@utils/hooks';
Expand Down
31 changes: 31 additions & 0 deletions src/redux/appConfig/appConfig.listeners.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as k8s from '@kubernetes/client-node';

import {AppListenerFn} from '@redux/listeners/base';

import {KubeConfigContext} from '@shared/models/config';

import {setKubeConfig} from './appConfig.slice';

const loadKubeConfigListener: AppListenerFn = listen => {
listen({
actionCreator: setKubeConfig,
async effect(_action, {dispatch, delay, signal, cancelActiveListeners}) {
// Cancel any other listeners that are listening to the same action
cancelActiveListeners();
const configPath = _action.payload.path;
if (!configPath) {
return;
}

try {
const kc = new k8s.KubeConfig();
kc.loadFromFile(configPath);
dispatch(setKubeConfig({isPathValid: true, contexts: kc.contexts as KubeConfigContext[]}));
} catch (error) {
dispatch(setKubeConfig({isPathValid: false, contexts: []}));
}
},
});
};

export const appConfigListeners = [loadKubeConfigListener];
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import electronStore from '@shared/utils/electronStore';
import {createKubeClient, getKubeAccess} from '@shared/utils/kubeclient';

import initialState from '../initialState';
import {setLeftBottomMenuSelection, setLeftMenuSelection, toggleStartProjectPane} from './ui';
import {setLeftBottomMenuSelection, setLeftMenuSelection, toggleStartProjectPane} from '../reducers/ui';

export const setCreateProject = createAsyncThunk('config/setCreateProject', async (project: Project, thunkAPI: any) => {
const isGitRepo = await promiseFromIpcRenderer(
Expand Down Expand Up @@ -234,6 +234,8 @@ export const configSlice = createSlice({
},
setKubeConfig: (state: Draft<AppConfig>, action: PayloadAction<KubeConfig>) => {
state.kubeConfig = {...state.kubeConfig, ...action.payload};
electronStore.set('appConfig.kubeConfig', state.kubeConfig.path);

new KubeConfigManager().initializeKubeConfig(state.kubeConfig.path as string, state.kubeConfig.currentContext);
},
createProject: (state: Draft<AppConfig>, action: PayloadAction<Project>) => {
Expand Down
1 change: 1 addition & 0 deletions src/redux/appConfig/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './appConfig.slice';
2 changes: 1 addition & 1 deletion src/redux/services/gitFolderMonitor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {FSWatcher, watch} from 'chokidar';
import {sep} from 'path';

import {updateProjectsGitRepo} from '@redux/appConfig';
import {setBranchCommits, setChangedFiles, setCommits, setRepo} from '@redux/git';
import {updateProjectsGitRepo} from '@redux/reducers/appConfig';

import {promiseFromIpcRenderer} from '@utils/promises';

Expand Down
4 changes: 2 additions & 2 deletions src/redux/services/monitorKubeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import fs from 'fs';
import log from 'loglevel';
import {AnyAction} from 'redux';

import {setAlert} from '@redux/reducers/alert';
import {
addNamespaceToContext,
removeNamespaceFromContext,
setAccessLoading,
updateProjectKubeConfig,
} from '@redux/reducers/appConfig';
} from '@redux/appConfig';
import {setAlert} from '@redux/reducers/alert';

import {AlertEnum} from '@shared/models/alert';
import {KubeConfig, KubeConfigContext} from '@shared/models/config';
Expand Down
2 changes: 1 addition & 1 deletion src/redux/services/projectConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {sep} from 'path';
import {AnyAction} from 'redux';
import invariant from 'tiny-invariant';

import {updateProjectConfig} from '@redux/reducers/appConfig';
import {updateProjectConfig} from '@redux/appConfig';

import {K8S_VERSIONS, PREDEFINED_K8S_VERSION} from '@shared/constants/k8s';
import {AppConfig, ProjectConfig} from '@shared/models/config';
Expand Down
4 changes: 3 additions & 1 deletion src/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import {createLogger} from 'redux-logger';

import {sectionBlueprintMiddleware} from '@src/navsections/sectionBlueprintMiddleware';

import {configSlice, crdsPathChangedListener, k8sVersionSchemaListener} from './appConfig';
import {appConfigListeners} from './appConfig/appConfig.listeners';
import * as compareListeners from './compare/listeners';
import {compareSlice} from './compare/slice';
import {dashboardSlice} from './dashboard';
import {formSlice} from './forms';
import {gitSlice} from './git';
import {combineListeners, listenerMiddleware} from './listeners/base';
import {alertSlice} from './reducers/alert';
import {configSlice, crdsPathChangedListener, k8sVersionSchemaListener} from './reducers/appConfig';
import {extensionSlice} from './reducers/extension';
import {mainSlice} from './reducers/main';
import {imageListParserListener} from './reducers/main/mainListeners';
Expand Down Expand Up @@ -43,6 +44,7 @@ combineListeners([
k8sVersionSchemaListener,
crdsPathChangedListener,
...validationListeners,
...appConfigListeners,
imageListParserListener,
]);

Expand Down
2 changes: 1 addition & 1 deletion src/redux/thunks/cluster/startClusterConnection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createAsyncThunk} from '@reduxjs/toolkit';

import {setClusterProxyPort} from '@redux/reducers/appConfig';
import {setClusterProxyPort} from '@redux/appConfig';
import {disconnectFromCluster} from '@redux/services/clusterResourceWatcher';
import {stopPreview} from '@redux/services/preview';

Expand Down
2 changes: 1 addition & 1 deletion src/redux/thunks/cluster/stopClusterConnection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createAsyncThunk} from '@reduxjs/toolkit';

import {setClusterProxyPort} from '@redux/reducers/appConfig';
import {setClusterProxyPort} from '@redux/appConfig';
import {disconnectFromCluster} from '@redux/services/clusterResourceWatcher';

import {AppDispatch} from '@shared/models/appDispatch';
Expand Down
2 changes: 1 addition & 1 deletion src/redux/thunks/previewConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {createAsyncThunk} from '@reduxjs/toolkit';

import {cloneDeep} from 'lodash';

import {updateProjectConfig} from '@redux/reducers/appConfig';
import {updateProjectConfig} from '@redux/appConfig';
import {clearSelection, selectFile} from '@redux/reducers/main';

import {AppDispatch} from '@shared/models/appDispatch';
Expand Down
2 changes: 1 addition & 1 deletion src/redux/validation/validation.listeners.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {isAnyOf} from '@reduxjs/toolkit';

import {isEmpty, isEqual} from 'lodash';

import {updateK8sVersion, updateProjectK8sVersion} from '@redux/appConfig';
import {AppListenerFn} from '@redux/listeners/base';
import {updateK8sVersion, updateProjectK8sVersion} from '@redux/reducers/appConfig';
import {addMultipleResources, addResource, clearPreview, clearPreviewAndSelectionHistory} from '@redux/reducers/main';
import {setIsInQuickClusterMode} from '@redux/reducers/ui';
import {currentConfigSelector} from '@redux/selectors';
Expand Down

0 comments on commit de4974d

Please sign in to comment.