Browse code

Truncate build pod label to allowed size

Cesar Wong authored on 2016/05/12 22:10:47
Showing 30 changed files
... ...
@@ -38,10 +38,11 @@ func FilterBuilds(builds []Build, predicate PredicateFunc) []Build {
38 38
 	return result
39 39
 }
40 40
 
41
-// ByBuildConfigLabelPredicate matches all builds that have build config label with specified value.
42
-func ByBuildConfigLabelPredicate(labelValue string) PredicateFunc {
41
+// ByBuildConfigPredicate matches all builds that have build config annotation or label with specified value.
42
+func ByBuildConfigPredicate(labelValue string) PredicateFunc {
43 43
 	return func(arg interface{}) bool {
44
-		return (hasBuildConfigLabel(arg.(Build), BuildConfigLabel, labelValue) ||
44
+		return (hasBuildConfigAnnotation(arg.(Build), BuildConfigAnnotation, labelValue) ||
45
+			hasBuildConfigLabel(arg.(Build), BuildConfigLabel, labelValue) ||
45 46
 			hasBuildConfigLabel(arg.(Build), BuildConfigLabelDeprecated, labelValue))
46 47
 	}
47 48
 }
... ...
@@ -50,3 +51,11 @@ func hasBuildConfigLabel(build Build, labelName, labelValue string) bool {
50 50
 	value, ok := build.Labels[labelName]
51 51
 	return ok && value == labelValue
52 52
 }
53
+
54
+func hasBuildConfigAnnotation(build Build, annotationName, annotationValue string) bool {
55
+	if build.Annotations == nil {
56
+		return false
57
+	}
58
+	value, ok := build.Annotations[annotationName]
59
+	return ok && value == annotationValue
60
+}
... ...
@@ -64,7 +64,32 @@ func TestFilterBuilds_withFilteredElements(t *testing.T) {
64 64
 	assertThatArraysAreEquals(t, actual, expected)
65 65
 }
66 66
 
67
-func TestByBuildConfigLabelPredicate_withBuildConfigLabel(t *testing.T) {
67
+func TestByBuildConfigPredicate_withBuildConfigAnnotation(t *testing.T) {
68
+	input := []Build{
69
+		{
70
+			ObjectMeta: kapi.ObjectMeta{
71
+				Name:        "build1-abc",
72
+				Annotations: map[string]string{BuildConfigAnnotation: "foo"},
73
+			},
74
+		},
75
+		{
76
+			ObjectMeta: kapi.ObjectMeta{
77
+				Name:   "build2-abc",
78
+				Labels: map[string]string{"bar": "baz"},
79
+			},
80
+		},
81
+	}
82
+
83
+	expected := []Build{input[0]}
84
+
85
+	actual := FilterBuilds(input, ByBuildConfigPredicate("foo"))
86
+	assertThatArraysAreEquals(t, actual, expected)
87
+
88
+	actual = FilterBuilds(input, ByBuildConfigPredicate("not-foo"))
89
+	assertThatArrayIsEmpty(t, actual)
90
+}
91
+
92
+func TestByBuildConfigPredicate_withBuildConfigLabel(t *testing.T) {
68 93
 	input := []Build{
69 94
 		{
70 95
 			ObjectMeta: kapi.ObjectMeta{
... ...
@@ -82,14 +107,14 @@ func TestByBuildConfigLabelPredicate_withBuildConfigLabel(t *testing.T) {
82 82
 
83 83
 	expected := []Build{input[0]}
84 84
 
85
-	actual := FilterBuilds(input, ByBuildConfigLabelPredicate("foo"))
85
+	actual := FilterBuilds(input, ByBuildConfigPredicate("foo"))
86 86
 	assertThatArraysAreEquals(t, actual, expected)
87 87
 
88
-	actual = FilterBuilds(input, ByBuildConfigLabelPredicate("not-foo"))
88
+	actual = FilterBuilds(input, ByBuildConfigPredicate("not-foo"))
89 89
 	assertThatArrayIsEmpty(t, actual)
90 90
 }
91 91
 
92
-func TestByBuildConfigLabelPredicate_withBuildConfigLabelDeprecated(t *testing.T) {
92
+func TestByBuildConfigPredicate_withBuildConfigLabelDeprecated(t *testing.T) {
93 93
 	input := []Build{
94 94
 		{
95 95
 			ObjectMeta: kapi.ObjectMeta{
... ...
@@ -107,14 +132,14 @@ func TestByBuildConfigLabelPredicate_withBuildConfigLabelDeprecated(t *testing.T
107 107
 
108 108
 	expected := []Build{input[0]}
109 109
 
110
-	actual := FilterBuilds(input, ByBuildConfigLabelPredicate("foo"))
110
+	actual := FilterBuilds(input, ByBuildConfigPredicate("foo"))
111 111
 	assertThatArraysAreEquals(t, actual, expected)
112 112
 
113
-	actual = FilterBuilds(input, ByBuildConfigLabelPredicate("not-foo"))
113
+	actual = FilterBuilds(input, ByBuildConfigPredicate("not-foo"))
114 114
 	assertThatArrayIsEmpty(t, actual)
115 115
 }
116 116
 
117
-func TestByBuildConfigLabelPredicate_withBothBuildConfigLabels(t *testing.T) {
117
+func TestByBuildConfigPredicate_withBothBuildConfigLabels(t *testing.T) {
118 118
 	input := []Build{
119 119
 		{
120 120
 			ObjectMeta: kapi.ObjectMeta{
... ...
@@ -138,14 +163,14 @@ func TestByBuildConfigLabelPredicate_withBothBuildConfigLabels(t *testing.T) {
138 138
 
139 139
 	expected := []Build{input[0], input[2]}
140 140
 
141
-	actual := FilterBuilds(input, ByBuildConfigLabelPredicate("foo"))
141
+	actual := FilterBuilds(input, ByBuildConfigPredicate("foo"))
142 142
 	assertThatArraysAreEquals(t, actual, expected)
143 143
 
144
-	actual = FilterBuilds(input, ByBuildConfigLabelPredicate("not-foo"))
144
+	actual = FilterBuilds(input, ByBuildConfigPredicate("not-foo"))
145 145
 	assertThatArrayIsEmpty(t, actual)
146 146
 }
147 147
 
148
-func TestByBuildConfigLabelPredicate_withoutBuildConfigLabels(t *testing.T) {
148
+func TestByBuildConfigPredicate_withoutBuildConfigLabels(t *testing.T) {
149 149
 	input := []Build{
150 150
 		{
151 151
 			ObjectMeta: kapi.ObjectMeta{
... ...
@@ -155,7 +180,7 @@ func TestByBuildConfigLabelPredicate_withoutBuildConfigLabels(t *testing.T) {
155 155
 		},
156 156
 	}
157 157
 
158
-	actual := FilterBuilds(input, ByBuildConfigLabelPredicate("not-foo"))
158
+	actual := FilterBuilds(input, ByBuildConfigPredicate("not-foo"))
159 159
 	assertThatArrayIsEmpty(t, actual)
160 160
 }
161 161
 
... ...
@@ -11,6 +11,8 @@ import (
11 11
 const (
12 12
 	// BuildAnnotation is an annotation that identifies a Pod as being for a Build
13 13
 	BuildAnnotation = "openshift.io/build.name"
14
+	// BuildConfigAnnotation is an annotation that identifies the BuildConfig that a Build was created from
15
+	BuildConfigAnnotation = "openshift.io/build-config.name"
14 16
 	// BuildNumberAnnotation is an annotation whose value is the sequential number for this Build
15 17
 	BuildNumberAnnotation = "openshift.io/build.number"
16 18
 	// BuildCloneAnnotation is an annotation whose value is the name of the build this build was cloned from
... ...
@@ -18,6 +20,8 @@ const (
18 18
 	// BuildPodNameAnnotation is an annotation whose value is the name of the pod running this build
19 19
 	BuildPodNameAnnotation = "openshift.io/build.pod-name"
20 20
 	// BuildLabel is the key of a Pod label whose value is the Name of a Build which is run.
21
+	// NOTE: The value for this label may not contain the entire Build name because it will be
22
+	// truncated to maximum label length.
21 23
 	BuildLabel = "openshift.io/build.name"
22 24
 	// BuildRunPolicyLabel represents the start policy used to to start the build.
23 25
 	BuildRunPolicyLabel = "openshift.io/build.start-policy"
... ...
@@ -33,7 +37,8 @@ const (
33 33
 	// executing a Source build
34 34
 	DropCapabilities = "DROP_CAPS"
35 35
 	// BuildConfigLabel is the key of a Build label whose value is the ID of a BuildConfig
36
-	// on which the Build is based.
36
+	// on which the Build is based. NOTE: The value for this label may not contain the entire
37
+	// BuildConfig name because it will be truncated to maximum label length.
37 38
 	BuildConfigLabel = "openshift.io/build-config.name"
38 39
 	// BuildConfigLabelDeprecated was used as BuildConfigLabel before adding namespaces.
39 40
 	// We keep it for backward compatibility.
... ...
@@ -1,6 +1,11 @@
1 1
 package api
2 2
 
3
-import "github.com/openshift/origin/pkg/util/namer"
3
+import (
4
+	kapi "k8s.io/kubernetes/pkg/api"
5
+	"k8s.io/kubernetes/pkg/util/validation"
6
+
7
+	"github.com/openshift/origin/pkg/util/namer"
8
+)
4 9
 
5 10
 const (
6 11
 	// BuildPodSuffix is the suffix used to append to a build pod name given a build name
... ...
@@ -45,3 +50,19 @@ func SourceType(source BuildSource) string {
45 45
 	}
46 46
 	return sourceType
47 47
 }
48
+
49
+// LabelValue returns a string to use as a value for the Build
50
+// label in a pod. If the length of the string parameter exceeds
51
+// the maximum label length, the value will be truncated.
52
+func LabelValue(name string) string {
53
+	if len(name) <= validation.DNS1123LabelMaxLength {
54
+		return name
55
+	}
56
+	return name[:validation.DNS1123LabelMaxLength]
57
+}
58
+
59
+// GetBuildName returns the name of a Build associated with the
60
+// given Pod.
61
+func GetBuildName(pod *kapi.Pod) string {
62
+	return pod.Annotations[BuildAnnotation]
63
+}
48 64
new file mode 100644
... ...
@@ -0,0 +1,13 @@
0
+package api
1
+
2
+import (
3
+	"testing"
4
+
5
+	kapi "k8s.io/kubernetes/pkg/api"
6
+)
7
+
8
+func TestGetBuildPodName(t *testing.T) {
9
+	if expected, actual := "mybuild-build", GetBuildPodName(&Build{ObjectMeta: kapi.ObjectMeta{Name: "mybuild"}}); expected != actual {
10
+		t.Errorf("Expected %s, got %s", expected, actual)
11
+	}
12
+}
... ...
@@ -54,7 +54,7 @@ func (bc *BuildController) CancelBuild(build *buildapi.Build) error {
54 54
 
55 55
 	glog.V(4).Infof("Cancelling build %s/%s.", build.Namespace, build.Name)
56 56
 
57
-	pod, err := bc.PodManager.GetPod(build.Namespace, buildutil.GetBuildPodName(build))
57
+	pod, err := bc.PodManager.GetPod(build.Namespace, buildapi.GetBuildPodName(build))
58 58
 	if err != nil {
59 59
 		if !errors.IsNotFound(err) {
60 60
 			return fmt.Errorf("Failed to get pod for build %s/%s: %v", build.Namespace, build.Name, err)
... ...
@@ -388,7 +388,7 @@ type BuildDeleteController struct {
388 388
 // HandleBuildDeletion deletes a build pod if the corresponding build has been deleted
389 389
 func (bc *BuildDeleteController) HandleBuildDeletion(build *buildapi.Build) error {
390 390
 	glog.V(4).Infof("Handling deletion of build %s", build.Name)
391
-	podName := buildutil.GetBuildPodName(build)
391
+	podName := buildapi.GetBuildPodName(build)
392 392
 	pod, err := bc.PodManager.GetPod(build.Namespace, podName)
393 393
 	if err != nil && !errors.IsNotFound(err) {
394 394
 		glog.V(2).Infof("Failed to find pod with name %s for build %s in namespace %s due to error: %v", podName, build.Name, build.Namespace, err)
... ...
@@ -398,7 +398,7 @@ func (bc *BuildDeleteController) HandleBuildDeletion(build *buildapi.Build) erro
398 398
 		glog.V(2).Infof("Did not find pod with name %s for build %s in namespace %s", podName, build.Name, build.Namespace)
399 399
 		return nil
400 400
 	}
401
-	if buildName := pod.Labels[buildapi.BuildLabel]; buildName != build.Name {
401
+	if buildName := buildapi.GetBuildName(pod); buildName != build.Name {
402 402
 		glog.V(2).Infof("Not deleting pod %s/%s because the build label %s does not match the build name %s", pod.Namespace, podName, buildName, build.Name)
403 403
 		return nil
404 404
 	}
... ...
@@ -120,6 +120,9 @@ func mockBuild(phase buildapi.BuildPhase, output buildapi.BuildOutput) *buildapi
120 120
 		ObjectMeta: kapi.ObjectMeta{
121 121
 			Name:      "data-build",
122 122
 			Namespace: "namespace",
123
+			Annotations: map[string]string{
124
+				buildapi.BuildConfigAnnotation: "test-bc",
125
+			},
123 126
 			Labels: map[string]string{
124 127
 				"name": "dataBuild",
125 128
 				// TODO: Switch this test to use Serial policy
... ...
@@ -716,7 +719,10 @@ func TestHandleHandleBuildDeletionOK(t *testing.T) {
716 716
 	build := mockBuild(buildapi.BuildPhaseComplete, buildapi.BuildOutput{})
717 717
 	ctrl := BuildDeleteController{&customPodManager{
718 718
 		GetPodFunc: func(namespace, names string) (*kapi.Pod, error) {
719
-			return &kapi.Pod{ObjectMeta: kapi.ObjectMeta{Labels: map[string]string{buildapi.BuildLabel: build.Name}}}, nil
719
+			return &kapi.Pod{ObjectMeta: kapi.ObjectMeta{
720
+				Labels:      map[string]string{buildapi.BuildLabel: buildapi.LabelValue(build.Name)},
721
+				Annotations: map[string]string{buildapi.BuildAnnotation: build.Name},
722
+			}}, nil
720 723
 		},
721 724
 		DeletePodFunc: func(namespace string, pod *kapi.Pod) error {
722 725
 			deleteWasCalled = true
... ...
@@ -738,7 +744,10 @@ func TestHandleHandleBuildDeletionOKDeprecatedLabel(t *testing.T) {
738 738
 	build := mockBuild(buildapi.BuildPhaseComplete, buildapi.BuildOutput{})
739 739
 	ctrl := BuildDeleteController{&customPodManager{
740 740
 		GetPodFunc: func(namespace, names string) (*kapi.Pod, error) {
741
-			return &kapi.Pod{ObjectMeta: kapi.ObjectMeta{Labels: map[string]string{buildapi.BuildLabel: build.Name}}}, nil
741
+			return &kapi.Pod{ObjectMeta: kapi.ObjectMeta{
742
+				Labels:      map[string]string{buildapi.BuildLabel: buildapi.LabelValue(build.Name)},
743
+				Annotations: map[string]string{buildapi.BuildAnnotation: build.Name},
744
+			}}, nil
742 745
 		},
743 746
 		DeletePodFunc: func(namespace string, pod *kapi.Pod) error {
744 747
 			deleteWasCalled = true
... ...
@@ -817,7 +826,10 @@ func TestHandleHandleBuildDeletionDeletePodError(t *testing.T) {
817 817
 	build := mockBuild(buildapi.BuildPhaseComplete, buildapi.BuildOutput{})
818 818
 	ctrl := BuildDeleteController{&customPodManager{
819 819
 		GetPodFunc: func(namespace, names string) (*kapi.Pod, error) {
820
-			return &kapi.Pod{ObjectMeta: kapi.ObjectMeta{Labels: map[string]string{buildapi.BuildLabel: build.Name}}}, nil
820
+			return &kapi.Pod{ObjectMeta: kapi.ObjectMeta{
821
+				Labels:      map[string]string{buildapi.BuildLabel: buildapi.LabelValue(build.Name)},
822
+				Annotations: map[string]string{buildapi.BuildAnnotation: build.Name},
823
+			}}, nil
821 824
 		},
822 825
 		DeletePodFunc: func(namespace string, pod *kapi.Pod) error {
823 826
 			return errors.New("random")
... ...
@@ -489,7 +489,7 @@ func (lw *buildDeleteLW) List(options kapi.ListOptions) (runtime.Object, error)
489 489
 	}
490 490
 
491 491
 	for _, pod := range podList.Items {
492
-		buildName := pod.Labels[buildapi.BuildLabel]
492
+		buildName := buildapi.GetBuildName(&pod)
493 493
 		if len(buildName) == 0 {
494 494
 			continue
495 495
 		}
... ...
@@ -578,7 +578,7 @@ func (lw *buildPodDeleteLW) List(options kapi.ListOptions) (runtime.Object, erro
578 578
 			glog.V(5).Infof("Ignoring build %s/%s because it is complete", build.Namespace, build.Name)
579 579
 			continue
580 580
 		}
581
-		pod, err := lw.KubeClient.Pods(build.Namespace).Get(buildutil.GetBuildPodName(&build))
581
+		pod, err := lw.KubeClient.Pods(build.Namespace).Get(buildapi.GetBuildPodName(&build))
582 582
 		if err != nil {
583 583
 			if !kerrors.IsNotFound(err) {
584 584
 				glog.V(4).Infof("Error getting pod for build %s/%s: %v", build.Namespace, build.Name, err)
... ...
@@ -587,14 +587,14 @@ func (lw *buildPodDeleteLW) List(options kapi.ListOptions) (runtime.Object, erro
587 587
 				pod = nil
588 588
 			}
589 589
 		} else {
590
-			if buildName := pod.Labels[buildapi.BuildLabel]; buildName != build.Name {
590
+			if buildName := buildapi.GetBuildName(pod); buildName != build.Name {
591 591
 				pod = nil
592 592
 			}
593 593
 		}
594 594
 		if pod == nil {
595 595
 			deletedPod := &kapi.Pod{
596 596
 				ObjectMeta: kapi.ObjectMeta{
597
-					Name:      buildutil.GetBuildPodName(&build),
597
+					Name:      buildapi.GetBuildPodName(&build),
598 598
 					Namespace: build.Namespace,
599 599
 				},
600 600
 			}
... ...
@@ -10,7 +10,6 @@ import (
10 10
 	"k8s.io/kubernetes/pkg/runtime"
11 11
 
12 12
 	buildapi "github.com/openshift/origin/pkg/build/api"
13
-	buildutil "github.com/openshift/origin/pkg/build/util"
14 13
 )
15 14
 
16 15
 // CustomBuildStrategy creates a build using a custom builder image.
... ...
@@ -69,7 +68,7 @@ func (bs *CustomBuildStrategy) CreateBuildPod(build *buildapi.Build) (*kapi.Pod,
69 69
 	privileged := true
70 70
 	pod := &kapi.Pod{
71 71
 		ObjectMeta: kapi.ObjectMeta{
72
-			Name:      buildutil.GetBuildPodName(build),
72
+			Name:      buildapi.GetBuildPodName(build),
73 73
 			Namespace: build.Namespace,
74 74
 			Labels:    getPodLabels(build),
75 75
 		},
... ...
@@ -10,10 +10,10 @@ import (
10 10
 	"k8s.io/kubernetes/pkg/api/resource"
11 11
 	"k8s.io/kubernetes/pkg/apimachinery/registered"
12 12
 	"k8s.io/kubernetes/pkg/runtime"
13
+	"k8s.io/kubernetes/pkg/util/validation"
13 14
 
14 15
 	buildapi "github.com/openshift/origin/pkg/build/api"
15 16
 	_ "github.com/openshift/origin/pkg/build/api/install"
16
-	buildutil "github.com/openshift/origin/pkg/build/util"
17 17
 )
18 18
 
19 19
 func TestCustomCreateBuildPod(t *testing.T) {
... ...
@@ -36,10 +36,10 @@ func TestCustomCreateBuildPod(t *testing.T) {
36 36
 		t.Fatalf("Unexpected error: %v", err)
37 37
 	}
38 38
 
39
-	if expected, actual := buildutil.GetBuildPodName(expected), actual.ObjectMeta.Name; expected != actual {
39
+	if expected, actual := buildapi.GetBuildPodName(expected), actual.ObjectMeta.Name; expected != actual {
40 40
 		t.Errorf("Expected %s, but got %s!", expected, actual)
41 41
 	}
42
-	if !reflect.DeepEqual(map[string]string{buildapi.BuildLabel: expected.Name}, actual.Labels) {
42
+	if !reflect.DeepEqual(map[string]string{buildapi.BuildLabel: buildapi.LabelValue(expected.Name)}, actual.Labels) {
43 43
 		t.Errorf("Pod Labels does not match Build Labels!")
44 44
 	}
45 45
 	container := actual.Spec.Containers[0]
... ...
@@ -150,6 +150,21 @@ func TestCustomCreateBuildPodWithCustomCodec(t *testing.T) {
150 150
 	}
151 151
 }
152 152
 
153
+func TestCustomBuildLongName(t *testing.T) {
154
+	strategy := CustomBuildStrategy{
155
+		Codec: kapi.Codecs.LegacyCodec(buildapi.SchemeGroupVersion),
156
+	}
157
+	build := mockCustomBuild(false, false)
158
+	build.Name = strings.Repeat("a", validation.DNS1123LabelMaxLength*2)
159
+	pod, err := strategy.CreateBuildPod(build)
160
+	if err != nil {
161
+		t.Fatalf("unexpected: %v", err)
162
+	}
163
+	if pod.Labels[buildapi.BuildLabel] != build.Name[:validation.DNS1123LabelMaxLength] {
164
+		t.Errorf("Unexpected build label value: %s", pod.Labels[buildapi.BuildLabel])
165
+	}
166
+}
167
+
153 168
 func mockCustomBuild(forcePull, emptySource bool) *buildapi.Build {
154 169
 	timeout := int64(60)
155 170
 	src := buildapi.BuildSource{}
... ...
@@ -7,7 +7,6 @@ import (
7 7
 	"k8s.io/kubernetes/pkg/runtime"
8 8
 
9 9
 	buildapi "github.com/openshift/origin/pkg/build/api"
10
-	buildutil "github.com/openshift/origin/pkg/build/util"
11 10
 	cmdutil "github.com/openshift/origin/pkg/cmd/util"
12 11
 )
13 12
 
... ...
@@ -45,7 +44,7 @@ func (bs *DockerBuildStrategy) CreateBuildPod(build *buildapi.Build) (*kapi.Pod,
45 45
 
46 46
 	pod := &kapi.Pod{
47 47
 		ObjectMeta: kapi.ObjectMeta{
48
-			Name:      buildutil.GetBuildPodName(build),
48
+			Name:      buildapi.GetBuildPodName(build),
49 49
 			Namespace: build.Namespace,
50 50
 			Labels:    getPodLabels(build),
51 51
 		},
... ...
@@ -8,10 +8,10 @@ import (
8 8
 	kapi "k8s.io/kubernetes/pkg/api"
9 9
 	"k8s.io/kubernetes/pkg/api/resource"
10 10
 	"k8s.io/kubernetes/pkg/runtime"
11
+	"k8s.io/kubernetes/pkg/util/validation"
11 12
 
12 13
 	buildapi "github.com/openshift/origin/pkg/build/api"
13 14
 	_ "github.com/openshift/origin/pkg/build/api/install"
14
-	buildutil "github.com/openshift/origin/pkg/build/util"
15 15
 )
16 16
 
17 17
 func TestDockerCreateBuildPod(t *testing.T) {
... ...
@@ -26,10 +26,10 @@ func TestDockerCreateBuildPod(t *testing.T) {
26 26
 		t.Errorf("Unexpected error: %v", err)
27 27
 	}
28 28
 
29
-	if expected, actual := buildutil.GetBuildPodName(expected), actual.ObjectMeta.Name; expected != actual {
29
+	if expected, actual := buildapi.GetBuildPodName(expected), actual.ObjectMeta.Name; expected != actual {
30 30
 		t.Errorf("Expected %s, but got %s!", expected, actual)
31 31
 	}
32
-	if !reflect.DeepEqual(map[string]string{buildapi.BuildLabel: expected.Name}, actual.Labels) {
32
+	if !reflect.DeepEqual(map[string]string{buildapi.BuildLabel: buildapi.LabelValue(expected.Name)}, actual.Labels) {
33 33
 		t.Errorf("Pod Labels does not match Build Labels!")
34 34
 	}
35 35
 	container := actual.Spec.Containers[0]
... ...
@@ -97,6 +97,22 @@ func TestDockerCreateBuildPod(t *testing.T) {
97 97
 	}
98 98
 }
99 99
 
100
+func TestDockerBuildLongName(t *testing.T) {
101
+	strategy := DockerBuildStrategy{
102
+		Image: "docker-test-image",
103
+		Codec: kapi.Codecs.LegacyCodec(buildapi.SchemeGroupVersion),
104
+	}
105
+	build := mockDockerBuild()
106
+	build.Name = strings.Repeat("a", validation.DNS1123LabelMaxLength*2)
107
+	pod, err := strategy.CreateBuildPod(build)
108
+	if err != nil {
109
+		t.Fatalf("unexpected: %v", err)
110
+	}
111
+	if pod.Labels[buildapi.BuildLabel] != build.Name[:validation.DNS1123LabelMaxLength] {
112
+		t.Errorf("Unexpected build label value: %s", pod.Labels[buildapi.BuildLabel])
113
+	}
114
+}
115
+
100 116
 func mockDockerBuild() *buildapi.Build {
101 117
 	timeout := int64(60)
102 118
 	return &buildapi.Build{
... ...
@@ -11,7 +11,6 @@ import (
11 11
 	"k8s.io/kubernetes/pkg/serviceaccount"
12 12
 
13 13
 	buildapi "github.com/openshift/origin/pkg/build/api"
14
-	buildutil "github.com/openshift/origin/pkg/build/util"
15 14
 	cmdutil "github.com/openshift/origin/pkg/cmd/util"
16 15
 )
17 16
 
... ...
@@ -68,7 +67,7 @@ func (bs *SourceBuildStrategy) CreateBuildPod(build *buildapi.Build) (*kapi.Pod,
68 68
 	privileged := true
69 69
 	pod := &kapi.Pod{
70 70
 		ObjectMeta: kapi.ObjectMeta{
71
-			Name:      buildutil.GetBuildPodName(build),
71
+			Name:      buildapi.GetBuildPodName(build),
72 72
 			Namespace: build.Namespace,
73 73
 			Labels:    getPodLabels(build),
74 74
 		},
... ...
@@ -112,7 +111,7 @@ func (bs *SourceBuildStrategy) canRunAsRoot(build *buildapi.Build) bool {
112 112
 	rootUser = 0
113 113
 	pod := &kapi.Pod{
114 114
 		ObjectMeta: kapi.ObjectMeta{
115
-			Name:      buildutil.GetBuildPodName(build),
115
+			Name:      buildapi.GetBuildPodName(build),
116 116
 			Namespace: build.Namespace,
117 117
 		},
118 118
 		Spec: kapi.PodSpec{
... ...
@@ -10,10 +10,10 @@ import (
10 10
 	kapi "k8s.io/kubernetes/pkg/api"
11 11
 	"k8s.io/kubernetes/pkg/api/resource"
12 12
 	"k8s.io/kubernetes/pkg/runtime"
13
+	"k8s.io/kubernetes/pkg/util/validation"
13 14
 
14 15
 	buildapi "github.com/openshift/origin/pkg/build/api"
15 16
 	_ "github.com/openshift/origin/pkg/build/api/install"
16
-	buildutil "github.com/openshift/origin/pkg/build/util"
17 17
 )
18 18
 
19 19
 type FakeAdmissionControl struct {
... ...
@@ -52,10 +52,10 @@ func testSTICreateBuildPod(t *testing.T, rootAllowed bool) {
52 52
 		t.Errorf("Unexpected error: %v", err)
53 53
 	}
54 54
 
55
-	if expected, actual := buildutil.GetBuildPodName(expected), actual.ObjectMeta.Name; expected != actual {
55
+	if expected, actual := buildapi.GetBuildPodName(expected), actual.ObjectMeta.Name; expected != actual {
56 56
 		t.Errorf("Expected %s, but got %s!", expected, actual)
57 57
 	}
58
-	if !reflect.DeepEqual(map[string]string{buildapi.BuildLabel: expected.Name}, actual.Labels) {
58
+	if !reflect.DeepEqual(map[string]string{buildapi.BuildLabel: buildapi.LabelValue(expected.Name)}, actual.Labels) {
59 59
 		t.Errorf("Pod Labels does not match Build Labels!")
60 60
 	}
61 61
 	container := actual.Spec.Containers[0]
... ...
@@ -148,6 +148,23 @@ func testSTICreateBuildPod(t *testing.T, rootAllowed bool) {
148 148
 	}
149 149
 }
150 150
 
151
+func TestS2IBuildLongName(t *testing.T) {
152
+	strategy := &SourceBuildStrategy{
153
+		Image:            "sti-test-image",
154
+		Codec:            kapi.Codecs.LegacyCodec(buildapi.SchemeGroupVersion),
155
+		AdmissionControl: &FakeAdmissionControl{admit: true},
156
+	}
157
+	build := mockSTIBuild()
158
+	build.Name = strings.Repeat("a", validation.DNS1123LabelMaxLength*2)
159
+	pod, err := strategy.CreateBuildPod(build)
160
+	if err != nil {
161
+		t.Fatalf("unexpected: %v", err)
162
+	}
163
+	if pod.Labels[buildapi.BuildLabel] != build.Name[:validation.DNS1123LabelMaxLength] {
164
+		t.Errorf("Unexpected build label value: %s", pod.Labels[buildapi.BuildLabel])
165
+	}
166
+}
167
+
151 168
 func mockSTIBuild() *buildapi.Build {
152 169
 	timeout := int64(60)
153 170
 	return &buildapi.Build{
... ...
@@ -257,5 +257,5 @@ func getContainerVerbosity(containerEnv []kapi.EnvVar) (verbosity string) {
257 257
 
258 258
 // getPodLabels creates labels for the Build Pod
259 259
 func getPodLabels(build *buildapi.Build) map[string]string {
260
-	return map[string]string{buildapi.BuildLabel: build.Name}
260
+	return map[string]string{buildapi.BuildLabel: buildapi.LabelValue(build.Name)}
261 261
 }
... ...
@@ -416,6 +416,7 @@ func (g *BuildGenerator) generateBuildFromConfig(ctx kapi.Context, bc *buildapi.
416 416
 		build.Annotations = make(map[string]string)
417 417
 	}
418 418
 	build.Annotations[buildapi.BuildNumberAnnotation] = strconv.Itoa(bc.Status.LastVersion)
419
+	build.Annotations[buildapi.BuildConfigAnnotation] = bcCopy.Name
419 420
 	if build.Labels == nil {
420 421
 		build.Labels = make(map[string]string)
421 422
 	}
... ...
@@ -666,6 +666,9 @@ func TestGenerateBuildFromConfig(t *testing.T) {
666 666
 	if build.Labels["testlabel"] != bc.Labels["testlabel"] {
667 667
 		t.Errorf("Build does not contain labels from BuildConfig")
668 668
 	}
669
+	if build.Annotations[buildapi.BuildConfigAnnotation] != bc.Name {
670
+		t.Errorf("Build does not contain annotation from BuildConfig")
671
+	}
669 672
 	if build.Labels[buildapi.BuildConfigLabel] != bc.Name {
670 673
 		t.Errorf("Build does not contain labels from BuildConfig")
671 674
 	}
... ...
@@ -31,6 +31,7 @@ func TestNamespaceEdgeMatching(t *testing.T) {
31 31
 		b.Namespace = namespace
32 32
 		b.Name = "the-build"
33 33
 		b.Labels = map[string]string{api.BuildConfigLabel: "the-bc"}
34
+		b.Annotations = map[string]string{api.BuildConfigAnnotation: "the-bc"}
34 35
 		nodes.EnsureBuildNode(g, b)
35 36
 	}
36 37
 
... ...
@@ -55,6 +55,9 @@ func belongsToBuildConfig(config *buildapi.BuildConfig, b *buildapi.Build) bool
55 55
 	if b.Labels == nil {
56 56
 		return false
57 57
 	}
58
+	if b.Annotations != nil && b.Annotations[buildapi.BuildConfigAnnotation] == config.Name {
59
+		return true
60
+	}
58 61
 	if b.Labels[buildapi.BuildConfigLabel] == config.Name {
59 62
 		return true
60 63
 	}
... ...
@@ -75,6 +75,15 @@ func (reaper *BuildConfigReaper) Stop(namespace, name string, timeout time.Durat
75 75
 	}
76 76
 	errList := []error{}
77 77
 	for _, build := range builds.Items {
78
+		if build.Annotations != nil {
79
+			if bcName, ok := build.Annotations[buildapi.BuildConfigAnnotation]; ok {
80
+				// The annotation, if present, has the full build config name.
81
+				// Check it before proceeding.
82
+				if bcName != name {
83
+					continue
84
+				}
85
+			}
86
+		}
78 87
 		noBuildFound = false
79 88
 		if err := reaper.oc.Builds(namespace).Delete(build.Name); err != nil {
80 89
 			glog.Warningf("Cannot delete Build %s/%s: %v", build.Namespace, build.Name, err)
... ...
@@ -3,6 +3,7 @@ package reaper
3 3
 import (
4 4
 	"fmt"
5 5
 	"reflect"
6
+	"strings"
6 7
 	"testing"
7 8
 	"time"
8 9
 
... ...
@@ -11,6 +12,7 @@ import (
11 11
 	ktestclient "k8s.io/kubernetes/pkg/client/unversioned/testclient"
12 12
 	"k8s.io/kubernetes/pkg/labels"
13 13
 	"k8s.io/kubernetes/pkg/runtime"
14
+	"k8s.io/kubernetes/pkg/util/validation"
14 15
 
15 16
 	buildapi "github.com/openshift/origin/pkg/build/api"
16 17
 	_ "github.com/openshift/origin/pkg/build/api/install"
... ...
@@ -18,10 +20,14 @@ import (
18 18
 	"github.com/openshift/origin/pkg/client/testclient"
19 19
 )
20 20
 
21
+var (
22
+	configName = strings.Repeat("a", validation.DNS1123LabelMaxLength)
23
+)
24
+
21 25
 func makeBuildConfig(version int, deleting bool) *buildapi.BuildConfig {
22 26
 	ret := &buildapi.BuildConfig{
23 27
 		ObjectMeta: kapi.ObjectMeta{
24
-			Name:        "config",
28
+			Name:        configName,
25 29
 			Namespace:   "default",
26 30
 			Annotations: make(map[string]string),
27 31
 		},
... ...
@@ -39,9 +45,10 @@ func makeBuildConfig(version int, deleting bool) *buildapi.BuildConfig {
39 39
 func makeBuild(version int) buildapi.Build {
40 40
 	return buildapi.Build{
41 41
 		ObjectMeta: kapi.ObjectMeta{
42
-			Name:      fmt.Sprintf("build-%d", version),
43
-			Namespace: "default",
44
-			Labels:    map[string]string{buildapi.BuildConfigLabel: "config"},
42
+			Name:        fmt.Sprintf("build-%d", version),
43
+			Namespace:   "default",
44
+			Labels:      map[string]string{buildapi.BuildConfigLabel: buildapi.LabelValue(configName)},
45
+			Annotations: map[string]string{buildapi.BuildConfigAnnotation: configName},
45 46
 		},
46 47
 	}
47 48
 }
... ...
@@ -49,9 +56,10 @@ func makeBuild(version int) buildapi.Build {
49 49
 func makeDeprecatedBuild(version int) buildapi.Build {
50 50
 	return buildapi.Build{
51 51
 		ObjectMeta: kapi.ObjectMeta{
52
-			Name:      fmt.Sprintf("build-%d", version),
53
-			Namespace: "default",
54
-			Labels:    map[string]string{buildapi.BuildConfigLabelDeprecated: "config"},
52
+			Name:        fmt.Sprintf("build-%d", version),
53
+			Namespace:   "default",
54
+			Labels:      map[string]string{buildapi.BuildConfigLabelDeprecated: buildapi.LabelValue(configName)},
55
+			Annotations: map[string]string{buildapi.BuildConfigAnnotation: configName},
55 56
 		},
56 57
 	}
57 58
 }
... ...
@@ -61,6 +69,7 @@ func makeBuildList(version int) *buildapi.BuildList {
61 61
 		panic("version needs be even")
62 62
 	}
63 63
 	list := &buildapi.BuildList{}
64
+
64 65
 	for i := 1; i <= version; i += 2 {
65 66
 		list.Items = append(list.Items, makeBuild(i))
66 67
 		list.Items = append(list.Items, makeDeprecatedBuild(i+1))
... ...
@@ -106,7 +115,7 @@ func actionsAreEqual(a, b ktestclient.Action) bool {
106 106
 
107 107
 func TestStop(t *testing.T) {
108 108
 	notFound := func() runtime.Object {
109
-		return &(kerrors.NewNotFound(buildapi.Resource("BuildConfig"), "config").(*kerrors.StatusError).ErrStatus)
109
+		return &(kerrors.NewNotFound(buildapi.Resource("BuildConfig"), configName).(*kerrors.StatusError).ErrStatus)
110 110
 	}
111 111
 
112 112
 	tests := map[string]struct {
... ...
@@ -117,36 +126,36 @@ func TestStop(t *testing.T) {
117 117
 		"simple stop": {
118 118
 			oc: newBuildListFake(makeBuildConfig(0, false)),
119 119
 			expected: []ktestclient.Action{
120
-				ktestclient.NewGetAction("buildconfigs", "default", "config"),
120
+				ktestclient.NewGetAction("buildconfigs", "default", configName),
121 121
 				ktestclient.NewUpdateAction("buildconfigs", "default", makeBuildConfig(0, true)),
122
-				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelector("config")}),
123
-				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelectorDeprecated("config")}),
124
-				ktestclient.NewDeleteAction("buildconfigs", "default", "config"),
122
+				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelector(configName)}),
123
+				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelectorDeprecated(configName)}),
124
+				ktestclient.NewDeleteAction("buildconfigs", "default", configName),
125 125
 			},
126 126
 			err: false,
127 127
 		},
128 128
 		"multiple builds": {
129 129
 			oc: newBuildListFake(makeBuildConfig(4, false), makeBuildList(4)),
130 130
 			expected: []ktestclient.Action{
131
-				ktestclient.NewGetAction("buildconfigs", "default", "config"),
131
+				ktestclient.NewGetAction("buildconfigs", "default", configName),
132 132
 				ktestclient.NewUpdateAction("buildconfigs", "default", makeBuildConfig(4, true)),
133
-				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelector("config")}),
133
+				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelector(configName)}),
134 134
 				ktestclient.NewDeleteAction("builds", "default", "build-1"),
135 135
 				ktestclient.NewDeleteAction("builds", "default", "build-3"),
136
-				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelectorDeprecated("config")}),
136
+				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelectorDeprecated(configName)}),
137 137
 				ktestclient.NewDeleteAction("builds", "default", "build-2"),
138 138
 				ktestclient.NewDeleteAction("builds", "default", "build-4"),
139
-				ktestclient.NewDeleteAction("buildconfigs", "default", "config"),
139
+				ktestclient.NewDeleteAction("buildconfigs", "default", configName),
140 140
 			},
141 141
 			err: false,
142 142
 		},
143 143
 		"no config, some builds": {
144 144
 			oc: newBuildListFake(makeBuildList(2)),
145 145
 			expected: []ktestclient.Action{
146
-				ktestclient.NewGetAction("buildconfigs", "default", "config"),
147
-				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelector("config")}),
146
+				ktestclient.NewGetAction("buildconfigs", "default", configName),
147
+				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelector(configName)}),
148 148
 				ktestclient.NewDeleteAction("builds", "default", "build-1"),
149
-				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelectorDeprecated("config")}),
149
+				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelectorDeprecated(configName)}),
150 150
 				ktestclient.NewDeleteAction("builds", "default", "build-2"),
151 151
 			},
152 152
 			err: false,
... ...
@@ -154,20 +163,20 @@ func TestStop(t *testing.T) {
154 154
 		"no config, no builds": {
155 155
 			oc: testclient.NewSimpleFake(notFound()),
156 156
 			expected: []ktestclient.Action{
157
-				ktestclient.NewGetAction("buildconfigs", "default", "config"),
158
-				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelector("config")}),
159
-				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelectorDeprecated("config")}),
157
+				ktestclient.NewGetAction("buildconfigs", "default", configName),
158
+				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelector(configName)}),
159
+				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelectorDeprecated(configName)}),
160 160
 			},
161 161
 			err: true,
162 162
 		},
163 163
 		"config, no builds": {
164 164
 			oc: testclient.NewSimpleFake(makeBuildConfig(0, false)),
165 165
 			expected: []ktestclient.Action{
166
-				ktestclient.NewGetAction("buildconfigs", "default", "config"),
166
+				ktestclient.NewGetAction("buildconfigs", "default", configName),
167 167
 				ktestclient.NewUpdateAction("buildconfigs", "default", makeBuildConfig(0, true)),
168
-				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelector("config")}),
169
-				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelectorDeprecated("config")}),
170
-				ktestclient.NewDeleteAction("buildconfigs", "default", "config"),
168
+				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelector(configName)}),
169
+				ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelectorDeprecated(configName)}),
170
+				ktestclient.NewDeleteAction("buildconfigs", "default", configName),
171 171
 			},
172 172
 			err: false,
173 173
 		},
... ...
@@ -175,7 +184,7 @@ func TestStop(t *testing.T) {
175 175
 
176 176
 	for testName, test := range tests {
177 177
 		reaper := &BuildConfigReaper{oc: test.oc, pollInterval: time.Millisecond, timeout: time.Millisecond}
178
-		err := reaper.Stop("default", "config", 1*time.Second, nil)
178
+		err := reaper.Stop("default", configName, 1*time.Second, nil)
179 179
 
180 180
 		if !test.err && err != nil {
181 181
 			t.Errorf("%s: unexpected error: %v", testName, err)
... ...
@@ -190,7 +190,7 @@ func (h *binaryInstantiateHandler) handle(r io.Reader) (runtime.Object, error) {
190 190
 	}
191 191
 
192 192
 	// The container should be the default build container, so setting it to blank
193
-	buildPodName := buildutil.GetBuildPodName(build)
193
+	buildPodName := buildapi.GetBuildPodName(build)
194 194
 	opts := &kapi.PodAttachOptions{
195 195
 		Stdin: true,
196 196
 	}
... ...
@@ -116,7 +116,7 @@ func (r *REST) Get(ctx kapi.Context, name string, opts runtime.Object) (runtime.
116 116
 		return nil, errors.NewBadRequest(fmt.Sprintf("build %s is in an error state. %s", build.Name, buildutil.NoBuildLogsMessage))
117 117
 	}
118 118
 	// The container should be the default build container, so setting it to blank
119
-	buildPodName := buildutil.GetBuildPodName(build)
119
+	buildPodName := api.GetBuildPodName(build)
120 120
 	logOpts := api.BuildToPodLogOptions(buildLogOpts)
121 121
 	location, transport, err := pod.LogLocation(r.PodGetter, r.ConnectionInfo, ctx, buildPodName, logOpts)
122 122
 	if err != nil {
... ...
@@ -18,12 +18,6 @@ const (
18 18
 	NoBuildLogsMessage = "No logs are available."
19 19
 )
20 20
 
21
-// GetBuildPodName returns name of the build pod.
22
-// TODO: remove in favor of the one in the api package
23
-func GetBuildPodName(build *buildapi.Build) string {
24
-	return buildapi.GetBuildPodName(build)
25
-}
26
-
27 21
 // GetBuildName returns name of the build pod.
28 22
 func GetBuildName(pod *kapi.Pod) string {
29 23
 	if pod == nil {
... ...
@@ -110,7 +104,7 @@ func BuildNameForConfigVersion(name string, version int) string {
110 110
 // BuildConfigSelector returns a label Selector which can be used to find all
111 111
 // builds for a BuildConfig.
112 112
 func BuildConfigSelector(name string) labels.Selector {
113
-	return labels.Set{buildapi.BuildConfigLabel: name}.AsSelector()
113
+	return labels.Set{buildapi.BuildConfigLabel: buildapi.LabelValue(name)}.AsSelector()
114 114
 }
115 115
 
116 116
 // BuildConfigSelectorDeprecated returns a label Selector which can be used to find
... ...
@@ -149,6 +143,11 @@ func ConfigNameForBuild(build *buildapi.Build) string {
149 149
 	if build == nil {
150 150
 		return ""
151 151
 	}
152
+	if build.Annotations != nil {
153
+		if _, exists := build.Annotations[buildapi.BuildConfigAnnotation]; exists {
154
+			return build.Annotations[buildapi.BuildConfigAnnotation]
155
+		}
156
+	}
152 157
 	if _, exists := build.Labels[buildapi.BuildConfigLabel]; exists {
153 158
 		return build.Labels[buildapi.BuildConfigLabel]
154 159
 	}
155 160
deleted file mode 100644
... ...
@@ -1,14 +0,0 @@
1
-package util
2
-
3
-import (
4
-	"testing"
5
-
6
-	buildapi "github.com/openshift/origin/pkg/build/api"
7
-	kapi "k8s.io/kubernetes/pkg/api"
8
-)
9
-
10
-func TestGetBuildPodName(t *testing.T) {
11
-	if expected, actual := "mybuild-build", GetBuildPodName(&buildapi.Build{ObjectMeta: kapi.ObjectMeta{Name: "mybuild"}}); expected != actual {
12
-		t.Errorf("Expected %s, got %s", expected, actual)
13
-	}
14
-}
... ...
@@ -24,7 +24,6 @@ import (
24 24
 
25 25
 	authorizationapi "github.com/openshift/origin/pkg/authorization/api"
26 26
 	buildapi "github.com/openshift/origin/pkg/build/api"
27
-	buildutil "github.com/openshift/origin/pkg/build/util"
28 27
 	"github.com/openshift/origin/pkg/client"
29 28
 	deployapi "github.com/openshift/origin/pkg/deploy/api"
30 29
 	imageapi "github.com/openshift/origin/pkg/image/api"
... ...
@@ -101,7 +100,7 @@ func (d *BuildDescriber) Describe(namespace, name string) (string, error) {
101 101
 		events = &kapi.EventList{}
102 102
 	}
103 103
 	// get also pod events and merge it all into one list for describe
104
-	if pod, err := d.kubeClient.Pods(namespace).Get(buildutil.GetBuildPodName(build)); err == nil {
104
+	if pod, err := d.kubeClient.Pods(namespace).Get(buildapi.GetBuildPodName(build)); err == nil {
105 105
 		if podEvents, _ := d.kubeClient.Events(namespace).Search(pod); podEvents != nil {
106 106
 			events.Items = append(events.Items, podEvents.Items...)
107 107
 		}
... ...
@@ -128,7 +127,7 @@ func (d *BuildDescriber) Describe(namespace, name string) (string, error) {
128 128
 		if build.Status.Config != nil {
129 129
 			formatString(out, "Build Config", build.Status.Config.Name)
130 130
 		}
131
-		formatString(out, "Build Pod", buildutil.GetBuildPodName(build))
131
+		formatString(out, "Build Pod", buildapi.GetBuildPodName(build))
132 132
 
133 133
 		describeBuildSpec(build.Spec, out)
134 134
 
... ...
@@ -422,7 +421,7 @@ func (d *BuildConfigDescriber) Describe(namespace, name string) (string, error)
422 422
 	if err != nil {
423 423
 		return "", err
424 424
 	}
425
-	buildList.Items = buildapi.FilterBuilds(buildList.Items, buildapi.ByBuildConfigLabelPredicate(name))
425
+	buildList.Items = buildapi.FilterBuilds(buildList.Items, buildapi.ByBuildConfigPredicate(name))
426 426
 
427 427
 	return tabbedString(func(out *tabwriter.Writer) error {
428 428
 		formatMeta(out, buildConfig.ObjectMeta)
... ...
@@ -349,7 +349,7 @@ func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
349 349
 			if err != nil {
350 350
 				return nil, err
351 351
 			}
352
-			builds.Items = buildapi.FilterBuilds(builds.Items, buildapi.ByBuildConfigLabelPredicate(t.Name))
352
+			builds.Items = buildapi.FilterBuilds(builds.Items, buildapi.ByBuildConfigPredicate(t.Name))
353 353
 			if len(builds.Items) == 0 {
354 354
 				return nil, fmt.Errorf("no builds found for %q", t.Name)
355 355
 			}
... ...
@@ -7,7 +7,6 @@ import (
7 7
 	o "github.com/onsi/gomega"
8 8
 
9 9
 	buildapi "github.com/openshift/origin/pkg/build/api"
10
-	buildutil "github.com/openshift/origin/pkg/build/util"
11 10
 	exutil "github.com/openshift/origin/test/extended/util"
12 11
 )
13 12
 
... ...
@@ -45,7 +44,7 @@ var _ = g.Describe("[builds][Slow] builds should have deadlines", func() {
45 45
 			o.Expect(build.Status.Phase).Should(o.BeEquivalentTo(buildapi.BuildPhaseFailed))
46 46
 
47 47
 			g.By("verifying the build pod status")
48
-			pod, err := oc.KubeREST().Pods(oc.Namespace()).Get(buildutil.GetBuildPodName(&build))
48
+			pod, err := oc.KubeREST().Pods(oc.Namespace()).Get(buildapi.GetBuildPodName(&build))
49 49
 			o.Expect(err).NotTo(o.HaveOccurred())
50 50
 			o.Expect(pod.Status.Phase).Should(o.BeEquivalentTo(kapi.PodFailed))
51 51
 			o.Expect(pod.Status.Reason).Should(o.ContainSubstring("DeadlineExceeded"))
... ...
@@ -72,7 +71,7 @@ var _ = g.Describe("[builds][Slow] builds should have deadlines", func() {
72 72
 			o.Expect(build.Status.Phase).Should(o.BeEquivalentTo(buildapi.BuildPhaseFailed))
73 73
 
74 74
 			g.By("verifying the build pod status")
75
-			pod, err := oc.KubeREST().Pods(oc.Namespace()).Get(buildutil.GetBuildPodName(&build))
75
+			pod, err := oc.KubeREST().Pods(oc.Namespace()).Get(buildapi.GetBuildPodName(&build))
76 76
 			o.Expect(err).NotTo(o.HaveOccurred())
77 77
 			o.Expect(pod.Status.Phase).Should(o.BeEquivalentTo(kapi.PodFailed))
78 78
 			o.Expect(pod.Status.Reason).Should(o.ContainSubstring("DeadlineExceeded"))
... ...
@@ -14,7 +14,6 @@ import (
14 14
 	watchapi "k8s.io/kubernetes/pkg/watch"
15 15
 
16 16
 	buildapi "github.com/openshift/origin/pkg/build/api"
17
-	buildutil "github.com/openshift/origin/pkg/build/util"
18 17
 	"github.com/openshift/origin/pkg/client"
19 18
 	"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
20 19
 	"github.com/openshift/origin/pkg/cmd/server/origin"
... ...
@@ -116,7 +115,7 @@ func TestConcurrentBuildControllers(t *testing.T) {
116 116
 	}()
117 117
 
118 118
 	// Watch build pods as they are created
119
-	podWatch, err := kClient.Pods(ns).Watch(kapi.ListOptions{FieldSelector: fields.OneTermEqualSelector("metadata.name", buildutil.GetBuildPodName(b))})
119
+	podWatch, err := kClient.Pods(ns).Watch(kapi.ListOptions{FieldSelector: fields.OneTermEqualSelector("metadata.name", buildapi.GetBuildPodName(b))})
120 120
 	checkErr(t, err)
121 121
 	defer podWatch.Stop()
122 122
 	podAddedCount := int32(0)
... ...
@@ -208,7 +207,7 @@ func TestConcurrentBuildPodControllers(t *testing.T) {
208 208
 		checkErr(t, err)
209 209
 
210 210
 		// Watch build pod for transition to pending
211
-		podWatch, err := kClient.Pods(ns).Watch(kapi.ListOptions{FieldSelector: fields.OneTermEqualSelector("metadata.name", buildutil.GetBuildPodName(b))})
211
+		podWatch, err := kClient.Pods(ns).Watch(kapi.ListOptions{FieldSelector: fields.OneTermEqualSelector("metadata.name", buildapi.GetBuildPodName(b))})
212 212
 		checkErr(t, err)
213 213
 		go func() {
214 214
 			for e := range podWatch.ResultChan() {
... ...
@@ -597,7 +596,7 @@ func runBuildDeleteTest(t *testing.T, clusterAdminClient *client.Client, cluster
597 597
 		t.Fatalf("expected watch event type %s, got %s", e, a)
598 598
 	}
599 599
 	pod := event.Object.(*kapi.Pod)
600
-	if expected := buildutil.GetBuildPodName(newBuild); pod.Name != expected {
600
+	if expected := buildapi.GetBuildPodName(newBuild); pod.Name != expected {
601 601
 		t.Fatalf("Expected pod %s to be deleted, but pod %s was deleted", expected, pod.Name)
602 602
 	}
603 603
 
... ...
@@ -679,7 +678,7 @@ func runBuildRunningPodDeleteTest(t *testing.T, clusterAdminClient *client.Clien
679 679
 		t.Fatalf("expected build status to be marked pending, but was marked %s", newBuild.Status.Phase)
680 680
 	}
681 681
 
682
-	clusterAdminKubeClient.Pods(testutil.Namespace()).Delete(buildutil.GetBuildPodName(newBuild), kapi.NewDeleteOptions(0))
682
+	clusterAdminKubeClient.Pods(testutil.Namespace()).Delete(buildapi.GetBuildPodName(newBuild), kapi.NewDeleteOptions(0))
683 683
 	event = waitForWatch(t, "build updated to error", buildWatch)
684 684
 	if e, a := watchapi.Modified, event.Type; e != a {
685 685
 		t.Fatalf("expected watch event type %s, got %s", e, a)
... ...
@@ -743,7 +742,7 @@ func runBuildCompletePodDeleteTest(t *testing.T, clusterAdminClient *client.Clie
743 743
 		t.Fatalf("expected build status to be marked complete, but was marked %s", newBuild.Status.Phase)
744 744
 	}
745 745
 
746
-	clusterAdminKubeClient.Pods(testutil.Namespace()).Delete(buildutil.GetBuildPodName(newBuild), kapi.NewDeleteOptions(0))
746
+	clusterAdminKubeClient.Pods(testutil.Namespace()).Delete(buildapi.GetBuildPodName(newBuild), kapi.NewDeleteOptions(0))
747 747
 	time.Sleep(10 * time.Second)
748 748
 	newBuild, err = clusterAdminClient.Builds(testutil.Namespace()).Get(newBuild.Name)
749 749
 	if err != nil {
... ...
@@ -16,7 +16,6 @@ import (
16 16
 	overridesapi "github.com/openshift/origin/pkg/build/admission/overrides/api"
17 17
 	buildtestutil "github.com/openshift/origin/pkg/build/admission/testutil"
18 18
 	buildapi "github.com/openshift/origin/pkg/build/api"
19
-	buildutil "github.com/openshift/origin/pkg/build/util"
20 19
 	"github.com/openshift/origin/pkg/client"
21 20
 	configapi "github.com/openshift/origin/pkg/cmd/server/api"
22 21
 	"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
... ...
@@ -130,7 +129,7 @@ func runBuildPodAdmissionTest(t *testing.T, client *client.Client, kclient *kcli
130 130
 	watchOpt := kapi.ListOptions{
131 131
 		FieldSelector: fields.OneTermEqualSelector(
132 132
 			"metadata.name",
133
-			buildutil.GetBuildPodName(build),
133
+			buildapi.GetBuildPodName(build),
134 134
 		),
135 135
 	}
136 136
 	podWatch, err := kclient.Pods(ns).Watch(watchOpt)