prow/pod-utils/decorate/podspec.go
func LabelsAndAnnotationsForSpec(spec prowapi.ProwJobSpec, extraLabels, extraAnnotations map[string]string) (map[string]string, map[string]string) {
	jobNameForLabel := spec.Job
	if len(jobNameForLabel) > validation.LabelValueMaxLength {
		// TODO(fejta): consider truncating middle rather than end.
		jobNameForLabel = strings.TrimRight(spec.Job[:validation.LabelValueMaxLength], ".-")
		logrus.WithFields(logrus.Fields{
			"job":       spec.Job,
			"key":       kube.ProwJobAnnotation,
			"value":     spec.Job,
			"truncated": jobNameForLabel,
		}).Info("Cannot use full job name, will truncate.")
	}
	labels := map[string]string{
		kube.CreatedByProw:     "true",
		kube.ProwJobTypeLabel:  string(spec.Type),
		kube.ProwJobAnnotation: jobNameForLabel,
	}
	if spec.Type != prowapi.PeriodicJob && spec.Refs != nil {
		labels[kube.OrgLabel] = spec.Refs.Org
		labels[kube.RepoLabel] = spec.Refs.Repo
		if len(spec.Refs.Pulls) > 0 {
			labels[kube.PullLabel] = strconv.Itoa(spec.Refs.Pulls[0].Number)
		}
	}

	for k, v := range extraLabels {
		labels[k] = v
	}

	// let's validate labels
	for key, value := range labels {
		if errs := validation.IsValidLabelValue(value); len(errs) > 0 {
			// try to use basename of a path, if path contains invalid //
			base := filepath.Base(value)
			if errs := validation.IsValidLabelValue(base); len(errs) == 0 {
				labels[key] = base
				continue
			}
			logrus.WithFields(logrus.Fields{
				"key":    key,
				"value":  value,
				"errors": errs,
			}).Warn("Removing invalid label")
			delete(labels, key)
		}
	}

	annotations := map[string]string{
		kube.ProwJobAnnotation: spec.Job,
	}
	for k, v := range extraAnnotations {
		annotations[k] = v
	}

	return labels, annotations
}
func LabelsAndAnnotationsForSpec(spec prowapi.ProwJobSpec, extraLabels, extraAnnotations map[string]string) (map[string]string, map[string]string) {
	jobNameForLabel := spec.Job
	if len(jobNameForLabel) > validation.LabelValueMaxLength {
		// TODO(fejta): consider truncating middle rather than end.
		jobNameForLabel = strings.TrimRight(spec.Job[:validation.LabelValueMaxLength], ".-")
		logrus.WithFields(logrus.Fields{
			"job":       spec.Job,
			"key":       kube.ProwJobAnnotation,
			"value":     spec.Job,
			"truncated": jobNameForLabel,
		}).Info("Cannot use full job name, will truncate.")
	}
	labels := map[string]string{
		kube.CreatedByProw:     "true",
		kube.ProwJobTypeLabel:  string(spec.Type),
		kube.ProwJobAnnotation: jobNameForLabel,
	}
	if spec.Type != prowapi.PeriodicJob && spec.Refs != nil {
		labels[kube.OrgLabel] = spec.Refs.Org
		labels[kube.RepoLabel] = spec.Refs.Repo
		if len(spec.Refs.Pulls) > 0 {
			labels[kube.PullLabel] = strconv.Itoa(spec.Refs.Pulls[0].Number)
		}
	}

	for k, v := range extraLabels {
		labels[k] = v
	}

	// let's validate labels
	for key, value := range labels {
		if errs := validation.IsValidLabelValue(value); len(errs) > 0 {
			// try to use basename of a path, if path contains invalid //
			base := filepath.Base(value)
			if errs := validation.IsValidLabelValue(base); len(errs) == 0 {
				labels[key] = base
				continue
			}
			logrus.WithFields(logrus.Fields{
				"key":    key,
				"value":  value,
				"errors": errs,
			}).Warn("Removing invalid label")
			delete(labels, key)
		}
	}

	annotations := map[string]string{
		kube.ProwJobAnnotation: spec.Job,
	}
	for k, v := range extraAnnotations {
		annotations[k] = v
	}

	return labels, annotations
}
func LabelsAndAnnotationsForSpec ( spec prowapi . ProwJobSpec , extraLabels , extraAnnotations map [ string ] string ) ( map [ string ] string , map [ string ] string ) { jobNameForLabel := spec . Job if len ( jobNameForLabel ) > validation . LabelValueMaxLength { // TODO(fejta): consider truncating middle rather than end. jobNameForLabel = strings . TrimRight ( spec . Job [ : validation . LabelValueMaxLength ] , " " ) logrus . WithFields ( logrus . Fields { " " : spec . Job , " " : kube . ProwJobAnnotation , " " : spec . Job , " " : jobNameForLabel , } ) . Info ( " " ) } labels := map [ string ] string { kube . CreatedByProw : " " , kube . ProwJobTypeLabel : string ( spec . Type ) , kube . ProwJobAnnotation : jobNameForLabel , } if spec . Type != prowapi . PeriodicJob && spec . Refs != nil { labels [ kube . OrgLabel ] = spec . Refs . Org labels [ kube . RepoLabel ] = spec . Refs . Repo if len ( spec . Refs . Pulls ) > 0 { labels [ kube . PullLabel ] = strconv . Itoa ( spec . Refs . Pulls [ 0 ] . Number ) } } for k , v := range extraLabels { labels [ k ] = v } // let's validate labels for key , value := range labels { if errs := validation . IsValidLabelValue ( value ) ; len ( errs ) > 0 { // try to use basename of a path, if path contains invalid // base := filepath . Base ( value ) if errs := validation . IsValidLabelValue ( base ) ; len ( errs ) == 0 { labels [ key ] = base continue } logrus . WithFields ( logrus . Fields { " " : key , " " : value , " " : errs , } ) . Warn ( " " ) delete ( labels , key ) } } annotations := map [ string ] string { kube . ProwJobAnnotation : spec . Job , } for k , v := range extraAnnotations { annotations [ k ] = v } return labels , annotations }
// LabelsAndAnnotationsForSpec returns a minimal set of labels to add to prowjobs or its owned resources.
//
// User-provided extraLabels and extraAnnotations values will take precedence over auto-provided values.
LabelsAndAnnotationsForSpec returns a minimal set of labels to add to prowjobs or its owned resources . User - provided extraLabels and extraAnnotations values will take precedence over auto - provided values .