in pkg/controller/policy.go [84:122]
func (p *defaultPolicy) Check(ck *PolicyCheck) (bool, error) {
log := p.log.WithFields(logfields.Intent(ck.Intent)).
WithFields(logrus.Fields{
"cluster-active": fmt.Sprintf("%d", ck.ClusterActive),
"cluster-count": fmt.Sprintf("%d", ck.ClusterCount),
})
// policy checks are applied to intended actions, Intents that are next in
// line to be executed. Projections are made without considering the policy
// at time of the projection to the next state. So, we have to check when
// the update process is starting up.
startingUpdate := ck.Intent.Active == marker.NodeActionStabilize
if !startingUpdate {
if ck.Intent.InProgress() {
if logging.Debuggable {
log.Debug("permit already in progress")
}
return true, nil
}
if ck.Intent.Terminal() {
if logging.Debuggable {
log.Debug("permit terminal intent")
}
return true, nil
}
}
// If there are no other active nodes in the cluster, then go ahead with the
// intended action.
if ck.ClusterActive < maxClusterActive {
log.WithField("allowed-active", fmt.Sprintf("%d", maxClusterActive)).Debugf("permit according to active threshold")
return true, nil
}
log.Debug("deny intent")
return false, nil
}