@@ -488,6 +488,21 @@ func (s *Server) ListResourceEvents(ctx context.Context, q *application.Applicat
488
488
"involvedObject.namespace" : a .Namespace ,
489
489
}).String ()
490
490
} else {
491
+ tree , err := s .getAppResources (ctx , a )
492
+ if err != nil {
493
+ return nil , err
494
+ }
495
+ found := false
496
+ for _ , n := range append (tree .Nodes , tree .OrphanedNodes ... ) {
497
+ if n .ResourceRef .UID == q .ResourceUID && n .ResourceRef .Name == q .ResourceName && n .ResourceRef .Namespace == q .ResourceNamespace {
498
+ found = true
499
+ break
500
+ }
501
+ }
502
+ if ! found {
503
+ return nil , status .Errorf (codes .InvalidArgument , "%s not found as part of application %s" , q .ResourceName , * q .Name )
504
+ }
505
+
491
506
namespace = q .ResourceNamespace
492
507
var config * rest.Config
493
508
config , err = s .getApplicationClusterConfig (ctx , a )
@@ -937,7 +952,7 @@ func (s *Server) getAppResources(ctx context.Context, a *appv1.Application) (*ap
937
952
return & tree , err
938
953
}
939
954
940
- func (s * Server ) getAppResource (ctx context.Context , action string , q * application.ApplicationResourceRequest ) (* appv1.ResourceNode , * rest.Config , * appv1.Application , error ) {
955
+ func (s * Server ) getAppLiveResource (ctx context.Context , action string , q * application.ApplicationResourceRequest ) (* appv1.ResourceNode , * rest.Config , * appv1.Application , error ) {
941
956
a , err := s .appLister .Get (* q .Name )
942
957
if err != nil {
943
958
return nil , nil , nil , err
@@ -952,7 +967,7 @@ func (s *Server) getAppResource(ctx context.Context, action string, q *applicati
952
967
}
953
968
954
969
found := tree .FindNode (q .Group , q .Kind , q .Namespace , q .ResourceName )
955
- if found == nil {
970
+ if found == nil || found . ResourceRef . UID == "" {
956
971
return nil , nil , nil , status .Errorf (codes .InvalidArgument , "%s %s %s not found as part of application %s" , q .Kind , q .Group , q .ResourceName , * q .Name )
957
972
}
958
973
config , err := s .getApplicationClusterConfig (ctx , a )
@@ -963,7 +978,7 @@ func (s *Server) getAppResource(ctx context.Context, action string, q *applicati
963
978
}
964
979
965
980
func (s * Server ) GetResource (ctx context.Context , q * application.ApplicationResourceRequest ) (* application.ApplicationResourceResponse , error ) {
966
- res , config , _ , err := s .getAppResource (ctx , rbacpolicy .ActionGet , q )
981
+ res , config , _ , err := s .getAppLiveResource (ctx , rbacpolicy .ActionGet , q )
967
982
if err != nil {
968
983
return nil , err
969
984
}
@@ -1008,7 +1023,7 @@ func (s *Server) PatchResource(ctx context.Context, q *application.ApplicationRe
1008
1023
Version : q .Version ,
1009
1024
Group : q .Group ,
1010
1025
}
1011
- res , config , a , err := s .getAppResource (ctx , rbacpolicy .ActionUpdate , resourceRequest )
1026
+ res , config , a , err := s .getAppLiveResource (ctx , rbacpolicy .ActionUpdate , resourceRequest )
1012
1027
if err != nil {
1013
1028
return nil , err
1014
1029
}
@@ -1048,7 +1063,7 @@ func (s *Server) DeleteResource(ctx context.Context, q *application.ApplicationR
1048
1063
Version : q .Version ,
1049
1064
Group : q .Group ,
1050
1065
}
1051
- res , config , a , err := s .getAppResource (ctx , rbacpolicy .ActionDelete , resourceRequest )
1066
+ res , config , a , err := s .getAppLiveResource (ctx , rbacpolicy .ActionDelete , resourceRequest )
1052
1067
if err != nil {
1053
1068
return nil , err
1054
1069
}
@@ -1335,7 +1350,7 @@ func getSelectedPods(treeNodes []appv1.ResourceNode, q *application.ApplicationP
1335
1350
var pods []appv1.ResourceNode
1336
1351
isTheOneMap := make (map [string ]bool )
1337
1352
for _ , treeNode := range treeNodes {
1338
- if treeNode .Kind == kube .PodKind && treeNode .Group == "" {
1353
+ if treeNode .Kind == kube .PodKind && treeNode .Group == "" && treeNode . UID != "" {
1339
1354
if isTheSelectedOne (& treeNode , q , treeNodes , isTheOneMap ) {
1340
1355
pods = append (pods , treeNode )
1341
1356
}
@@ -1625,7 +1640,7 @@ func (s *Server) logResourceEvent(res *appv1.ResourceNode, ctx context.Context,
1625
1640
}
1626
1641
1627
1642
func (s * Server ) ListResourceActions (ctx context.Context , q * application.ApplicationResourceRequest ) (* application.ResourceActionsListResponse , error ) {
1628
- res , config , _ , err := s .getAppResource (ctx , rbacpolicy .ActionGet , q )
1643
+ res , config , _ , err := s .getAppLiveResource (ctx , rbacpolicy .ActionGet , q )
1629
1644
if err != nil {
1630
1645
return nil , err
1631
1646
}
@@ -1676,7 +1691,7 @@ func (s *Server) RunResourceAction(ctx context.Context, q *application.ResourceA
1676
1691
Group : q .Group ,
1677
1692
}
1678
1693
actionRequest := fmt .Sprintf ("%s/%s/%s/%s" , rbacpolicy .ActionAction , q .Group , q .Kind , q .Action )
1679
- res , config , a , err := s .getAppResource (ctx , actionRequest , resourceRequest )
1694
+ res , config , a , err := s .getAppLiveResource (ctx , actionRequest , resourceRequest )
1680
1695
if err != nil {
1681
1696
return nil , err
1682
1697
}
0 commit comments