@@ -4,7 +4,7 @@ import * as path from 'path';
4
4
import { exec , ExecOptions } from './util/shell' ;
5
5
import { Werft } from './util/werft' ;
6
6
import { waitForDeploymentToSucceed , wipeAndRecreateNamespace , setKubectlContextNamespace , deleteNonNamespaceObjects , findFreeHostPorts , createNamespace , helmInstallName } from './util/kubectl' ;
7
- import { newIssueCertficate , installCertficate , IssueCertificateParams , InstallCertificateParams } from './util/certs' ;
7
+ import { issueCertficate , installCertficate , IssueCertificateParams , InstallCertificateParams } from './util/certs' ;
8
8
import { reportBuildFailureInSlack } from './util/slack' ;
9
9
import * as semver from 'semver' ;
10
10
import * as util from 'util' ;
@@ -77,6 +77,7 @@ const installerSlices = {
77
77
INSTALLER_POST_PROCESSING : "installer post processing" ,
78
78
APPLY_INSTALL_MANIFESTS : "installer apply" ,
79
79
DEPLOYMENT_WAITING : "monitor server deployment" ,
80
+ DNS_ADD_RECORD : "add dns record"
80
81
}
81
82
82
83
const vmSlices = {
@@ -303,6 +304,8 @@ export async function build(context, version) {
303
304
withVM,
304
305
} ;
305
306
307
+ exec ( `kubectl --namespace keys get secret host-key -o yaml > /workspace/host-key.yaml` )
308
+
306
309
if ( withVM ) {
307
310
werft . phase ( phases . VM , "Start VM" ) ;
308
311
@@ -431,6 +434,7 @@ export async function deployToDevWithInstaller(deploymentConfig: DeploymentConfi
431
434
// in a VM, the secrets have alreay been copied
432
435
// If using core-dev, we want to execute further kubectl operations only in the created namespace
433
436
setKubectlContextNamespace ( namespace , metaEnv ( { slice : installerSlices . SET_CONTEXT } ) ) ;
437
+ werft . done ( installerSlices . SET_CONTEXT )
434
438
try {
435
439
werft . log ( installerSlices . ISSUE_CERTIFICATES , "organizing a certificate for the preview environment..." ) ;
436
440
@@ -535,7 +539,7 @@ export async function deployToDevWithInstaller(deploymentConfig: DeploymentConfi
535
539
536
540
werft . log ( "SSH gateway hostkey" , "copy host-key from secret" )
537
541
try {
538
- exec ( `kubectl --namespace keys get secret host-key -o yaml \
542
+ exec ( `cat /workspace/ host-key. yaml \
539
543
| yq w - metadata.namespace ${ namespace } \
540
544
| yq d - metadata.uid \
541
545
| yq d - metadata.resourceVersion \
@@ -610,6 +614,8 @@ export async function deployToDevWithInstaller(deploymentConfig: DeploymentConfi
610
614
werft . fail ( installerSlices . DEPLOYMENT_WAITING , err ) ;
611
615
}
612
616
617
+ await addDNSRecord ( deploymentConfig . namespace , deploymentConfig . domain , ! withVM )
618
+
613
619
// TODO: Fix sweeper, it does not appear to be doing clean-up
614
620
werft . log ( 'sweeper' , 'installing Sweeper' ) ;
615
621
const sweeperVersion = deploymentConfig . sweeperImage . split ( ":" ) [ 1 ] ;
@@ -695,7 +701,7 @@ export async function deployToDevWithHelm(deploymentConfig: DeploymentConfig, wo
695
701
await issueMetaCerts ( namespace , domain ) ;
696
702
await installMetaCertificates ( namespace ) ;
697
703
werft . done ( 'certificate' ) ;
698
-
704
+ await addDNSRecord ( deploymentConfig . namespace , deploymentConfig . domain , false )
699
705
werft . done ( 'prep' ) ;
700
706
} catch ( err ) {
701
707
werft . fail ( 'prep' , err ) ;
@@ -893,10 +899,50 @@ export async function deployToDevWithHelm(deploymentConfig: DeploymentConfig, wo
893
899
}
894
900
}
895
901
902
+ async function addDNSRecord ( namespace : string , domain : string , isLoadbalancer : boolean ) {
903
+ let wsProxyLBIP = null
904
+ if ( isLoadbalancer === true ) {
905
+ werft . log ( installerSlices . DNS_ADD_RECORD , "Getting ws-proxy loadbalancer IP" ) ;
906
+ for ( let i = 0 ; i < 60 ; i ++ ) {
907
+ try {
908
+ let lb = exec ( `kubectl -n ${ namespace } get service ws-proxy -o=jsonpath='{.status.loadBalancer.ingress[0].ip}'` , { silent : true } )
909
+ if ( lb . length > 4 ) {
910
+ wsProxyLBIP = lb
911
+ break
912
+ }
913
+ await sleep ( 1000 )
914
+ } catch ( err ) {
915
+ await sleep ( 1000 )
916
+ }
917
+ }
918
+ if ( wsProxyLBIP == null ) {
919
+ werft . fail ( installerSlices . DNS_ADD_RECORD , new Error ( "Can't get ws-proxy loadbalancer IP" ) ) ;
920
+ }
921
+ werft . log ( installerSlices . DNS_ADD_RECORD , "Get ws-proxy loadbalancer IP: " + wsProxyLBIP ) ;
922
+ } else {
923
+ wsProxyLBIP = getCoreDevIngressIP ( )
924
+ }
925
+
926
+ var cmd = `set -x \
927
+ && cd /workspace/.werft/dns \
928
+ && rm -rf .terraform* \
929
+ && export GOOGLE_APPLICATION_CREDENTIALS="${ GCLOUD_SERVICE_ACCOUNT_PATH } " \
930
+ && terraform init -backend-config='prefix=${ namespace } ' -migrate-state -upgrade \
931
+ && terraform apply -auto-approve \
932
+ -var 'dns_zone_domain=gitpod-dev.com' \
933
+ -var 'domain=${ domain } ' \
934
+ -var 'ingress_ip=${ getCoreDevIngressIP ( ) } ' \
935
+ -var 'ws_proxy_ip=${ wsProxyLBIP } '` ;
936
+
937
+ werft . log ( installerSlices . DNS_ADD_RECORD , "Terraform command for create dns record: " + cmd )
938
+ exec ( cmd , { ...metaEnv ( ) , slice : installerSlices . DNS_ADD_RECORD } ) ;
939
+ werft . done ( installerSlices . DNS_ADD_RECORD ) ;
940
+ }
941
+
896
942
export async function issueMetaCerts ( namespace : string , domain : string ) {
897
943
let additionalSubdomains : string [ ] = [ "" , "*." , "*.ws-dev." ]
898
944
var metaClusterCertParams = new IssueCertificateParams ( ) ;
899
- metaClusterCertParams . pathToTerraform = "/workspace/.werft/certs " ;
945
+ metaClusterCertParams . pathToTemplate = "/workspace/.werft/util/templates " ;
900
946
metaClusterCertParams . gcpSaPath = GCLOUD_SERVICE_ACCOUNT_PATH ;
901
947
metaClusterCertParams . namespace = namespace ;
902
948
metaClusterCertParams . certNamespace = "certs" ;
@@ -905,7 +951,7 @@ export async function issueMetaCerts(namespace: string, domain: string) {
905
951
metaClusterCertParams . ip = getCoreDevIngressIP ( ) ;
906
952
metaClusterCertParams . bucketPrefixTail = ""
907
953
metaClusterCertParams . additionalSubdomains = additionalSubdomains
908
- await newIssueCertficate ( werft , metaClusterCertParams , metaEnv ( ) ) ;
954
+ await issueCertficate ( werft , metaClusterCertParams , metaEnv ( ) ) ;
909
955
}
910
956
911
957
async function installMetaCertificates ( namespace : string ) {
0 commit comments