Skip to content

Commit

Permalink
feat: improve StatefulSet immutable field error messages (argoproj#21209
Browse files Browse the repository at this point in the history
)

Signed-off-by: Atif Ali <[email protected]>
  • Loading branch information
aali309 authored Feb 26, 2025
1 parent 3baca9b commit c09e6fa
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,24 @@ export const ApplicationOperationState: React.StatelessComponent<Props> = ({appl
const operationAttributes = [
{title: 'OPERATION', value: utils.getOperationType(application)},
{title: 'PHASE', value: operationState.phase},
...(operationState.message ? [{title: 'MESSAGE', value: operationState.message}] : []),
...(operationState.message
? [
{
title: 'MESSAGE',
value: (
<pre
style={{
whiteSpace: 'pre-wrap',
wordBreak: 'break-word',
margin: 0,
fontFamily: 'inherit'
}}>
{utils.formatOperationMessage(operationState.message)}
</pre>
)
}
]
: []),
{title: 'STARTED AT', value: <Timestamp date={operationState.startedAt} />},
{
title: 'DURATION',
Expand Down
38 changes: 38 additions & 0 deletions ui/src/app/applications/components/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,44 @@ export function formatCreationTimestamp(creationTimestamp: string) {
);
}

/*
* formatStatefulSetChange reformats a single line describing changes to immutable fields in a StatefulSet.
* It extracts the field name and its "from" and "to" values for better readability.
*/
function formatStatefulSetChange(line: string): string {
if (line.startsWith('-')) {
// Remove leading "- " from the line and split into field and changes
const [field, changes] = line.substring(2).split(':');
if (changes) {
// Split "from: X to: Y" into separate lines with aligned values
const [from, to] = changes.split('to:').map(s => s.trim());
return ` - ${field}:\n from: ${from.replace('from:', '').trim()}\n to: ${to}`;
}
}
return line;
}

export function formatOperationMessage(message: string): string {
if (!message) {
return message;
}

// Format immutable fields error message
if (message.includes('attempting to change immutable fields:')) {
const [header, ...details] = message.split('\n');
const formattedDetails = details
// Remove empty lines
.filter(line => line.trim())
// Use helper function
.map(formatStatefulSetChange)
.join('\n');

return `${header}\n${formattedDetails}`;
}

return message;
}

export const selectPostfix = (arr: string[], singular: string, plural: string) => (arr.length > 1 ? plural : singular);

export function getUsrMsgKeyToDisplay(appName: string, msgKey: string, usrMessages: appModels.UserMessages[]) {
Expand Down

0 comments on commit c09e6fa

Please sign in to comment.