func (d *delta) add(i *item) {
	key := mustKeyObject(i.obj)
	if other, ok := d.cache[key]; ok && other.event == eventAdd && i.event == eventDelete {
		delete(d.cache, key)
	} else if ok && other.event == eventAdd && i.event == eventUpdate {
		i.event = eventAdd
		d.cache[key] = i
	} else if ok && other.event == eventDelete && (i.event == eventAdd || i.event == eventUpdate) {
		i.event = eventUpdate
		d.cache[key] = i
	} else {
		d.cache[key] = i
	}
}
add will add an item to the delta cache. It will debounce the objects.
package controller
import (
	"encoding/base64"
	"encoding/json"
	"fmt"
	"reflect"
	"time"
	"github.com/sirupsen/logrus"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime"
	"castai-agent/internal/castai"
)
func newDelta(log logrus.FieldLogger, clusterID, clusterVersion string) *delta {
	return &delta{
		log:            log,
		clusterID:      clusterID,
		clusterVersion: clusterVersion,
		fullSnapshot:   true,
		cache:          map[string]*item{},
	}
}
type delta struct {
	log            logrus.FieldLogger
	clusterID      string
	clusterVersion string
	fullSnapshot   bool
	cache          map[string]*item
}