Skip to content

Commit 7ed935f

Browse files
Fix: Container and log missing in resource tree (#686)
* resource tree pod meta data container logic fix * fix podmetadata for replicaset * fix pods manifest for Jobs * duplicate container fix -n case replicaset and demonset on resource tree
1 parent beb2664 commit 7ed935f

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

client/argocdServer/application/Application.go

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -403,14 +403,15 @@ func (c ServiceClientImpl) ResourceTree(ctxt context.Context, query *application
403403
return &ResourceTreeResponse{resp, newReplicaSet, status, podMetadata, conditions}, err
404404
}
405405

406-
func (c ServiceClientImpl) buildPodMetadata(resp *v1alpha1.ApplicationTree, responses []*Result) (podMetadata []*PodMetadata, newReplicaSet string) {
406+
func (c ServiceClientImpl) buildPodMetadata(resp *v1alpha1.ApplicationTree, responses []*Result) (podMetaData []*PodMetadata, newReplicaSet string) {
407407
rolloutManifest := make(map[string]interface{})
408408
statefulSetManifest := make(map[string]interface{})
409409
deploymentManifest := make(map[string]interface{})
410410
daemonSetManifest := make(map[string]interface{})
411411
replicaSetManifests := make([]map[string]interface{}, 0)
412412
podManifests := make([]map[string]interface{}, 0)
413413
controllerRevisionManifests := make([]map[string]interface{}, 0)
414+
jobsManifest := make(map[string]interface{})
414415
for _, response := range responses {
415416
if response != nil && response.Response != nil && response.Request.Kind == "Rollout" {
416417
err := json.Unmarshal([]byte(response.Response.Manifest), &rolloutManifest)
@@ -453,6 +454,11 @@ func (c ServiceClientImpl) buildPodMetadata(resp *v1alpha1.ApplicationTree, resp
453454
c.logger.Error(err)
454455
}
455456
controllerRevisionManifests = append(controllerRevisionManifests, manifest)
457+
} else if response != nil && response.Response != nil && response.Request.Kind == "Job" {
458+
err := json.Unmarshal([]byte(response.Response.Manifest), &jobsManifest)
459+
if err != nil {
460+
c.logger.Error(err)
461+
}
456462
}
457463
}
458464
newPodNames := make(map[string]bool, 0)
@@ -473,10 +479,26 @@ func (c ServiceClientImpl) buildPodMetadata(resp *v1alpha1.ApplicationTree, resp
473479
newPodNames = c.getDaemonSetNewPods(daemonSetManifest, podManifests, controllerRevisionManifests)
474480
}
475481

482+
if _, ok := jobsManifest["kind"]; ok {
483+
newPodNames = c.getJobsNewPods(jobsManifest, podManifests)
484+
}
485+
486+
//podMetaData := make([]*PodMetadata, 0)
487+
duplicateCheck := make(map[string]bool)
476488
if newReplicaSet != "" {
477-
podMetadata = buildPodMetadataFromReplicaSet(resp, newReplicaSet, replicaSetManifests)
478-
} else {
479-
podMetadata = buildPodMetadataFromPod(resp, podManifests, newPodNames)
489+
results := buildPodMetadataFromReplicaSet(resp, newReplicaSet, replicaSetManifests)
490+
for _, meta := range results {
491+
duplicateCheck[meta.Name] = true
492+
podMetaData = append(podMetaData, meta)
493+
}
494+
}
495+
if newPodNames != nil {
496+
results := buildPodMetadataFromPod(resp, podManifests, newPodNames)
497+
for _, meta := range results {
498+
if _, ok := duplicateCheck[meta.Name]; !ok {
499+
podMetaData = append(podMetaData, meta)
500+
}
501+
}
480502
}
481503
return
482504
}
@@ -513,6 +535,11 @@ func parseResult(resp *v1alpha1.ApplicationTree, query *application.ResourcesQue
513535
if node.Kind == "StatefulSet" || node.Kind == "DaemonSet" {
514536
needPods = true
515537
}
538+
539+
if node.Kind == "CronJob" || node.Kind == "Job" {
540+
queryNodes = append(queryNodes, node)
541+
needPods = true
542+
}
516543
}
517544

518545
c.logger.Debugw("needPods", "pods", needPods)
@@ -770,7 +797,7 @@ func buildPodMetadataFromPod(resp *v1alpha1.ApplicationTree, podManifests []map[
770797
for _, node := range resp.Nodes {
771798
if node.Kind == "Pod" {
772799
isNew := newPodNames[node.Name]
773-
metadata := PodMetadata{Name: node.Name, UID: node.UID, Containers: containerMapping[node.Name],InitContainers: initContainerMapping[node.Name], IsNew: isNew}
800+
metadata := PodMetadata{Name: node.Name, UID: node.UID, Containers: containerMapping[node.Name], InitContainers: initContainerMapping[node.Name], IsNew: isNew}
774801
podMetadata = append(podMetadata, &metadata)
775802
}
776803
}
@@ -833,11 +860,13 @@ func buildPodMetadataFromReplicaSet(resp *v1alpha1.ApplicationTree, newReplicaSe
833860
parentName = p.Name
834861
}
835862
}
836-
isNew := parentName == newReplicaSet
837-
replicaSet := replicaSets[parentName]
838-
containers, intContainers := getReplicaSetContainers(replicaSet)
839-
metadata := PodMetadata{Name: node.Name, UID: node.UID, Containers: containers, InitContainers: intContainers, IsNew: isNew}
840-
podMetadata = append(podMetadata, &metadata)
863+
if parentName != "" {
864+
isNew := parentName == newReplicaSet
865+
replicaSet := replicaSets[parentName]
866+
containers, intContainers := getReplicaSetContainers(replicaSet)
867+
metadata := PodMetadata{Name: node.Name, UID: node.UID, Containers: containers, InitContainers: intContainers, IsNew: isNew}
868+
podMetadata = append(podMetadata, &metadata)
869+
}
841870
}
842871
}
843872
return
@@ -911,3 +940,13 @@ func transform(resource v1alpha1.ResourceNode, name *string) *application.Applic
911940

912941
return request
913942
}
943+
944+
func (c ServiceClientImpl) getJobsNewPods(jobManifest map[string]interface{}, podManifests []map[string]interface{}) (newPodNames map[string]bool) {
945+
newPodNames = make(map[string]bool, 0)
946+
for _, pod := range podManifests {
947+
newPodNames[getResourceName(pod)] = true
948+
}
949+
950+
//TODO - new or old logic
951+
return
952+
}

wire_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)