in pkg/controllers/member/endpointslice/controller.go [414:432]
func (r *Reconciler) collectAndVerifyLastSeenGenerationAndTimestamp(ctx context.Context, endpointslice *discoveryv1.EndpointSlice, startTime time.Time) (time.Time, error) {
// Check if the two annotations are present; assign new values if they are absent.
lastSeenGenerationData, lastSeenGenerationOk := endpointslice.Annotations[metrics.MetricsAnnotationLastSeenGeneration]
lastSeenTimestampData, lastSeenTimestampOk := endpointslice.Annotations[metrics.MetricsAnnotationLastSeenTimestamp]
if !lastSeenGenerationOk || !lastSeenTimestampOk {
return startTime, r.annotateLastSeenGenerationAndTimestamp(ctx, endpointslice, startTime)
}
// Check if the two values are valid and up-to-date; assign new ones if they are not.
lastSeenGeneration, lastSeenGenerationErr := strconv.ParseInt(lastSeenGenerationData, 10, 64)
lastSeenTimestamp, lastSeenTimestampErr := time.Parse(metrics.MetricsLastSeenTimestampFormat, lastSeenTimestampData)
if lastSeenGenerationErr != nil || lastSeenTimestampErr != nil {
return startTime, r.annotateLastSeenGenerationAndTimestamp(ctx, endpointslice, startTime)
}
if lastSeenGeneration != endpointslice.Generation || lastSeenTimestamp.After(startTime) {
return startTime, r.annotateLastSeenGenerationAndTimestamp(ctx, endpointslice, startTime)
}
return lastSeenTimestamp, nil
}