Skip to content

Commit

Permalink
Prevent duplicity post of creating/replacing elyra secret
Browse files Browse the repository at this point in the history
  • Loading branch information
DaoDaoNoCode committed Aug 22, 2024
1 parent 5d35d7e commit bb1ba4a
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions frontend/src/concepts/pipelines/context/useManageElyraSecret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const useManageElyraSecret = (
namespace,
);
const notification = useNotification();
const isCreatingSecretRef = React.useRef(false);

React.useEffect(() => {
const error = elyraSecretError || dataConnectionError;
Expand All @@ -32,24 +33,31 @@ const useManageElyraSecret = (
}, [dataConnectionError, elyraSecretError]);

const fullLoadedState = elyraSecretLoaded && dataConnectionLoaded;
React.useEffect(() => {

const generatedSecret = React.useMemo(() => {
const externalStorage = cr?.spec.objectStorage.externalStorage;
if (fullLoadedState && dataConnection && routePath && externalStorage) {
let generatedSecret;
try {
generatedSecret = generateElyraSecret(externalStorage, dataConnection, routePath);
} catch (e) {
if (e instanceof Error) {
notification.error(e.message);
}
try {
if (externalStorage && dataConnection && routePath) {
return generateElyraSecret(externalStorage, dataConnection, routePath);
}

if (!generatedSecret) {
return;
return null;
} catch (e) {
if (e instanceof Error) {
notification.error(e.message);
}
return null;
}
}, [cr?.spec.objectStorage.externalStorage, dataConnection, notification, routePath]);

// const externalStorage = useDeepCompareMemoize(cr?.spec.objectStorage.externalStorage);
React.useEffect(() => {
if (fullLoadedState && generatedSecret) {
if (!elyraSecret) {
// Create a new secret
createSecret(generatedSecret);
if (!isCreatingSecretRef.current) {
isCreatingSecretRef.current = true;
// Create a new secret
createSecret(generatedSecret).then(() => (isCreatingSecretRef.current = false));
}
return;
}
try {
Expand All @@ -61,13 +69,16 @@ const useManageElyraSecret = (
const usingOldUrl = !secretValue.metadata[ELYRA_SECRET_DATA_ENDPOINT].endsWith('/view/');
if (usingOldDataType || usingOldUrl) {
// Secret is out of date, update it
replaceSecret(generateElyraSecret(externalStorage, dataConnection, routePath));
if (!isCreatingSecretRef.current) {
isCreatingSecretRef.current = true;
replaceSecret(generatedSecret).then(() => (isCreatingSecretRef.current = false));
}
}
} catch (e) {
// do nothing
}
}
}, [fullLoadedState, routePath, elyraSecret, dataConnection, cr, notification]);
}, [elyraSecret, fullLoadedState, generatedSecret]);
};

export default useManageElyraSecret;

0 comments on commit bb1ba4a

Please sign in to comment.