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

Kubernetes resources are unable to get type casted #300

Open
jhsinger-klotho opened this issue Nov 2, 2022 · 0 comments
Open

Kubernetes resources are unable to get type casted #300

jhsinger-klotho opened this issue Nov 2, 2022 · 0 comments
Labels
feature/pac Impacts the Policy as Code offering kind/bug Some behavior is incorrect or out of spec

Comments

@jhsinger-klotho
Copy link

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).

@jhsinger-klotho jhsinger-klotho added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Nov 2, 2022
@mikhailshilkov mikhailshilkov added feature/pac Impacts the Policy as Code offering and removed needs-triage Needs attention from the triage team labels Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/pac Impacts the Policy as Code offering kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

No branches or pull requests

2 participants