sparse-intern-71089
12/19/2018, 9:12 AMgifted-island-55702
12/19/2018, 9:14 AMfunction createKubernetesProvider(name: string, gkeCluster: gke.Cluster): k8s.Provider {
const context = pulumi.
all([gkeCluster.name, gkeCluster.project, gkeCluster.region, gkeCluster.zone]).
apply(([name, project, region, zone]) => {
const location = region || zone
return `${project}_${location}_${name}`
})
const kubeconfig = pulumi.
all([context, gkeCluster.endpoint, gkeCluster.masterAuth]).
apply(([context, endpoint, auth]) => {
return `apiVersion: v1
clusters:
- cluster:
certificate-authority-data: ${auth.clusterCaCertificate}
server: https://${endpoint}
name: ${context}
contexts:
- context:
cluster: ${context}
user: ${context}
name: ${context}
current-context: ${context}
kind: Config
preferences: {}
users:
- name: ${context}
user:
auth-provider:
config:
cmd-args: config config-helper --format=json
cmd-path: gcloud
expiry-key: '{.credential.token_expiry}'
token-key: '{.credential.access_token}'
name: gcp
`;
});
return new k8s.Provider(name, {
context: context,
kubeconfig: kubeconfig,
})
}
gifted-island-55702
12/19/2018, 9:15 AMconst infraStack = new pulumi.StackReference('example-infra-dev')
const k8sProvider = infraStack.getProvider('k8sProvider')
const appName = 'example'
const appLabels = {app: appName, env: 'dev'}
const exampleConfig = new k8s.core.v1.ConfigMap(appName, {
metadata: { labels: appLabels },
data: { 'config.txt': fs.readFileSync('config.txt').toString()}
}, {
provider: k8sProvider
})
gifted-island-55702
12/19/2018, 9:16 AMpulumi update
my config map is not created in the cluster configured in my k8s provider but instead in the default cluster selected in my ~/.kube
configurationgifted-island-55702
12/19/2018, 9:16 AMfaint-motherboard-95438
12/19/2018, 10:13 AMResource.getProvider
is used for. It gets the provider attached to the resource you call it on. (like the provider you pass to your ConfigMap
in the opts
parameter).
Here you want to get something defined in another stack. Reading the doc of StackReference
, you have
Manages a reference to a Pulumi stack. The referenced stack's outputs are available via the
`outputs` property or the `output` method.
Which means you have first to export the provider from the stack example-infra-dev
in order to get it with infraStack.outputs.k8sProvider
or infraStack.getOutput('k8sProvider')
faint-motherboard-95438
12/19/2018, 10:18 AMexample-infra-dev
stack you simply need to do something like that in your index.ts
:
export const k8sProvider = createKubernetesProvider('my-provider', my_cluster);
gifted-island-55702
12/19/2018, 10:19 AMgifted-island-55702
12/19/2018, 10:20 AMgifted-island-55702
12/19/2018, 10:24 AMconst k8sProvider = infraStack.getOutput('k8sProvider') as pulumi.Output<k8s.Provider>
...
const appConfig = new k8s.core.v1.ConfigMap(appName, {
metadata: { labels: appLabels },
data: { 'config.txt': fs.readFileSync('config.txt').toString()}
}, {
provider: k8sProvider
})
gifted-island-55702
12/19/2018, 10:25 AMOutput<k8s.Provider>
vs just plain k8s.Provider
gifted-island-55702
12/19/2018, 10:25 AMk8sProvider.get()
but I am not sure when it would be safe to call Output.get()
methodfaint-motherboard-95438
12/19/2018, 10:50 AMOutput<any>
but since you are actually referencing a value exported from another stack, I would guess it is already defined when you call it.
I would try first
const { k8sProvider } = infraStack.outputs
...
const appConfig = new k8s.core.v1.ConfigMap(appName, {
metadata: { labels: appLabels },
data: { 'config.txt': fs.readFileSync('config.txt').toString()}
}, {
provider: k8sProvider
})
That should avoid compilation issue and maybe give you straight away what you needwhite-balloon-205
kubeconfig
constructed in createKubernetesProvider
.
cc also @microscopic-florist-22719 and @creamy-potato-29402 who have been working on reference architectures for multi-stack Kubernetes deployments and can suggest what patterns we've seen work well.gifted-island-55702
12/19/2018, 2:59 PMcreamy-potato-29402
12/19/2018, 6:33 PMcreamy-potato-29402
12/19/2018, 6:33 PM