This message was deleted.
# general
s
This message was deleted.
b
how are you specifying this in the code? it should always use the provider creds first
c
Copy code
const config = new loft.LoftKubeconfig("stack", {
        spaceName: ns.metadata.name,
        vclusterName: virKube.metadata.name,
    }, {dependsOn: virKube})

    return new k8s.Provider("loftK8s", {
        kubeconfig: config.data,
        cluster: config.clusterName,
        context: config.ctx,
    }, {dependsOn: config})
b
and
config.data
is just a standard kubeconfig string?
c
Yup
I'm using ti right now, kubectl lists secrets fine. I can double check right now that outputting it to a file actually fixes the issue like I mentioned.
b
huh, I have no idea why that's not working
b
Could be config.ctx related
What is that set to?
c
I literally grab it from the file by parsing the yaml. It doesn't work if I remove it; specifying the context was an attempted fix on my end
b
Do you actually need to set the cluster? Isn’t it already in the kubeconfig? I do the following elsewhere https://github.com/pulumi/examples/blob/c9558f3a236ca284933d105efad0c99ba89a6d6a/aws-go-eks/main.go#L146 Notice I only set the kubeconfig and nothing else and it works
(I’m throwing the dice here as I don’t know what happens in the loft package here)
c
The loft package is a dynamic provider I wrote 😜 Give me a few minutes to see if I actually messed something else up completely, although this is the second time I've run into this
uh oh... config.data is undefined o.o
Copy code
import * as pulumi from "@pulumi/pulumi";
import * as child_process from "child_process";

export interface LoftKubeconfigOptions {
    spaceName: pulumi.Input<string> //Name of namespace where vcluster is located
    vclusterName: pulumi.Input<string> //name of vcluster itself
}

interface LoftKubeconfigDynamicProviderInputs {
    spaceName: string; //Name of namespace where vcluster is located
    vclusterName: string //name of vcluster itself
}

class LoftKubeconfigResourceProvider implements pulumi.dynamic.ResourceProvider {
    async create(inputs: LoftKubeconfigDynamicProviderInputs): Promise<pulumi.dynamic.CreateResult> {
        return {
            id: inputs.spaceName + "-" + inputs.vclusterName,
            outs: {
                data: child_process.execSync("loft use vcluster " + inputs.vclusterName + " --print --space " + inputs.spaceName + " --cluster loft-cluster --silent"),
                ...inputs
            }
        };
    }
}

export class LoftKubeconfig extends pulumi.dynamic.Resource {
    public readonly spaceName!: pulumi.Output<string> //Name of namespace where vcluster is located
    public readonly vclusterName!: pulumi.Output<string> //name of vcluster itself

    //Other outputs
    public readonly data!: pulumi.Output<string> //kubeconfig yaml file
    public readonly ctx!: pulumi.Output<string> //context in yaml file
    public readonly clusterName!: pulumi.Output<string> //context in yaml file

    constructor(name: string, args: LoftKubeconfigOptions, opts?: pulumi.CustomResourceOptions) {
        super(new LoftKubeconfigResourceProvider(), `loft:vclusterKubeConfig:${name}`, args, pulumi.mergeOptions(opts || {}, {
            additionalSecretOutputs: ["config"],
        }));
    }
}
A lot of this is boilerplate I copied over, I know nothing about typescript
sorry for bothering you guys so much btw
I'm fixing the issue with my dynamic provider rn, misunderstood what happens when you omit so many asynchronous functions from the spec
I may just develop a loft provider, as I now realize what I shouldve done is wrap the loft vcluster resource in there and write out all the methods, but atm I'm pretty lazy
It's been a couple hours and I cannot seem to figure out how I'm supposed to intialize this .data parameter, so that it's a regular Output object and not undefined. As far as I can tell, the docs talk as if this happens after the resource constructor is called. This doesn't happen though, and anytime I try to .apply() it from the newly instantiated resource pulumi crashes during the prview. Not really sure what to do but I'm trying to look through the pulumi code/docs to see if I'm missing something. I'm very new to typescript so that's probably not helping. (loft.ts):
Copy code
import * as pulumi from "@pulumi/pulumi";

export interface LoftKubeconfigOptions {
    vclusterName: pulumi.Input<string> //name of vcluster itself
}

interface LoftKubeconfigDynamicProviderInputs {
    vclusterName: string //name of vcluster itself
}

interface LoftKubeconfigDynamicProviderOutputs extends LoftKubeconfigDynamicProviderInputs {
    data: string
}

class LoftKubeconfigResourceProvider implements pulumi.dynamic.ResourceProvider {
    async create(inputs: LoftKubeconfigDynamicProviderInputs): Promise<pulumi.dynamic.CreateResult> {
        const data = await require('child_process').exec("loft use vcluster " + inputs.vclusterName + " --print --silent").toString('utf8')
        const outs: LoftKubeconfigDynamicProviderOutputs = {
            vclusterName: inputs.vclusterName,
            data: data,
        }
        return {
            id: inputs.vclusterName,
            outs: outs
        };
    }

    async read(id: string, props: LoftKubeconfigDynamicProviderOutputs): Promise<pulumi.dynamic.ReadResult> {
        const data = await require('child_process').exec("loft use vcluster " + props.vclusterName + " --print --silent").toString('utf8')
        props.data = data
        return {
            id: id,
            props: props,
        };
    }
}

export class LoftKubeconfig extends pulumi.dynamic.Resource {
    public readonly vclusterName!: pulumi.Output<string> //name of vcluster itself
    public readonly data!: pulumi.Output<string> //kubeconfig yaml file

    constructor(name: string, args: LoftKubeconfigOptions, opts?: pulumi.CustomResourceOptions) {
        super(new LoftKubeconfigResourceProvider(), `loft:vclusterKubeConfig:${name}`, args, pulumi.mergeOptions(opts || {}, {
            additionalSecretOutputs: ["data"],
        }));
    }
}
(index.ts):
Copy code
...
    const config12 = new loft.LoftKubeconfig("main12", {
        vclusterName: virKube.metadata.name,
    }, {dependsOn: virKube})

    config12.data.apply(v => {
        return v
    }) //Crash happens here
...
It's defining vclusterName, if that helps
This: https://github.com/pulumi/examples/blob/master/classic-azure-ts-dynamicresource/cdnCustomDomain.ts Is outdated/misleading. I found a newer example with an EKS dynamic provider that showed that you have to manually define output properties in the super() call, which the above doesn't do. Now the output is instantiated and apply() works.
The above example is what is referenced in the dynamic providers tutorial