Skip to content

Commit

Permalink
Temp Test Fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Dylan Orzel <[email protected]>
  • Loading branch information
dorzel committed Jan 14, 2025
1 parent d876ab6 commit 996c71e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/reconciler/buildrun/buildrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req
if getTaskRunErr != nil {
if apierrors.IsNotFound(getTaskRunErr) {
build = &buildv1beta1.Build{}
// BUG HERE! GetBuildObject ends up not setting build spec fields to inherit from BuildRun Spec fields correctly!
if err := resources.GetBuildObject(ctx, r.client, buildRun, build); err != nil {
if !resources.IsClientStatusUpdateError(err) && buildRun.Status.IsFailed(buildv1beta1.Succeeded) {
return reconcile.Result{}, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/buildrun/buildrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ var _ = Describe("Reconcile BuildRun", func() {
// set SchedulerName to be invalid
buildRunSample.Spec.SchedulerName = strings.Repeat("s", 64)

statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SchedulerNameNotValid, validation.MaxLenError(64))
statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SchedulerNameNotValid, validation.MaxLenError(63))
statusWriter.UpdateCalls(statusCall)

_, err := reconciler.Reconcile(context.TODO(), buildRunRequest)
Expand Down
5 changes: 5 additions & 0 deletions pkg/reconciler/buildrun/resources/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ func GetBuildObject(ctx context.Context, client client.Client, buildRun *buildv1
build.Name = ""
build.Namespace = buildRun.Namespace
build.Status = buildv1beta1.BuildStatus{}
// BUG HERE: buildrun Spec fields do not get set on this object! therefore they are not actually validated!
buildRun.Spec.Build.Spec.DeepCopyInto(&build.Spec)
// these fields can be specified on both Build and BuildRun objects, and still need to be validated in this case
build.Spec.SchedulerName = buildRun.Spec.SchedulerName
build.Spec.NodeSelector = buildRun.Spec.NodeSelector
build.Spec.Tolerations = buildRun.Spec.Tolerations
return nil
}

Expand Down
25 changes: 25 additions & 0 deletions test/integration/buildruns_to_taskruns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,4 +679,29 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {
})
})
})

Context("when a buildrun is created with a build spec defined", func() {
BeforeEach(func() {
buildSample = []byte(test.MinimalBuild)
buildRunSample = []byte(test.MinimalBuildRunWithSchedulerNameAndBuildName)
})

Context("when the buildRun is created", func() {
It("should fail to register when schedulerName is invalid", func() {
// set buildRun schedulerName to be invalid
buildRunObject.Spec.SchedulerName = strings.Repeat("s", 64)

Expect(tb.CreateBR(buildRunObject)).To(BeNil())

br, err := tb.GetBRTillCompletion(buildRunObject.Name)
Expect(err).To(BeNil())

condition := br.Status.GetCondition(v1beta1.Succeeded)
Expect(condition.Status).To(Equal(corev1.ConditionFalse))
Expect(condition.Reason).To(Equal(resources.ConditionBuildRegistrationFailed))
Expect(condition.Message).To(ContainSubstring(validation.MaxLenError(63)))

})
})
})
})
25 changes: 22 additions & 3 deletions test/v1beta1_samples/buildrun_samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ spec:
`

// MinimalBuildRunWithNodeSelector defines a minimal BuildRun
// with a reference to a not existing Build,
// with a reference to a non-existing Build,
// and a nodeSelector
const MinimalBuildRunWithNodeSelector = `
apiVersion: shipwright.io/v1beta1
Expand All @@ -241,7 +241,7 @@ spec:
`

// MinimalBuildRunWithToleration defines a minimal BuildRun
// with a reference to a not existing Build,
// with a reference to a non-existing Build,
// and a Toleration specified
const MinimalBuildRunWithToleration = `
apiVersion: shipwright.io/v1beta1
Expand All @@ -256,7 +256,7 @@ spec:
`

// MinimalBuildRunWithSchedulerName defines a minimal BuildRun
// with a reference to a not existing Build,
// with a reference to a non-existing Build,
// and a SchedulerName specified
const MinimalBuildRunWithSchedulerName = `
apiVersion: shipwright.io/v1beta1
Expand All @@ -267,6 +267,25 @@ spec:
schedulerName: "buildrun-test-schedulername"
`

// MinimalBuildRunWithSchedulerNameAndBuildName defines a minimal BuildRun
// with a reference to a non-existing Build,
// and a SchedulerName specified
const MinimalBuildRunWithSchedulerNameAndBuildName = `
apiVersion: shipwright.io/v1beta1
kind: BuildRun
metadata:
name: test-buildrun-name
spec:
build:
spec:
strategy:
kind: ClusterBuildStrategy
name: buildah
output:
image: image-registry.openshift-image-registry.svc:5000/example/buildpacks-app
schedulerName: "buildrun-test-schedulername"
`

// MinimalBuildRunWithVulnerabilityScan defines a BuildRun with
// an override for the Build Output
const MinimalBuildRunWithVulnerabilityScan = `
Expand Down

0 comments on commit 996c71e

Please sign in to comment.