Hi! Maybe this was questioned thousand times but t...
# kubernetes
b
Hi! Maybe this was questioned thousand times but today I spent a lot of time trying to find info how to list existing resources with kubernetes module. Class method Get required id of a resource
so according to latest messages in channel there are no such functionality and I should use native module instead
the problem is - I can't convert Output types onto simple types to use it with other modules
m
Let's take a step back to avoid solving an XY problem. What are you ultimately trying to accomplish?
b
Let's say find an IP of service which I did't created and managed but I can find it with labels.
m
OK, so you have an existing service created outside of Pulumi (e.g., someone used
kubectl apply
), which you cannot find through labels. What information do you want to use to identify the service? Do you know in which namespace it should be or its name?
And say you didn't use Pulumi but did everything manually through
kubectl
, what would "finding the IP and using it" look like?
b
Let's say I am starting using Pulumi to provision my deployments and I want to deploy new deployment which have some dependencies on existing infrastructure which could be recreated by not my team but I could find it by labels and annotations. And other team is not ready to implement Pulumi
m
Yeah, that's a classic scenario. We need to distinguish two things here, then: Getting information into Pulumi, and getting information back to the non-Pulumi teams.
Getting information into Pulumi is relatively straightforward: You query the information via the Kubernetes SDK within your program:
Copy code
def find_deployment_by_labels(labels: dict[str, str]) -> (str, str):
   """Utility function to find an existing deployment."""
   ...
   return (namespace, name)

dep_namespace, dep_name = find_deployment_by_labels({"internal/app": "my-app", "internal/team": "my-team"})

my_new_secret = k8s.core.v1.Secret("my-new-secret", 
                                   metadata={"namespace": dep_namespace,
                                             "name": "my-shiny-new-secret"}
                                   )
Alternatively, you can pass in information as configuration but if you can query it just when the program is running, that's preferable in all cases, I think.
Getting information back to your team can work in several ways: You can do it within the context of Kubernetes, either by having them find resources through labels etc. or by maintaining a ConfigMap. Or you generate stack outputs and pass it to them outside of Kubernetes. Again, doing things within Kubernetes should be your best option.
I think it might help to think about Pulumi as "just" one way to create and evolve Kubernetes resources, similar to (but more powerful than) kubectl or Helm.
b
Thanks!