cache

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigMapName = "dynatrace-node-cache"
)

Variables

View Source
var ErrEntryNotFound = errors.New("node entry not found")

ErrEntryNotFound is returned when entry hasn't been found in the cache.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache manages information about Nodes where Dynatrace OneAgents are/were running. There is a reason behind not directly having a `map[string]Entry`: "lazy parsing". The `map` within the ConfigMap can have 100+ entries, if the k8s cluster was big enough. So the idea is that we only parse the Entry that we are actually working on, and leave the rest alone. (we still load it into memory, but that comes with having the cache in memory :P ) The Reconcile loop will only work with 1 Node at a time, so it make sense to not always parse the other n-1 entries for no good reason.

Every now and then, we will need to clean up the cache, that is when we will need to parse all of the Entries, but this only happens every 10m. Note: This logic is old, and was only cleaned up for (hopefully) better understandability.

func New

func New(ctx context.Context, apiReader client.Reader, ns string, owner client.Object) (*Cache, error)

func (*Cache) Changed

func (cache *Cache) Changed() bool

Changed returns true if changes have been made to the cache instance.

func (*Cache) DeleteEntry

func (cache *Cache) DeleteEntry(node string)

DeleteEntry removes the node from the cache.

func (*Cache) GetEntry

func (cache *Cache) GetEntry(node string) (Entry, error)

GetEntry returns the information about node, or error if not found or failed to unmarshall the data.

func (*Cache) IsOutdated

func (cache *Cache) IsOutdated(now time.Time) bool

func (*Cache) Keys

func (cache *Cache) Keys() []string

Keys returns a list of node names in the cache.

func (*Cache) Prune

func (cache *Cache) Prune(ctx context.Context, client client.Client, now time.Time) ([]string, error)

Prune will collect the nodeNames from the Cache that do not have a corresponding k8s Node in cluster. - We return these nodeNames to the Controller, to send a mark for termination if need, just in case. It will also remove the Entries that have a corresponding k8s Node in cluster, but have not had a OneAgent on them for a over an hour.

func (*Cache) SetEntry

func (cache *Cache) SetEntry(node string, entry Entry) error

SetEntry updates the information about node, or error if failed to marshall the data.

func (*Cache) Store

func (cache *Cache) Store(ctx context.Context, client client.Client) error

func (*Cache) UpdateTimestamp

func (cache *Cache) UpdateTimestamp(now time.Time)

type Entry

type Entry struct {
	LastSeen                 time.Time `json:"seen"`
	LastMarkedForTermination time.Time `json:"marked"`
	IPAddress                string    `json:"ip"`

	// Only informational
	NodeName     string `json:"-"`        // only here to simplify the code
	DynaKubeName string `json:"instance"` // the mismatch is intentional, this has no real purpose, left it in for compatibility reasons
}

Entry contains information about a Node where a Dynatrace OneAgent is/was.

func (*Entry) IsMarkableForTermination

func (entry *Entry) IsMarkableForTermination(now time.Time) bool

IsMarkableForTermination checks if the timestamp from last mark is at least one hour old

func (*Entry) SetLastMarkedForTerminationTimestamp

func (entry *Entry) SetLastMarkedForTerminationTimestamp(now time.Time)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL