I’m trying to extract the underlying IP of a kuber...
# python
w
I’m trying to extract the underlying IP of a kubernetes service that is managed by a python-pulumi app which finishes with these important lines:
Copy code
# Apply the Argo CD installation manifest from a URL
argocd_install_manifest = k8s.yaml.ConfigGroup(
    "argocd-install-manifest",
    files=["<https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/install.yaml>"],
    transformations=[set_namespace],
    opts=opts,
)

# Extract the argocd-server Service and register it's IP address as an output.
argocd_service = argocd_install_manifest.get_resource("service", "argocd-server")
argocd_service_ip = argocd_service.status.loadBalancer.ingress[0].ip
pulumi.export("argocd-service-ip", argocd_service_ip)
This code fails with an error saying that it can’t find a service by that name. I’ve also tried calling k8s.core.v1.Service.get(“argocd-server”, None, opts) but the second argument, ‘id’, it’s not clear to me what I should supply it an None does not work. The service definitely does exist, although to be fair I think it is currently a ClusterIP service, but the error seems to be directly related to service not being found as
pulumi up
errors out with this final stack frame:
Copy code
File "/Users/erich/Library/Caches/pypoetry/virtualenvs/blumeops-yejfY_2Q-py3.11/lib/python3.11/site-packages/pulumi/output.py", line 263, in lift
        return UNKNOWN if isinstance(v, Unknown) else cast(Any, v)[key]
                                                      ~~~~~~~~~~~~^^^^^
    KeyError: 'service:argocd-server'
Can anyone help me figure out how to extract this service’s IP?
b
@white-forest-65475 the format for
.get
is
<namespace>/<service-name>
w
Do you mean I should try:
Copy code
argocd_service = k8s.core.v1.Service.get(namespace.metadata.name, "argocd-server")
This produces an error about expecting a name. I also tried:
Copy code
argocd_service = k8s.core.v1.Service.get(pulumi.Output.concat(namespace.metadata.name, "/argocd-server"))
But this fails with a typerror as
.get
requires at least 2 args -
resource_name
and `id`: https://github.com/pulumi/pulumi-kubernetes/blob/3157468a01a22603ae0a2e618851929770c1b762/sdk/python/pulumi_kubernetes/core/v1/Service.py#L285-L286
b
Copy code
argocd_service = k8s.core.v1.Service.get("argo-service", pulumi.Output.concat(namespace.metadata.name, "/argocd-server"))
the first argument is the name you want to pass to your resource
the second is the id of it
w
Ahah! A new error, but an expected one. Thanks! Just to check something - this doesn’t create a new Service resource, right? The ConfigGroup created this Service resource first and I’m just trying to extract info from it, not build a new one. I guess all resources must have a name even if those names don’t end up resulting in any diff output?
b
correct, it retrieves an existing resource
w
Worked. Thanks again! That’s twice you’ve helped me… is there anything I can do to help you? 🙂
b
spread the Pulumi word far and wide 😄
w
I’m building this as a POC for a devops org I’m about to start working at in two weeks, so maybe I can convince them 🙂 fairly large org, so it would be a big shift, but I like to bring a pitch with me.
b
feel free to DM me, I can send out some swag
w
cheers! might do.