pulumi-kubernetes
pulumi-kubernetes copied to clipboard
Unable to get list of existing cluster nodes
What happened?
I am trying to retrieve a list of existing kubernetes cluster nodes, the same thing that kubectl get node provides.
Based on the documentation, the .get() method of each resource should provide a way to retrieve an existing resource.
Moreover, based on this answer: https://www.pulumi.com/ai/answers/1030542e-799d-49e2-b67d-75846a09c1c0 it should be simple as calling get("nodes") on pulumi_kubernetes.core.v1.NodeList.
However, that does not work as expected. It fails with NodeList.get() missing 1 required positional argument: 'id'. That does not make sense. The NodeList.get("nodes") should not need an id.
I have tried providing the following values for the id parameter of the NodeList.get method:
- The
idproperty of the kubernetesProviderclass. None- Empty string
kubectl describe nodeSystem Info -> Machine IDkubectl describe nodeSystem Info -> System UUIDkubectl describe nodeProviderID- Kubernetes node name
- System hostname
None of them work.
See the example below.
Example
Minimal Python example:
# File: __main__.py
import pulumi_kubernetes as k8s
nodes = k8s.core.v1.NodeList.get("nodes")
Output of the above example on pulumi up:
Previewing update (example):
Type Name Plan Info
pulumi:pulumi:Stack example-example 1 error
Diagnostics:
pulumi:pulumi:Stack (example-example):
error: Program failed with an unhandled exception:
Traceback (most recent call last):
File "/home/mnovak/Documents/pulumi-test/./__main__.py", line 3, in <module>
nodes = k8s.core.v1.NodeList.get("nodes")
TypeError: NodeList.get() missing 1 required positional argument: 'id'
Output of pulumi about
CLI
Version 3.99.0
Go Version go1.21.5
Go Compiler gc
Plugins
NAME VERSION
kubernetes 4.6.1
python unknown
Host
OS ubuntu
Version 22.04
Arch x86_64
This project is written in python: executable='/home/mnovak/Documents/pulumi-test/venv/bin/python3' version='3.10.12'
Backend
Name mnovak-thinkpad
URL file://~
User mnovak
Organizations
Token type personal
Dependencies:
NAME VERSION
pip 22.0.2
pulumi-kubernetes 4.6.1
setuptools 59.6.0
Pulumi locates its logs in /tmp by default
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).
The get functions are mainly designed to retrieve a single resource. For example, it is possible to get a specific node by name (in this case, the node named docker-desktop):
node = k8s.core.v1.Node.get("docker-desktop", "docker-desktop")
pulumi.export("resourceVersion", node.metadata.resource_version)
While the NodeList class does have a get function, it isn't an actual resource and doesn't work as expected. That's my understanding, at least.