https://pulumi.com logo
#kubernetes
Title
# kubernetes
f

faint-motherboard-95438

06/23/2020, 2:32 PM
Hi there, Trying to use
getResource()
on a
k8s.helm.v2.Chart
yields a weird error:
Error: invocation of kubernetes:yaml:decode returned an error: error converting YAML to JSON: yaml: line 29: could not find expected ':'
I’m installing
mongodb-replicaset
chart and try to access the
StatefulSet
:
Copy code
this.statefulSet = this.chart.getResource(
      'apps/v1/StatefulSet',
      replicaSetName,
    )

    const uri = `mongodb://${this.statefulSet.spec.serviceName}:27017`
Following snippet example from here : https://www.pulumi.com/docs/guides/adopting/from_kubernetes/#provisioning-a-helm-chart
g

gorgeous-egg-16927

06/23/2020, 3:32 PM
That error sounds like it may be a problem with invalid YAML in the chart. The code snippet you posted looks right to me, and I verified that the linked example is working.
f

faint-motherboard-95438

06/23/2020, 3:38 PM
Hi @gorgeous-egg-16927 sorry I forgot to update this one. I had a problem with input/output extrapolation elsewhere (as usual) leading to this error. I’m still stuck though, because no matter how I try to access the
statefulSet
of this chart I get with
getResource()
, its always
undefined
I can’t access its properties (
metadata
,
spec
, etc). I try to
apply()
or
interpolate
but there’s no way to get anything out of a
getResource()
at that point for me. Doing like your example yields
undefined
too.
g

gorgeous-egg-16927

06/23/2020, 4:01 PM
This is working for me:
Copy code
const wordpress = new k8s.helm.v2.Chart("wpdev", {
    repo: "stable",
    chart: "wordpress",
    version: "9.0.3",
});

// Export the public IP for WordPress.
export const frontend = wordpress.getResource("v1/Service", "wpdev-wordpress");
I did notice that the
frontendIp
was undefined running on docker for mac because the loadbalancer status field is actually
frontend.status.loadBalancer.ingress[0].hostname
. This varies depending on which k8s you’re running.
f

faint-motherboard-95438

06/23/2020, 4:13 PM
I’m on aws eks, I didn’t try on any other k8s instance yet, but shouldn’t
getResource()
returns a component of the expected type with its properties set no matter what ? How can I rely on it if it does not ? I need the
StatefulSet.spec.serviceName
and it seems I can’t get it and will have to rely on a manual concatenation guess.
g

gorgeous-egg-16927

06/23/2020, 4:21 PM
Sorry, I think my previous answer was confusing. Yes,
getResource
works as you expect. However, it returns an Output, and it looks like you’re trying to use a normal string interpolation rather than
pulumi.interpolate
to build the
uri
string. I suspect this is the actual problem.
f

faint-motherboard-95438

06/23/2020, 4:26 PM
As I said I tried all of these :
Copy code
const uri = `mongodb://${this.statefulSet.spec.serviceName}:27017`

const uri = pulumi.interpolate`mongodb://${this.statefulSet.spec.serviceName}:27017`

const uri = this.statefulSet.spec.apply(spec => `mongodb://${spec.serviceName}:27017`)
Always get something like
unable to get serviceName from undefined
One thing I don’t understand is that I actually get the errors during the preview, while the resource does not actually exist yet, which makes sense, but pulumi should know that, right ? I ensured the
replicasetName
variable I use in
getResource()
is the valid expected name of the resource, so we should be safe here.
g

gorgeous-egg-16927

06/23/2020, 4:41 PM
Is
replicasetName
an
Output<string>
, or a
string
?
f

faint-motherboard-95438

06/23/2020, 4:50 PM
that’s a simple raw
string
If
getResource()
does not find the resource, what’s its behavior ? fail silently with an
undefined
value or something more definitive ? Again since the error is raised during preview, that’s not easy to guess what would have been the final state, services are not provisioned yet.
g

gorgeous-egg-16927

06/23/2020, 4:57 PM
For TypeScript, it will return
undefined
Is the resource namespaced?
f

faint-motherboard-95438

06/23/2020, 4:58 PM
I think the chart is having its own namespace yes, let me check that
yes it is
ok so I should write something like
${namespace}/${replicasetName}
if I understand it right ?
g

gorgeous-egg-16927

06/23/2020, 5:01 PM
Yes, that’s right
f

faint-motherboard-95438

06/23/2020, 5:07 PM
Thanks it finally works ! Sorry I didn’t notice this earlier 😞
g

gorgeous-egg-16927

06/23/2020, 5:10 PM
Glad to hear it! 🙂 I opened https://github.com/pulumi/pulumi-kubernetes/issues/1173 to make this a little easier to track down in the future
f

faint-motherboard-95438

06/23/2020, 5:11 PM
Would definitely help, thanks ! 🙂
4 Views