Skip to content

Commit

Permalink
Trigger new builds on new lifecycle version, not commit
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
natalieparellano committed Jun 6, 2024
1 parent c1595ab commit 38b4b80
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 52 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/build/v1alpha2/builder_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type BuilderResource interface {
UpToDate() bool
BuildpackMetadata() corev1alpha1.BuildpackMetadataList
RunImage() string
LifecycleCommit() string
LifecycleVersion() string
GetKind() string
ConditionReadyMessage() string
}
1 change: 0 additions & 1 deletion pkg/apis/build/v1alpha2/cluster_lifecycle_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
24 changes: 12 additions & 12 deletions pkg/apis/build/v1alpha2/image_builds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion pkg/cnb/create_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/duckbuilder/duck_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/image/build_required.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
40 changes: 20 additions & 20 deletions pkg/reconciler/image/build_required_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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",
},
}

Expand Down Expand Up @@ -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"
}
]`)

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
26 changes: 13 additions & 13 deletions pkg/reconciler/image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
{
Expand Down Expand Up @@ -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{
{
Expand Down Expand Up @@ -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{
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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{
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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{
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
]`),
},
Expand Down Expand Up @@ -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{
{
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 38b4b80

Please sign in to comment.