Skip to content
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

feat(buildkit): support buildkit auto-discovery on Kubernetes #33

Merged

Conversation

nettoclaudio
Copy link
Member

  • Auto-discovery BuildKit's pods on Kubernetes
  • Lock the selected BuildKit pod using Leases
  • Set/unset Tsuru app labels on the selected BuildKit pod (allowing the BuildKit pod to inherit the same NetworkPolicies as Tsuru app)

@nettoclaudio nettoclaudio marked this pull request as ready for review March 7, 2023 20:04
@nettoclaudio nettoclaudio requested a review from wpjunior March 10, 2023 15:11
Copy link

@tcarreira tcarreira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job. I added some simple comments/RfChange

main.go Outdated Show resolved Hide resolved
@@ -64,24 +100,33 @@ func (b *BuildKit) Build(ctx context.Context, r *pb.BuildRequest, w io.Writer) (
return nil, errors.New("writer must implement console.File")
}

c, clientCleanUp, err := b.client(ctx, r)
if err != nil {
Copy link

@tcarreira tcarreira Mar 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is possible for b.client() to return an err and still leave something to cleanUp. We would need to call clientCleanUp() inside this if.
(eg: not cleaned things from function func (d *k8sDiscoverer) discoverBuildKitClientFromApp())

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum... For sure it's possible but I'm not comfortable with this approach. I usually discard any other return object when the error is not zero (empty). I'm not 100% but I think it's a Go convention BTW.

pkg/build/buildkit/k8s_autodiscovery.go Outdated Show resolved Hide resolved
OnStartedLeading: func(c context.Context) {
select {
case ch <- pod:
klog.V(4).Infof("Selected BuildKit pod: %s/%s", pod.Namespace, pod.Name)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding the uniqueHolderName on this log could be useful (also, the 2 logs after this one)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, this info (uniqueHolderName) doesn't help anything. This name it's mostly like a random number around each build call, it's important just to avoid conflict while getting the lease (lock). Two consecutive build calls will generate different holder names, so they will not share the lease lock.

@tcarreira tcarreira self-requested a review March 13, 2023 19:06
@nettoclaudio nettoclaudio merged commit b3792f3 into tsuru:main Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants