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

creamy-jelly-91590

05/17/2019, 11:23 AM
Copy code
export 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}'
`;
}
c

creamy-potato-29402

05/17/2019, 4:57 PM
I think it’s saying you need a string instead of an object.
you’re exporting an object, right?
c

creamy-jelly-91590

05/17/2019, 5:10 PM
@creamy-potato-29402 No, I am exporting a string.
createKubeconfig
returns a string
Been following the Kubernetes the Prod Way tutorial which does this 🙂
I played around with it and filed an issue with my findings https://github.com/pulumi/pulumi/issues/2741
2 Views