Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent deletion of active connection secrets when updating note… #3445

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -154,6 +154,7 @@ const SpawnerFooter: React.FC<SpawnerFooterProps> = ({
envVariables,
dataConnection,
existingNotebookDataConnection,
connections,
dryRun,
);

Expand Down
9 changes: 6 additions & 3 deletions frontend/src/pages/projects/screens/spawner/SpawnerPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ const SpawnerPage: React.FC<SpawnerPageProps> = ({ existingNotebook }) => {
defaultStorageClassName,
);

const [envVariables, setEnvVariables, envVariablesLoaded, deletedConfigMaps, deletedSecrets] =
useNotebookEnvVariables(existingNotebook);

const [dataConnectionData, setDataConnectionData] = useNotebookDataConnection(
dataConnections.data,
existingNotebook,
Expand All @@ -103,6 +100,12 @@ const SpawnerPage: React.FC<SpawnerPageProps> = ({ existingNotebook }) => {
: [],
);

const [envVariables, setEnvVariables, envVariablesLoaded, deletedConfigMaps, deletedSecrets] =
useNotebookEnvVariables(existingNotebook, [
...notebookConnections.map((connection) => connection.metadata.name),
dataConnectionData.existing?.secretRef.name || '',
]);

const restartNotebooks = useWillNotebooksRestart([existingNotebook?.metadata.name || '']);

const [data, loaded, loadError] = useNotebookImageData(existingNotebook);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const fetchNotebookEnvVariables = (notebook: NotebookKind): Promise<EnvVa

export const useNotebookEnvVariables = (
notebook?: NotebookKind,
excludedResources: string[] = [],
): [
envVariables: EnvVariable[],
setEnvVariables: (envVars: EnvVariable[]) => void,
Expand All @@ -96,6 +97,7 @@ export const useNotebookEnvVariables = (
const { deletedConfigMaps, deletedSecrets } = getDeletedConfigMapOrSecretVariables(
notebook,
existingEnvVariables,
excludedResources,
);
React.useEffect(() => {
setEnvVariables(existingEnvVariables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const isStringKeyValuePairObject = (object: unknown): object is Record<st
export const getDeletedConfigMapOrSecretVariables = (
notebook: NotebookKind | undefined,
envVariables: EnvVariable[],
excludedResources: string[] = [],
): {
deletedSecrets: string[];
deletedConfigMaps: string[];
Expand All @@ -32,10 +33,18 @@ export const getDeletedConfigMapOrSecretVariables = (
const deletedSecrets: string[] = [];

(notebook?.spec.template.spec.containers[0].envFrom || []).forEach((env) => {
if (env.configMapRef && !existingEnvVariables.has(env.configMapRef.name)) {
if (
env.configMapRef &&
!existingEnvVariables.has(env.configMapRef.name) &&
!excludedResources.includes(env.configMapRef.name)
) {
deletedConfigMaps.push(env.configMapRef.name);
}
if (env.secretRef && !existingEnvVariables.has(env.secretRef.name)) {
if (
env.secretRef &&
!existingEnvVariables.has(env.secretRef.name) &&
!excludedResources.includes(env.secretRef.name)
) {
deletedSecrets.push(env.secretRef.name);
}
});
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/pages/projects/screens/spawner/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from '~/pages/projects/types';
import { ROOT_MOUNT_PATH } from '~/pages/projects/pvc/const';
import { ConfigMapKind, NotebookKind, SecretKind } from '~/k8sTypes';
import { Connection } from '~/concepts/connectionTypes/types';
import { getVolumesByStorageData } from './spawnerUtils';
import { fetchNotebookEnvVariables } from './environmentVariables/useNotebookEnvVariables';
import { getDeletedConfigMapOrSecretVariables } from './environmentVariables/utils';
Expand Down Expand Up @@ -194,12 +195,17 @@ export const updateConfigMapsAndSecretsForNotebook = async (
envVariables: EnvVariable[],
dataConnection?: DataConnectionData,
existingDataConnection?: DataConnection,
connections?: Connection[],
dryRun = false,
): Promise<EnvironmentFromVariable[]> => {
const existingEnvVars = await fetchNotebookEnvVariables(notebook);
const { deletedConfigMaps, deletedSecrets } = getDeletedConfigMapOrSecretVariables(
notebook,
existingEnvVars,
[
existingDataConnection?.data.metadata.name || '',
...(connections || []).map((connection) => connection.metadata.name),
],
);
const newDataConnection =
dataConnection?.enabled && dataConnection.type === 'creating' && dataConnection.creating
Expand Down
Loading