From 38b4b8063adbe1e4d52c9a62572c4767820e6db6 Mon Sep 17 00:00:00 2001 From: Natalie Arellano Date: Thu, 6 Jun 2024 17:35:38 -0400 Subject: [PATCH] Trigger new builds on new lifecycle version, not commit Commit is not going to work because we can't get this information from the lifecycle image labels, it is only available after a build from the application image labels Signed-off-by: Natalie Arellano --- pkg/apis/build/v1alpha2/builder_resource.go | 2 +- .../build/v1alpha2/cluster_lifecycle_types.go | 1 - pkg/apis/build/v1alpha2/image_builds_test.go | 24 +++++------ pkg/cnb/create_builder.go | 1 - pkg/duckbuilder/duck_builder.go | 4 +- pkg/reconciler/image/build_required.go | 4 +- pkg/reconciler/image/build_required_test.go | 40 +++++++++---------- pkg/reconciler/image/image_test.go | 26 ++++++------ 8 files changed, 50 insertions(+), 52 deletions(-) diff --git a/pkg/apis/build/v1alpha2/builder_resource.go b/pkg/apis/build/v1alpha2/builder_resource.go index 22621b9ca..4c8ed3aac 100644 --- a/pkg/apis/build/v1alpha2/builder_resource.go +++ b/pkg/apis/build/v1alpha2/builder_resource.go @@ -10,7 +10,7 @@ type BuilderResource interface { UpToDate() bool BuildpackMetadata() corev1alpha1.BuildpackMetadataList RunImage() string - LifecycleCommit() string + LifecycleVersion() string GetKind() string ConditionReadyMessage() string } diff --git a/pkg/apis/build/v1alpha2/cluster_lifecycle_types.go b/pkg/apis/build/v1alpha2/cluster_lifecycle_types.go index 9242ddce2..8d9847b6c 100644 --- a/pkg/apis/build/v1alpha2/cluster_lifecycle_types.go +++ b/pkg/apis/build/v1alpha2/cluster_lifecycle_types.go @@ -42,7 +42,6 @@ type ClusterLifecycleStatus struct { // +k8s:openapi-gen=true type ResolvedClusterLifecycle struct { Version string `json:"version,omitempty"` - Commit string `json:"commit,omitempty"` // Deprecated: Use `LifecycleAPIs` instead API LifecycleAPI `json:"api,omitempty"` diff --git a/pkg/apis/build/v1alpha2/image_builds_test.go b/pkg/apis/build/v1alpha2/image_builds_test.go index f68f3e133..caa934c08 100644 --- a/pkg/apis/build/v1alpha2/image_builds_test.go +++ b/pkg/apis/build/v1alpha2/image_builds_test.go @@ -371,16 +371,16 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) { } type TestBuilderResource struct { - BuilderReady bool - BuilderUpToDate bool - BuilderMetadata []corev1alpha1.BuildpackMetadata - ImagePullSecrets []corev1.LocalObjectReference - Kind string - LatestImage string - LatestRunImage string - LatestLifecycleCommit string - Name string - Namespace string + BuilderReady bool + BuilderUpToDate bool + BuilderMetadata []corev1alpha1.BuildpackMetadata + ImagePullSecrets []corev1.LocalObjectReference + Kind string + LatestImage string + LatestRunImage string + LatestLifecycleVersion string + Name string + Namespace string } func (t TestBuilderResource) ConditionReadyMessage() string { @@ -410,8 +410,8 @@ func (t TestBuilderResource) RunImage() string { return t.LatestRunImage } -func (t TestBuilderResource) LifecycleCommit() string { - return t.LatestLifecycleCommit +func (t TestBuilderResource) LifecycleVersion() string { + return t.LatestLifecycleVersion } func (t TestBuilderResource) GetName() string { diff --git a/pkg/cnb/create_builder.go b/pkg/cnb/create_builder.go index 6e6b37a42..ccd71748f 100644 --- a/pkg/cnb/create_builder.go +++ b/pkg/cnb/create_builder.go @@ -119,7 +119,6 @@ func (r *RemoteBuilderCreator) CreateBuilder( }, Lifecycle: buildapi.ResolvedClusterLifecycle{ // TODO: test Version: clusterLifecycle.Status.ResolvedClusterLifecycle.Version, - Commit: clusterLifecycle.Status.ResolvedClusterLifecycle.Commit, API: clusterLifecycle.Status.ResolvedClusterLifecycle.API, APIs: clusterLifecycle.Status.ResolvedClusterLifecycle.APIs, }, diff --git a/pkg/duckbuilder/duck_builder.go b/pkg/duckbuilder/duck_builder.go index b5924f5a4..617e6fa91 100644 --- a/pkg/duckbuilder/duck_builder.go +++ b/pkg/duckbuilder/duck_builder.go @@ -57,8 +57,8 @@ func (b *DuckBuilder) RunImage() string { return b.Status.Stack.RunImage } -func (b *DuckBuilder) LifecycleCommit() string { - return b.Status.Lifecycle.Commit +func (b *DuckBuilder) LifecycleVersion() string { + return b.Status.Lifecycle.Version } func (b *DuckBuilder) ConditionReadyMessage() string { diff --git a/pkg/reconciler/image/build_required.go b/pkg/reconciler/image/build_required.go index db2c22e28..e4bf06797 100644 --- a/pkg/reconciler/image/build_required.go +++ b/pkg/reconciler/image/build_required.go @@ -138,7 +138,7 @@ func lifecycleChange(lastBuild *buildapi.Build, builder buildapi.BuilderResource return nil } - oldLifecycle := lastBuild.Status.LifecycleCommit - newLifecycle := builder.LifecycleCommit() + oldLifecycle := lastBuild.Status.LifecycleVersion + newLifecycle := builder.LifecycleVersion() return buildchange.NewLifecycleChange(oldLifecycle, newLifecycle) } diff --git a/pkg/reconciler/image/build_required_test.go b/pkg/reconciler/image/build_required_test.go index e5026b3d8..c669e67d5 100644 --- a/pkg/reconciler/image/build_required_test.go +++ b/pkg/reconciler/image/build_required_test.go @@ -63,9 +63,9 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) { BuilderMetadata: []corev1alpha1.BuildpackMetadata{ {Id: "buildpack.matches", Version: "1"}, }, - LatestRunImage: "some.registry.io/run-image@sha256:67e3de2af270bf09c02e9a644aeb7e87e6b3c049abe6766bf6b6c3728a83e7fb", - LatestLifecycleCommit: "some-git-commit", - Kind: buildapi.BuilderKind, + LatestRunImage: "some.registry.io/run-image@sha256:67e3de2af270bf09c02e9a644aeb7e87e6b3c049abe6766bf6b6c3728a83e7fb", + LatestLifecycleVersion: "some-version", + Kind: buildapi.BuilderKind, } latestBuild := &buildapi.Build{ @@ -93,8 +93,8 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) { RunImage: "some.registry.io/run-image@sha256:67e3de2af270bf09c02e9a644aeb7e87e6b3c049abe6766bf6b6c3728a83e7fb", ID: "io.buildpacks.stack.bionic", }, - LatestImage: "some.registry.io/built@sha256:67e3de2af270bf09c02e9a644aeb7e87e6b3c049abe6766bf6b6c3728a83e7fb", - LifecycleCommit: "some-git-commit", + LatestImage: "some.registry.io/built@sha256:67e3de2af270bf09c02e9a644aeb7e87e6b3c049abe6766bf6b6c3728a83e7fb", + LifecycleVersion: "some-version", }, } @@ -401,14 +401,14 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) { }) it("true if builder has a different lifecycle image", func() { - builder.LatestLifecycleCommit = "some-new-git-commit" + builder.LatestLifecycleVersion = "some-new-version" expectedChanges := testhelpers.CompactJSON(` [ { "reason": "LIFECYCLE", - "old": "some-git-commit", - "new": "some-new-git-commit" + "old": "some-version", + "new": "some-new-version" } ]`) @@ -821,16 +821,16 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) { } type TestBuilderResource struct { - BuilderReady bool - BuilderUpToDate bool - BuilderMetadata []corev1alpha1.BuildpackMetadata - ImagePullSecrets []corev1.LocalObjectReference - LatestImage string - LatestRunImage string - LatestLifecycleCommit string - Name string - Namespace string - Kind string + BuilderReady bool + BuilderUpToDate bool + BuilderMetadata []corev1alpha1.BuildpackMetadata + ImagePullSecrets []corev1.LocalObjectReference + LatestImage string + LatestRunImage string + LatestLifecycleVersion string + Name string + Namespace string + Kind string } func (t TestBuilderResource) BuildBuilderSpec() corev1alpha1.BuildBuilderSpec { @@ -856,8 +856,8 @@ func (t TestBuilderResource) RunImage() string { return t.LatestRunImage } -func (t TestBuilderResource) LifecycleCommit() string { - return t.LatestLifecycleCommit +func (t TestBuilderResource) LifecycleVersion() string { + return t.LatestLifecycleVersion } func (t TestBuilderResource) GetName() string { diff --git a/pkg/reconciler/image/image_test.go b/pkg/reconciler/image/image_test.go index f3389be5e..7fb1dc138 100644 --- a/pkg/reconciler/image/image_test.go +++ b/pkg/reconciler/image/image_test.go @@ -167,7 +167,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { ID: "io.buildpacks.stacks.bionic", }, Lifecycle: buildapi.ResolvedClusterLifecycle{ - Commit: "some-commit", + Version: "some-version", }, Status: corev1alpha1.Status{ Conditions: corev1alpha1.Conditions{ @@ -1467,7 +1467,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { RunImage: "some/run@sha256:67e3de2af270bf09c02e9a644aeb7e87e6b3c049abe6766bf6b6c3728a83e7fb", ID: "io.buildpacks.stacks.bionic", }, - LifecycleCommit: "some-commit", + LifecycleVersion: "some-version", Status: corev1alpha1.Status{ Conditions: corev1alpha1.Conditions{ { @@ -1628,7 +1628,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { RunImage: "some/run@sha256:67e3de2af270bf09c02e9a644aeb7e87e6b3c049abe6766bf6b6c3728a83e7fb", ID: "io.buildpacks.stacks.bionic", }, - LifecycleCommit: "some-commit", + LifecycleVersion: "some-version", Status: corev1alpha1.Status{ Conditions: corev1alpha1.Conditions{ { @@ -1742,7 +1742,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { ID: "io.buildpacks.stacks.bionic", }, Lifecycle: buildapi.ResolvedClusterLifecycle{ - Commit: "some-commit", + Version: "some-version", }, BuilderMetadata: corev1alpha1.BuildpackMetadataList{ { @@ -1792,7 +1792,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { RunImage: "some/run@sha256:67e3de2af270bf09c02e9a644aeb7e87e6b3c049abe6766bf6b6c3728a83e7fb", ID: "io.buildpacks.stacks.bionic", }, - LifecycleCommit: "some-commit", + LifecycleVersion: "some-version", BuildMetadata: corev1alpha1.BuildpackMetadataList{ { Id: "io.buildpack", @@ -1920,7 +1920,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { ID: "io.buildpacks.stacks.bionic", }, Lifecycle: buildapi.ResolvedClusterLifecycle{ - Commit: "some-commit", + Version: "some-version", }, BuilderMetadata: corev1alpha1.BuildpackMetadataList{ { @@ -1970,7 +1970,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { RunImage: "gcr.io/test-project/install/run@sha256:42841631725942db48b7ba8b788b97374a2ada34c84ee02ca5e02ef3d4b0dfca", ID: "io.buildpacks.stacks.bionic", }, - LifecycleCommit: "some-commit", + LifecycleVersion: "some-version", BuildMetadata: corev1alpha1.BuildpackMetadataList{ { Id: "io.buildpack", @@ -2089,7 +2089,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { ID: "io.buildpacks.stacks.bionic", }, Lifecycle: buildapi.ResolvedClusterLifecycle{ - Commit: "some-new-commit", + Version: "some-new-version", }, BuilderMetadata: corev1alpha1.BuildpackMetadataList{ { @@ -2139,7 +2139,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { RunImage: "some/run@sha256:67e3de2af270bf09c02e9a644aeb7e87e6b3c049abe6766bf6b6c3728a83e7fb", ID: "io.buildpacks.stacks.bionic", }, - LifecycleCommit: "some-commit", + LifecycleVersion: "some-version", BuildMetadata: corev1alpha1.BuildpackMetadataList{ { Id: "io.buildpack", @@ -2172,8 +2172,8 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { [ { "reason": "LIFECYCLE", - "old": "some-commit", - "new": "some-new-commit" + "old": "some-version", + "new": "some-new-version" } ]`), }, @@ -2499,7 +2499,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) { RunImage: "some/run@sha256:67e3de2af270bf09c02e9a644aeb7e87e6b3c049abe6766bf6b6c3728a83e7fb", ID: "io.buildpacks.stacks.bionic", }, - LifecycleCommit: "some-commit", + LifecycleVersion: "some-version", Status: corev1alpha1.Status{ Conditions: corev1alpha1.Conditions{ { @@ -2930,7 +2930,7 @@ func builds(image *buildapi.Image, sourceResolver *buildapi.SourceResolver, coun RunImage: runImageRef, ID: "io.buildpacks.stacks.bionic", }, - LifecycleCommit: "some-commit", + LifecycleVersion: "some-version", Status: corev1alpha1.Status{ Conditions: corev1alpha1.Conditions{ condition,