-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcluster.ts
88 lines (74 loc) · 2.59 KB
/
cluster.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import * as gcp from '@pulumi/gcp'
import * as k8s from '@pulumi/kubernetes'
import * as pulumi from '@pulumi/pulumi'
import * as os from 'os'
import { URL } from 'url'
import { clusterConfig, gcloudConfig } from './config'
const name = clusterConfig.name || `${os.userInfo().username}-sourcegraph-test`
const cluster = new gcp.container.Cluster(name, {
// Don't auto-generate a name iff the user explicitly defined one.
name: clusterConfig.name,
description: 'Scratch cluster used for testing sourcegraph/deploy-sourcegraph',
location: gcloudConfig.location,
project: gcloudConfig.project,
initialNodeCount: clusterConfig.nodeCount,
nodeConfig: {
diskType: 'pd-ssd',
localSsdCount: 1,
machineType: clusterConfig.machineType,
oauthScopes: [
'https://www.googleapis.com/auth/compute',
'https://www.googleapis.com/auth/devstorage.read_only',
'https://www.googleapis.com/auth/logging.write',
'https://www.googleapis.com/auth/monitoring',
],
},
})
export const clusterContext = pulumi
.all([cluster.name, cluster.location, cluster.project])
.apply(([name, location, project]) => `gke_${project}_${location}_${name}`)
export const kubeconfig = pulumi
.all([clusterContext, cluster.endpoint, cluster.masterAuth])
.apply(([context, endpoint, masterAuth]) => {
return `apiVersion: v1
clusters:
- cluster:
certificate-authority-data: ${masterAuth.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
`
})
export const gcloudAuthCommand = pulumi
.all([cluster.name, cluster.location, cluster.project])
.apply(
([name, location, project]) =>
`gcloud container clusters get-credentials ${name} --location ${location} --project ${project}`
)
export const gcpURL = pulumi
.all([cluster.name, cluster.location, cluster.project])
.apply(([name, location, project]) => {
const url = new URL(`${location}/${name}`, 'https://console.cloud.google.com/kubernetes/clusters/details/')
url.searchParams.set('project', project)
return url.toString()
})
export const k8sProvider = new k8s.Provider(name, {
kubeconfig,
})