Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update image status to current build status during reconcile if there is a build running #1146

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/reconciler/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func (c *Reconciler) reconcileImage(ctx context.Context, image *buildapi.Image)
return nil, err
} else if k8serrors.IsNotFound(err) {
image.Status.Conditions = image.BuilderNotFound()
image.Status.ObservedGeneration = image.Generation
return image, nil
}

Expand All @@ -153,6 +152,7 @@ func (c *Reconciler) reconcileImage(ctx context.Context, image *buildapi.Image)
}

if lastBuild.IsRunning() {
image.Status.Conditions = buildRunningCondition(lastBuild, builder)
return image, nil
}

Expand Down
34 changes: 31 additions & 3 deletions pkg/reconciler/image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,7 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
})
})

it("does not schedule a build if the previous build is running", func() {
it("does not schedule a build if the previous build is running and updates image status with build status", func() {
imageWithBuilder.Status.BuildCounter = 1
imageWithBuilder.Status.LatestBuildRef = "image-name-build-1"

Expand Down Expand Up @@ -2073,15 +2073,43 @@ func testImageReconciler(t *testing.T, when spec.G, it spec.S) {
Status: corev1alpha1.Status{
Conditions: corev1alpha1.Conditions{
{
Type: corev1alpha1.ConditionSucceeded,
Status: corev1.ConditionUnknown,
Type: corev1alpha1.ConditionSucceeded,
Status: corev1.ConditionUnknown,
Message: "Some build message",
},
},
},
},
},
},
WantErr: false,
WantStatusUpdates: []clientgotesting.UpdateActionImpl{
{
Object: &buildapi.Image{
ObjectMeta: imageWithBuilder.ObjectMeta,
Spec: imageWithBuilder.Spec,
Status: buildapi.ImageStatus{
Status: corev1alpha1.Status{
ObservedGeneration: originalGeneration,
Conditions: corev1alpha1.Conditions{
{
Type: corev1alpha1.ConditionReady,
Status: corev1.ConditionUnknown,
Reason: "BuildRunning",
Message: "Some build message",
},
{
Type: buildapi.ConditionBuilderReady,
Status: corev1.ConditionTrue,
},
},
},
LatestBuildRef: "image-name-build-1",
BuildCounter: 1,
},
},
},
},
})
})

Expand Down
15 changes: 15 additions & 0 deletions pkg/reconciler/image/reconcile_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
corev1alpha1 "github.com/pivotal/kpack/pkg/apis/core/v1alpha1"
)

const BuildRunningReason = "BuildRunning"

func (c *Reconciler) reconcileBuild(ctx context.Context, image *buildapi.Image, latestBuild *buildapi.Build, sourceResolver *buildapi.SourceResolver, builder buildapi.BuilderResource, buildCacheName string) (buildapi.ImageStatus, error) {
currentBuildNumber, err := buildCounter(latestBuild)
if err != nil {
Expand Down Expand Up @@ -157,3 +159,16 @@ func buildCounter(build *buildapi.Build) (int64, error) {
buildNumber := build.Labels[buildapi.BuildNumberLabel]
return strconv.ParseInt(buildNumber, 10, 64)
}

func buildRunningCondition(build *buildapi.Build, builder buildapi.BuilderResource) corev1alpha1.Conditions {
return corev1alpha1.Conditions{
{
Type: corev1alpha1.ConditionReady,
Status: corev1.ConditionUnknown,
Reason: BuildRunningReason,
Message: emptyMessageIfNil(build.Status.GetCondition(corev1alpha1.ConditionSucceeded)),
LastTransitionTime: corev1alpha1.VolatileTime{Inner: metav1.Now()},
},
builderCondition(builder),
}
}