Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix statuses #1523

Merged
merged 11 commits into from Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -192,8 +192,7 @@ export const namespaceMatchTargetServer = (relatedKind, resourceMapForObject) =>

// try to match app destination clusters with hub clusters using search data
export const updateAppClustersMatchingSearch = (node, searchClusters) => {
const nodeId = _.get(node, 'id', '')
if (nodeId !== 'member--clusters--') {
if (node.type !== 'cluster') {
//acm cluster node
_.set(node, 'specs.clusters', searchClusters)
return node
Expand Down Expand Up @@ -243,7 +242,6 @@ export const updateAppClustersMatchingSearch = (node, searchClusters) => {
}
})
_.set(node, 'specs.appClusters', _.sortBy(appClusters))
_.set(node, 'specs.clusters', searchClusters)
return node
}

Expand Down
Expand Up @@ -400,6 +400,7 @@ export const getNameWithoutPodHash = (relatedKind) => {
//openshift.io/deployment-config.name
deployableName = values[1].trim()
nameNoHash = deployableName
podTemplateHashLabelFound = true
}
}
})
Expand Down Expand Up @@ -580,15 +581,15 @@ export const addIngressNodeInfo = (node, details, t) => {

//for service
export const addNodeServiceLocation = (node, clusterName, targetNS, details, t) => {
if (R.pathOr('', ['specs', 'raw', 'kind'])(node) === 'Service') {
if (node.type === 'service') {
return addNodeInfoPerCluster(node, clusterName, targetNS, details, addNodeServiceLocationForCluster, t) //process only services
}
return details
}

//generic function to write location info
export const addNodeInfoPerCluster = (node, clusterName, targetNS, details, getDetailsFunction, t) => {
const resourceName = _.get(node, 'namespace', '')
const resourceName = _.get(node, 'name', '')
const resourceMap = _.get(node, `specs.${node.type}Model`, {})

const locationDetails = []
Expand Down
Expand Up @@ -44,28 +44,16 @@ export const addDiagramDetails = (resourceStatuses, resourceMap, isClusterGroupe
const hasMultipleSubs = _.get(appNode, 'specs.allSubscriptions', []).length > 1

topology.nodes.forEach((node) => {
const nodeId = _.get(node, 'id', '')
if (nodeId.startsWith('member--clusters--')) {
if (node.type === 'cluster') {
// only do this for Argo clusters
//cluster node, set search found clusters objects here
updateAppClustersMatchingSearch(node, clustersObjects)
}
const nodeClusters = nodeId.startsWith('member--subscription')
? clusterNamesList
: getClusterName(nodeId).split(',')
_.set(
node,
'specs.clustersNames',
hasMultipleSubs
? nodeClusters
: nodeId.includes('clusters----') || nodeId === 'member--clusters--'
? clusterNamesList
: _.sortBy(_.uniq(_.union(nodeClusters, clusterNamesList)))
)
const nodeClusters = node.type === 'subscription' ? clusterNamesList : _.get(node, 'specs.clustersNames')
_.set(
node,
'specs.searchClusters',
hasMultipleSubs && !nodeId.startsWith('application--')
hasMultipleSubs && node.type === 'application'
? _.filter(clustersObjects, (cls) => _.includes(nodeClusters, _.get(cls, 'name', '')))
: clustersObjects // get all search clusters when one cluster node or this is the main app node
)
Expand Down Expand Up @@ -96,7 +84,7 @@ export const addDiagramDetails = (resourceStatuses, resourceMap, isClusterGroupe
const { kind, cluster } = relatedKind

//look for pod template hash and remove it from the name if there
const { nameNoHash, deployableName, podHash } = getNameWithoutPodHash(relatedKind)
const { nameNoHash, deployableName } = getNameWithoutPodHash(relatedKind)

//for routes generated by Ingress, remove route name hash
const nameNoHashIngressPod = getRouteNameWithoutIngressHash(relatedKind, nameNoHash)
Expand All @@ -107,71 +95,45 @@ export const addDiagramDetails = (resourceStatuses, resourceMap, isClusterGroupe
hasHelmReleases
)

let name = computeResourceName(relatedKind, deployableName, nameWithoutChartRelease, isClusterGrouped)
let resourceName = computeResourceName(
relatedKind,
deployableName,
nameWithoutChartRelease,
isClusterGrouped
)

if (
kind === 'subscription' &&
cluster === 'local-cluster' &&
_.get(relatedKind, 'localPlacement', '') === 'true' &&
_.endsWith(name, '-local')
_.endsWith(resourceName, '-local')
) {
//match local hub subscription after removing -local suffix
name = _.trimEnd(name, '-local')
resourceName = _.trimEnd(resourceName, '-local')
}

const existingResourceMapKey = getExistingResourceMapKey(resourceMap, name, relatedKind)
if (checkAndObjects(podHash, existingResourceMapKey)) {
//update resource map key with podHash if the resource has a pod hash ( deployment, replicaset, deploymentconig, etc )
//this is going to be used to link pods with this parent resource
resourceMap[`pod-${podHash}-${cluster}`] = resourceMap[existingResourceMapKey]
} else if (checkAndObjects(deployableName, existingResourceMapKey)) {
resourceMap[`pod-deploymentconfig-${deployableName}`] = resourceMap[existingResourceMapKey]
}

let ownerUID
let resourceMapForObject =
resourceMap[name] || (existingResourceMapKey && resourceMap[existingResourceMapKey])
if (!resourceMapForObject && kind === 'pod') {
if (podHash) {
//just found a pod object, try to map it to the parent resource using the podHash
resourceMapForObject = resourceMap[`pod-${podHash}-${cluster}`]
} else if (deployableName) {
resourceMapForObject = resourceMap[`pod-deploymentconfig-${deployableName}`]
const resourceMapForObject = Object.values(resourceMap).find(({ name, namespace, type, specs = {} }) => {
if (specs.resourceCount) {
if (type === relatedKind.kind && (specs.clustersNames || []).includes(relatedKind.cluster)) {
return (
(specs.resources || []).findIndex((spec) => {
return spec.name === nameNoHash && spec.namespace === relatedKind.namespace
}) !== -1
)
} else {
ownerUID = relatedKind._ownerUID
return false
}
}

if (ownerUID) {
findParentForOwnerID(
resourceMap,
ownerUID,
kind,
relatedKind,
nameWithoutChartRelease,
addResourceToModel
)
} else if (resourceMapForObject) {
addResourceToModel(resourceMapForObject, kind, relatedKind, nameWithoutChartRelease)
} else {
//get resource by looking at the cluster grouping
Object.keys(resourceMap).forEach((key) => {
resourceMapForObject = resourceMap[key]
if (
_.startsWith(key, name) &&
(_.includes(
_.get(
resourceMapForObject,
'clusters.specs.clustersNames',
['local-cluster'] // if no cluster found for this resource, this could be a local deployment
),
_.get(relatedKind, 'cluster')
) ||
namespaceMatchTargetServer(relatedKind, resourceMapForObject))
) {
addResourceToModel(resourceMapForObject, kind, relatedKind, nameWithoutChartRelease)
return (
(kind === 'subscription' ? name === resourceName : name === nameNoHash) &&
namespace === relatedKind.namespace &&
type === relatedKind.kind &&
(specs.clustersNames || []).includes(relatedKind.cluster)
)
}
})
if (resourceMapForObject) {
addResourceToModel(resourceMapForObject, kind, relatedKind, nameWithoutChartRelease)
}
})
})
Expand Down