Documentation
¶
Index ¶
- Constants
- Variables
- type Cache
- func (cache *Cache) Changed() bool
- func (cache *Cache) DeleteEntry(node string)
- func (cache *Cache) GetEntry(node string) (Entry, error)
- func (cache *Cache) IsOutdated(now time.Time) bool
- func (cache *Cache) Keys() []string
- func (cache *Cache) Prune(ctx context.Context, client client.Client, now time.Time) ([]string, error)
- func (cache *Cache) SetEntry(node string, entry Entry) error
- func (cache *Cache) Store(ctx context.Context, client client.Client) error
- func (cache *Cache) UpdateTimestamp(now time.Time)
- type Entry
Constants ¶
const (
ConfigMapName = "dynatrace-node-cache"
)
Variables ¶
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 (*Cache) DeleteEntry ¶
DeleteEntry removes the node from the cache.
func (*Cache) GetEntry ¶
GetEntry returns the information about node, or error if not found or failed to unmarshall the data.
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 ¶
SetEntry updates the information about node, or error if failed to marshall the data.
func (*Cache) UpdateTimestamp ¶
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 ¶
IsMarkableForTermination checks if the timestamp from last mark is at least one hour old