I am trying to get the service load balancer that ...
# general
c
I am trying to get the service load balancer that is created within
k8s
? I have deployed this using helm chart. I am able to get the hang of the service withsomething like this
istio.getResource("v1/Service", "istio-ingressgateway");
which returns the
k8s
service object https://github.com/pulumi/pulumi-kubernetes/blob/d301148551488034535fc2a66c29aa5a2f86380b/sdk/nodejs/provider.ts#L8435 From this service how do I get the reference to load balancer that was created?
c
@gorgeous-egg-16927 Thank you!
🙂 1
I am running into an error.
Copy code
pulumi:pulumi:Stack (eks-eks-naveen):
    (node:61714) ExperimentalWarning: queueMicrotask() is experimental.
    TypeError: Cannot read property 'status' of undefined
Copy code
const i = istio.getResource("v1/Service", "istio-ingressgateway");
const s = i.apply(u => u.status);
@gorgeous-egg-16927 ☝️
g
@chilly-photographer-60932 I haven't used
.getResource
myself yet, but I suspect you need to add a type hint to
const i
so that the compiler knows what kind of resource that call is returning.
c
It is a runtime error
g
@creamy-potato-29402 Any ideas?
c
I'm not in yet
I will be soon
the problem seems to be that you failed to get a service
try enumerating all the keys in the object to see what your options are
this is not a type error. TS knows nothing about types at run time
c
Which keys?
c
the chart object has a dictionary of resources somewhere in there
I am not at my computer so I forget what it's called
c
Is there an example that you can share?
c
no
do you have autocomplete in your editor?
c
Yes
I am using vscode
Copy code
const istio = createIstio(cluster);

const i = istio.getResource(
  "v1/Service",
  "istio-ingressgateway.istio-system.svc.cluster.local"
);
c
when you type
.
what shows up?
istio.
c
createIstio
returns an helm chart
c
no
c
c
I mean, type
istio.
ok so resoruces
can you iterate over the object keys and print out what’s in there?
c
istio.resources.apply(o => console.log(o));
Is that good?
c
that will probably print
[Object object]
or something like that.
Copy code
istio.resources.apply(o => Object.keys(o).forEach(console.log));
something like that.
c
A huge dump
Copy code
urn:
          Output {
            __pulumiOutput: true,
            isKnown: Promise { true },
            resources: [Function],
            promise: [Function],
            apply: [Function],
            get: [Function] },
         id:
          Output {
            __pulumiOutput: true,
            isKnown: Promise { <pending> },
            resources: [Function],
            promise: [Function],
            apply: [Function],
            get: [Function] },
         apiVersion:
          Output {
            __pulumiOutput: true,
            isKnown: Promise { <pending> },
            resources: [Function],
            promise: [Function],
            apply: [Function],
            get: [Function] },
         kind:
          Output {
            __pulumiOutput: true,
            isKnown: Promise { <pending> },
            resources: [Function],
            promise: [Function],
            apply: [Function],
            get: [Function] },
         metadata:
          Output {
            __pulumiOutput: true,
            isKnown: Promise { <pending> },
            resources: [Function],
            promise: [Function],
            apply: [Function],
            get: [Function]
c
Hmm.
pulumi.all(istio.resources).apply(...
?
or
pulumi.output(istio.resources)
, maybe
c
My pulumi up is stuck and can’t cancel it
c
stuck how?
c
And now
error: refusing to proceed
@creamy-potato-29402?
c
pulumi cancel
I don’t know why that happened, it could be for any number of reasons.
that list of things shoudl tell you the name to put into
getResource
c
I did pulumi cancel
c
You mean
pulumi cancel
doesn’t work?
c
Copy code
Output {
      __pulumiOutput: true,
      isKnown: Promise { <pending> },
      resources: [Function],
      promise: [Function],
      apply: [Function],
      get: [Function] }
c
metadata is populated, right?
that’s all you need, is it not?
c
Yes
console.log(pulumi.output(istio.resources));
c
ok, so this should solve your original issue, I think?
c
Copy code
const istio = createIstio(cluster);
console.log(pulumi.output(istio.resources));
const i = istio.getResource(
  "v1/Service",
  "istio-ingressgateway.istio-system.svc.cluster.local"
);

const s = i.apply(u => u.status);
console.log(s);
I am still running into an error.
Cannot read property 'status' of undefined
c
is that the actual name of the service?
evidently not, right?
what does the metadata look like for that object.
c
Waiting for the output of this.
Copy code
const istio = createIstio(cluster);
pulumi.output(istio.resources).apply(({ a, b }) => console.log(a, b));
c
at its core this means that
getResource
has failed to return something sensible. That means your second argument is wrong.
that name does not seem right.
so let’s figure out what the name should be.
it looks like you’re asking for the DNS name, which is probably not what you want.
c
Copy code
pulumi:pulumi:Stack (eks-eks-naveen):
    undefined undefined
Istio resource are
undefined
c
wait, you already printed this out
I see it in the screenshot above
c
Copy code
const istio = createIstio(cluster);
pulumi.output(istio.resources).apply(({ a, b }) => console.log(a, b));
c
can you look at the metadata emitted for that object, from what you printed above?
c
istio.resources
?
c
you are looking for a service object.
you emitted the metadata.name for that object.
in that screenshot above I see you did it.
so if you scroll up and look for the service you’re trying to print, that shoudl solve the problem.
c
Let me try that
c
Youw ere on the right track, now you are doing things that are not on the right track. YOu need to find the metadata for the service you’re looking for which is, I guess:
istio.getResource("v1/Service", "istio-ingressgateway")
so it looks like you already printed out what you need. So you need to find the metadata for that service,
istio-ingressgateway
, if that’s what you’re looking for.
c
I am trying it.
c
you can’t just scroll up and look?
c
Yes, waiting for the code to run
The issue was
"istio-system/istio-ingressgateway"
I didn’t know how to get the servicename within a namespace.
Thank you!
c
ok
np, lmk if you have more questions
c
The docs on the code would have helped. Just some feedback.
But you guys are awesome!!
Love the framework and the support