func()

in pkg/operator/apis/monitoring/v1/monitoring_types.go [86:132]


func (status *MonitoringStatus) SetMonitoringCondition(gen int64, now metav1.Time, cond *MonitoringCondition) bool {
	var (
		specChanged              = status.ObservedGeneration != gen
		statusTransition, update bool
		conds                    = make(map[MonitoringConditionType]*MonitoringCondition)
	)

	if !cond.IsValid() {
		return false
	}

	// Set up defaults.
	for _, mc := range NewDefaultConditions(now) {
		conds[mc.Type] = &mc
	}
	// Overwrite with any previous state.
	for _, mc := range status.Conditions {
		conds[mc.Type] = &mc
	}

	// Set some timestamp defaults if unspecified.
	cond.LastUpdateTime = now

	// Check if the condition results in a transition of status state.
	if old := conds[cond.Type]; old.Status == cond.Status {
		cond.LastTransitionTime = old.LastTransitionTime
	} else {
		cond.LastTransitionTime = cond.LastUpdateTime
		statusTransition = true
	}

	// Set condition.
	conds[cond.Type] = cond

	// Only update status if the spec has changed (indicated by Generation field) or
	// if this update transitions status state.
	if specChanged || statusTransition {
		update = true
		status.ObservedGeneration = gen
		status.Conditions = status.Conditions[:0]
		for _, c := range conds {
			status.Conditions = append(status.Conditions, *c)
		}
	}

	return update
}