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

Add tilt for debug configuration #45

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nagygergo
Copy link

Added dockerfiles, scripts and docs on how to do live debugging of the various porch components.
The wrapper server and the kpt function processes are not easily modifiable this way, so those were left out.
If there is need to debug into those, then the attached can be extended.

@nephio-prow nephio-prow bot requested a review from henderiw May 11, 2024 20:00
Copy link
Contributor

nephio-prow bot commented May 11, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: nagygergo
Once this PR has been reviewed and has the lgtm label, please assign s3wong for approval by writing /assign @s3wong in a comment. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

linux-foundation-easycla bot commented May 11, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@nephio-prow nephio-prow bot requested a review from johnbelamaric May 11, 2024 20:00
Copy link
Contributor

nephio-prow bot commented May 11, 2024

Hi @nagygergo. Thanks for your PR.

I'm waiting for a nephio-project member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@liamfallon
Copy link
Member

/ok-to-test


### What's happening underneath
For each of the porch components there is a `Dockerfile.debug`, which has 2 significant differences from the original process.
The application code is compiled with flags so that all inlining of code and other optimalizations done by the compiler are disabled, so the debugger can track source code lines correctly.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
The application code is compiled with flags so that all inlining of code and other optimalizations done by the compiler are disabled, so the debugger can track source code lines correctly.
The application code is compiled with flags so that all inlining of code and other optimizations done by the compiler are disabled, so the debugger can track source code lines correctly.

Copy link
Author

Choose a reason for hiding this comment

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

Done

### What's happening underneath
For each of the porch components there is a `Dockerfile.debug`, which has 2 significant differences from the original process.
The application code is compiled with flags so that all inlining of code and other optimalizations done by the compiler are disabled, so the debugger can track source code lines correctly.
A wrapper application is replacing the entrypoint of the container, called [delve](https://github.com/go-delve/delve). This will expose a rpc API called [dap](https://microsoft.github.io/debug-adapter-protocol/overview), which can be used by many IDEs for remote debugging. The ports `:4000`, `:4001`, `:4002` are hardcoded into the respective images. Delve will wait until there is a debugger attached before kicking off the porch application process.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
A wrapper application is replacing the entrypoint of the container, called [delve](https://github.com/go-delve/delve). This will expose a rpc API called [dap](https://microsoft.github.io/debug-adapter-protocol/overview), which can be used by many IDEs for remote debugging. The ports `:4000`, `:4001`, `:4002` are hardcoded into the respective images. Delve will wait until there is a debugger attached before kicking off the porch application process.
A wrapper application is replacing the entrypoint of the container, called [delve](https://github.com/go-delve/delve). This will expose an rpc API called [dap](https://microsoft.github.io/debug-adapter-protocol/overview), which can be used by many IDEs for remote debugging. The ports `:4000`, `:4001`, `:4002` are hardcoded into the respective images. Delve will wait until there is a debugger attached before kicking off the porch application process.

Copy link
Author

Choose a reason for hiding this comment

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

Done

For each of the porch components there is a `Dockerfile.debug`, which has 2 significant differences from the original process.
The application code is compiled with flags so that all inlining of code and other optimalizations done by the compiler are disabled, so the debugger can track source code lines correctly.
A wrapper application is replacing the entrypoint of the container, called [delve](https://github.com/go-delve/delve). This will expose a rpc API called [dap](https://microsoft.github.io/debug-adapter-protocol/overview), which can be used by many IDEs for remote debugging. The ports `:4000`, `:4001`, `:4002` are hardcoded into the respective images. Delve will wait until there is a debugger attached before kicking off the porch application process.
There is a configuration in `Tiltfile`, which whenever one of the containers are deployed in debug mode, creates a `kubectl port-forward` for the respective port to `localhost`. This means that VS Code can now attach it's remote debugger to the `localhost:400x` port, and start monitoring the running application in k8s.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
There is a configuration in `Tiltfile`, which whenever one of the containers are deployed in debug mode, creates a `kubectl port-forward` for the respective port to `localhost`. This means that VS Code can now attach it's remote debugger to the `localhost:400x` port, and start monitoring the running application in k8s.
There is also configuration in `Tiltfile`, which whenever one of the containers are deployed in debug mode, creates a `kubectl port-forward` for the respective port to `localhost`. This means that VS Code can now attach it's remote debugger to the `localhost:400x` port, and start monitoring the running application in k8s.

Copy link
Author

Choose a reason for hiding this comment

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

Done

crds = [
"api/porchconfig/v1alpha1/config.porch.kpt.dev_functions.yaml",
"api/porchconfig/v1alpha1/config.porch.kpt.dev_repositories.yaml",
"controllers/config/crd/bases/config.porch.kpt.dev_fleetmembershipbindings.yaml",
Copy link
Collaborator

Choose a reason for hiding this comment

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

The fleet stuff is junk left over from the migration from kpt and needs to be removed/moved to another repo. We don't use it so can be ignored. Same goes for the Function CRD above.

@@ -37,16 +37,15 @@ spec:
serviceAccountName: porch-fn-runner
containers:
- name: function-runner
image: gcr.io/example-google-project-id/porch-function-runner:latest
image: nephio-project/porch-function-runner:latest
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if this might cause issues with some of the other Make targets.

Copy link
Author

Choose a reason for hiding this comment

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

Seems like scripts/create-deployment-blueprint.sh is looking for those, for replacing them. Fixed it, but I couldn't get the associated make target working, seems like has some google things in there.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ye I think some/most of that google specific stuff should be removed.
I started using the same pkg when doing the kind deploy target but switched to use the catalog pkg instead.
https://github.com/nephio-project/porch/blob/main/Makefile#L325

We need to refine the Make file to reduce the bloat.

image: gcr.io/example-google-project-id/porch-controllers:latest
image: nephio-project/porch-controllers:latest
args:
- --reconcilers=*
Copy link
Collaborator

Choose a reason for hiding this comment

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

This dummy porch pkg is not ideal. We should prob look to remove it and just use the upstream pkg here - https://github.com/nephio-project/catalog/blob/main/nephio/core/porch/9-controllers.yaml

The above will prob enable the fleetsync controller which we don't want.
Some of this logic needs to be refactored also - https://github.com/nephio-project/porch/blob/main/controllers/main.go#L145

Especially this - https://github.com/nephio-project/porch/blob/main/controllers/main.go#L186

Copy link
Author

Choose a reason for hiding this comment

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

Yes, this package is missing an ClusterRole/RoleBinding for the porch-controllers as well. Do you think if it's a good idea to manage the deployment artifacts outside the repo? Or you want to copy it into this repo?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a messy one, but ideally we have 1 source of truth for the porch pkg. The official repo is the catalog repo.
It does break/confuse the Make/test setup somewhat though.

@liamfallon
Copy link
Member

/assign @tliron

@liamfallon
Copy link
Member

@nagygergo Thanks for the great work.

I think we should not integrate Tilt into the main codebase but should place this work in the Porch developer tutorial (or a separate tutorial) so that users can set Tilt and in-cluster debugging themselves, as @tliron suggested. If we integrate Tilt supprot into the main codebase, then we will have to provide ongoing support for it and also offer support for any environment for all comers. This is likely to be very difficult to do.

If we provide the description of how to set Tilt up and provide example configurations (stating the environment on which the configurations worked), then we can ask users to download and tweak those configurations themselves. I think this is reasonable because any developer that is attempting in-cluster debugging will likely need to be an advanced user and should be capable of tweaking the config.

Copy link
Member

@liamfallon liamfallon left a comment

Choose a reason for hiding this comment

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

See comment above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants