-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set ownerReference to build->buildrun #409
Set ownerReference to build->buildrun #409
Conversation
17150eb
to
9a9340a
Compare
ea0f11c
to
11845fc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provided a couple of comments where I would like to see the feedback first.
2a9640a
to
0194f75
Compare
dd9ce65
to
3993240
Compare
74a12b4
to
d5dcb1f
Compare
f3a32b5
to
6d208fa
Compare
6d208fa
to
0fecde8
Compare
/retest |
if err := r.client.Update(ctx, &buildRun); err != nil { | ||
return err | ||
} | ||
ctxlog.Info(ctx, fmt.Sprintf("succesfully updated BuildRun %s", buildRun.Name), namespace, buildRun.Namespace, name, buildRun.Name) | ||
} | ||
} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it is else
, the end user may set the AnnotationBuildRunDeletion
to yes
or aha
, then it will also enter this logic which is not good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I would suggest to rewrite the if
/else
to a switch
:
switch b.GetAnnotations()[build.AnnotationBuildRunDeletion] {
case "true":
// ...
case "false":
// ...
default:
// error case ...
}
Could also improve readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was on purpose, the important value was "false", but I agree it should be more strict. Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hold on, I didnt see @HeavyWombat comment, enhancing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HeavyWombat so I added this in
build/pkg/controller/build/build_controller.go
Lines 326 to 358 in 98b81eb
switch b.GetAnnotations()[build.AnnotationBuildRunDeletion] { | |
case "true": | |
// if the buildRun does not have an ownerreference to the Build, lets add it. | |
for _, buildRun := range buildRunList.Items { | |
if index := r.validateBuildOwnerReference(buildRun.OwnerReferences, b); index == -1 { | |
if err := r.setOwnerReferenceFunc(b, &buildRun, r.scheme); err != nil { | |
b.Status.Reason = fmt.Sprintf("unexpected error when trying to set the ownerreference: %v", err) | |
if err := r.client.Status().Update(ctx, b); err != nil { | |
return err | |
} | |
} | |
if err = r.client.Update(ctx, &buildRun); err != nil { | |
return err | |
} | |
ctxlog.Info(ctx, fmt.Sprintf("succesfully updated BuildRun %s", buildRun.Name), namespace, buildRun.Namespace, name, buildRun.Name) | |
} | |
} | |
case "false": | |
// if the buildRun have an ownerreference to the Build, lets remove it | |
for _, buildRun := range buildRunList.Items { | |
if index := r.validateBuildOwnerReference(buildRun.OwnerReferences, b); index != -1 { | |
buildRun.OwnerReferences = removeOwnerReferenceByIndex(buildRun.OwnerReferences, index) | |
if err := r.client.Update(ctx, &buildRun); err != nil { | |
return err | |
} | |
ctxlog.Info(ctx, fmt.Sprintf("succesfully updated BuildRun %s", buildRun.Name), namespace, buildRun.Namespace, name, buildRun.Name) | |
} | |
} | |
default: | |
ctxlog.Info(ctx, fmt.Sprintf("the annotation %s was not properly defined, supported values are true or false", build.AnnotationBuildRunDeletion), namespace, b.Namespace, name, b.Name) | |
return fmt.Errorf("the annotation %s was not properly defined, supported values are true or false", build.AnnotationBuildRunDeletion) | |
} |
There is one caveat, if the user defines a wrong annotation value (not true or false), then the logic will return an error (ignored in the reconcile parent func) and we will get an INFO log (that illustrates the problem). Ideally I think we want the Build
to reflect this issue in its Status.Reason and fail the Build
Registration.
But I will prefer to do the above in a second pr, mainly because this use-case was not supported before. Opinions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, an annotation value that is neither true
nor false
is good to be reflected in the build status.I am okay doing this separately.
I am thinking if dynamically update the buildrun in build is a good way for the ownerReference way. In the new solution, we need to get all buildrun every time no matter if we need to update the buildrun or not in each reconciliation. if there are lots of buildrun or once the build controller is restart, it may be slow. So our goal is we can provide an option to allow end user:
So not sure if we can:
or use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comments where I see where we could further improve.
d5f6e9a
to
bead38a
Compare
@zhangtbj thanks for the feedback.
The above is a valid concern but is not fully accurate. It is correct that the
This is already done in the buildrun controller, during the BuildRun creation only if the annotation is set to true.
This is not possible at this point in time. The annotation belongs to the
I´m not sure what you mean.
Not sure if I understand your point. If you want to keep the associated BuildRuns then do not use the "annotation". If you use the annotation all dependent objects will be deleted. |
What I mean is:
It can keep our logic more easy and clear, I think. |
bead38a
to
5d00b09
Compare
@zhangtbj can u take this requirement as a separate issue then? this pr is about replacing finalizers in favor of ownerreferenes, by keeping the same behaviour and more importantly adding test cases for the initial feature. I honestly do not understand the UX rational you are saying. But as I said, please open another issue, this is not the right PR for it. |
Sure thing. Let me open another new issue to track the improvement for that. |
This replace finalizers logic. Add unit-test for the new ownerReference behaviour Update documentation to illustrate the new approach
The above func is not longer needed, we assert for the behaviour of an automatic deletion of a BuildRun in the integration test for builds_and_buildruns.
5d00b09
to
98b81eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: HeavyWombat, SaschaSchwarze0 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Fixes #324
This PR is the continuation of #371 . I addressed all concerns there into this PR, and preserve @routerhan commits.
This PR replaces the finalizers approach we have in the Build -> BuildRun in favour of OwnerReferences for the same resources, aligning to the same approach as we have between BuildRuns -> TaskRuns. The PR have one commit for fixing go linters I found by using
staticcheck ./...
(I couldn´t avoid fixing this now)@zhangtbj @HeavyWombat for your information:
Note: When dealing with OwnerReferences between the Build(owner) and BuildRun(owned), both controllers
Build
andBuildRun
plays a role on ensuring that the BuildRun gets the Ownerreference or that the OwnerReference is removed. Following scenarios to consider:For the above case, the Ownerreference is added during the
CREATION
event of a BuildRun, meaning on theBuildRun
controller side.For the above case, the Ownerreference needs to be removed during the
UPDATE
event of a Build, meaning we need logic on theBuild
controller reconciler side.For the above case, the Ownerreference needs to be removed or added during the
UPDATE
event of a Build, meaning we need logic on theBuild
controller reconciler side.Also please consider that this PR have quite a lot of test cases, both unit-tests and integration-tests. I recommend you to read the integration tests ones.