Skip to content

Commit

Permalink
fix: tree output with app selector permission denied. (#18990)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* chore: Fix the name of the application used with tree=detailed output

Signed-off-by: TheCoolDrop <[email protected]>

---------

Signed-off-by: TheCoolDrop <[email protected]>
  • Loading branch information
thecooldrop authored Jul 22, 2024
1 parent 64b76f2 commit a7cb6ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 9 additions & 10 deletions util/argo/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a7cb6ed

Please sign in to comment.