Feature request - subtype support for member predicates #133

Closed
opened 2025-12-30 01:21:22 +01:00 by adam · 5 comments
Owner

Originally created by @bvalyou on GitHub (Apr 5, 2024).

I'm working on migrating helm charts to Pkl and the way I've structured my shared code leverages a Listing<K8sResource> (pkl-k8s) that various pipe functions amend to add features, e.g. a database pipeline adds database env vars, ConfigMaps, and initContainers.

Summary

Quick pseudocode to show the general idea:

class Resources {
  environment: Environment

  k8sResources: Listing<K8sResource>
}

function getPostgresPipeline(databases: Listing<PostgresDatabase>) = (resources: Resources) -> (resources) {
  local environment = resources.environment
  k8sResources {
    [[kind == "Deployment"]] {
      spec {
        template {
          spec {
            initContainers { ... }
          }
        }
      }
    }
  }
}

new Resources { environment = getEnvironment(props) }
  |> getPostgresPipeline(environment.postgresDatabases)
  |> (resources: Resources) -> resources.k8sResources

This works, but the Deployment object I'm amending doesn't know it's a Deployment object, so my IDE can only autocomplete the K8sResource attributes apiVersion and kind.

Requested feature

Subtype syntax - [[is Deployment]] {} or [[kind == "Deployment"] as Deployment] {} where the subtype is known in the following amend block.

It's definitely workable as is but it would be a nice quality of life enhancement.

Thanks for the great work on this!

Originally created by @bvalyou on GitHub (Apr 5, 2024). I'm working on migrating helm charts to Pkl and the way I've structured my shared code leverages a `Listing<K8sResource>` (pkl-k8s) that various pipe functions amend to add features, e.g. a database pipeline adds database env vars, ConfigMaps, and initContainers. # Summary Quick pseudocode to show the general idea: ``` class Resources { environment: Environment k8sResources: Listing<K8sResource> } function getPostgresPipeline(databases: Listing<PostgresDatabase>) = (resources: Resources) -> (resources) { local environment = resources.environment k8sResources { [[kind == "Deployment"]] { spec { template { spec { initContainers { ... } } } } } } } new Resources { environment = getEnvironment(props) } |> getPostgresPipeline(environment.postgresDatabases) |> (resources: Resources) -> resources.k8sResources ``` This works, but the `Deployment` object I'm amending doesn't know it's a `Deployment` object, so my IDE can only autocomplete the `K8sResource` attributes `apiVersion` and `kind`. # Requested feature Subtype syntax - `[[is Deployment]] {}` or `[[kind == "Deployment"] as Deployment] {}` where the subtype is known in the following amend block. It's definitely workable as is but it would be a nice quality of life enhancement. Thanks for the great work on this!
adam closed this issue 2025-12-30 01:21:22 +01:00
Author
Owner

@odenix commented on GitHub (Apr 5, 2024):

Does [[this is Deployment]] do the trick?

@odenix commented on GitHub (Apr 5, 2024): Does `[[this is Deployment]]` do the trick?
Author
Owner

@bvalyou commented on GitHub (Apr 5, 2024):

The one syntax variation I didn't think of! That does it. Thanks!

@bvalyou commented on GitHub (Apr 5, 2024): The one syntax variation I didn't think of! That does it. Thanks!
Author
Owner

@odenix commented on GitHub (Apr 5, 2024):

Is it also understood by the IDE?

@odenix commented on GitHub (Apr 5, 2024): Is it also understood by the IDE?
Author
Owner

@bvalyou commented on GitHub (Apr 5, 2024):

Mostly, though I am seeing a gap within the predicate itself

[[this is ConfigMap && metadata.name == environment.resourceName("app-env")]] {

On that line there's a warning "Unresolved reference: metadata" but on the next line it autocompletes fine

image
@bvalyou commented on GitHub (Apr 5, 2024): Mostly, though I am seeing a gap within the predicate itself ``` [[this is ConfigMap && metadata.name == environment.resourceName("app-env")]] { ``` On that line there's a warning "Unresolved reference: metadata" but on the next line it autocompletes fine <img width="626" alt="image" src="https://github.com/apple/pkl/assets/16170157/a1e6455a-ea3b-42a3-9691-ad191ed7dadc">
Author
Owner

@odenix commented on GitHub (Apr 5, 2024):

Probably worth filing an issue in pkl-intellij.

@odenix commented on GitHub (Apr 5, 2024): Probably worth filing an issue in pkl-intellij.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#133