Skip to content

Commit

Permalink
code review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Sascha Schwarze <[email protected]>
  • Loading branch information
qu1queee authored and SaschaSchwarze0 committed Feb 19, 2024
1 parent 6c6f3d8 commit 4615a84
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 50 deletions.
2 changes: 0 additions & 2 deletions pkg/apis/build/v1beta1/buildrun_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ func (src *BuildRun) ConvertTo(ctx context.Context, obj *unstructured.Unstructur
CompletionTime: src.Status.CompletionTime,
}

// Note: .Status.FailedAt is deprecated, so we do not
// convert it, only .Status.FailureDetails
if src.Status.FailureDetails != nil {
alphaBuildRun.Status.FailureDetails = &v1alpha1.FailureDetails{
Reason: src.Status.FailureDetails.Reason,
Expand Down
13 changes: 11 additions & 2 deletions pkg/reconciler/build/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,20 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo
if !reflect.DeepEqual(oldBuildRetention, newBuildRetention) {
switch {
case o.Spec.Retention == nil && n.Spec.Retention != nil:
if n.Spec.Retention.AtBuildDeletion != nil {
if n.Spec.Retention.AtBuildDeletion != nil && *n.Spec.Retention.AtBuildDeletion {
logAndEnableDeletion()
}
case o.Spec.Retention != nil && n.Spec.Retention == nil:
if o.Spec.Retention.AtBuildDeletion != nil {
if o.Spec.Retention.AtBuildDeletion != nil && *o.Spec.Retention.AtBuildDeletion {
logAndEnableDeletion()
}
case o.Spec.Retention != nil && n.Spec.Retention != nil:
if o.Spec.Retention.AtBuildDeletion != nil && *o.Spec.Retention.AtBuildDeletion &&
(n.Spec.Retention.AtBuildDeletion == nil || !*n.Spec.Retention.AtBuildDeletion) {
logAndEnableDeletion()
}
if n.Spec.Retention.AtBuildDeletion != nil && *n.Spec.Retention.AtBuildDeletion &&
(o.Spec.Retention.AtBuildDeletion == nil || !*o.Spec.Retention.AtBuildDeletion) {
logAndEnableDeletion()
}
}
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 @@ -1173,7 +1173,7 @@ var _ = Describe("Reconcile BuildRun", func() {
)

// Ensure the BuildRun gets an ownershipReference when
// the buildv1beta1.AnnotationBuildRunDeletion is set to true
// the spec.Retention.AtBuildDeletion is set to true
// in the build
clientUpdateCalls := ctl.StubBuildUpdateOwnerReferences("Build",
buildName,
Expand Down
8 changes: 4 additions & 4 deletions pkg/reconciler/buildrun/resources/results_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var _ = Describe("TaskRun results to BuildRun", func() {

resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.Results, taskRunRequest)

Expect(br.Status.Source).ToNot(Equal(nil))
Expect(br.Status.Source).ToNot(BeNil())
Expect(br.Status.Source.Git.CommitSha).To(Equal(commitSha))
Expect(br.Status.Source.Git.CommitAuthor).To(Equal("foo bar"))
})
Expand All @@ -102,7 +102,7 @@ var _ = Describe("TaskRun results to BuildRun", func() {

resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.Results, taskRunRequest)

Expect(br.Status.Source).ToNot(Equal(nil))
Expect(br.Status.Source).ToNot(BeNil())
Expect(br.Status.Source.OciArtifact.Digest).To(Equal(bundleImageDigest))
})

Expand Down Expand Up @@ -175,8 +175,8 @@ var _ = Describe("TaskRun results to BuildRun", func() {

resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.Results, taskRunRequest)

Expect(br.Status.Source).ToNot(Equal(nil))
Expect(br.Status.Source.Git).ToNot(Equal(nil))
Expect(br.Status.Source).ToNot(BeNil())
Expect(br.Status.Source.Git).ToNot(BeNil())
Expect(br.Status.Source.Git.CommitSha).To(Equal(commitSha))
Expect(br.Status.Source.Git.CommitAuthor).To(Equal("foo bar"))
Expect(br.Status.Output.Digest).To(Equal(imageDigest))
Expand Down
25 changes: 1 addition & 24 deletions pkg/reconciler/buildrun/resources/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ var _ = Describe("GenerateTaskrun", func() {
buildStrategy *buildv1beta1.BuildStrategy
buildStrategyStepNames map[string]struct{}
buildStrategyWithEnvs *buildv1beta1.BuildStrategy
builderImage *buildv1beta1.Image
dockerfile, buildpacks string
buildpacks string
ctl test.Catalog
)

BeforeEach(func() {
buildpacks = "buildpacks-v3"
dockerfile = "Dockerfile"
})

Describe("Generate the TaskSpec", func() {
Expand All @@ -51,11 +49,6 @@ var _ = Describe("GenerateTaskrun", func() {
got *pipelineapi.TaskSpec
err error
)
BeforeEach(func() {
builderImage = &buildv1beta1.Image{
Image: "quay.io/builder/image",
}
})

Context("when the task spec is generated", func() {
BeforeEach(func() {
Expand Down Expand Up @@ -413,9 +406,6 @@ var _ = Describe("GenerateTaskrun", func() {

namespace = "build-test"
contextDir = "docker-build"
builderImage = &buildv1beta1.Image{
Image: "heroku/builder:22",
}
outputPath = "image-registry.openshift-image-registry.svc:5000/example/buildpacks-app"
outputPathBuildRun = "image-registry.openshift-image-registry.svc:5000/example/buildpacks-app-v2"
serviceAccountName = buildpacks + "-serviceaccount"
Expand Down Expand Up @@ -508,8 +498,6 @@ var _ = Describe("GenerateTaskrun", func() {
paramOutputInsecureFound := false

// legacy params
paramBuilderImageFound := false
paramDockerfileFound := false
paramContextDirFound := false

for _, param := range params {
Expand All @@ -530,14 +518,6 @@ var _ = Describe("GenerateTaskrun", func() {
paramOutputInsecureFound = true
Expect(param.Value.StringVal).To(Equal("false"))

case "builder-image":
paramBuilderImageFound = true
Expect(param.Value.StringVal).To(Equal(builderImage.Image))

case "dockerfile":
paramDockerfileFound = true
Expect(param.Value.StringVal).To(Equal(dockerfile))

case "CONTEXT_DIR":
paramContextDirFound = true
Expect(param.Value.StringVal).To(Equal(contextDir))
Expand All @@ -551,9 +531,6 @@ var _ = Describe("GenerateTaskrun", func() {
Expect(paramSourceContextFound).To(BeTrue())
Expect(paramOutputImageFound).To(BeTrue())
Expect(paramOutputInsecureFound).To(BeTrue())

Expect(paramBuilderImageFound).To(BeTrue())
Expect(paramDockerfileFound).To(BeTrue())
Expect(paramContextDirFound).To(BeTrue())
})

Expand Down
6 changes: 3 additions & 3 deletions pkg/validate/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ func (s *SourceRef) validateSourceEntry(source build.Source) error {

switch source.Type {
case "Git":
if source.GitSource == nil {
if source.GitSource == nil || source.OCIArtifact != nil || source.LocalSource != nil {
return fmt.Errorf("type does not match the source")
}
case "OCI":
if source.OCIArtifact == nil {
if source.OCIArtifact == nil || source.GitSource != nil || source.LocalSource != nil {
return fmt.Errorf("type does not match the source")
}
case "Local":
if source.LocalSource == nil {
if source.LocalSource == nil || source.OCIArtifact != nil || source.GitSource != nil {
return fmt.Errorf("type does not match the source")
}
case "":
Expand Down
1 change: 0 additions & 1 deletion test/e2e/v1beta1/common_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func (b *buildPrototype) SourceBundle(image string) *buildPrototype {
b.build.Spec.Source.OCIArtifact = &buildv1beta1.OCIArtifact{}
}
b.build.Spec.Source.Type = buildv1beta1.OCIArtifactType
b.build.Spec.Source.Type = buildv1beta1.OCIArtifactType
b.build.Spec.Source.OCIArtifact.Image = image
return b
}
Expand Down
5 changes: 0 additions & 5 deletions test/v1beta1_samples/build_samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ spec:
strategy:
name: buildpacks-v3
kind: ClusterBuildStrategy
paramValues:
- name: dockerfile
value: Dockerfile
- name: builder-image
value: heroku/builder:22
output:
image: image-registry.openshift-image-registry.svc:5000/example/buildpacks-app
timeout: 30s
Expand Down
8 changes: 0 additions & 8 deletions test/v1beta1_samples/buildstrategy_samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,6 @@ spec:
volumeMounts:
- name: varlibcontainers
mountPath: /var/lib/containers
parameters:
- name: dockerfile
description: The path to the Dockerfile to be used for building the image.
type: string
default: "Dockerfile"
- name: builder-image
description: The builder image.
type: string
`

// BuildStrategyWithParameters is a strategy that uses a
Expand Down

0 comments on commit 4615a84

Please sign in to comment.