// check performs a consistency check on the container.
764163
func (c *Container) check() error {
	var a ErrorList

	if c.isArray() {
		array := c.array()
		if int32(len(array)) != c.n {
			a.Append(fmt.Errorf("array count mismatch: count=%d, n=%d", len(array), c.n))
		}
	} else if c.isRun() {
		n := c.runCountRange(0, maxContainerVal+1)
		if n != c.n {
			a.Append(fmt.Errorf("run count mismatch: count=%d, n=%d", n, c.n))
		}
	} else if c.isBitmap() {
		if n := c.bitmapCountRange(0, maxContainerVal+1); n != c.n {
			a.Append(fmt.Errorf("bitmap count mismatch: count=%d, n=%d", n, c.n))
		}
	} else {
		a.Append(fmt.Errorf("empty container"))
		if c.n != 0 {
			a.Append(fmt.Errorf("empty container with nonzero count: n=%d", c.n))
		}
	}

	if a == nil {
		return nil
	}
	return a
}
327790
func (r *ready) check() bool {
	rwMutex := r.c.L.(*sync.RWMutex)
	rwMutex.RLock()
	defer rwMutex.RUnlock()
	return r.ok
}
1022140
func (l *HealthzAdaptor) Check(req *http.Request) error {
	l.pointerLock.Lock()
	defer l.pointerLock.Unlock()
	if l.le == nil {
		return nil
	}
	return l.le.Check(l.timeout)
}
1052980
func (v *Validator) Check(password string) error {
	if strings.TrimSpace(password) == "" {
		return ErrEmpty
	}
	if len(password) < v.options.MinLength {
		return ErrTooShort
	}
	if countUniqueChars(password) < v.options.MinDiff {
		return ErrTooFewChars
	}

	// Inspired by cracklib
	maxrepeat := 3.0 + (0.09 * float64(len(password)))
	if countSystematicChars(password) > int(maxrepeat) {
		return ErrTooSystematic
	}

	return v.foundInDictionaries(password)
}
966792
func (c *Checker) Check(rel string, recurse bool, beforeRev, afterRev string) ([]Change, error) {
	// If revision is unset use VCS's default revision
	dBefore, dAfter := c.vcs.DefaultRevision()
	if beforeRev == "" {
		beforeRev = dBefore
	}
	if afterRev == "" {
		afterRev = dAfter
	}
	c.recurse = recurse

	var err error
	c.path, err = importPathTo(rel)
	if err != nil {
		return nil, err
	}

	c.logf("import path: %q before: %q after: %q recursive: %v\n", c.path, beforeRev, afterRev, c.recurse)

	// Parse revisions from VCS into go/ast
	start := time.Now()
	if c.b, err = c.parse(beforeRev); err != nil {
		return nil, err
	}
	if c.a, err = c.parse(afterRev); err != nil {
		return nil, err
	}
	parse := time.Since(start)

	start = time.Now()
	changes, err := c.compareDecls()
	if err != nil {
		var buf bytes.Buffer
		fmt.Fprintf(&buf, "error comparing declarations: %s\n", err)
		if derr, ok := err.(*diffError); ok {
			_ = ast.Fprint(&buf, c.b[derr.pkg].fset, derr.bdecl, ast.NotNilFilter)
			_ = ast.Fprint(&buf, c.a[derr.pkg].fset, derr.adecl, ast.NotNilFilter)
		}
		return nil, errors.New(buf.String())
	}
	diff := time.Since(start)

	start = time.Now()
	sort.Sort(byID(changes))
	sort := time.Since(start)

	c.logf("Timing: parse: %v, diff: %v, sort: %v, total: %v\n", parse, diff, sort, parse+diff+sort)
	c.logf("Changes detected: %v\n", len(changes))

	return changes, nil
}
355615
func (ipc ImagePullCheck) Check() (warnings, errorList []error) {
	for _, image := range ipc.imageList {
		ret, err := ipc.runtime.ImageExists(image)
		if ret && err == nil {
			klog.V(1).Infof("image exists: %s", image)
			continue
		}
		if err != nil {
			errorList = append(errorList, errors.Wrapf(err, "failed to check if image %s exists", image))
		}
		klog.V(1).Infof("pulling %s", image)
		if err := ipc.runtime.PullImage(image); err != nil {
			errorList = append(errorList, errors.Wrapf(err, "failed to pull image %s", image))
		}
	}
	return warnings, errorList
}
737359
func (sc ServiceCheck) Check() (warnings, errorList []error) {
	klog.V(1).Infoln("validating if the service is enabled and active")
	initSystem, err := initsystem.GetInitSystem()
	if err != nil {
		return []error{err}, nil
	}

	warnings = []error{}

	if !initSystem.ServiceExists(sc.Service) {
		warnings = append(warnings, errors.Errorf("%s service does not exist", sc.Service))
		return warnings, nil
	}

	if !initSystem.ServiceIsEnabled(sc.Service) {
		warnings = append(warnings,
			errors.Errorf("%s service is not enabled, please run 'systemctl enable %s.service'",
				sc.Service, sc.Service))
	}

	if sc.CheckIfActive && !initSystem.ServiceIsActive(sc.Service) {
		errorList = append(errorList,
			errors.Errorf("%s service is not active, please run 'systemctl start %s.service'",
				sc.Service, sc.Service))
	}

	return warnings, errorList
}
979106
func (c *CheckTCP) check() {
	var currentStatus string
	previousStatus := c.Status

	conn, err := c.dialer.Dial(`tcp`, c.tcp)
	if err != nil {
		logrus.Warnf("[health-check] TCP Check is failing => %s", err)
		currentStatus = BAD
	} else {
		logrus.Debugf("[health-check] TCP check on '%v' at '%s' is passing", c.DestinationID, c.tcp)
		currentStatus = OK
		conn.Close()
	}

	if currentStatus != previousStatus {
		c.Status = currentStatus
		c.updateCh <- true
	}
}
1362769
func Check(err error, checker func(error) bool) bool {
	if annotated, ok := err.(*annotatedError); ok {
		return checker(annotated.LastError())
	}
	return checker(err)
}
1143024
func (c DeclChecker) Check(before, after ast.Decl) (DeclChange, error) {
	// compare types, ignore comments etc, so reflect.DeepEqual isn't good enough

	if reflect.TypeOf(before) != reflect.TypeOf(after) {
		// Declaration type changed, such as GenDecl to FuncDecl (eg var/const to func)
		return breaking("changed declaration", after.Pos()), nil
	}

	switch b := before.(type) {
	case *ast.GenDecl:
		a := after.(*ast.GenDecl)

		// getDecls flattened var/const blocks, so .Specs should contain just 1

		if reflect.TypeOf(b.Specs[0]) != reflect.TypeOf(a.Specs[0]) {
			// Spec changed, such as ValueSpec to TypeSpec (eg var/const to struct)
			return breaking("changed spec", a.Specs[0].Pos()), nil
		}

		switch bspec := b.Specs[0].(type) {
		case *ast.ValueSpec:
			// var / const
			aspec := a.Specs[0].(*ast.ValueSpec)

			btype := c.binfo.ObjectOf(bspec.Names[0])
			atype := c.ainfo.ObjectOf(aspec.Names[0])

			if !types.Identical(btype.Type(), atype.Type()) {
				// Inferred types from external packages (inc. stdlib) aren't identical
				// according to types.Identical(), so compare the string representations
				if btype.String() != atype.String() {
					return breaking("changed type", atype.Pos()), nil
				}
			}
		case *ast.TypeSpec:
			// type struct/interface/aliased
			aspec := a.Specs[0].(*ast.TypeSpec)

			if reflect.TypeOf(bspec.Type) != reflect.TypeOf(aspec.Type) {
				// Spec change, such as from StructType to InterfaceType or different aliased types
				return breaking("changed type of value spec", aspec.Pos()), nil
			}

			switch btype := bspec.Type.(type) {
			case *ast.InterfaceType:
				atype := aspec.Type.(*ast.InterfaceType)
				return c.checkInterface(btype, atype, disallowRemoval)
			case *ast.StructType:
				atype := aspec.Type.(*ast.StructType)
				return c.checkStruct(btype, atype)
			case *ast.Ident:
				// alias
				atype := aspec.Type.(*ast.Ident)
				if btype.Name != atype.Name {
					// Alias typing changed underlying types
					return breaking("alias changed its underlying type", atype.Pos()), nil
				}
			}
		}
	case *ast.FuncDecl:
		a := after.(*ast.FuncDecl)
		return c.checkFunc(b.Type, a.Type)
	default:
		return DeclChange{}, fmt.Errorf("unknown declaration type: %T", before)
	}
	return none(), nil
}
107968
func (ld *etcdLockDescriptor) Check(ctx context.Context) error {
	_, err := ld.s.cli.KeepAliveOnce(ctx, ld.leaseID)
	if err != nil {
		return convertError(err, "lease")
	}
	return nil
}
198348
func (c *inflationOptions) Check() error {
	_, err := strkey.Decode(strkey.VersionByteAccountID, c.AccountID)
	if err != nil {
		return ErrInvalidAccountID
	}
	if c.Destination == "" {
		return ErrDestinationMissing
	}

	return nil
}
336610
func (sc ServiceCheck) Check() error {
	if len(sc.Name) == 0 {
		return fmt.Errorf("statsd.ServiceCheck name is required")
	}
	if byte(sc.Status) < 0 || byte(sc.Status) > 3 {
		return fmt.Errorf("statsd.ServiceCheck status has invalid value")
	}
	return nil
}
793078
func (cc *ConnChecker) Check(h *host.Host, swarm bool) (string, *auth.Options, error) {
	authOptions := h.AuthOptions()
	dockerHost, err := h.Driver.GetURL()
	if err != nil {
		return "", &auth.Options{}, err
	}
	return dockerHost, authOptions, nil
}
167863
func (s *Safety) Check(raw string) Level {
	l := len([]rune(raw))
	if l < s.ml {
		return Terrible
	}

	if s.isAsdf(raw) || s.isByStep(raw) {
		return Simple
	}

	if s.isCommonPassword(raw, s.mf) {
		return Simple
	}

	typ := 0

	if lower.MatchString(raw) {
		typ++
	}
	if upper.MatchString(raw) {
		typ++
	}
	if number.MatchString(raw) {
		typ++
	}
	if marks.MatchString(raw) {
		typ++
	}

	if l < 8 && typ == 2 {
		return Simple
	}

	if typ < s.mt {
		return Medium
	}

	return Strong
}
951128
func (idsc IsDockerSystemdCheck) Check() (warnings, errorList []error) {
	warnings = []error{}
	driver, err := util.GetCgroupDriverDocker(exec.New())
	if err != nil {
		errorList = append(errorList, err)
		return nil, errorList
	}
	if driver != util.CgroupDriverSystemd {
		err = errors.Errorf("detected %q as the Docker cgroup driver. "+
			"The recommended driver is %q. "+
			"Please follow the guide at https://kubernetes.io/docs/setup/cri/",
			driver,
			util.CgroupDriverSystemd)
		warnings = append(warnings, err)
	}
	return warnings, nil
}
195532
func (c *BundlingChecker) check(items []checkerItem) {
	c.waitc <- struct{}{}
	c.wg.Add(1)
	go func() {
		c.doCheck(items)
		c.wg.Done()
		<-c.waitc
	}()

}