https://pulumi.com logo
#general
Title
# general
b

billions-lock-80282

09/30/2019, 1:50 PM
Hi, can I convert an Output<string> to a normal string. I need the gke kubeconfig variable in string format.
r

rhythmic-finland-36256

09/30/2019, 2:20 PM
If you want to create a
kubernetes provider
programmatically, you can just work with the output because a provider is also a
CustomResource
and does the await for you. The same applies for stack outputs you export. Just export the Output<string> and you will get the string. If you need programmatic access to the string value, this cannot be done synchronously, therefore just use the
apply
method like here: https://www.pulumi.com/docs/intro/concepts/programming-model/#apply
b

billions-lock-80282

09/30/2019, 3:24 PM
Thanks, although I've tried with apply already but you still end up with an Output<string>. Can I somehow programmatically save that gke kubeconfig into an actual string variable. There is a long winded explanation why I need this.
e.g. if I want to programmatically write the kubeconfig to a file using fs.writeFile(), I can't do that with an Output<string>
n

nice-cat-91582

09/30/2019, 3:48 PM
@billions-lock-80282 are you trying to get at the string prior to the plan finishing?
b

billions-lock-80282

09/30/2019, 3:48 PM
yes
n

nice-cat-91582

09/30/2019, 3:48 PM
Yeah, that's the hard part. There is no string there, because Outputs aren't fulfilled until the plan runs. It's like asking for an RDS address before the RDS instance is even created.
I was just fighting with this yesterday, in fact.
b

billions-lock-80282

09/30/2019, 3:51 PM
ah ok, the main issue is is that I have a separate cert-manager class that both eks and gke both call. But its using the
Copy code
const kubeconfig = new KubeConfig();
            kubeconfig.loadFromString(JSON.stringify(kc));
but for eks the kubeconfig is passed in as cluster.kubeconfig. But it doesn't work with the gke format unless I loadFromFile("kubeconfig")
but I wanted to create the kubeconfig file programmatically
n

nice-cat-91582

09/30/2019, 3:54 PM
IIUC that would need to become something like
Copy code
kc.apply((kcString) => { 
    kubeconfig.loadFromString(kcString)
})
b

billions-lock-80282

09/30/2019, 4:04 PM
ok, I'll give that a try, thanks
r

rhythmic-finland-36256

09/30/2019, 4:25 PM
I would assume that in the EKS case you are also working with an unresolved kubeconfig. Is there no way of just modifying the kubeconfig in flight (using apply) and handing it in the same way? Could you show the EKS way and your KubeConfig class to better understand what you are trying to do? I don’t see why you should require the resolved string…
b

billions-lock-80282

09/30/2019, 5:00 PM
I get the following error for gke kubeconfig
Copy code
TypeError: unknown version: undefined
so it can't find the version: v1 string in the kubeconfig because its not in JSON format
I've found a way around it. EKS uses a function called generateKubeconfig which just creates the kubeconfig in JSON format. I've had to recreate that in GKE basically:
2 Views