brave-glass-88708
04/19/2020, 9:05 PMimport * 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
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?gorgeous-egg-16927
04/20/2020, 4:23 PMstring
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/brave-glass-88708
04/20/2020, 5:50 PMtokenName
which i interpolate into a string and pass that to the Secret.get
method. if i change Secret.get("somevalue"...)
it worksgorgeous-egg-16927
04/20/2020, 8:03 PMget
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