// bestMatch tries to pick best matching GroupVersionKind and falls back to the first
// found if no exact match exists.
506539
func bestMatch(kinds []GroupVersionKind, targets []GroupVersionKind) GroupVersionKind {
	for _, gvk := range targets {
		for _, k := range kinds {
			if k == gvk {
				return k
			}
		}
	}
	return targets[0]
}
510610
func (n EndpointSelector) GetMatch(key string) ([]string, bool) {
	if value, ok := n.MatchLabels[key]; ok {
		return []string{value}, true
	}
	for _, v := range n.MatchExpressions {
		if v.Key == key && v.Operator == metav1.LabelSelectorOpIn {
			return v.Values, true
		}
	}
	return nil, false
}
279506
func (m PriorityRESTMapper) KindFor(partiallySpecifiedResource schema.GroupVersionResource) (schema.GroupVersionKind, error) {
	originalGVKs, originalErr := m.Delegate.KindsFor(partiallySpecifiedResource)
	if originalErr != nil && len(originalGVKs) == 0 {
		return schema.GroupVersionKind{}, originalErr
	}
	if len(originalGVKs) == 1 {
		return originalGVKs[0], originalErr
	}

	remainingGVKs := append([]schema.GroupVersionKind{}, originalGVKs...)
	for _, pattern := range m.KindPriority {
		matchedGVKs := []schema.GroupVersionKind{}
		for _, gvr := range remainingGVKs {
			if kindMatches(pattern, gvr) {
				matchedGVKs = append(matchedGVKs, gvr)
			}
		}

		switch len(matchedGVKs) {
		case 0:
			// if you have no matches, then nothing matched this pattern just move to the next
			continue
		case 1:
			// one match, return
			return matchedGVKs[0], originalErr
		default:
			// more than one match, use the matched hits as the list moving to the next pattern.
			// this way you can have a series of selection criteria
			remainingGVKs = matchedGVKs
		}
	}

	return schema.GroupVersionKind{}, &AmbiguousResourceError{PartialResource: partiallySpecifiedResource, MatchingKinds: originalGVKs}
}
1304789
func MatchesServerVersion(clientVersion apimachineryversion.Info, client DiscoveryInterface) error {
	sVer, err := client.ServerVersion()
	if err != nil {
		return fmt.Errorf("couldn't read version from server: %v", err)
	}
	// GitVersion includes GitCommit and GitTreeState, but best to be safe?
	if clientVersion.GitVersion != sVer.GitVersion || clientVersion.GitCommit != sVer.GitCommit || clientVersion.GitTreeState != sVer.GitTreeState {
		return fmt.Errorf("server version (%#v) differs from client version (%#v)", sVer, clientVersion)
	}

	return nil
}
53462
func (q *SimpleQueryStringQuery) MinimumShouldMatch(minimumShouldMatch string) *SimpleQueryStringQuery {
	q.minimumShouldMatch = minimumShouldMatch
	return q
}
39315
func GroupVersionKinds(s spec.Schema) []schema.GroupVersionKind {
	e := s.Extensions["x-kubernetes-group-version-kind"]
	if e == nil {
		return nil
	}

	gvks := make([]schema.GroupVersionKind, 0, len(e.([]interface{})))
	for _, gvk := range e.([]interface{}) {
		gvk := gvk.(map[string]interface{})
		gvks = append(gvks, schema.GroupVersionKind{
			Group:   gvk["group"].(string),
			Version: gvk["version"].(string),
			Kind:    gvk["kind"].(string),
		})
	}

	return gvks
}
426648
func (c *Client) versionMismatch(ctx context.Context) (bool, error) {
	const shortRFC3339 = "2006-01-02"
	version := buildinfo.GitInfo
	if version == "" {
		return false, errors.New("unknown client version")
	}
	version = version[:10] // keep only the date part
	clientDate, err := time.Parse(shortRFC3339, version)
	if err != nil {
		return false, fmt.Errorf("could not parse date from version %q: %v", version, err)
	}
	apiChangeDate, _ := time.Parse(shortRFC3339, "2018-01-13")
	if !clientDate.After(apiChangeDate) {
		// client is old enough, all good.
		return false, nil
	}
	url := c.discoRoot() + "/status/status.json"
	req := c.newRequest(ctx, "GET", url)
	res, err := c.doReqGated(req)
	if err != nil {
		return false, err
	}
	if res.StatusCode != 200 {
		body, _ := ioutil.ReadAll(io.LimitReader(res.Body, 1<<20))
		res.Body.Close()
		return false, fmt.Errorf("got status code %d from URL %s; body %s", res.StatusCode, url, body)
	}
	var status struct {
		Version string `json:"version"`
	}
	if err := httputil.DecodeJSON(res, &status); err != nil {
		return false, fmt.Errorf("error parsing JSON from URL %s: %v", url, err)
	}
	serverVersion := status.Version[:10]
	serverDate, err := time.Parse(shortRFC3339, serverVersion)
	if err != nil {
		return false, fmt.Errorf("could not parse date from server version %q: %v", status.Version, err)
	}
	if serverDate.After(apiChangeDate) {
		// server is recent enough, all good.
		return false, nil
	}
	return true, nil
}
915726
func (p SupportsAllVerbs) Match(groupVersion string, r *metav1.APIResource) bool {
	return sets.NewString([]string(r.Verbs)...).HasAll(p.Verbs...)
}
1345594
func getGroupVersionKind(config map[string]interface{}) (schema.GroupVersionKind, error) {
	gvk := schema.GroupVersionKind{}
	if gv, found := config["apiVersion"]; found {
		casted, ok := gv.(string)
		if !ok {
			return gvk, fmt.Errorf("Expected string for apiVersion, found %T", gv)
		}
		s := strings.Split(casted, "/")
		if len(s) != 1 {
			gvk.Group = s[0]
		}
		gvk.Version = s[len(s)-1]
	} else {
		return gvk, fmt.Errorf("Missing apiVersion in Kind %v", config)
	}
	if k, found := config["kind"]; found {
		casted, ok := k.(string)
		if !ok {
			return gvk, fmt.Errorf("Expected string for kind, found %T", k)
		}
		gvk.Kind = casted
	} else {
		return gvk, fmt.Errorf("Missing kind in Kind %v", config)
	}
	return gvk, nil
}
506481
func TypeMatch(this interface{}, that interface{}) bool {
	t1 := reflect.TypeOf(this)
	t2 := reflect.TypeOf(that)
	if t1 == t2 {
		return true
	}
	if reflect.PtrTo(t1) == t2 || t1 == reflect.PtrTo(t2) {
		return true
	}
	return false
}
1338
func RankMatchFold(source, target string) int {
	return rank(source, target, unicode.ToLower)
}
726807
func (r *Matcher) Matches() bool {
	return r.scope() &&
		r.operation() &&
		r.group() &&
		r.version() &&
		r.resource()
}
1341229
func CompareVersion(version interface{}) int {
	return compareVersionsWithSuffix(CurrentVersion.Number, CurrentVersion.PatchLevel, CurrentVersion.Suffix, version)
}
1194154
func Match(ctx context.Context, expectedVersion string) bool {
	return If(GetVersion(ctx), expectedVersion)
}
799705
func checkAttributeVersionMatch(ctx Context, lVal, rVal *psstructs.Attribute) bool {
	// Parse the version
	var versionStr string
	if s, ok := lVal.GetString(); ok {
		versionStr = s
	} else if i, ok := lVal.GetInt(); ok {
		versionStr = fmt.Sprintf("%d", i)
	} else {
		return false
	}

	// Parse the version
	vers, err := version.NewVersion(versionStr)
	if err != nil {
		return false
	}

	// Constraint must be a string
	constraintStr, ok := rVal.GetString()
	if !ok {
		return false
	}

	// Check the cache for a match
	cache := ctx.VersionConstraintCache()
	constraints := cache[constraintStr]

	// Parse the constraints
	if constraints == nil {
		constraints, err = version.NewConstraint(constraintStr)
		if err != nil {
			return false
		}
		cache[constraintStr] = constraints
	}

	// Check the constraints against the version
	return constraints.Check(vers)
}
1141200
func (s *Selection) ClosestMatcher(m Matcher) *Selection {
	return pushStack(s, mapNodes(s.Nodes, func(i int, n *html.Node) []*html.Node {
		// For each node in the selection, test the node itself, then each parent
		// until a match is found.
		for ; n != nil; n = n.Parent {
			if m.Match(n) {
				return []*html.Node{n}
			}
		}
		return nil
	}))
}
595508
func (s *Selection) FilterMatcher(m Matcher) *Selection {
	return pushStack(s, winnow(s, m, true))
}