pantsbuild / pants

The Pants Build System
https://www.pantsbuild.org
Apache License 2.0
3.34k stars 638 forks source link

Make sure FirstPartyHelmDeploymentMapping doesn't get calculated if disabled #21633

Closed grihabor closed 1 week ago

grihabor commented 1 week ago

Option [helm-infer].deployment_dependencies was added in https://github.com/pantsbuild/pants/pull/21282. Unfortunately, I missed one place where FirstPartyHelmDeploymentMapping is requested:

@rule(desc="Prepare Helm deployment post-renderer", level=LogLevel.DEBUG)
async def prepare_post_renderer_for_helm_deployment(
    request: HelmDeploymentPostRendererRequest,
    union_membership: UnionMembership,
    docker_options: DockerOptions,
) -> SetupHelmPostRenderer:
    mapping = await Get(
        FirstPartyHelmDeploymentMapping, FirstPartyHelmDeploymentMappingRequest(request.field_set)
    )
    ...

Here I move this logic inside the rule, so that all consumers correctly handle the case when [helm-infer].deployment_dependencies is set to false

grihabor commented 1 week ago

Would this option benefit from a test of any sort?

I'm not sure if there is a good test that can check that we're not doing inference, but I can add one if you suggest how it should work exactly

tgolsson commented 1 week ago

I'm not sure if there is a good test that can check that we're not doing inference, but I can add one if you suggest how it should work exactly

Isn't this the exact same test as for doing inference, except that you the dependency shouldn't exist..?

tdyas commented 1 week ago

The reason why I'm asking for a test is primarily because this PR fixes a regression. And I generally want tests for regressions since they are failure modes which actually occurred.

The operative question in my view: How do we know that this PR in fact fixed the regression?

How did you account for tracking down all relevant call sites?

A test can provide proof. Or some additional narrative context on testing methodology could be fine as well.

benjyw commented 1 week ago

@grihabor Are you able to add a test and get this merged today? It is past time to get 2.23.0 out... :)

grihabor commented 1 week ago

Isn't this the exact same test as for doing inference, except that you the dependency shouldn't exist..?

If this test existed, it wouldn't have caught this problem, because it wouldn't have tested that we don't calculate FirstPartyHelmDeploymentMapping

grihabor commented 1 week ago

The operative question in my view: How do we know that this PR in fact fixed the regression?

I can explain how I noticed there is an issue. I ran this

$ pants experimental-deploy --no-experimental-deploy-publish-dependencies --dry-run :my-deployment

and got the error

UnownedDependencyError: Error resolving Docker image dependency of a Helm chart.
                `my-image:0.1.0` was supplied, but Pants cannot determine
                whether this should be a target's address or a 3rd-party dependency.
                If this should be an external image, add `my-image:0.1.0` to `[helm-infer].external_docker_images`
                If this should be a target address, use an absolute path instead (possibly `//my-image:0.1.0`).

This indirectly means that pants is trying to build FirstPartyHelmDeploymentMapping.

I could add the test that sets [helm-infer].unowned_dependency_behavior = "error" and [helm-infer].deployment_dependencies = false and makes sure there is no error, sounds good?

tdyas commented 1 week ago

I could add the test that sets [helm-infer].unowned_dependency_behavior = "error" and [helm-infer].deployment_dependencies = false and makes sure there is no error, sounds good?

That works for me.

grihabor commented 1 week ago

Done: https://github.com/pantsbuild/pants/pull/21633/commits/b8b3d834c37adffc354243965f660e37838520ca

PS Notes are probably not required, because there is already a note about the option: https://github.com/pantsbuild/pants/blob/b399758ce2c19027247c00ab29b15f8d9a042177/docs/notes/2.23.x.md?plain=1#L190

WorkerPants commented 1 week ago

I tried to automatically cherry-pick this change back to each relevant milestone, so that it is available in those older releases of Pants.

:heavy_check_mark: 2.23.x

Successfully opened https://github.com/pantsbuild/pants/pull/21635.


Thanks again for your contributions!

:robot: Beep Boop here's my run link