Skip to content

Commit

Permalink
sequential recursion without go routines
Browse files Browse the repository at this point in the history
  • Loading branch information
jkosik committed Aug 5, 2022
1 parent a3344dc commit 9ab9be4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## helm-decomposer
The tool templates the Helm package (.tgz or untarred folder) identifies all images in use and visualizes tree structure of the Chart and all dependencies.
The tool templates the Helm package (.tgz or untarred folder) identifies all images in use and visualizes tree structure of the Chart and all dependencies (aliased dependencies are merged).

## Usage
- `helm pull bitnami/nginx`
Expand Down
21 changes: 11 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"regexp"
"runtime"
"strings"
"time"

"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader"
Expand Down Expand Up @@ -162,25 +161,27 @@ func main() {
// root Node already declared, len == 1
shift := len(allNodeIDs)
for i, dep := range chartDeps {
// shifting currentDepsNodeIDs overcomes zero-based range indexing
currentDepsNodeIDs = append(currentDepsNodeIDs, shift+i) // [1,2,3,4], next parent: [5,6,7]...
// Composing from scratch slice of child Node IDs for the tested parent.
// Node ID == Slice KEY IDs for the zer-based Tree which will be submitted to vis().
// currentDepsNodeIDs's VALUES are +1 to KEYS from the Tree
currentDepsNodeIDs = append(currentDepsNodeIDs, shift+i) // [1,2,3,4], for the next parent: [5,6,7]...

// allNodeIDs grow with every new dependencies. Slice keys represent Node IDs. Length represents Node count.
// allNodeIDs grows with every new dependencies. Slice keys represent Node IDs (zero-based). Slice length represents Node count.
allNodeIDs = append(allNodeIDs, "node")

fmt.Printf("Adding \"%s\" Node to the Tree. Current Node count: %d \n", dep.Name(), len(allNodeIDs))
fmt.Printf("New Node \"%s\" (Node ID: %d) added to the Tree. Current Node count: %d \n", dep.Name(), shift+i, len(allNodeIDs))
fullTree = append(fullTree, node{label: dep.Name(), children: []int{}})
}

fmt.Printf("New Tree state: %v \n", fullTree)
fullTree[nodeID] = node{label: parent, children: currentDepsNodeIDs} // NodeID initially passed to the function
fmt.Printf("Children added to the Node in the Tree: %v \n", fullTree)
fmt.Printf("Childrens in Tree updated for Node \"%s\" (Node ID %d): %v \n", parent, nodeID, fullTree)

for i, dep := range chartDeps {
fmt.Printf("Recursive search for: %s\n", dep.Name())
//fmt.Println(shift + i)
go depRecursion(*dep, shift+i)
time.Sleep(100 * time.Millisecond)
fmt.Printf("Recursive search for: \"%s\", Node ID: %d\n", dep.Name(), shift+i)

depRecursion(*dep, shift+i)
//time.Sleep(100 * time.Millisecond)
}
}
return fullTree
Expand Down

0 comments on commit 9ab9be4

Please sign in to comment.