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

brave-glass-88708

04/19/2020, 9:05 PM
I am currently evaluating if Pulumi is something that we make use of for managing and bootstrapping our fleet of kubernetes cluster. idea is to bootstrap in common services (efk stack, ingress, namespaces, service account, etc...) i am doing something relatively simple in TypeScript because it has the kubernetes extension SDK, i wrote the same thing in Go and that's fine.
Copy code
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";

const config = new pulumi.Config();
const provider = new k8s.Provider("kubernetes", { kubeconfig: config.require("cluster-config") });

const ta = new k8s.core.v1.ServiceAccount("test-account", {
    metadata: {
        name: "test-account",
        namespace: "default"
    }
}, { provider });


export const tokenName = pulumi.interpolate `${ta.metadata.namespace}/${ta.secrets[0].name}`

type KubernetesData = { [key: string]: string }

export const token = k8s.core.v1.Secret.get(tokenName, tokenName).data.apply(v => {
    return (<KubernetesData>v)["token"]
});

// export const token = k8s.core.v1.Secret.get("default/test-account-token-7rz8w", "default/test-account-token-7rz8w").data.apply(v => {
//     return (<KubernetesData>v)["token"]
// });
1. Argument of type 'Output<string>' is not assignable to parameter of type 'string'.ts(2345) 2. Parameter 'v' implicitly has an 'any' type. however, if i use the call that is commented or this
Copy code
export const token = k8s.core.v1.Secret.get("harcoded-works", tokenName).data.apply(v => {
    return (<KubernetesData>v)["token"]
});
is this here a less verbose method to getting values from one resource and feed it into another?
g

gorgeous-egg-16927

04/20/2020, 4:23 PM
If I understand your question correctly, it looks like you’re trying to extract the token value as a
string
and use that value elsewhere in your program. The reason you got the error is because the
get
methods return an
Output
, which is a computed value (i.e. Promise). This means that the value isn’t known prior to running the update. Rather than trying to use the string value directly, you can pass the Output values around to other resources, and they will be resolved correctly during the update. https://www.pulumi.com/docs/intro/concepts/programming-model/#outputs explains this in more detail We also have extensive k8s-specific examples here: https://www.pulumi.com/docs/guides/crosswalk/kubernetes/
b

brave-glass-88708

04/20/2020, 5:50 PM
the problem is the
tokenName
which i interpolate into a string and pass that to the
Secret.get
method. if i change
Secret.get("somevalue"...)
it works
g

gorgeous-egg-16927

04/20/2020, 8:03 PM
Ah, understood. Currently, the
get
methods only accept a
string
for the
name
arg, not an Output. I can’t recall if there’s a technical reason for that, but you’re welcome to open an issue on the pulumi-kubernetes repo. https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/kubernetes/core/v1/#Secret-get
2 Views