From a7cb6ed9bb4e760d64e79ec1441a98b76cb2b2c3 Mon Sep 17 00:00:00 2001 From: thecooldrop Date: Mon, 22 Jul 2024 04:32:15 +0200 Subject: [PATCH] fix: tree output with app selector permission denied. (#18990) * Fix: wrong application name passed into function The application name which was passed into the function was a namespace-qualified name for the application, but actually a simple non-qualified name was needed. This leads to issue on the kube-apiserver side where qualified app name is used to retrieve the resource from a lister, leading to a cache-miss basically, since app was looked up by namespace/namespace/appname key, instead of namespace/appname key. Signed-off-by: TheCoolDrop * chore: Fix the name of the application used with tree=detailed output Signed-off-by: TheCoolDrop --------- Signed-off-by: TheCoolDrop --- cmd/argocd/commands/app.go | 4 ++-- util/argo/argo.go | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/cmd/argocd/commands/app.go b/cmd/argocd/commands/app.go index 3e530d74e5131..08af5431fa053 100644 --- a/cmd/argocd/commands/app.go +++ b/cmd/argocd/commands/app.go @@ -2400,13 +2400,13 @@ func waitOnApplicationStatus(ctx context.Context, acdClient argocdclient.Client, _ = w.Flush() } case "tree": - mapUidToNode, mapParentToChild, parentNode, mapNodeNameToResourceState := resourceParentChild(ctx, acdClient, appName, appNs) + mapUidToNode, mapParentToChild, parentNode, mapNodeNameToResourceState := resourceParentChild(ctx, acdClient, appRealName, appNs) if len(mapUidToNode) > 0 { fmt.Println() printTreeView(mapUidToNode, mapParentToChild, parentNode, mapNodeNameToResourceState) } case "tree=detailed": - mapUidToNode, mapParentToChild, parentNode, mapNodeNameToResourceState := resourceParentChild(ctx, acdClient, appName, appNs) + mapUidToNode, mapParentToChild, parentNode, mapNodeNameToResourceState := resourceParentChild(ctx, acdClient, appRealName, appNs) if len(mapUidToNode) > 0 { fmt.Println() printTreeViewDetailed(mapUidToNode, mapParentToChild, parentNode, mapNodeNameToResourceState) diff --git a/util/argo/argo.go b/util/argo/argo.go index 2afcce850e71a..a4d4ed603533c 100644 --- a/util/argo/argo.go +++ b/util/argo/argo.go @@ -1019,26 +1019,25 @@ func GetDifferentPathsBetweenStructs(a, b interface{}) ([]string, error) { return difference, nil } -// parseName will -func parseName(appName string, defaultNs string, delim string) (string, string) { - var ns string - var name string - t := strings.SplitN(appName, delim, 2) +// parseName will split the qualified name into its components, which are separated by the delimiter. +// If delimiter is not contained in the string qualifiedName then returned namespace is defaultNs. +func parseName(qualifiedName string, defaultNs string, delim string) (name string, namespace string) { + t := strings.SplitN(qualifiedName, delim, 2) if len(t) == 2 { - ns = t[0] + namespace = t[0] name = t[1] } else { - ns = defaultNs + namespace = defaultNs name = t[0] } - return name, ns + return } // ParseAppNamespacedName parses a namespaced name in the format namespace/name // and returns the components. If name wasn't namespaced, defaultNs will be // returned as namespace component. -func ParseFromQualifiedName(appName string, defaultNs string) (string, string) { - return parseName(appName, defaultNs, "/") +func ParseFromQualifiedName(qualifiedAppName string, defaultNs string) (appName string, appNamespace string) { + return parseName(qualifiedAppName, defaultNs, "/") } // ParseInstanceName parses a namespaced name in the format namespace_name