Skip to content

Commit

Permalink
~aws-py-eks: Add kubeconfig output. (pulumi#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Stokes committed Sep 28, 2020
1 parent f0732dc commit 749bdf6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions aws-py-eks/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import iam
import vpc
import utils
import pulumi
from pulumi_aws import eks

Expand Down Expand Up @@ -35,3 +36,4 @@
)

pulumi.export('cluster-name', eks_cluster.name)
pulumi.export('kubeconfig', utils.generate_kube_config(eks_cluster))
39 changes: 39 additions & 0 deletions aws-py-eks/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json
import pulumi

def generate_kube_config(eks_cluster):

kubeconfig = pulumi.Output.all(eks_cluster.endpoint, eks_cluster.certificate_authority.apply(lambda v: v.data), eks_cluster.name).apply(lambda args: json.dumps({
"apiVersion": "v1",
"clusters": [{
"cluster": {
"server": args[0],
"certificate-authority-data": args[1]
},
"name": "kubernetes",
}],
"contexts": [{
"context": {
"cluster": "kubernetes",
"user": "aws",
},
"name": "aws",
}],
"current-context": "aws",
"kind": "Config",
"users": [{
"name": "aws",
"user": {
"exec": {
"apiVersion": "client.authentication.k8s.io/v1alpha1",
"command": "aws-iam-authenticator",
"args": [
"token",
"-i",
args[2],
],
},
},
}],
}))
return kubeconfig

0 comments on commit 749bdf6

Please sign in to comment.