// Check returns true if the task can be scheduled into the given node.
165249
func (f *ReadyFilter) Check(n *NodeInfo) bool {
	return n.Status.State == api.NodeStatus_READY &&
		n.Spec.Availability == api.NodeAvailabilityActive
}
1345285
func (p Plist) Check(path string) (bool, error) {
	if p.binPath == "" {
		return false, fmt.Errorf("Invalid ProgramArguments")
	}

	// If path doesn't exist, we don't match
	if _, err := os.Stat(path); os.IsNotExist(err) {
		return false, nil
	}

	buf, err := ioutil.ReadFile(path)
	if err != nil {
		return false, err
	}

	plistXML := p.plistXML()
	if string(buf) == plistXML {
		return true, nil
	}

	return false, nil
}
814982
func (f *LevelFilter) Check(line []byte) bool {
	f.once.Do(f.init)

	// Check for a log level
	var level LogLevel
	x := bytes.IndexByte(line, '[')
	if x >= 0 {
		y := bytes.IndexByte(line[x:], ']')
		if y >= 0 {
			level = LogLevel(line[x+1 : x+y])
		}
	}

	_, ok := f.badLevels[level]
	return !ok
}
1032798
func CheckNodeUnschedulablePredicate(pod *v1.Pod, meta PredicateMetadata, nodeInfo *schedulernodeinfo.NodeInfo) (bool, []PredicateFailureReason, error) {
	if nodeInfo == nil || nodeInfo.Node() == nil {
		return false, []PredicateFailureReason{ErrNodeUnknownCondition}, nil
	}

	// If pod tolerate unschedulable taint, it's also tolerate `node.Spec.Unschedulable`.
	podToleratesUnschedulable := v1helper.TolerationsTolerateTaint(pod.Spec.Tolerations, &v1.Taint{
		Key:    schedulerapi.TaintNodeUnschedulable,
		Effect: v1.TaintEffectNoSchedule,
	})

	// TODO (k82cn): deprecates `node.Spec.Unschedulable` in 1.13.
	if nodeInfo.Node().Spec.Unschedulable && !podToleratesUnschedulable {
		return false, []PredicateFailureReason{ErrNodeUnschedulable}, nil
	}

	return true, nil, nil
}
1103678
func (la *LoginAttempt) Check() error {
	if la.Time.IsZero() {
		return trace.BadParameter("missing parameter time")
	}
	return nil
}
531664
func (evm *egressVXLANMonitor) check(retryOnly bool) bool {
	inFlows, err := evm.ovsif.DumpFlows("table=10")
	if err != nil {
		utilruntime.HandleError(err)
		return false
	}
	outFlows, err := evm.ovsif.DumpFlows("table=100")
	if err != nil {
		utilruntime.HandleError(err)
		return false
	}

	inTraffic := make(map[string]uint64)
	for _, flow := range inFlows {
		parsed, err := ovs.ParseFlow(ovs.ParseForDump, flow)
		if err != nil {
			utilruntime.HandleError(fmt.Errorf("Error parsing VXLAN input flow: %v", err))
			continue
		}
		tunSrc, _ := parsed.FindField("tun_src")
		if tunSrc == nil {
			continue
		}
		if evm.monitorNodes[tunSrc.Value] == nil {
			continue
		}
		nPackets, err := parseNPackets(parsed)
		if err != nil {
			utilruntime.HandleError(fmt.Errorf("Could not parse %q: %v", flow, err))
			continue
		}
		inTraffic[tunSrc.Value] = nPackets
	}

	outTraffic := make(map[string]uint64)
	for _, flow := range outFlows {
		parsed, err := ovs.ParseFlow(ovs.ParseForDump, flow)
		if err != nil {
			utilruntime.HandleError(fmt.Errorf("Error parsing VXLAN output flow: %v", err))
			continue
		}
		tunDst := ""
		for _, act := range parsed.Actions {
			if act.Name == "set_field" && strings.HasSuffix(act.Value, "->tun_dst") {
				tunDst = strings.TrimSuffix(act.Value, "->tun_dst")
				break
			}
		}
		if tunDst == "" {
			continue
		}
		if evm.monitorNodes[tunDst] == nil {
			continue
		}
		nPackets, err := parseNPackets(parsed)
		if err != nil {
			utilruntime.HandleError(fmt.Errorf("Could not parse %q: %v", flow, err))
			continue
		}
		outTraffic[tunDst] += nPackets
	}

	retry := false
	for _, node := range evm.monitorNodes {
		if retryOnly && node.retries == 0 {
			continue
		}

		in := inTraffic[node.nodeIP]
		out := outTraffic[node.nodeIP]

		// If `in` was missing from the OVS output then `out` should be missing
		// too, so both variables will be 0 and we won't end up doing anything
		// below. If `out` is missing but `in` isn't then that means we know about
		// the node but aren't currently routing egress traffic to it. If it is
		// currently marked offline, then we'll keep monitoring for it to come
		// back online (by watching `in`) but if it is currently marked online
		// then we *won't* notice if it goes offline.
		//
		// Note also that the code doesn't have to worry about n_packets
		// overflowing and rolling over; the worst that can happen is that if
		// `out` rolls over at the same time as the node goes offline then we
		// won't notice the node being offline until the next poll.

		if node.offline {
			if in > node.in {
				klog.Infof("Node %s is back online", node.nodeIP)
				node.offline = false
				evm.updates <- node
			} else if evm.tracker != nil {
				// We can ignore the return value because if the node responds
				// (with either success or "connection refused") we'll see it
				// in the OVS packet counts.
				go evm.tracker.Ping(node.nodeIP, defaultPollInterval)
			}
		} else {
			if out > node.out && in == node.in {
				node.retries++
				if node.retries > maxRetries {
					klog.Warningf("Node %s is offline", node.nodeIP)
					node.retries = 0
					node.offline = true
					evm.updates <- node
				} else {
					klog.V(2).Infof("Node %s may be offline... retrying", node.nodeIP)
					retry = true
					continue
				}
			}
		}

		node.in = in
		node.out = out
	}

	return retry
}
195532
func (c *BundlingChecker) check(items []checkerItem) {
	c.waitc <- struct{}{}
	c.wg.Add(1)
	go func() {
		c.doCheck(items)
		c.wg.Done()
		<-c.waitc
	}()

}
243695
func (b *Bitmap) Check() error {
	var a ErrorList

	// Check each container.
	citer, _ := b.Containers.Iterator(0)
	for citer.Next() {
		k, c := citer.Value()
		if err := c.check(); err != nil {
			a.AppendWithPrefix(err, fmt.Sprintf("%d/", k))
		}
	}

	if len(a) == 0 {
		return nil
	}
	return a
}
234655
func Check(conn *grpc.ClientConn) (bool, error) {
	res, err := healthpb.NewHealthClient(conn).Check(context.Background(), &healthpb.HealthCheckRequest{})
	if err != nil {
		return false, err
	}
	return res.Status == healthpb.HealthCheckResponse_SERVING, nil
}
627410
func (le *LeaderElector) Check(maxTolerableExpiredLease time.Duration) error {
	if !le.IsLeader() {
		// Currently not concerned with the case that we are hot standby
		return nil
	}
	// If we are more than timeout seconds after the lease duration that is past the timeout
	// on the lease renew. Time to start reporting ourselves as unhealthy. We should have
	// died but conditions like deadlock can prevent this. (See #70819)
	if le.clock.Since(le.observedTime) > le.config.LeaseDuration+maxTolerableExpiredLease {
		return fmt.Errorf("failed election to renew leadership on lease %s", le.config.Name)
	}

	return nil
}
473763
func (crc ContainerRuntimeCheck) Check() (warnings, errorList []error) {
	klog.V(1).Infoln("validating the container runtime")
	if err := crc.runtime.IsRunning(); err != nil {
		errorList = append(errorList, err)
	}
	return warnings, errorList
}
148403
func (p *leakcheckElemTypePool) Check(t *testing.T) {
	p.Lock()
	defer p.Unlock()

	require.Equal(t, p.NumGets, p.NumPuts)
	require.Empty(t, p.PendingItems)
}
1352757
func (c *CheckTCP) check() {
	conn, err := c.dialer.Dial(`tcp`, c.TCP)
	if err != nil {
		c.Logger.Printf("[WARN] agent: Check %q socket connection failed: %s", c.CheckID, err)
		c.Notify.UpdateCheck(c.CheckID, api.HealthCritical, err.Error())
		return
	}
	conn.Close()
	c.Logger.Printf("[DEBUG] agent: Check %q is passing", c.CheckID)
	c.Notify.UpdateCheck(c.CheckID, api.HealthPassing, fmt.Sprintf("TCP connect %s: Success", c.TCP))
}
782410
func (f *PlatformFilter) Check(n *NodeInfo) bool {
	// if the supportedPlatforms field is empty, then either it wasn't
	// provided or there are no constraints
	if len(f.supportedPlatforms) == 0 {
		return true
	}
	// check if the platform for the node is supported
	if n.Description != nil {
		if nodePlatform := n.Description.Platform; nodePlatform != nil {
			for _, p := range f.supportedPlatforms {
				if f.platformEqual(*p, *nodePlatform) {
					return true
				}
			}
		}
	}
	return false
}
728911
func (swc SwapCheck) Check() (warnings, errorList []error) {
	klog.V(1).Infoln("validating whether swap is enabled or not")
	f, err := os.Open("/proc/swaps")
	if err != nil {
		// /proc/swaps not available, thus no reasons to warn
		return nil, nil
	}
	defer f.Close()
	var buf []string
	scanner := bufio.NewScanner(f)
	for scanner.Scan() {
		buf = append(buf, scanner.Text())
	}
	if err := scanner.Err(); err != nil {
		return nil, []error{errors.Wrap(err, "error parsing /proc/swaps")}
	}

	if len(buf) > 1 {
		return nil, []error{errors.New("running with swap on is not supported. Please disable swap")}
	}

	return nil, nil
}
530544
func (s *Store) NodeCheck(nodeName string, checkID types.CheckID) (uint64, *structs.HealthCheck, error) {
	tx := s.db.Txn(false)
	defer tx.Abort()

	return s.getNodeCheckTxn(tx, nodeName, checkID)
}
1019811
func Check() []Result {
	results := make([]Result, 0, len(checkers))
	for _, checker := range checkers {
		startTime := time.Now()
		if raw, err := checker.check(); err != nil && err != ErrDisabledComponent {
			results = append(results, Result{
				Name:     checker.name,
				Raw:      raw,
				Status:   "fail - " + err.Error(),
				Duration: time.Now().Sub(startTime),
			})
		} else if err == nil {
			results = append(results, Result{
				Name:     checker.name,
				Raw:      raw,
				Status:   HealthCheckOK,
				Duration: time.Now().Sub(startTime),
			})
		}
	}
	return results
}