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

Consider generating encoders for output args #423

Open
pawelprazak opened this issue Mar 28, 2024 · 2 comments
Open

Consider generating encoders for output args #423

pawelprazak opened this issue Mar 28, 2024 · 2 comments
Labels
area/codegen Schema to code generator impact/usability Something that impacts users' ability to use the product easily and intuitively kind/improvement An improvement with existing workaround

Comments

@pawelprazak
Copy link
Contributor

pawelprazak commented Mar 28, 2024

The following use case:

 val nginxService = Service(
    "nginx",
    ServiceArgs(
      spec = ServiceSpecArgs(
        selector = labels,
        `type` = k8s.core.v1.enums.ServiceSpecType.LoadBalancer,
        ports = List(...)
      ),
      metadata = ObjectMetaArgs(...)
    )
  )

  Stack.exports(
    nginxUrl = nginxService.status.loadBalancer
  )

Requires the following workaround:

  given besom.types.Encoder[besom.api.kubernetes.core.v1.outputs.PortStatus] = besom.internal.Encoder.derived
  given besom.types.Encoder[besom.api.kubernetes.core.v1.outputs.LoadBalancerIngress] = besom.internal.Encoder.derived
  given besom.types.Encoder[besom.api.kubernetes.core.v1.outputs.LoadBalancerStatus] = besom.internal.Encoder.derived

To get this output from pulumi:

...
Outputs:
    nginxUrl           : {
        ingress: [
            [0]: {
                hostname: "localhost"
            }
        ]
    }
...
@pawelprazak pawelprazak added kind/improvement An improvement with existing workaround area/codegen Schema to code generator impact/usability Something that impacts users' ability to use the product easily and intuitively labels Mar 28, 2024
@lbialy
Copy link
Collaborator

lbialy commented Mar 28, 2024

Don't we generate that already? There are two options if we don't:
a) add that in codegen and look how much large packages swell, I guess it might be a non trivial amount

b) provide an inline given for Encoders in exports that reach user's code and therefore allow user to derive Encoder on demand

Option A has the benefit of us knowing on package publishing level that something is no yes with caveat of swollen packages.

Option B has the benefit of smaller package size with caveat of missing given errors exposed to the user if something can't be derived.

There's a middle ground option of verifying that we can derive all Encoders for all output args in some kind of post-build test stage (would require two stage generation in codegen, one package would be the core package that we publish, second would depend on first and just verify that we can derive Encoders for all output args so compile failure would prevent publish of first package).

@pawelprazak
Copy link
Contributor Author

We have encoders for input args but not for output args, only decoder there.

This works OOTB in other implementations, so my expectation, if I was a use, was to be of parity.

I agree this adds code to providers and technical limitations of that needs to be taken into account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/codegen Schema to code generator impact/usability Something that impacts users' ability to use the product easily and intuitively kind/improvement An improvement with existing workaround
Projects
None yet
Development

No branches or pull requests

2 participants