pulumi / pulumi-policy

Pulumi's Policy as Code SDK, CrossGuard. Define infrastructure checks in code to enforce security, compliance, cost, and other practices, enforced at deployment time.

Home Page:https://www.pulumi.com/docs/guides/crossguard/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kubernetes resources are unable to get type casted

jhsinger-klotho opened this issue · comments

What happened?

pulumi policy pack is unable to work properly with the k8s resources im testing (Deployments and Services). The match works for finding 3 of them and prints the policyResource output in the first log. The second log after i try to cast it, just prints {}

If i try to do conditions (commented out below) on any of the objects attributes, it says that the object is empty and anything within it is undefined.

The check to ensure there are 3 of the resources works, so it seems to me like it does not cast the type correctly.

Steps to reproduce

    const k8Services = args.resources.filter(r => r.isType(k8s.core.v1.Service));
    if (k8Services.length !== 3) {
        reportViolation(`Expected three kubernetes services but found ${k8Services.length}`);
        return;
    }
    console.log(k8Services[0])
    console.log(k8Services[0].asType(k8s.core.v1.Service))
    // for (const i in k8Services) {
    //     const service = k8Services[i].asType(k8s.core.v1.Service)!;
    //     console.log(service.id)
    //     if (["users-store", "users-api", "users-info"].includes(service.id)) {
    //         if (service.metadata.labels["klotho-fargate-enabled"]) {
    //             reportViolation(`Kubernetes Service expected to run on node compute type, but found label 'klotho-fargate-enabled: ${service.metadata.labels["klotho-fargate-enabled"]}'`)
    //         }
    //     } else {
    //         reportViolation(`Unknown Kubernetes Service, found ${service.id}`)
    //     }
    // }

Expected Behavior

would expect the asType directive to cast the appropriate object

Actual Behavior

the asType creates an empty object

Output of pulumi about

CLI
Version 3.42.0
Go Version go1.19.2
Go Compiler gc

Plugins
NAME VERSION
aws 5.16.0
command 0.5.2
docker 3.4.1
eks 0.42.0
kubernetes 3.21.4
kubernetes-cert-manager 0.0.3
nodejs unknown

Host
OS darwin
Version 12.5
Arch arm64

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).