mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-08-19 12:36:39 +00:00
feat: upstream enterprise preview --------- Signed-off-by: Oliver Baehler <oliver@sudo-i.net> Co-authored-by: CorentinPtrl <pitrel.corentin@gmail.com>
56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
// Copyright 2020-2026 Project Capsule Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package processor
|
|
|
|
import (
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
|
|
"github.com/projectcapsule/capsule/pkg/runtime/gvk"
|
|
)
|
|
|
|
// Keeps track of generated items.
|
|
type Accumulator = map[string]*AccumulatorItem
|
|
|
|
// Keeps track of generated items.
|
|
type AccumulatorItem struct {
|
|
Resource gvk.ResourceID
|
|
Objects *[]AccumulatorObject
|
|
}
|
|
|
|
// Keeps track of generated items.
|
|
type AccumulatorObject struct {
|
|
Origin gvk.TenantResourceIDWithOrigin
|
|
Object *unstructured.Unstructured
|
|
}
|
|
|
|
func AccumulatorAdd(
|
|
acc Accumulator,
|
|
resource gvk.ResourceID,
|
|
obj AccumulatorObject,
|
|
) {
|
|
if acc == nil {
|
|
return
|
|
}
|
|
|
|
key := resource.GetKey("")
|
|
|
|
if entry, ok := acc[key]; ok && entry != nil {
|
|
if entry.Objects == nil {
|
|
list := make([]AccumulatorObject, 0, 1)
|
|
entry.Objects = &list
|
|
}
|
|
|
|
*entry.Objects = append(*entry.Objects, obj)
|
|
|
|
return
|
|
}
|
|
|
|
list := []AccumulatorObject{obj}
|
|
|
|
acc[key] = &AccumulatorItem{
|
|
Resource: resource,
|
|
Objects: &list,
|
|
}
|
|
}
|