diff --git a/pkg/api/graph/graphview/veneering_test.go b/pkg/api/graph/graphview/veneering_test.go index fbc9ff3e5455..1fb89c363c62 100644 --- a/pkg/api/graph/graphview/veneering_test.go +++ b/pkg/api/graph/graphview/veneering_test.go @@ -162,7 +162,7 @@ func TestGraph(t *testing.T) { { ObjectMeta: kapi.ObjectMeta{ Name: "build1-1-abc", - Labels: map[string]string{buildapi.BuildConfigLabel: "build1"}, + Labels: map[string]string{buildapi.DeprecatedBuildConfigLabel: "build1"}, CreationTimestamp: unversioned.NewTime(now.Add(-10 * time.Second)), }, Status: buildapi.BuildStatus{ @@ -172,7 +172,7 @@ func TestGraph(t *testing.T) { { ObjectMeta: kapi.ObjectMeta{ Name: "build1-2-abc", - Labels: map[string]string{buildapi.BuildConfigLabel: "build1"}, + Labels: map[string]string{buildapi.DeprecatedBuildConfigLabel: "build1"}, CreationTimestamp: unversioned.NewTime(now.Add(-5 * time.Second)), }, Status: buildapi.BuildStatus{ @@ -182,7 +182,7 @@ func TestGraph(t *testing.T) { { ObjectMeta: kapi.ObjectMeta{ Name: "build1-3-abc", - Labels: map[string]string{buildapi.BuildConfigLabel: "build1"}, + Labels: map[string]string{buildapi.DeprecatedBuildConfigLabel: "build1"}, CreationTimestamp: unversioned.NewTime(now.Add(-15 * time.Second)), }, Status: buildapi.BuildStatus{ diff --git a/pkg/build/api/types.go b/pkg/build/api/types.go index d33ffc631a1f..05e0cc31439a 100644 --- a/pkg/build/api/types.go +++ b/pkg/build/api/types.go @@ -401,9 +401,14 @@ type BuildOutput struct { PushSecret *kapi.LocalObjectReference } -// BuildConfigLabel is the key of a Build label whose value is the ID of a BuildConfig -// on which the Build is based. -const BuildConfigLabel = "buildconfig" +const ( + // BuildConfigLabel is the key of a Build label whose value is the ID of a BuildConfig + // on which the Build is based. + BuildConfigLabel = "openshift.io/build-config.name" + // DeprecatedBuildConfigLabel was used as BuildConfigLabel before adding namespaces. + // We keep it for backward compatibility. + DeprecatedBuildConfigLabel = "buildconfig" +) // BuildConfig is a template which can be used to create new builds. type BuildConfig struct { diff --git a/pkg/build/api/v1/types.go b/pkg/build/api/v1/types.go index cecffdb1c217..cbeb71721ff0 100644 --- a/pkg/build/api/v1/types.go +++ b/pkg/build/api/v1/types.go @@ -351,10 +351,6 @@ type BuildOutput struct { PushSecret *kapi.LocalObjectReference `json:"pushSecret,omitempty" description:"supported type: dockercfg"` } -// BuildConfigLabel is the key of a Build label whose value is the ID of a BuildConfig -// on which the Build is based. -const BuildConfigLabel = "buildconfig" - // BuildConfig is a template which can be used to create new builds. type BuildConfig struct { unversioned.TypeMeta `json:",inline"` diff --git a/pkg/build/api/v1beta3/types.go b/pkg/build/api/v1beta3/types.go index 51f6b4666718..426ae483a29d 100644 --- a/pkg/build/api/v1beta3/types.go +++ b/pkg/build/api/v1beta3/types.go @@ -340,10 +340,6 @@ type BuildOutput struct { PushSecret *kapi.LocalObjectReference `json:"pushSecret,omitempty" description:"supported type: dockercfg"` } -// BuildConfigLabel is the key of a Build label whose value is the ID of a BuildConfig -// on which the Build is based. -const BuildConfigLabel = "buildconfig" - // BuildConfig is a template which can be used to create new builds. type BuildConfig struct { unversioned.TypeMeta `json:",inline"` diff --git a/pkg/build/generator/generator.go b/pkg/build/generator/generator.go index 848f8a9caccd..459981dead5a 100644 --- a/pkg/build/generator/generator.go +++ b/pkg/build/generator/generator.go @@ -355,6 +355,7 @@ func (g *BuildGenerator) generateBuildFromConfig(ctx kapi.Context, bc *buildapi. if build.Labels == nil { build.Labels = make(map[string]string) } + build.Labels[buildapi.DeprecatedBuildConfigLabel] = bcCopy.Name build.Labels[buildapi.BuildConfigLabel] = bcCopy.Name builderSecrets, err := g.FetchServiceAccountSecrets(bc.Namespace, serviceAccount) diff --git a/pkg/build/generator/generator_test.go b/pkg/build/generator/generator_test.go index 3874d7714717..cd22d18c116c 100644 --- a/pkg/build/generator/generator_test.go +++ b/pkg/build/generator/generator_test.go @@ -601,6 +601,9 @@ func TestGenerateBuildFromConfig(t *testing.T) { if build.Labels[buildapi.BuildConfigLabel] != bc.Name { t.Errorf("Build does not contain labels from BuildConfig") } + if build.Labels[buildapi.DeprecatedBuildConfigLabel] != bc.Name { + t.Errorf("Build does not contain labels from BuildConfig") + } if build.Status.Config.Name != bc.Name || build.Status.Config.Namespace != bc.Namespace || build.Status.Config.Kind != "BuildConfig" { t.Errorf("Build does not contain correct BuildConfig reference: %v", build.Status.Config) } diff --git a/pkg/build/graph/helpers.go b/pkg/build/graph/helpers.go index 342d9123d3ad..6dd1b47d4e65 100644 --- a/pkg/build/graph/helpers.go +++ b/pkg/build/graph/helpers.go @@ -53,7 +53,7 @@ func belongsToBuildConfig(config *buildapi.BuildConfig, b *buildapi.Build) bool if b.Labels == nil { return false } - if b.Labels[buildapi.BuildConfigLabel] == config.Name { + if b.Labels[buildapi.DeprecatedBuildConfigLabel] == config.Name { return true } return false diff --git a/pkg/cmd/cli/describe/describer.go b/pkg/cmd/cli/describe/describer.go index 1fdbe7bdcd57..547fcf0fefe2 100644 --- a/pkg/cmd/cli/describe/describer.go +++ b/pkg/cmd/cli/describe/describer.go @@ -377,7 +377,7 @@ func (d *BuildConfigDescriber) Describe(namespace, name string) (string, error) if err != nil { return "", err } - buildList, err := d.Builds(namespace).List(labels.SelectorFromSet(labels.Set{buildapi.BuildConfigLabel: name}), fields.Everything()) + buildList, err := d.Builds(namespace).List(labels.SelectorFromSet(labels.Set{buildapi.DeprecatedBuildConfigLabel: name}), fields.Everything()) if err != nil { return "", err } diff --git a/pkg/cmd/util/clientcmd/factory.go b/pkg/cmd/util/clientcmd/factory.go index 284611911f4d..b38d6b2954f7 100644 --- a/pkg/cmd/util/clientcmd/factory.go +++ b/pkg/cmd/util/clientcmd/factory.go @@ -196,7 +196,7 @@ func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory { if !ok { return nil, errors.New("provided options object is not a BuildLogOptions") } - buildsForBCSelector := labels.SelectorFromSet(map[string]string{buildapi.BuildConfigLabel: t.Name}) + buildsForBCSelector := labels.SelectorFromSet(map[string]string{buildapi.DeprecatedBuildConfigLabel: t.Name}) builds, err := oc.Builds(t.Namespace).List(buildsForBCSelector, fields.Everything()) if err != nil { return nil, err