Skip to content

Commit

Permalink
Fix inventory resource fetching for no namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ashu8912 committed Aug 28, 2024
1 parent f4d3f35 commit 060a249
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
43 changes: 21 additions & 22 deletions flux-plugin/src/flux-applications/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function GetResourcesFromInventory(props: {
in the format '<namespace>_<name>_<group>_<kind>'.
*/
const parsedID = id.split('_');
const namespace = parsedID[0];
const namespace = parsedID[0] === '' ? undefined : parsedID[0];
const name = parsedID[1];
const group = parsedID[2];
const kind = parsedID[3];
Expand All @@ -55,26 +55,26 @@ function GetResourcesFromInventory(props: {
const { namespace, name, group, kind } = parsedID;
const resource = K8s.ResourceClasses[kind];


if (!resource) {
return;
}
resource.useApiGet(
data => {
// if the resource already exist replace it with the new one which is data otherwise add it
// use uid as the filter
const index = resources.findIndex(it => it.metadata.uid === data.metadata.uid);
if (index !== -1) {
resources[index] = data;
} else {
resources.push(data);
}
setResources([...resources]);
},
name,
namespace
);
});

resource.useApiGet(
data => {
// if the resource already exist replace it with the new one which is data otherwise add it
// use uid as the filter
const index = resources.findIndex(it => it.metadata.uid === data.metadata.uid);
if (index !== -1) {
resources[index] = data;
} else {
resources.push(data);
}
setResources([...resources]);
},
name,
namespace
);
});

return (
<Table
Expand All @@ -91,10 +91,10 @@ function GetResourcesFromInventory(props: {
<Link
routeName={`namespace`}
params={{
name: item.metadata.namespace,
name: item?.metadata?.namespace,
}}
>
{item.metadata.namespace}
{item?.metadata?.namespace}
</Link>
) : (
''
Expand All @@ -116,7 +116,7 @@ function GetResourcesFromInventory(props: {
},
{
header: 'Age',
accessorFn: item => <DateLabel date={item.metadata.creationTimestamp} />,
accessorFn: item => <DateLabel date={item?.metadata?.creationTimestamp} />,
},
]}
/>
Expand Down Expand Up @@ -229,7 +229,6 @@ function CustomResourceDetails(props) {
function prepareExtraInfo(cr) {
const { name: sourceName, type: sourceType } = getSourceNameAndType(cr);
let extraInfo = [];
console.log(sourceName, sourceType)
if (cr?.jsonData.kind === 'HelmRelease') {
extraInfo.push({
name: 'Chart',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default function FluxCustomResource(props: {
}) {
const { resourceClass, title, type } = props;
const [resource] = resourceClass.useList();
console.log('resource is ', resource);

function prepareStatus(item: KubeCRD) {

Expand Down Expand Up @@ -53,7 +52,6 @@ export default function FluxCustomResource(props: {
{
header: 'Name',
accessorFn: item => {
console.log(item);
return (
<Link
routeName={`/flux/${type}/:namespace/:type/:name`}
Expand Down

0 comments on commit 060a249

Please sign in to comment.