Skip to content

Commit

Permalink
Add Builder UpToDate condition to image status
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Kennedy <[email protected]>
  • Loading branch information
tomkennedy513 committed Nov 13, 2023
1 parent b07bfa7 commit f9d54c0
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 14 deletions.
1 change: 1 addition & 0 deletions pkg/apis/build/v1alpha2/builder_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type BuilderResource interface {
GetNamespace() string
BuildBuilderSpec() corev1alpha1.BuildBuilderSpec
Ready() bool
UpToDate() bool
BuildpackMetadata() corev1alpha1.BuildpackMetadataList
RunImage() string
GetKind() string
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/build/v1alpha2/image_builds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ 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
Expand All @@ -396,6 +397,10 @@ func (t TestBuilderResource) Ready() bool {
return t.BuilderReady
}

func (t TestBuilderResource) UpToDate() bool {
return t.BuilderUpToDate
}

func (t TestBuilderResource) BuildpackMetadata() corev1alpha1.BuildpackMetadataList {
return t.BuilderMetadata
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/apis/build/v1alpha2/image_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
)

const (
BuilderNotFound = "BuilderNotFound"
BuilderNotReady = "BuilderNotReady"
BuilderReady = "BuilderReady"
BuilderNotFound = "BuilderNotFound"
BuilderNotReady = "BuilderNotReady"
BuilderReady = "BuilderReady"
BuilderNotUpToDate = "BuilderNotUpToDate"
BuilderUpToDate = "BuilderUpToDate"
)

func (im *Image) BuilderNotFound() corev1alpha1.Conditions {
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/build/v1alpha2/image_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,4 @@ func (i *Image) NamespacedName() types.NamespacedName {
}

const ConditionBuilderReady corev1alpha1.ConditionType = "BuilderReady"
const ConditionBuilderUpToDate corev1alpha1.ConditionType = "BuilderUpToDate"
5 changes: 5 additions & 0 deletions pkg/duckbuilder/duck_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func (b *DuckBuilder) Ready() bool {
(b.Generation == b.Status.ObservedGeneration)
}

func (b *DuckBuilder) UpToDate() bool {
return b.Status.GetCondition(buildapi.ConditionUpToDate).IsTrue() &&
(b.Generation == b.Status.ObservedGeneration)
}

func (b *DuckBuilder) BuildBuilderSpec() corev1alpha1.BuildBuilderSpec {
return corev1alpha1.BuildBuilderSpec{
Image: b.Status.LatestImage,
Expand Down
5 changes: 5 additions & 0 deletions pkg/reconciler/image/build_required_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ 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
Expand All @@ -820,6 +821,10 @@ func (t TestBuilderResource) Ready() bool {
return t.BuilderReady
}

func (t TestBuilderResource) UpToDate() bool {
return t.BuilderUpToDate
}

func (t TestBuilderResource) BuildpackMetadata() corev1alpha1.BuildpackMetadataList {
return t.BuilderMetadata
}
Expand Down
199 changes: 193 additions & 6 deletions pkg/reconciler/image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
return r, actionRecorderList, eventList
})

imageWithBuilder := &buildapi.Image{
imageWithBuilder := &buildapi.Image{
ObjectMeta: metav1.ObjectMeta{
Name: imageName,
Namespace: namespace,
Expand Down Expand Up @@ -172,6 +172,10 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
Type: corev1alpha1.ConditionReady,
Status: corev1.ConditionTrue,
},
{
Type: buildapi.ConditionUpToDate,
Status: corev1.ConditionTrue,
},
},
},
},
Expand Down Expand Up @@ -208,6 +212,10 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
Type: corev1alpha1.ConditionReady,
Status: corev1.ConditionTrue,
},
{
Type: buildapi.ConditionUpToDate,
Status: corev1.ConditionTrue,
},
},
},
},
Expand Down Expand Up @@ -778,11 +786,18 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
Key: key,
Objects: []runtime.Object{
imageWithBuilder,
builderWithCondition(builder, corev1alpha1.Condition{
Type: corev1alpha1.ConditionReady,
Status: corev1.ConditionFalse,
Message: "something went wrong",
}),
builderWithCondition(
builder,
corev1alpha1.Condition{
Type: corev1alpha1.ConditionReady,
Status: corev1.ConditionFalse,
Message: "something went wrong",
},
corev1alpha1.Condition{
Type: buildapi.ConditionUpToDate,
Status: corev1.ConditionFalse,
},
),
resolvedSourceResolver(imageWithBuilder),
},
WantErr: false,
Expand All @@ -807,6 +822,129 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
Reason: buildapi.BuilderNotReady,
Message: "Error: Builder 'builder-name' is not ready in namespace 'some-namespace'; Message: something went wrong",
},
{
Type: buildapi.ConditionBuilderUpToDate,
Status: corev1.ConditionFalse,
Reason: buildapi.BuilderNotUpToDate,
Message: "Builder is not up to date. The latest stack and buildpacks may not be in use.",
},
},
},
},
},
},
},
})
})

