func newPolicyCheck()

in pkg/controller/policy.go [32:72]


func newPolicyCheck(in *intent.Intent, resources cache.Store) (*PolicyCheck, error) {
	// TODO: use a workqueue (or other facility) to pull a stable consistent
	// view at each intent.
	ress := resources.List()
	clusterCount := len(ress)
	clusterActive := 0
	for _, res := range ress {
		node, ok := res.(*v1.Node)
		if !ok {
			clusterCount--
			continue
		}
		cin := intent.Given(node)
		if isClusterActive(cin) {
			clusterActive++
			if logging.Debuggable {
				logging.New("policy-check").WithFields(logfields.Intent(cin)).
					WithField("cluster-active", fmt.Sprintf("%d", clusterActive)).
					Debug("cluster node's intent considered active")
			}
		}
	}

	if logging.Debuggable {
		logging.New("policy-check").WithFields(logfields.Intent(in)).WithFields(logrus.Fields{
			"cluster-count":  fmt.Sprintf("%d", clusterCount),
			"cluster-active": fmt.Sprintf("%d", clusterActive),
			"resource-count": fmt.Sprintf("%d", len(ress)),
		}).Debug("collected policy check")
	}

	if clusterCount <= 0 {
		return nil, errors.Errorf("%d resources listed of inappropriate type", len(ress))
	}

	return &PolicyCheck{
		Intent:        in,
		ClusterActive: clusterActive,
		ClusterCount:  clusterCount,
	}, nil
}