Skip to content

Commit

Permalink
Formatting and default sort by status
Browse files Browse the repository at this point in the history
Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
  • Loading branch information
ashu8912 committed Sep 30, 2024
1 parent f75c800 commit e8bb153
Show file tree
Hide file tree
Showing 11 changed files with 666 additions and 445 deletions.
193 changes: 125 additions & 68 deletions flux-plugin/src/actions/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ActionButton, ConfirmDialog, Dialog } from '@kinvolk/headlamp-plugin/lib/components/common';
import {
ActionButton,
ConfirmDialog,
Dialog,
} from '@kinvolk/headlamp-plugin/lib/components/common';
import { useSnackbar } from 'notistack';
import React from 'react';
import { KubeObject } from '@kinvolk/headlamp-plugin/lib/lib/k8s/cluster';
Expand All @@ -15,36 +19,54 @@ function SuspendAction(props) {
description="Suspend"
icon={'mdi:pause'}
iconButtonProps={{
style: {
display: resource?.jsonData.spec.hasOwnProperty('suspend') ? resource.jsonData.spec.suspend ? 'none' : 'inline-flex' : 'inline-flex',
}
style: {
display: resource?.jsonData.spec.hasOwnProperty('suspend')
? resource.jsonData.spec.suspend
? 'none'
: 'inline-flex'
: 'inline-flex',
},
}}
onClick={() => {
setOpen(true);
}}
/>
<ConfirmDialog
<ConfirmDialog
// @ts-ignore
open={open}
handleClose={() => setOpen(false)}
handleClose={() => setOpen(false)}
onConfirm={() => {
setOpen(false);
resource.jsonData.spec['suspend'] = true;
const patch = resource.constructor.apiEndpoint.patch;
patch({
setOpen(false);
resource.jsonData.spec['suspend'] = true;
const patch = resource.constructor.apiEndpoint.patch;
patch(
{
spec: {
suspend: true,
}
}, resource.jsonData.metadata.namespace, resource.jsonData.metadata.name).then((response) => {
if(response.spec.suspend) {
enqueueSnackbar(`Successfully suspended reconciliation for ${resource.metadata.name}`, { variant: 'success' });
},
},
resource.jsonData.metadata.namespace,
resource.jsonData.metadata.name
)
.then(response => {
if (response.spec.suspend) {
enqueueSnackbar(
`Successfully suspended reconciliation for ${resource.metadata.name}`,
{ variant: 'success' }
);
} else {
enqueueSnackbar(`Failed to suspend reconciliation for ${resource.metadata.name}`, { variant: 'error' });
enqueueSnackbar(`Failed to suspend reconciliation for ${resource.metadata.name}`, {
variant: 'error',
});
}
}).catch((error) => {
enqueueSnackbar(`Failed to suspend reconciliation for ${resource.metadata.name} error ${error}`, { variant: 'error' });
})
}}
.catch(error => {
enqueueSnackbar(
`Failed to suspend reconciliation for ${resource.metadata.name} error ${error}`,
{ variant: 'error' }
);
});
}}
title={'Suspend Reconciliation'}
description={`Are you sure you want to suspend reconciliation for ${resource?.jsonData.metadata.name}?`}
/>
Expand All @@ -60,46 +82,66 @@ function ResumeAction(props) {
<ActionButton
iconButtonProps={{
style: {
display: resource?.jsonData.spec.hasOwnProperty('suspend') ? resource.jsonData.spec.suspend ? 'inline-flex' : 'none' : 'none',
}
display: resource?.jsonData.spec.hasOwnProperty('suspend')
? resource.jsonData.spec.suspend
? 'inline-flex'
: 'none'
: 'none',
},
}}
description="Resume"
icon={'mdi:play'}
onClick={() => {
const patch = resource.constructor.apiEndpoint.patch;
patch({
spec: {
suspend: false,
}
}, resource.jsonData.metadata.namespace, resource.jsonData.metadata.name).then((response) => {
if(!response.spec.suspend) {
enqueueSnackbar(`Successfully resumed reconciliation for ${response.metadata.name}`, { variant: 'success' });
} else {
enqueueSnackbar(`Failed to resume reconciliation for ${response.metadata.name}`, { variant: 'error' });
}
}).catch((error) => {
enqueueSnackbar(`Failed to resume reconciliation for ${resource.metadata.name} error ${error}`, { variant: 'error' });
})
patch(
{
spec: {
suspend: false,
},
},
resource.jsonData.metadata.namespace,
resource.jsonData.metadata.name
)
.then(response => {
if (!response.spec.suspend) {
enqueueSnackbar(`Successfully resumed reconciliation for ${response.metadata.name}`, {
variant: 'success',
});
} else {
enqueueSnackbar(`Failed to resume reconciliation for ${response.metadata.name}`, {
variant: 'error',
});
}
})
.catch(error => {
enqueueSnackbar(
`Failed to resume reconciliation for ${resource.metadata.name} error ${error}`,
{ variant: 'error' }
);
});
}}
/>
);
}

