Skip to content

fix: containers are missing from app-details page in argocd app #4973

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

Merged
merged 12 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 43 additions & 7 deletions client/argocdServer/application/Application.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,55 @@ func (c ServiceClientImpl) buildPodMetadata(resp *v1alpha1.ApplicationTree, resp
}

//podMetaData := make([]*PodMetadata, 0)
duplicateCheck := make(map[string]bool)
duplicatePodToReplicasetMapping := make(map[string]string)
if len(newReplicaSets) > 0 {
results := buildPodMetadataFromReplicaSet(resp, newReplicaSets, replicaSetManifests)
results, duplicateMapping := buildPodMetadataFromReplicaSet(resp, newReplicaSets, replicaSetManifests)
for _, meta := range results {
duplicateCheck[meta.Name] = true
podMetaData = append(podMetaData, meta)
}
duplicatePodToReplicasetMapping = duplicateMapping
}

if newPodNames != nil {
results := buildPodMetadataFromPod(resp, podManifests, newPodNames)
for _, meta := range results {
if _, ok := duplicateCheck[meta.Name]; !ok {
podMetaData = append(podMetaData, meta)
podsMetadataFromPods := buildPodMetadataFromPod(resp, podManifests, newPodNames)
containersPodMapping := make(map[string][]*string)
initContainersPodMapping := make(map[string][]*string)
for _, podMetadataFromPod := range podsMetadataFromPods {
if _, ok := duplicatePodToReplicasetMapping[podMetadataFromPod.Name]; !ok {
podMetaData = append(podMetaData, podMetadataFromPod)
} else {
for _, podMetadataFromReplicaSet := range podMetaData {
if podMetadataFromReplicaSet.Name == podMetadataFromPod.Name {
if podMetadataFromPod.Containers != nil {
containersPodMapping[podMetadataFromPod.Name] = podMetadataFromPod.Containers
currentPodParentName := duplicatePodToReplicasetMapping[podMetadataFromPod.Name]
for podName, podParentName := range duplicatePodToReplicasetMapping {
if podParentName == currentPodParentName {
containersPodMapping[podName] = podMetadataFromPod.Containers
}
}
}
if podMetadataFromPod.InitContainers != nil {
initContainersPodMapping[podMetadataFromPod.Name] = podMetadataFromPod.InitContainers
currentPodParentName := duplicatePodToReplicasetMapping[podMetadataFromPod.Name]
for podName, podParentName := range duplicatePodToReplicasetMapping {
if podParentName == currentPodParentName {
initContainersPodMapping[podName] = podMetadataFromPod.InitContainers
}
}
}
}
}
}
}
for _, podMetadataFromPods := range podsMetadataFromPods {
if _, ok := duplicatePodToReplicasetMapping[podMetadataFromPods.Name]; ok {
for _, val := range podMetaData {
if val.Name == podMetadataFromPods.Name {
val.Containers = containersPodMapping[podMetadataFromPods.Name]
val.InitContainers = initContainersPodMapping[podMetadataFromPods.Name]
}
}
}
}
}
Expand Down
22 changes: 13 additions & 9 deletions client/argocdServer/application/ApplicationUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func parseResult(resp *v1alpha1.ApplicationTree, query *application.ResourcesQue
}
needPods := false
queryNodes := make([]v1alpha1.ResourceNode, 0)
podParents := make([]string, 0)
podParents := make(map[string]v1alpha1.ResourceNode)
for _, node := range resp.Nodes {
if node.Kind == "Pod" {
for _, pr := range node.ParentRefs {
podParents = append(podParents, pr.Name)
podParents[pr.Name] = node
}
}
}
Expand All @@ -65,11 +65,8 @@ func parseResult(resp *v1alpha1.ApplicationTree, query *application.ResourcesQue
queryNodes = append(queryNodes, node)
}
if node.Kind == "ReplicaSet" {
for _, pr := range podParents {
if pr == node.Name {
queryNodes = append(queryNodes, node)
break
}
if _, ok := podParents[node.Name]; ok {
queryNodes = append(queryNodes, node)
}
}
if node.Kind == "StatefulSet" || node.Kind == "DaemonSet" || node.Kind == "Workflow" {
Expand All @@ -84,6 +81,10 @@ func parseResult(resp *v1alpha1.ApplicationTree, query *application.ResourcesQue

c.logger.Debugw("needPods", "pods", needPods)

for _, node := range podParents {
queryNodes = append(queryNodes, node)
}

if needPods {
for _, node := range resp.Nodes {
if node.Kind == "Pod" {
Expand Down Expand Up @@ -398,8 +399,10 @@ func getPodInitContainers(resource map[string]interface{}) []*string {
return containers
}

func buildPodMetadataFromReplicaSet(resp *v1alpha1.ApplicationTree, newReplicaSets []string, replicaSetManifests []map[string]interface{}) (podMetadata []*argoApplication.PodMetadata) {
func buildPodMetadataFromReplicaSet(resp *v1alpha1.ApplicationTree, newReplicaSets []string, replicaSetManifests []map[string]interface{}) ([]*argoApplication.PodMetadata, map[string]string) {
replicaSets := make(map[string]map[string]interface{})
podToReplicasetMapping := make(map[string]string)
var podMetadata []*argoApplication.PodMetadata
for _, replicaSet := range replicaSetManifests {
replicaSets[getResourceName(replicaSet)] = replicaSet
}
Expand All @@ -421,12 +424,13 @@ func buildPodMetadataFromReplicaSet(resp *v1alpha1.ApplicationTree, newReplicaSe
}
replicaSet := replicaSets[parentName]
containers, intContainers := getReplicaSetContainers(replicaSet)
podToReplicasetMapping[node.Name] = parentName
metadata := argoApplication.PodMetadata{Name: node.Name, UID: node.UID, Containers: containers, InitContainers: intContainers, IsNew: isNew}
podMetadata = append(podMetadata, &metadata)
}
}
}
return
return podMetadata, podToReplicasetMapping
}

func getReplicaSetContainers(resource map[string]interface{}) (containers []*string, intContainers []*string) {
Expand Down
Loading