@@ -2,7 +2,8 @@ const shell = require('shelljs');
2
2
const fs = require ( 'fs' ) ;
3
3
const { werft, exec, gitTag } = require ( './util/shell.js' ) ;
4
4
const { sleep } = require ( './util/util.js' ) ;
5
- const { recreateNamespace } = require ( './util/kubectl.js' ) ;
5
+ const { wipeAndRecreateNamespace, setKubectlContextNamespace, deleteNonNamespaceObjects } = require ( './util/kubectl.js' ) ;
6
+ const { issueAndInstallCertficate } = require ( './util/certs.js' ) ;
6
7
7
8
const GCLOUD_SERVICE_ACCOUNT_PATH = "/mnt/secrets/gcp-sa/service-account.json" ;
8
9
@@ -15,7 +16,7 @@ build(context, version)
15
16
function parseVersion ( context ) {
16
17
let buildConfig = context . Annotations || { } ;
17
18
const explicitVersion = buildConfig . version ;
18
- if ( explicitVersion ) {
19
+ if ( explicitVersion ) {
19
20
return explicitVersion ;
20
21
}
21
22
let version = context . Name ;
@@ -80,7 +81,8 @@ async function build(context, version) {
80
81
} ;
81
82
const imageRepo = publishRelease ? "gcr.io/gitpod-io/self-hosted" : "eu.gcr.io/gitpod-core-dev/build" ;
82
83
83
- exec ( `leeway vet --ignore-warnings` ) ;
84
+ // TODO https://github.com/gitpod-io/leeway/issues/47
85
+ // exec(`leeway vet --ignore-warnings`);
84
86
exec ( `leeway build --werft=true -c ${ cacheLevel } ${ dontTest ? '--dont-test' :'' } -Dversion=${ version } -DimageRepoBase=eu.gcr.io/gitpod-core-dev/dev dev:all` , buildEnv ) ;
85
87
if ( publishRelease ) {
86
88
exec ( `gcloud auth activate-service-account --key-file "/mnt/secrets/gcp-sa-release/service-account.json"` ) ;
@@ -129,28 +131,25 @@ async function deployToDev(version, workspaceFeatureFlags, dynamicCPULimits, reg
129
131
const registryProxyPort = `2${ Math . floor ( Math . random ( ) * 1000 ) } ` ;
130
132
const registryNodePort = `${ 30000 + Math . floor ( Math . random ( ) * 1000 ) } ` ;
131
133
132
- try {
133
- const objs = shell
134
- . exec ( `kubectl get pod -l component=workspace --namespace ${ namespace } --no-headers -o=custom-columns=:metadata.name` )
135
- . split ( "\n" )
136
- . map ( o => o . trim ( ) )
137
- . filter ( o => o . length > 0 ) ;
138
-
139
- objs . forEach ( o => {
140
- werft . log ( "prep" , `deleting workspace ${ o } ` ) ;
141
- exec ( `kubectl delete pod --namespace ${ namespace } ${ o } ` , { slice : 'prep' } ) ;
142
- } ) ;
134
+ // trigger certificate issuing
135
+ werft . log ( 'certificate' , "organizing a certificate for the preview environment..." ) ;
136
+ let namespaceRecreatedResolve = undefined ;
137
+ let namespaceRecreatedPromise = new Promise ( ( resolve ) => {
138
+ namespaceRecreatedResolve = resolve ;
139
+ } ) ;
140
+ const certificatePromise = issueAndInstallCertficate ( werft , ".werft/certs" , GCLOUD_SERVICE_ACCOUNT_PATH , namespace , "gitpod-dev.com" , domain , "34.76.116.244" , namespaceRecreatedPromise , "proxy-config-certificates" ) ;
143
141
144
- recreateNamespace ( namespace , { slice : 'prep' } ) ;
145
- [
146
- "kubectl config current-context" ,
147
- `kubectl config set-context --current -- namespace= ${ namespace } `
148
- ] . forEach ( cmd => exec ( cmd , { slice : 'prep' } ) ) ;
142
+ // re-create namespace
143
+ try {
144
+ wipeAndRecreateNamespace ( namespace , { slice : 'prep' } ) ;
145
+ setKubectlContextNamespace ( namespace , { slice : 'prep' } ) ;
146
+ namespaceRecreatedResolve ( ) ; // <-- signal for certificate
149
147
werft . done ( 'prep' ) ;
150
148
} catch ( err ) {
151
149
werft . fail ( 'prep' , err ) ;
152
150
}
153
151
152
+ // core-dev specific section start
154
153
werft . log ( "secret" , "copy secret into namespace" )
155
154
try {
156
155
const auth = exec ( `echo -n "_json_key:$(kubectl get secret gcp-sa-registry-auth --namespace=keys -o yaml \
@@ -180,39 +179,18 @@ async function deployToDev(version, workspaceFeatureFlags, dynamicCPULimits, reg
180
179
} catch ( err ) {
181
180
werft . fail ( 'authProviders' , err ) ;
182
181
}
182
+ // core-dev specific section end
183
183
184
- let certificatePromise = undefined ;
185
-
186
- // TODO(geropl): Now that the certs reside in a separate namespaces, start the actual certificate issuing _before_ the namespace cleanup
187
- werft . log ( 'certificate' , "organizing a certificate for the preview environment..." ) ;
188
- certificatePromise = issueAndInstallCertficate ( namespace , domain ) ;
189
-
184
+ // cleanup non-namespace objects
190
185
werft . log ( "predeploy cleanup" , "removing old unnamespaced objects - this might take a while" ) ;
191
186
try {
192
- exec ( `/usr/local/bin/helm3 delete gitpod-${ destname } || echo gitpod-${ destname } was not installed yet` , { slice : 'predeploy cleanup' } ) ;
193
- exec ( `/usr/local/bin/helm3 delete jaeger-${ destname } || echo jaeger-${ destname } was not installed yet` , { slice : 'predeploy cleanup' } ) ;
194
-
195
- let objs = [ ] ;
196
- [ "ws-scheduler" , "node-daemon" , "cluster" , "workspace" , "jaeger" , "jaeger-agent" , "ws-sync" , "ws-manager-node" , "ws-daemon" , "registry-facade" ] . forEach ( comp =>
197
- [ "ClusterRole" , "ClusterRoleBinding" , "PodSecurityPolicy" ] . forEach ( kind =>
198
- shell
199
- . exec ( `kubectl get ${ kind } -l component=${ comp } --no-headers -o=custom-columns=:metadata.name | grep ${ namespace } -ns` )
200
- . split ( "\n" )
201
- . map ( o => o . trim ( ) )
202
- . filter ( o => o . length > 0 )
203
- . forEach ( obj => objs . push ( { 'kind' : kind , 'obj' : obj } ) )
204
- )
205
- )
206
-
207
- objs . forEach ( o => {
208
- werft . log ( "predeploy cleanup" , `deleting old ${ o . kind } ${ o . obj } ` ) ;
209
- exec ( `kubectl delete ${ o . kind } ${ o . obj } ` , { slice : 'predeploy cleanup' } ) ;
210
- } ) ;
187
+ deleteNonNamespaceObjects ( namespace , destname , { slice : 'predeploy cleanup' } )
211
188
werft . done ( 'predeploy cleanup' ) ;
212
189
} catch ( err ) {
213
190
werft . fail ( 'predeploy cleanup' , err ) ;
214
191
}
215
192
193
+ // versions
216
194
werft . log ( "deploy" , "extracting versions" ) ;
217
195
try {
218
196
// TODO [geropl] versions is not a core component yet
@@ -222,6 +200,7 @@ async function deployToDev(version, workspaceFeatureFlags, dynamicCPULimits, reg
222
200
werft . fail ( 'deploy' , err ) ;
223
201
}
224
202
203
+ // deployment config
225
204
let flags = "" ;
226
205
flags += ` --namespace ${ namespace } ` ;
227
206
flags += ` --set components.imageBuilder.hostDindData=/mnt/disks/ssd0/docker-${ namespace } ` ;
@@ -287,42 +266,6 @@ async function deployToDev(version, workspaceFeatureFlags, dynamicCPULimits, reg
287
266
}
288
267
}
289
268
290
- async function issueAndInstallCertficate ( namespace , domain ) {
291
- // Always use 'terraform apply' to make sure the certificate is present and up-to-date
292
- await exec ( `set -x \
293
- && cd .werft/certs \
294
- && terraform init \
295
- && export GOOGLE_APPLICATION_CREDENTIALS="${ GCLOUD_SERVICE_ACCOUNT_PATH } " \
296
- && terraform apply -auto-approve \
297
- -var 'namespace=${ namespace } ' \
298
- -var 'dns_zone_domain=gitpod-dev.com' \
299
- -var 'domain=${ domain } ' \
300
- -var 'public_ip=34.76.116.244' \
301
- -var 'subdomains=["", "*.", "*.ws-dev."]'` , { slice : 'certificate' , async : true } ) ;
302
-
303
- werft . log ( 'certificate' , `waiting until certificate certs/${ namespace } is ready...` )
304
- let notReadyYet = true ;
305
- while ( notReadyYet ) {
306
- werft . log ( 'certificate' , `polling state of certs/${ namespace } ...` )
307
- const result = exec ( `kubectl -n certs get certificate ${ namespace } -o jsonpath="{.status.conditions[?(@.type == 'Ready')].status}"` , { silent : true , dontCheckRc : true } ) ;
308
- if ( result . code === 0 && result . stdout === "True" ) {
309
- notReadyYet = false ;
310
- break ;
311
- }
312
-
313
- sleep ( 5000 ) ;
314
- }
315
-
316
- werft . log ( 'certificate' , `copying certificate from "certs/${ namespace } " to "${ namespace } /proxy-config-certificates"` ) ;
317
- // certmanager is configured to create a secret in the namespace "certs" with the name "${namespace}".
318
- exec ( `kubectl get secret ${ namespace } --namespace=certs -o yaml \
319
- | yq d - 'metadata.namespace' \
320
- | yq d - 'metadata.uid' \
321
- | yq d - 'metadata.resourceVersion' \
322
- | yq d - 'metadata.creationTimestamp' \
323
- | sed 's/${ namespace } /proxy-config-certificates/g' \
324
- | kubectl apply --namespace=${ namespace } -f -` ) ;
325
- }
326
269
327
270
/**
328
271
* Publish Charts
@@ -347,6 +290,5 @@ async function publishHelmChart(imageRepoBase) {
347
290
module . exports = {
348
291
parseVersion,
349
292
build,
350
- issueAndInstallCertficate,
351
293
deployToDev
352
294
}
0 commit comments