-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parser for subscription application
Signed-off-by: Timothy Asir Jeyasingh <[email protected]>
- Loading branch information
1 parent
9b55fef
commit a2a16cb
Showing
15 changed files
with
596 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...ges/mco/components/mco-dashboard/data-policy/application-parser/applicationset-parser.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import * as React from 'react'; | ||
import { APPLICATION_TYPE, DRPC_STATUS } from '@odf/mco/constants'; | ||
import { | ||
DisasterRecoveryResourceKind, | ||
useArgoApplicationSetResourceWatch, | ||
} from '@odf/mco/hooks'; | ||
import { | ||
ACMManagedClusterKind, | ||
DRClusterAppsMap, | ||
DRClusterKind, | ||
} from '@odf/mco/types'; | ||
import { | ||
findDRType, | ||
findDeploymentClusters, | ||
getProtectedPVCsFromDRPC, | ||
getRemoteNamespaceFromAppSet, | ||
} from '@odf/mco/utils'; | ||
import { getName, getNamespace } from '@odf/shared/selectors'; | ||
import * as _ from 'lodash-es'; | ||
|
||
export const useApplicationSetParser = ( | ||
drResources: DisasterRecoveryResourceKind, | ||
drLoaded: boolean, | ||
drLoadError: any | ||
): DRClusterAppsMap => { | ||
const [argoApplicationSetResources, loaded, loadError] = | ||
useArgoApplicationSetResourceWatch({ | ||
drResources: { | ||
data: drResources, | ||
loaded: drLoaded, | ||
loadError: drLoadError, | ||
}, | ||
}); | ||
|
||
const drClusters: DRClusterKind[] = drResources?.drClusters; | ||
const managedClusters: ACMManagedClusterKind[] = | ||
argoApplicationSetResources?.managedClusters; | ||
const formattedArgoAppSetResources = | ||
argoApplicationSetResources?.formattedResources; | ||
|
||
const drClusterAppsMap: DRClusterAppsMap = React.useMemo(() => { | ||
if (loaded && !loadError) { | ||
// DRCluster to its ManagedCluster mapping | ||
const drClusterAppsMap: DRClusterAppsMap = drClusters.reduce( | ||
(acc, drCluster) => { | ||
acc[getName(drCluster)] = { | ||
managedCluster: managedClusters.find( | ||
(managedCluster) => getName(managedCluster) === getName(drCluster) | ||
), | ||
totalAppCount: 0, | ||
protectedApps: [], | ||
}; | ||
return acc; | ||
}, | ||
{} as DRClusterAppsMap | ||
); | ||
|
||
// DRCluster to its ApplicationSets (total and protected) mapping | ||
formattedArgoAppSetResources.forEach((argoApplicationSetResource) => { | ||
const { application } = argoApplicationSetResource || {}; | ||
const { | ||
drClusters: currentDrClusters, | ||
drPlacementControl, | ||
drPolicy, | ||
placementDecision, | ||
} = argoApplicationSetResource?.placements?.[0] || {}; | ||
const deploymentClusters = findDeploymentClusters( | ||
placementDecision, | ||
drPlacementControl | ||
); | ||
deploymentClusters.forEach((decisionCluster) => { | ||
if (drClusterAppsMap.hasOwnProperty(decisionCluster)) { | ||
drClusterAppsMap[decisionCluster].totalAppCount = | ||
drClusterAppsMap[decisionCluster].totalAppCount + 1; | ||
if (!_.isEmpty(drPlacementControl)) { | ||
drClusterAppsMap[decisionCluster].protectedApps.push({ | ||
appName: getName(application), | ||
appNamespace: getNamespace(application), | ||
appKind: application?.kind, | ||
appAPIVersion: application?.apiVersion, | ||
appType: APPLICATION_TYPE.APPSET, | ||
placementInfo: [ | ||
{ | ||
deploymentClusterName: decisionCluster, | ||
drpcName: getName(drPlacementControl), | ||
drpcNamespace: getNamespace(drPlacementControl), | ||
protectedPVCs: getProtectedPVCsFromDRPC(drPlacementControl), | ||
replicationType: findDRType(currentDrClusters), | ||
syncInterval: drPolicy?.spec?.schedulingInterval, | ||
workloadNamespace: | ||
getRemoteNamespaceFromAppSet(application), | ||
failoverCluster: drPlacementControl?.spec?.failoverCluster, | ||
preferredCluster: | ||
drPlacementControl?.spec?.preferredCluster, | ||
lastGroupSyncTime: | ||
drPlacementControl?.status?.lastGroupSyncTime, | ||
status: drPlacementControl?.status?.phase as DRPC_STATUS, | ||
}, | ||
], | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
return drClusterAppsMap; | ||
} | ||
return {}; | ||
}, [ | ||
drClusters, | ||
managedClusters, | ||
formattedArgoAppSetResources, | ||
loaded, | ||
loadError, | ||
]); | ||
|
||
return drClusterAppsMap; | ||
}; |
133 changes: 133 additions & 0 deletions
133
packages/mco/components/mco-dashboard/data-policy/application-parser/subscription-parser.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import { useMemo } from 'react'; | ||
import { APPLICATION_TYPE, DRPC_STATUS } from '@odf/mco/constants'; | ||
import { | ||
DisasterRecoveryResourceKind, | ||
useSubscriptionResourceWatch, | ||
} from '@odf/mco/hooks'; | ||
import { ACMManagedClusterKind, DRClusterAppsMap } from '@odf/mco/types'; | ||
import { | ||
findDeploymentClusters, | ||
getProtectedPVCsFromDRPC, | ||
} from '@odf/mco/utils'; | ||
import { getName, getNamespace } from '@odf/shared/selectors'; | ||
import * as _ from 'lodash-es'; | ||
|
||
export const useSubscriptionParser = ( | ||
drResources: DisasterRecoveryResourceKind, | ||
drLoaded: boolean, | ||
drLoadError: any | ||
): DRClusterAppsMap => { | ||
const [subscriptionResources, loaded, loadError] = | ||
useSubscriptionResourceWatch({ | ||
drResources: { | ||
data: drResources, | ||
loaded: drLoaded, | ||
loadError: drLoadError, | ||
}, | ||
}); | ||
|
||
const drClusterAppsMap: DRClusterAppsMap = useMemo(() => { | ||
const drClusters = drResources?.drClusters || []; | ||
|
||
const managedClusters: ACMManagedClusterKind[] = | ||
subscriptionResources.reduce((result, subscriptionResource) => { | ||
const clusters = subscriptionResource?.managedClusters || []; | ||
result.push(...clusters); | ||
return result; | ||
}, []); | ||
|
||
if (loaded && !loadError) { | ||
// DRCluster to its ManagedCluster mapping | ||
const drClusterAppsMap: DRClusterAppsMap = drClusters.reduce( | ||
(acc, drCluster) => { | ||
acc[getName(drCluster)] = { | ||
managedCluster: managedClusters.find( | ||
(managedCluster) => getName(managedCluster) === getName(drCluster) | ||
), | ||
totalAppCount: subscriptionResources.reduce( | ||
(count, { subscriptionGroupInfo }) => { | ||
return ( | ||
count + | ||
(subscriptionGroupInfo?.some( | ||
(subscriptionGroup) => | ||
subscriptionGroup?.placementDecision === | ||
getName(drCluster) | ||
) | ||
? 1 | ||
: 0) | ||
); | ||
}, | ||
0 | ||
), | ||
protectedApps: [], | ||
}; | ||
return acc; | ||
}, | ||
{} as DRClusterAppsMap | ||
); | ||
|
||
// DRCluster to its Subscriptions (total and protected) mapping | ||
subscriptionResources.forEach((subscriptionResource) => { | ||
const { application, subscriptionGroupInfo } = | ||
subscriptionResource || {}; | ||
subscriptionGroupInfo?.forEach((subscriptionGroup) => { | ||
const { placementDecision, drInfo } = subscriptionGroup || {}; | ||
const deploymentClusters = findDeploymentClusters( | ||
placementDecision, | ||
drInfo?.drPlacementControl | ||
); | ||
|
||
deploymentClusters?.forEach((decisionCluster) => { | ||
if (drClusterAppsMap.hasOwnProperty(decisionCluster)) { | ||
drClusterAppsMap[decisionCluster].totalAppCount += 1; | ||
if ( | ||
drInfo?.drPlacementControl && | ||
!Array.isArray(drInfo.drPlacementControl) && | ||
!_.isEmpty(drInfo.drPlacementControl) | ||
) { | ||
drClusterAppsMap[decisionCluster].protectedApps.push({ | ||
appName: getName(application), | ||
appNamespace: getNamespace(application), | ||
appKind: application?.kind, | ||
appAPIVersion: application?.apiVersion, | ||
appType: APPLICATION_TYPE.SUBSCRIPTION, | ||
placementInfo: [ | ||
{ | ||
deploymentClusterName: decisionCluster, | ||
drpcName: getName(drInfo.drPlacementControl), | ||
drpcNamespace: getNamespace(drInfo.drPlacementControl), | ||
protectedPVCs: getProtectedPVCsFromDRPC( | ||
drInfo.drPlacementControl | ||
), | ||
replicationType: null, | ||
syncInterval: drInfo.drPolicy?.spec?.schedulingInterval, | ||
workloadNamespace: null, | ||
failoverCluster: | ||
drInfo.drPlacementControl?.spec?.failoverCluster || | ||
null, | ||
preferredCluster: | ||
drInfo.drPlacementControl?.spec?.preferredCluster || | ||
null, | ||
lastGroupSyncTime: | ||
drInfo.drPlacementControl?.status?.lastGroupSyncTime || | ||
null, | ||
status: | ||
(drInfo.drPlacementControl?.status | ||
?.phase as DRPC_STATUS) || null, | ||
}, | ||
], | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
return drClusterAppsMap; | ||
} | ||
|
||
return {}; | ||
}, [drResources?.drClusters, subscriptionResources, loaded, loadError]); | ||
|
||
return drClusterAppsMap; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.