https://pulumi.com logo
g

gifted-island-55702

12/19/2018, 3:03 PM
Hello again! Today when I was trying to setup multi-stack configuration with exporting kubeconfig to another stack I found a strange issue with assembling kubeconfig yaml used as an export. This example shows how to create that kubeconfig: https://github.com/pulumi/examples/blob/master/gcp-ts-gke/cluster.ts#L27-L56. What I tried is to replace this part of the code:
Copy code
export const k8sConfig = pulumi.
    all([ k8sCluster.name, k8sCluster.endpoint, k8sCluster.masterAuth ]).
    apply(([ name, endpoint, auth ]) => {
        const context = `${gcp.config.project}_${gcp.config.zone}_${name}`;
        return `apiVersion: v1...
with:
Copy code
export const k8sConfig = pulumi.
    all([ k8sCluster.project, k8sCluster.region, k8sCluster.zone, k8sCluster.name, k8sCluster.endpoint, k8sCluster.masterAuth ]).
    apply(([ project, region, zone, name, endpoint, auth ]) => {
        const location = region || zone
        const context = `${project}_${location}_${name}`
        return `apiVersion: v1...
Please, notice that I in my version below I used a project, region and zone from
k8sCluster
object instead of project config. When I did that, pulumi was finding changes to be deployed every time I run
pulumi update
even though there were no changes in my code. When I added some debug logging I found out that when it checks the updates,
project
variable doesn’t contain a plain string value but instead an object (it’s printed in my debug output as
[object ...]
). Is it a bug?
@white-balloon-205 do you have any hints about my issue?
w

white-balloon-205

12/19/2018, 11:15 PM
If you are seeing
[object Object]
it typically means you are attempting to toString an
Output
. Instead, you need to use
output.apply(x => x.toString())
or similar. For example to log the Output you would want to do
output.apply(console.log)
. The value of these `Output`s is not known unti the deployment has happened, which is why these are wrapped inside
Output
instead of just string values. The
pulumi.all
and
pulumi.apply
above are part of taking all of these Outputs and using them to construct a new string value for the kubeconfig.
Some quality-of-life improvements in this area coming as part of https://github.com/pulumi/pulumi/issues/2206.
g

gifted-island-55702

12/19/2018, 11:21 PM
I am actually using pulumi.all 🙂
OK, I think I know what causes this behaviour. This is my code:
Copy code
export const k8sConfig = pulumi.
    all([ cluster.project, cluster.name, cluster.endpoint, cluster.masterAuth, cluster.region, cluster.zone ]).
    apply(([ project, name, endpoint, auth, region, zone ]) => {
        const location = region || zone
        const context = `${project}_${location}_${name}`
        return `apiVersion: v1
clusters:
.....
So this should generate the kubeconfig for the k8s provider. As you can see I use either
region
or
zone
depending on the actual cluster (regional vs zonal) to create the context name. In my case the cluster is zonal, and
region
is undefined. In this scenario whenever I run
pulumi update
it always shows there is a change in my k8s provider due to a change in kubeconfig even though there was no change in the code.
When I remove
region
(which in my scenario always has
undefined
value) then it work correctly
I know I can just remove region but I wanted to add that code to a reusable function that might be called for both types of clusters (regional/zonal)
So the question is if the behaviour described above is a bug or not @white-balloon-205?