Skip to content

fix: reuse custom environment when patching session launcher - #699

Merged
mohammad-alisafaee merged 3 commits into
kpack-resourcesfrom
pitch/custom-environment-build
Mar 5, 2025
Merged

mohammad-alisafaee merged 3 commits into
kpack-resourcesfrom
pitch/custom-environment-build

Conversation

@mohammad-alisafaee

@mohammad-alisafaee mohammad-alisafaee commented Mar 4, 2025 •

Copy link
Copy Markdown
Contributor

/deploy #notest renku=build/session-env-builders renku-notebooks=leafty/shipwright-buildrun-cache renku-ui=build/session-env-builders extra-values=dataService.imageBuilders.enabled=true,dataService.imageBuilders.pushSecretName=flora-docker-secret,dataService.imageBuilders.buildRunTimeoutSeconds=3600,dataService.imageBuilders.buildRunRetentionAfterFailedSeconds=86400,dataService.imageBuilders.buildRunRetentionAfterSucceededSeconds=3600,dataService.imageBuilders.nodeSelector.renku.io/node-purpose=image-build,dataService.imageBuilders.tolerations[0].key=renku.io/dedicated,dataService.imageBuilders.tolerations[0].operator=Equal,dataService.imageBuilders.tolerations[0].effect=NoSchedule,dataService.imageBuilders.tolerations[0].value=image-build,dataService.imageBuilders.outputImagePrefix=harbor.dev.renku.ch/flora-dev/

@mohammad-alisafaee
mohammad-alisafaee force-pushed the pitch/custom-environment-build branch from 640f791 to ed0d7f6 Compare March 4, 2025 01:37
@mohammad-alisafaee
mohammad-alisafaee marked this pull request as ready for review March 4, 2025 08:01
@mohammad-alisafaee
mohammad-alisafaee requested a review from a team as a code owner March 4, 2025 08:01
@leafty
leafty temporarily deployed to renku-ci-ds-699 March 4, 2025 08:18 — with GitHub Actions Inactive
@RenkuBot

RenkuBot commented Mar 4, 2025

Copy link
Copy Markdown
Contributor

@leafty leafty self-assigned this Mar 4, 2025
Comment on lines +250 to +253
assert patch.environment.build_parameters is not None # Make mypy happy in the following statement
# NOTE: The environment type is changed to be built, so, all required fields should be passed (as in
# a POST request). No need to get values from the current env, since they will be set by the build.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure assert is the right thing to do here. if this were to happen, it'd trigger an assertion error which probably isn't handled correctly by our error handling.

Is using if patch.environment.build_parameters is None: with the raise that we had before not enough to keep mypy happy (like changing the not ... to is None)?

@mohammad-alisafaee mohammad-alisafaee Mar 4, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We are already checking that patch.environment.build_parameters is not None in the previous if block and this check was redundant. However, mypy isn't smart enough to deduct that patch.environment.build_parameters is not null. I'm not sure what's the general policy to handle such cases, but we've used assertion before. I've replaced the assertion with a typing cast. I can re-introduce the if/raise block if you think that's a better way of handling it.

Comment on lines +677 to +700
launcher.environment.container_image = (
"image:unknown-at-the-moment" # TODO: This should come from the build
)
launcher.environment.default_url = "/lab" # TODO: This should come from the build
launcher.environment.port = 8888 # TODO: This should come from the build
launcher.environment.working_directory = None # TODO: This should come from the build
launcher.environment.mount_directory = None # TODO: This should come from the build
launcher.environment.uid = 1000 # TODO: This should come from the build
launcher.environment.gid = 1000 # TODO: This should come from the build
launcher.environment.environment_kind = models.EnvironmentKind.CUSTOM
launcher.environment.command = None # TODO: This should come from the build
launcher.environment.args = None # TODO: This should come from the build
launcher.environment.environment_image_source = models.EnvironmentImageSource.build
launcher.environment.build_parameters_id = build_parameters_orm.id
launcher.environment.build_parameters = build_parameters_orm

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know this is not really related to this PR(it was like this before) but I think we should handle this a bit better. Is there an issue for these TODOs? I think we'd either want some polymorphism in the db with an UnbuiltEnvironment type or to have a field in environment like environment.state that can be something like not_built and to allow the fields to be None (with dedicated types for built/unbuilt in code that validate that it's not None except for in this case)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We'll do some work to store the build result and update the environment once a build finishes (there's a scope's task for that in the build note). I'll create an issue for it and add your comment there.

@leafty leafty left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @mohammad-alisafaee!

I will test that the deployment works as expected.

Some early comments from me below.



@pytest.mark.asyncio
async def test_post_build(sanic_client: SanicASGITestClient, user_headers, create_project) -> None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this test removed? We still need to check that triggering a build is working as expected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We start the build when the session launcher is posted and starting the build again will fail. We can stop this build and then rebuild it again but that's what we exactly do in test_get_build. I'll re-introduce this test with some modification to at least keep the action name in the test.

@leafty
leafty temporarily deployed to renku-ci-ds-699 March 4, 2025 10:19 — with GitHub Actions Inactive
@leafty
leafty temporarily deployed to renku-ci-ds-699 March 4, 2025 10:30 — with GitHub Actions Inactive

@leafty leafty left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This works as expected when deployed. I had to do a small adjustment on the UI.

@Panaetius
Panaetius force-pushed the kpack-resources branch 2 times, most recently from ffe8c9a to 115cd4c Compare March 5, 2025 09:13
@leafty
leafty force-pushed the kpack-resources branch from 115cd4c to e26a64a Compare March 5, 2025 09:44
@RenkuBot

RenkuBot commented Mar 5, 2025

Copy link
Copy Markdown
Contributor

Tearing down the temporary RenkuLab deplyoment for this PR.

Panaetius pushed a commit that referenced this pull request Mar 6, 2025
* fix: reuse custom environment when patching session launcher
* feat: automatically start build when creating custom env from repo
leafty pushed a commit that referenced this pull request Mar 6, 2025
* fix: reuse custom environment when patching session launcher
* feat: automatically start build when creating custom env from repo

This branch had an error being deployed

1 failed deployment
renku-ci-ds-699 — b5e20fc5 Deployed Mar 5, 2025 by mohammad-alisafaee
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.

4 participants