function syncRequest(resource: KubeObject, enqueueSnackbar, date) {
const name = resource.jsonData.metadata.name;

const patch = resource.constructor.apiEndpoint.patch;
return patch({
const name = resource.jsonData.metadata.name;

const patch = resource.constructor.apiEndpoint.patch;
return patch(
{
metadata: {
annotations: {
...resource.jsonData.metadata.annotations,
'reconcile.fluxcd.io/requestedAt': date,
},
}
}, resource.jsonData.metadata.namespace, name);
},
},
resource.jsonData.metadata.namespace,
name
);
}


function SyncAction(props) {
// const dispatch = useDispatch();
const { resource } = props;
Expand All @@ -113,16 +155,20 @@ function SyncAction(props) {
const date = new Date().toISOString();
enqueueSnackbar(`Starting sync for ${resource.metadata.name}`, { variant: 'info' });
syncRequest(resource, enqueueSnackbar, date).then(() => {
const get = resource.constructor.apiEndpoint.get;
const get = resource.constructor.apiEndpoint.get;
let isResourceSynced = false;
get(resource.metadata.namespace, resource.metadata.name, (newResource) => {
if(newResource.status.lastHandledReconcileAt === date && !isResourceSynced) {
enqueueSnackbar(`Successfully synced ${resource.metadata.name}`, { variant: 'success' });
get(resource.metadata.namespace, resource.metadata.name, newResource => {
if (newResource.status.lastHandledReconcileAt === date && !isResourceSynced) {
enqueueSnackbar(`Successfully synced ${resource.metadata.name}`, {
variant: 'success',
});
isResourceSynced = true;
}
}).catch((error) => {
enqueueSnackbar(`Failed to sync ${resource.metadata.name} error ${error}`, { variant: 'error' });
})
}).catch(error => {
enqueueSnackbar(`Failed to sync ${resource.metadata.name} error ${error}`, {
variant: 'error',
});
});
});
}}
/>
Expand All @@ -141,27 +187,34 @@ function SyncWithSourceAction(props) {
syncRequest(source, enqueueSnackbar, date).then(() => {
const get = source.constructor.apiEndpoint.get;
let isSourceSynced = false;
get(source.metadata.namespace, source.metadata.name, (newSource) => {
if(newSource.status.lastHandledReconcileAt === date && !isSourceSynced) {
enqueueSnackbar(`Successfully synced source ${source.metadata.name}`, { variant: 'success' });
get(source.metadata.namespace, source.metadata.name, newSource => {
if (newSource.status.lastHandledReconcileAt === date && !isSourceSynced) {
enqueueSnackbar(`Successfully synced source ${source.metadata.name}`, {
variant: 'success',
});
isSourceSynced = true;
enqueueSnackbar(`Now starting sync for ${resource.metadata.name}`, { variant: 'info' });
enqueueSnackbar(`Now starting sync for ${resource.metadata.name}`, {
variant: 'info',
});
syncRequest(resource, enqueueSnackbar, date).then(() => {
const getResource = resource.constructor.apiEndpoint.get;
let isResourceSynced = false;
getResource(resource.metadata.namespace, resource.metadata.name, (newResource) => {
if(newResource.status.lastHandledReconcileAt === date && !isResourceSynced) {
enqueueSnackbar(`Successfully synced ${resource.metadata.name}`, { variant: 'success' });
getResource(resource.metadata.namespace, resource.metadata.name, newResource => {
if (newResource.status.lastHandledReconcileAt === date && !isResourceSynced) {
enqueueSnackbar(`Successfully synced ${resource.metadata.name}`, {
variant: 'success',
});
isResourceSynced = true;
}
})
})
}
});
});
}
}).catch((error) => {
enqueueSnackbar(`Failed to sync source ${source.metadata.name} error ${error}`, { variant: 'error' });
})
}).catch(error => {
enqueueSnackbar(`Failed to sync source ${source.metadata.name} error ${error}`, {
variant: 'error',
});
});
});

}}
icon="mdi:file-sync"
/>
Expand All @@ -180,16 +233,20 @@ function SyncWithoutSourceAction(props) {
const date = new Date().toISOString();
enqueueSnackbar(`Starting sync for ${resource.metadata.name}`, { variant: 'info' });
syncRequest(resource, enqueueSnackbar, date).then(() => {
const get = resource.constructor.apiEndpoint.get;
const get = resource.constructor.apiEndpoint.get;
let isResourceSynced = false;
get(resource.metadata.namespace, resource.metadata.name, (newResource) => {
if(newResource.status.lastHandledReconcileAt === date && !isResourceSynced) {
enqueueSnackbar(`Successfully synced ${resource.metadata.name}`, { variant: 'success' });
get(resource.metadata.namespace, resource.metadata.name, newResource => {
if (newResource.status.lastHandledReconcileAt === date && !isResourceSynced) {
enqueueSnackbar(`Successfully synced ${resource.metadata.name}`, {
variant: 'success',
});
isResourceSynced = true;
}
}).catch((error) => {
enqueueSnackbar(`Failed to sync ${resource.metadata.name} error ${error}`, { variant: 'error' });
})
}).catch(error => {
enqueueSnackbar(`Failed to sync ${resource.metadata.name} error ${error}`, {
variant: 'error',
});
});
});
});
}}
Expand Down
Loading

0 comments on commit e8bb153

Please sign in to comment.