// FindCRDCondition returns the condition you're looking for or nil.
488595
func FindCRDCondition(crd *CustomResourceDefinition, conditionType CustomResourceDefinitionConditionType) *CustomResourceDefinitionCondition {
	for i := range crd.Status.Conditions {
		if crd.Status.Conditions[i].Type == conditionType {
			return &crd.Status.Conditions[i]
		}
	}

	return nil
}
844368
func NewDefaultRocRWithSrcLen(sourceLength uint) (indicator *RocR, err error) {
	ind, err := NewDefaultRocR()

	// only initialise the storage if there is enough source data to require it
	if sourceLength-uint(ind.GetLookbackPeriod()) > 1 {
		ind.Data = make([]float64, 0, sourceLength-uint(ind.GetLookbackPeriod()))
	}

	return ind, err
}
919047
func SetCRDCondition(crd *CustomResourceDefinition, newCondition CustomResourceDefinitionCondition) {
	existingCondition := FindCRDCondition(crd, newCondition.Type)
	if existingCondition == nil {
		newCondition.LastTransitionTime = metav1.NewTime(time.Now())
		crd.Status.Conditions = append(crd.Status.Conditions, newCondition)
		return
	}

	if existingCondition.Status != newCondition.Status {
		existingCondition.Status = newCondition.Status
		existingCondition.LastTransitionTime = newCondition.LastTransitionTime
	}

	existingCondition.Reason = newCondition.Reason
	existingCondition.Message = newCondition.Message
}
479550
func (cli *client) isCRDReady(name string) error {
	var r k8sapi.CustomResourceDefinition
	err := cli.getResource("apiextensions.k8s.io/v1beta1", "", "customresourcedefinitions", name, &r)
	if err != nil {
		return fmt.Errorf("get crd %s: %v", name, err)
	}

	conds := make(map[string]string) // For debugging, keep the conditions around.
	for _, c := range r.Status.Conditions {
		if c.Type == k8sapi.Established && c.Status == k8sapi.ConditionTrue {
			return nil
		}
		conds[string(c.Type)] = string(c.Status)
	}
	return fmt.Errorf("crd %s not ready %#v", name, conds)
}
106532
func detachColumnCNFConditions(sctx sessionctx.Context, conditions []expression.Expression, checker *conditionChecker) ([]expression.Expression, []expression.Expression) {
	var accessConditions, filterConditions []expression.Expression
	for _, cond := range conditions {
		if sf, ok := cond.(*expression.ScalarFunction); ok && sf.FuncName.L == ast.LogicOr {
			dnfItems := expression.FlattenDNFConditions(sf)
			colulmnDNFItems, hasResidual := detachColumnDNFConditions(sctx, dnfItems, checker)
			// If this CNF has expression that cannot be resolved as access condition, then the total DNF expression
			// should be also appended into filter condition.
			if hasResidual {
				filterConditions = append(filterConditions, cond)
			}
			if len(colulmnDNFItems) == 0 {
				continue
			}
			rebuildDNF := expression.ComposeDNFCondition(sctx, colulmnDNFItems...)
			accessConditions = append(accessConditions, rebuildDNF)
			continue
		}
		if !checker.check(cond) {
			filterConditions = append(filterConditions, cond)
			continue
		}
		accessConditions = append(accessConditions, cond)
		if checker.shouldReserve {
			filterConditions = append(filterConditions, cond)
			checker.shouldReserve = checker.length != types.UnspecifiedLength
		}
	}
	return accessConditions, filterConditions
}
700731
func (s *DocumentService) FindDocumentStore(ctx context.Context, name string) (influxdb.DocumentStore, error) {
	return s.FindDocumentStoreFn(ctx, name)
}
621701
func IsCRDConditionFalse(crd *CustomResourceDefinition, conditionType CustomResourceDefinitionConditionType) bool {
	return IsCRDConditionPresentAndEqual(crd, conditionType, ConditionFalse)
}
580616
func (c *mockGCECloud) FindClusterStatus(cluster *kops.Cluster) (*kops.ClusterStatus, error) {
	return nil, fmt.Errorf("mockGCECloud::FindClusterStatus not implemented")
}
1120118
func GetRCSBackend(ctx context.Context) RCSBackend {
	be, ok := ctx.Value(ctxKeyRCSBackend).(RCSBackend)
	if !ok {
		return Noop
	}
	return be
}
817077
func (uvm *UtilityVM) findSCSIAttachment(findThisHostPath string) (int, int32, string, error) {
	for controller, luns := range uvm.scsiLocations {
		for lun, si := range luns {
			if si.hostPath == findThisHostPath {
				logrus.WithFields(logrus.Fields{
					logfields.UVMID: uvm.id,
					"host-path":     findThisHostPath,
					"uvm-path":      si.uvmPath,
					"isLayer":       si.isLayer,
					"refCount":      si.refCount,
					"controller":    controller,
					"lun":           int32(lun),
				}).Debug("uvm::findSCSIAttachment")
				return controller, int32(lun), si.uvmPath, nil
			}
		}
	}
	return -1, -1, "", ErrNotAttached
}
790616
func (session *Session) Find(rowsSlicePtr interface{}, condiBean ...interface{}) error {
	if session.isAutoClose {
		defer session.Close()
	}
	return session.find(rowsSlicePtr, condiBean...)
}
1180659
func IsCRDConditionEquivalent(lhs, rhs *CustomResourceDefinitionCondition) bool {
	if lhs == nil && rhs == nil {
		return true
	}
	if lhs == nil || rhs == nil {
		return false
	}

	return lhs.Message == rhs.Message && lhs.Reason == rhs.Reason && lhs.Status == rhs.Status && lhs.Type == rhs.Type
}
204193
func (d *Decbuf) Crc32(castagnoliTable *crc32.Table) uint32 {
	return crc32.Checksum(d.B, castagnoliTable)
}
614953
func GetCondition(status apps.ReplicaSetStatus, condType apps.ReplicaSetConditionType) *apps.ReplicaSetCondition {
	for _, c := range status.Conditions {
		if c.Type == condType {
			return &c
		}
	}
	return nil
}
66602
func (c *gceCloudImplementation) findEtcdStatus(cluster *kops.Cluster) ([]kops.EtcdClusterStatus, error) {
	statusMap := make(map[string]*kops.EtcdClusterStatus)

	labels := c.Labels()

	zones, err := c.allZones()
	if err != nil {
		return nil, err
	}

	var disks []*compute.Disk

	// TODO: Filter disks query by Label?
	ctx := context.Background()
	for _, zone := range zones {
		err := c.compute.Disks.List(c.project, zone).Pages(ctx, func(page *compute.DiskList) error {
			for _, d := range page.Items {
				glog.V(4).Infof("Found disk %q with labels %v", d.Name, d.Labels)

				match := true
				for k, v := range labels {
					if d.Labels[k] != v {
						match = false
					}
				}
				if match {
					disks = append(disks, d)
				}
			}
			return nil
		})
		if err != nil {
			return nil, fmt.Errorf("error describing volumes: %v", err)
		}
	}

	for _, disk := range disks {
		etcdClusterName := ""
		var etcdClusterSpec *etcd.EtcdClusterSpec
		master := false
		for k, v := range disk.Labels {
			if strings.HasPrefix(k, GceLabelNameEtcdClusterPrefix) {
				etcdClusterName = strings.TrimPrefix(k, GceLabelNameEtcdClusterPrefix)
				value, err := DecodeGCELabel(v)
				if err != nil {
					return nil, fmt.Errorf("unexpected etcd label on volume %q: %s=%s", disk.Name, k, v)
				}
				spec, err := etcd.ParseEtcdClusterSpec(etcdClusterName, value)
				if err != nil {
					return nil, fmt.Errorf("error parsing etcd cluster label %q on volume %q: %v", value, disk.Name, err)
				}
				etcdClusterSpec = spec
			} else if strings.HasPrefix(k, GceLabelNameRolePrefix) {
				roleName := strings.TrimPrefix(k, GceLabelNameRolePrefix)
				if roleName == "master" {
					master = true
				}
			}
		}
		if etcdClusterName == "" || etcdClusterSpec == nil || !master {
			continue
		}

		status := statusMap[etcdClusterName]
		if status == nil {
			status = &kops.EtcdClusterStatus{
				Name: etcdClusterName,
			}
			statusMap[etcdClusterName] = status
		}

		status.Members = append(status.Members, &kops.EtcdMemberStatus{
			Name:     etcdClusterSpec.NodeName,
			VolumeId: disk.Name,
		})
	}

	var status []kops.EtcdClusterStatus
	for _, v := range statusMap {
		status = append(status, *v)
	}
	return status, nil
}
1175927
func (d *frameDec) checkCRC() error {
	if !d.HasCheckSum {
		return nil
	}
	var tmp [8]byte
	gotB := d.crc.Sum(tmp[:0])
	// Flip to match file order.
	gotB[0] = gotB[7]
	gotB[1] = gotB[6]
	gotB[2] = gotB[5]
	gotB[3] = gotB[4]

	// We can overwrite upper tmp now
	want := d.rawInput.readSmall(4)
	if want == nil {
		println("CRC missing?")
		return io.ErrUnexpectedEOF
	}

	if !bytes.Equal(gotB[:4], want) {
		println("CRC Check Failed:", gotB[:4], "!=", want)
		return ErrCRCMismatch
	}
	println("CRC ok")
	return nil
}
1296787
func findCommonAncestor(m *compile.Module) (string, error) {
	var result []string
	var lastString string

	err := m.Walk(func(m *compile.Module) error {
		thriftPath := m.ThriftPath
		if !filepath.IsAbs(thriftPath) {
			return fmt.Errorf(
				"ThriftPath must be absolute: %q is not absolute", thriftPath)
		}

		thriftDir := filepath.Dir(thriftPath)

		// Split("/foo/bar", "/") = ["", "foo", "bar"]
		parts := strings.Split(thriftDir, string(filepath.Separator))
		if result == nil {
			result = parts
			lastString = thriftPath
			return nil
		}

		result = commonPrefix(result, parts)
		if len(result) == 1 && result[0] == "" {
			return fmt.Errorf(
				"%q does not share an ancestor with %q",
				thriftPath, lastString)
		}

		lastString = thriftPath
		return nil
	})
	if err != nil {
		return "", err
	}

	return strings.Join(result, string(filepath.Separator)), nil
}