func()

in internal/resource/tree.go [66:100]


func (b *treeBuilder) Build() *tree {
	t := &tree{
		byRef:     b.byRef,
		byManiRef: map[ManifestRef]*indexedResource{},
	}

	for _, idx := range b.byRef {
		t.byManiRef[idx.Resource.ManifestRef] = idx

		// CRs are dependent on their CRDs
		i := b.byGroup.IteratorAt(b.byGroup.GetNode(idx.Resource.ReadinessGroup))
		crd, ok := b.byDefiningGK[idx.Resource.GVK.GroupKind()]
		if ok {
			idx.PendingDependencies[crd.Resource.Ref] = struct{}{}
			crd.Dependents[idx.Resource.Ref] = idx
		}

		// Depend on any resources in the previous readiness group
		if i.Prev() {
			for _, dep := range i.Value() {
				idx.PendingDependencies[dep.Resource.Ref] = struct{}{}
			}
		}
		i.Next() // Prev always moves the cursor, even if it returns false

		// Any resources in the next readiness group depend on us
		if i.Next() && i.Key() > idx.Resource.ReadinessGroup {
			for _, cur := range i.Value() {
				idx.Dependents[cur.Resource.Ref] = cur
			}
		}
	}

	return t
}