// defaultLabelPrefixCfg returns a default LabelPrefixCfg using the latest
// LPCfgFileVersion
490018
func defaultLabelPrefixCfg() *labelPrefixCfg {
	cfg := &labelPrefixCfg{
		Version:       LPCfgFileVersion,
		LabelPrefixes: []*LabelPrefix{},
	}

	expressions := []string{
		k8sConst.PodNamespaceLabel,                                   // include io.kubernetes.pod.namspace
		k8sConst.PodNamespaceMetaLabels,                              // include all namespace labels
		"!io.kubernetes",                                             // ignore all other io.kubernetes labels
		"!.*kubernetes.io",                                           // ignore all other kubernetes.io labels (annotation.*.k8s.io)
		"!pod-template-generation",                                   // ignore pod-template-generation
		"!pod-template-hash",                                         // ignore pod-template-hash
		"!controller-revision-hash",                                  // ignore controller-revision-hash
		"!annotation." + k8sConst.CiliumK8sAnnotationPrefix,          // ignore all cilium annotations
		"!annotation." + k8sConst.CiliumIdentityAnnotationDeprecated, // ignore all cilium annotations
		"!annotation.sidecar.istio.io",                               // ignore all istio sidecar annotation labels
		"!annotation.etcd.version",                                   // ignore all etcd.version annotations
		"!etcd_node",                                                 // ignore etcd_node label
	}

	for _, e := range expressions {
		p, err := parseLabelPrefix(e)
		if err != nil {
			msg := fmt.Sprintf("BUG: Unable to parse default label prefix '%s': %s", e, err)
			panic(msg)
		}
		cfg.LabelPrefixes = append(cfg.LabelPrefixes, p)
	}

	return cfg
}
690905
func DefaultName(name string) string {
	return fmt.Sprintf("%s-%X", name, Rand(int(^uint(0)>>1)))
}
651615
func NodeFromLabels(labels map[string]string) *Node {
	keys := []string{}
	for key := range labels {
		keys = append(keys, key)
	}
	// Sort the label to have a repeatable order
	sort.Strings(keys)

	labelPairs := []string{}
	var rootNode *Node
	var prevNode *Node
	for _, key := range keys {
		value := labels[key]
		labelPairs = append(labelPairs, fmt.Sprintf("%q='%s'", key, value))
		// Value must be single quoted to prevent env variable expansion
		// See https://github.com/docker/docker/issues/26027
		node := newKeyValueNode(key, "'"+value+"'")
		rootNode, prevNode = appendKeyValueNode(node, rootNode, prevNode)
	}

	return &Node{
		Value:    command.Label,
		Original: commandLabel + " " + strings.Join(labelPairs, " "),
		Next:     rootNode,
	}
}
408961
func longestCommonPrefix(strs []string) string {
	if len(strs) == 0 {
		return ""
	}
	lcp := strs[0]
	for _, str := range strs {
		lcp = strlcp(lcp, str)
	}
	return lcp
}
359773
func parseLabelPrefix(label string) (*LabelPrefix, error) {
	labelPrefix := LabelPrefix{}
	i := strings.IndexByte(label, ':')
	if i >= 0 {
		labelPrefix.Source = label[:i]
		labelPrefix.Prefix = label[i+1:]
	} else {
		labelPrefix.Prefix = label
	}

	if labelPrefix.Prefix[0] == '!' {
		labelPrefix.Ignore = true
		labelPrefix.Prefix = labelPrefix.Prefix[1:]
	}

	r, err := regexp.Compile(labelPrefix.Prefix)
	if err != nil {
		return nil, fmt.Errorf("Unable to compile regexp: %s", err)
	}
	labelPrefix.expr = r

	return &labelPrefix, nil
}
881413
func DefaultConfig() Config {
	return Config{
		Left:        "{{",
		Right:       "}}",
		Layout:      "",
		Funcs:       make(map[string]interface{}, 0),
		LayoutFuncs: make(map[string]interface{}, 0),
	}
}
294821
func (cniApp *cniAppInfo) parseNwInfoLabels() {

	var cniNetInfo struct {
		Args struct {
			Mesos struct {
				NetworkInfo struct {
					Labels struct {
						NwLabel []cniapi.NetworkLabel `json:"labels"`
					} `json:"labels"`
				} `json:"network_info"`
			} `json:"org.apache.mesos"`
		} `json:"args"`
	}

	cniLog.Infof("parse config file %s ", cniApp.netcfgFile)
	cfgFile, err := ioutil.ReadFile(cniApp.netcfgFile)

	if err != nil {
		cniLog.Warnf("%s", err)
		return
	}

	if err := json.Unmarshal(cfgFile, &cniNetInfo); err != nil {
		cniLog.Errorf("failed to parse %s, %s", cniApp.netcfgFile, err)
		return
	}

	for idx, elem := range cniNetInfo.Args.Mesos.NetworkInfo.Labels.NwLabel {
		cniLog.Infof("configured labels [%d] {key: %s, val: %s}", idx,
			elem.Key, elem.Value)

		// copy netplugin related labels
		switch elem.Key {
		case cniapi.LabelTenantName:
			cniApp.cniMesosAttr.Labels.TenantName = elem.Value

		case cniapi.LabelNetworkName:
			cniApp.cniMesosAttr.Labels.NetworkName = elem.Value

		case cniapi.LabelNetworkGroup:
			cniApp.cniMesosAttr.Labels.NetworkGroup = elem.Value
		}
	}
}
94187
func ParseLabelPrefixCfg(prefixes []string, file string) error {
	cfg, err := readLabelPrefixCfgFrom(file)
	if err != nil {
		return fmt.Errorf("Unable to read label prefix file: %s", err)
	}

	for _, label := range prefixes {
		p, err := parseLabelPrefix(label)
		if err != nil {
			return err
		}

		if !p.Ignore {
			cfg.whitelist = true
		}

		cfg.LabelPrefixes = append(cfg.LabelPrefixes, p)
	}

	validLabelPrefixes = cfg

	log.Info("Valid label prefix configuration:")
	for _, l := range validLabelPrefixes.LabelPrefixes {
		log.Infof(" - %s", l)
	}

	return nil
}
568083
func (s *Scheme) AddFieldLabelConversionFunc(version, kind string, conversionFunc FieldLabelConversionFunc) error {
	if s.fieldLabelConversionFuncs[version] == nil {
		s.fieldLabelConversionFuncs[version] = map[string]FieldLabelConversionFunc{}
	}

	s.fieldLabelConversionFuncs[version][kind] = conversionFunc
	return nil
}
153688
func GenLabels(options string) (string, string, error) {
	return InitLabels(strings.Fields(options))
}
822720
func getDefaultReflectorName(ignoredPackages ...string) string {
	name := "????"
outer:
	for i := 1; i < 10; i++ {
		_, file, line, ok := goruntime.Caller(i)
		if !ok {
			break
		}
		for _, ignoredPackage := range ignoredPackages {
			if strings.Contains(file, ignoredPackage) {
				continue outer
			}

		}

		pkgLocation := strings.LastIndex(file, "/pkg/")
		if pkgLocation >= 0 {
			file = file[pkgLocation+1:]
		}
		name = fmt.Sprintf("%s:%d", file, line)
		break
	}

	return name
}
763430
func (g *Generator) DefaultPackageName(obj Object) string {
	pkg := obj.PackageName()
	if pkg == g.packageName {
		return ""
	}
	return pkg + "."
}
1372916
func (l Labels) AppendPrefixInKey(prefix string) Labels {
	newLabels := Labels{}
	for k, v := range l {
		newLabels[prefix+k] = Label{
			Key:    prefix + v.Key,
			Value:  v.Value,
			Source: v.Source,
		}
	}
	return newLabels
}
562669
func makeLabel(labelName string, labelVal string) map[string]string {
	return map[string]string{labelName: labelVal}
}
1201621
func GenerateLabelsFromConfig(labels map[string]string, config *api.Config, namespace string) map[string]string {
	if len(config.Description) > 0 {
		labels[constants.KubernetesDescriptionLabel] = config.Description
	}

	if len(config.DisplayName) > 0 {
		labels[constants.KubernetesDisplayNameLabel] = config.DisplayName
	} else if len(config.Tag) > 0 {
		labels[constants.KubernetesDisplayNameLabel] = config.Tag
	}

	addBuildLabel(labels, "image", config.BuilderImage, namespace)
	return labels
}
49463
func GetDefaultEPOptsStringWithPrefix(prefix string) string {
	strs := make([]string, 0, len(registeredWorkloads))
	crs := make([]string, 0, len(registeredWorkloads))

	for k := range registeredWorkloads {
		crs = append(crs, string(k))
	}
	sort.Strings(crs)

	for _, cr := range crs {
		v := registeredWorkloads[WorkloadRuntimeType(cr)].getConfig()
		strs = append(strs, fmt.Sprintf("%s%s=%s", prefix, cr, v[EpOpt]))
	}

	return strings.Join(strs, ", ")
}
765103
func hkdfEncodeLabel(labelIn string, hashValue []byte, outLen int) []byte {
	label := "tls13 " + labelIn

	labelLen := len(label)
	hashLen := len(hashValue)
	hkdfLabel := make([]byte, 2+1+labelLen+1+hashLen)
	hkdfLabel[0] = byte(outLen >> 8)
	hkdfLabel[1] = byte(outLen)
	hkdfLabel[2] = byte(labelLen)
	copy(hkdfLabel[3:3+labelLen], []byte(label))
	hkdfLabel[3+labelLen] = byte(hashLen)
	copy(hkdfLabel[3+labelLen+1:], hashValue)

	return hkdfLabel
}