I'm trying to accomplish something like: ``` cons...
# general
i
I'm trying to accomplish something like:
Copy code
const eksCluster = aws.eks.getCluster({name: 'cluster-name'})
const ns = new k8s.core.v1.Namespace('pulumi-test', {}, { provider: eksCluster.getProvider() })
However the
getCluster
fails with
Error: Missing required property 'roleArn'
s
Hmmm, that’s not particularly good.
Does it fail during compilation or execution?
i
not sure.
Copy code
error: Running program '/pulumi' failed with an unhandled exception:
    error: Error: Missing required property 'roleArn'
s
Hmm, I’ll see if I can reproduce this shortly - it’s definitely on the getCluster call?
i
Sorry, it happens on
aws.eks.Cluster.get
const eksCluster = aws.eks.Cluster.get({ name: 'cluster-name' })
s
Aha - that’s easier to diagnose I think
i
I'm not sure however if I'm using the correct route. I'm trying to build the provider for K8S
and do it dynamically from existing cluster. Is that possible?
s
I think either @breezy-hamburger-69619 or @creamy-potato-29402 might be the best person to help with that specifically
Ahh I see the issue - one sec let me look up the way to use that function
b
To create a k8s provider from an eks Cluster object e.g. named
cluster
, do the following:
Copy code
const k8sProvider = new k8s.Provider("myKubernetesCluster", {
    kubeconfig: cluster.kubeconfig.apply(JSON.stringify),
});
then in your ns declaration, set
{ provider: k8sProvider }
s
To fix the
cluster.get
, use this:
aws.eks.Cluster.get("pulumi-name", "aws-cluster-name")
(Instead of passing in an object)
i
@stocky-spoon-28903 @breezy-hamburger-69619 Thank you, checking now
It seems like
cluster
does not contain
kubeconfig
property
btw, the doc also doesn't say anything about kubeconfig: https://pulumi.io/reference/pkg/nodejs/@pulumi/aws/eks/#Cluster
s
@breezy-hamburger-69619 ?
b
@incalculable-diamond-5088 use the
@pulumi/eks
package instead of `pulumi/aws/eks`: https://pulumi.io/reference/pkg/nodejs/@pulumi/eks/index.html#Cluster-kubeconfig
i
Sure, but how do I use it with an existing cluster?
I'm trying something like:
Copy code
const eksCluster = new eks.Cluster('eks-cluster', {}, { id: ... })
and I get:
Copy code
Error: Cannot read an existing resource unless it has a custom provider
        at new Resource (/Users/igor/work/pulumi/node_modules/@pulumi/pulumi/resource.js:91:23)
        at new ComponentResource (/Users/igor/work/pulumi/node_modules/@pulumi/pulumi/resource.js:208:9)
b
@creamy-potato-29402
@incalculable-diamond-5088 so i dont think there’s currently a way to pull the kubeconfig on an existing cluster. however, you have the data to recreate it:
Copy code
const cluster = aws.eks.Cluster.get("myCluster", "nebula-eksCluster-efc46c2")
you can use the
cluster
props:
certificateAuthority
,
name
, and
endpoint
to fill in the blanks in https://gist.github.com/b01eeecacccc3e284771463ed626af5e
c
You should be able to, why not?
It’s a member of the EKS object, right?
Are you sure that that line corresponds to that error, though?
i
@creamy-potato-29402 yep. It's the line. Will try to compose the object
c
oh wait, mike is right, we’re building this in the constructor which is not the right thing to do.
this should be a
.kubeconfig()
method that constructs it on the fly.
@breezy-hamburger-69619 this should be pretty simple, are we doing this soon?
b
Ya seems straight forward enough
c
@microscopic-florist-22719 does that error look familiar to you?
Copy code
Error: Cannot read an existing resource unless it has a custom provider
        at new Resource (/Users/igor/work/pulumi/node_modules/@pulumi/pulumi/resource.js:91:23)
        at new ComponentResource (/Users/igor/work/pulumi/node_modules/@pulumi/pulumi/resource.js:208:9)
b
opened an issue to track the
kubeconfig()
method: https://github.com/pulumi/pulumi-eks/issues/68
i
Thanks @breezy-hamburger-69619!
👍🏼 1
m
@creamy-potato-29402 @breezy-hamburger-69619 it is not currently possible to construct a
@pulumi/eks.Cluster
from an exiting setup, as it encompasses much more than the EKS cluster itself
We should add an overlay in
@pulumi/aws
that can construct a Kubeconfig for a raw
aws.eks.Cluster
b
@microscopic-florist-22719 could you please elaborate on what is missing out of the
cluster
obj returned from doing a
aws.eks.Cluster.get(...)
?
m
Not sure what you mean
c
Why can’t we transitively get all the underlying resources it abstracts?
m
We'd need IDs for all of them. We could do that, but it would be quite unwieldy, and it is not necessary if all you want to do is get a kubeconfig for an existing cluster
b
ah i see
m
We probably do want to be able to build a
@pulumi/eks.Cluster
out of existing resources in the fullness of time
b
well in this case its just retrieving the kubeconfig, but i see what you mean about not having the full set of objects
m
But I think that
@pulumi/aws
is the right place to put the
kubeconfig()
helper
c
makes sense.
m
ideally as an overlaid instance method on
@pulumi/aws.eks.Cluster
b
got it
c
not the EKS package?
m
correct
c
AWS package doesn’t really understand anything about kubernetes or eks at all, though,right?
Where would it go in there?
c
I see.
m
So you could do this:
Copy code
const cluster = aws.eks.Cluster.get("myCluster", "my-cluster-id");
const kubeconfig = cluster.kubeconfig();
Given that the kubeconfig only relies on information from the cluster, I believe that is the right layer for this method
then the
@pulumi/eks
package can consume that method
c
I had forgotten that there is an
eks.Cluster
type.
for some reason I thought this was just a special case of
ec2.Instance
m
lol
c
I mean in my defense, everything else is so manual that this is actually not that crazy of an assumption.
b
closed the issue in
pulumi/eks
and moved it to `pulumi/aws`: https://github.com/pulumi/pulumi-aws/issues/478
m
@creamy-potato-29402 yeah, I saw how you could have arrived at that conclusion 🙂