creamy-jelly-91590
05/17/2019, 11:23 AMexport const kubeconfig = pulumi.secret(
pulumi
.all([cluster.name, cluster.endpoint, cluster.masterAuth, config.project])
.apply(([clusterName, clusterEndpoint, clusterAuth, project]) =>
createKubeconfig({
project,
region,
clusterCaCertificate: clusterAuth.clusterCaCertificate,
clusterEndpoint: clusterEndpoint,
clusterName: clusterName
})
)
);
const k8sProvider = new k8s.Provider(name, {
kubeconfig
});
export function createKubeconfig(ctx: {
project: string;
region: string;
clusterName: string;
clusterEndpoint: string;
clusterCaCertificate: string;
}) {
const context = `${ctx.project}_${ctx.region}_${ctx.clusterName}`;
return `apiVersion: v1
clusters:
- name: ${context}
cluster:
certificate-authority-data: ${ctx.clusterCaCertificate}
server: https://${ctx.clusterEndpoint}
contexts:
- name: ${context}
context:
cluster: ${context}
user: ${context}
current-context: ${context}
kind: Config
preferences: {}
users:
- name: ${context}
user:
auth-provider:
name: gcp
config:
cmd-args: config config-helper --format=json
cmd-path: gcloud
expiry-key: '{.credential.token_expiry}'
token-key: '{.credential.access_token}'
`;
}
creamy-potato-29402
05/17/2019, 4:57 PMcreamy-potato-29402
05/17/2019, 4:57 PMcreamy-jelly-91590
05/17/2019, 5:10 PMcreateKubeconfig
returns a stringcreamy-jelly-91590
05/17/2019, 5:11 PMcreamy-jelly-91590
05/17/2019, 5:11 PM