it("includes builder UpToDate condition in status", func() {
sourceResolver := resolvedSourceResolver(imageWithBuilder)
rt.Test(rtesting.TableRow{
Key: key,
Objects: []runtime.Object{
imageWithBuilder,
builderWithCondition(
builder,
corev1alpha1.Condition{
Type: corev1alpha1.ConditionReady,
Status: corev1.ConditionTrue,
},
corev1alpha1.Condition{
Type: buildapi.ConditionUpToDate,
Status: corev1.ConditionFalse,
Message: "Builder failed to reconcile",
Reason: buildapi.ReconcileFailedReason,
},
),
sourceResolver,
},
WantErr: false,
WantCreates: []runtime.Object{
&buildapi.Build{
ObjectMeta: metav1.ObjectMeta{
Name: imageName + "-build-1",
Namespace: namespace,
OwnerReferences: []metav1.OwnerReference{
*kmeta.NewControllerRef(imageWithBuilder),
},
Labels: map[string]string{
buildapi.BuildNumberLabel: "1",
buildapi.ImageLabel: imageName,
buildapi.ImageGenerationLabel: generation(imageWithBuilder),
someLabelKey: someValueToPassThrough,
},
Annotations: map[string]string{
buildapi.BuilderNameAnnotation: builderName,
buildapi.BuilderKindAnnotation: buildapi.BuilderKind,
buildapi.BuildReasonAnnotation: buildapi.BuildReasonConfig,
buildapi.BuildChangesAnnotation: testhelpers.CompactJSON(`
[
{
"reason": "CONFIG",
"old": {
"resources": {},
"source": {}
},
"new": {
"resources": {},
"source": {
"git": {
"url": "https://some.git/url-resolved",
"revision": "1234567-resolved"
}
}
}
}
]`),
},
},
Spec: buildapi.BuildSpec{
Tags: []string{imageWithBuilder.Spec.Tag},
Builder: corev1alpha1.BuildBuilderSpec{
Image: builder.Status.LatestImage,
},
ServiceAccountName: imageWithBuilder.Spec.ServiceAccountName,
Cache: &buildapi.BuildCacheConfig{},
RunImage: builderRunImage,
Source: corev1alpha1.SourceConfig{
Git: &corev1alpha1.Git{
URL: sourceResolver.Status.Source.Git.URL,
Revision: sourceResolver.Status.Source.Git.Revision,
},
},
},
},
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{
{
Object: &buildapi.Image{
ObjectMeta: imageWithBuilder.ObjectMeta,
Spec: imageWithBuilder.Spec,
Status: buildapi.ImageStatus{
LatestBuildRef: "image-name-build-1",
LatestBuildImageGeneration: 1,
BuildCounter: 1,
LatestBuildReason: "CONFIG",
Status: corev1alpha1.Status{
ObservedGeneration: originalGeneration,
Conditions: corev1alpha1.Conditions{
{
Type: corev1alpha1.ConditionReady,
Status: corev1.ConditionUnknown,
Reason: image.BuildRunningReason,
Message: "Build 'image-name-build-1' is executing",
},
{
Type: buildapi.ConditionBuilderReady,
Status: corev1.ConditionTrue,
Reason: buildapi.BuilderReady,
},
{
Type: buildapi.ConditionBuilderUpToDate,
Status: corev1.ConditionFalse,
Reason: buildapi.BuilderNotUpToDate,
Message: "Builder is not up to date. The latest stack and buildpacks may not be in use.",
},
},
},
},
Expand Down Expand Up @@ -1587,6 +1725,10 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
Type: corev1alpha1.ConditionReady,
Status: corev1.ConditionTrue,
},
{
Type: buildapi.ConditionUpToDate,
Status: corev1.ConditionTrue,
},
},
},
LatestImage: updatedBuilderImage,
Expand Down Expand Up @@ -1757,6 +1899,10 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
Type: corev1alpha1.ConditionReady,
Status: corev1.ConditionTrue,
},
{
Type: buildapi.ConditionUpToDate,
Status: corev1.ConditionTrue,
},
},
},
LatestImage: updatedBuilderImage,
Expand Down Expand Up @@ -2110,6 +2256,11 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
Status: corev1.ConditionTrue,
Reason: buildapi.BuilderReady,
},
{
Type: buildapi.ConditionBuilderUpToDate,
Status: corev1.ConditionTrue,
Reason: buildapi.BuilderUpToDate,
},
},
},
LatestBuildRef: "image-name-build-1",
Expand Down Expand Up @@ -2222,6 +2373,11 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
Status: corev1.ConditionTrue,
Reason: buildapi.BuilderReady,
},
{
Type: buildapi.ConditionBuilderUpToDate,
Status: corev1.ConditionTrue,
Reason: buildapi.BuilderUpToDate,
},
},
},
LatestBuildRef: "image-name-build-1",
Expand Down Expand Up @@ -2309,6 +2465,12 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
Reason: buildapi.BuilderNotReady,
Message: "Error: Builder 'builder-name' is not ready in namespace 'some-namespace'",
},
{
Type: buildapi.ConditionBuilderUpToDate,
Status: corev1.ConditionFalse,
Reason: buildapi.BuilderNotUpToDate,
Message: "Builder is not up to date. The latest stack and buildpacks may not be in use.",
},
},
},
LatestBuildRef: "image-name-build-1",
Expand Down Expand Up @@ -2394,6 +2556,11 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
Status: corev1.ConditionTrue,
Reason: buildapi.BuilderReady,
},
{
Type: buildapi.ConditionBuilderUpToDate,
Status: corev1.ConditionTrue,
Reason: buildapi.BuilderUpToDate,
},
},
},
LatestBuildRef: "image-name-build-1",
Expand Down Expand Up @@ -2613,6 +2780,11 @@ func conditionReadyUnknown() corev1alpha1.Conditions {
Status: corev1.ConditionTrue,
Reason: buildapi.BuilderReady,
},
{
Type: buildapi.ConditionBuilderUpToDate,
Status: corev1.ConditionTrue,
Reason: buildapi.BuilderUpToDate,
},
}
}

Expand All @@ -2629,6 +2801,11 @@ func conditionBuildExecuting(buildName string) corev1alpha1.Conditions {
Status: corev1.ConditionTrue,
Reason: buildapi.BuilderReady,
},
{
Type: buildapi.ConditionBuilderUpToDate,
Status: corev1.ConditionTrue,
Reason: buildapi.BuilderUpToDate,
},
}
}

Expand All @@ -2644,6 +2821,11 @@ func conditionReady() corev1alpha1.Conditions {
Status: corev1.ConditionTrue,
Reason: buildapi.BuilderReady,
},
{
Type: buildapi.ConditionBuilderUpToDate,
Status: corev1.ConditionTrue,
Reason: buildapi.BuilderUpToDate,
},
}
}

Expand All @@ -2660,5 +2842,10 @@ func conditionNotReady(failedBuild *buildapi.Image) corev1alpha1.Conditions {
Status: corev1.ConditionTrue,
Reason: buildapi.BuilderReady,
},
{
Type: buildapi.ConditionBuilderUpToDate,
Status: corev1.ConditionTrue,
Reason: buildapi.BuilderUpToDate,
},
}
}
Loading

0 comments on commit f9d54c0

Please sign in to comment.