@@ -18,7 +18,12 @@ const helmSecretVariableName = process.env.HELM_SECRET_VARIABLE_NAME;
1818const helmEnvVarVariableName = process . env . HELM_ENV_VAR_VARIABLE_NAME ;
1919const tag = process . env . TAG ;
2020
21- let helmDeploymentCommand = `helm --kubeconfig .kubeConfig --kube-context ${ environment } upgrade ${ name } ${ dryRun ? '\\\n ' : '' } --install ${ dryRun ? '\\\n ' : '' } --create-namespace ${ dryRun ? '\\\n ' : '' } --namespace ${ namespace } ${ dryRun ? '\\\n ' : '' } --set image.tag=${ tag } ${ dryRun ? '\\\n ' : '' } ` ;
21+ let helmDeploymentCommand = `helm upgrade ${ name } \\
22+ --install \\
23+ --create-namespace \\
24+ --namespace ${ namespace } \\
25+ --set image.tag=${ tag } \\
26+ ` ;
2227
2328if ( dryRun ) {
2429 console . log ( 'Executing Dry Run...' ) ;
@@ -66,31 +71,38 @@ Object.keys(variables).forEach((variableName) => {
6671 }
6772} ) ;
6873
69- Object . keys ( environmentVariables ) . forEach ( ( environmentVariableName ) => helmEnvVars . push ( { name : environmentVariableName , value : environmentVariables [ environmentVariableName ] . replace ( ',' , '\\,' ) } ) ) ;
74+ Object . keys ( environmentVariables ) . forEach ( ( environmentVariableName ) => helmEnvVars . push ( { name : environmentVariableName , value : environmentVariables [ environmentVariableName ] } ) ) ;
75+
76+ // We need to escape all the Go sequences.
77+ // Reference - https://stackoverflow.com/a/63636047/4546963
7078
7179helmSecrets . forEach ( ( dto , idx ) => {
72- helmDeploymentCommand = helmDeploymentCommand . concat ( `--set ${ helmSecretVariableName } [${ idx } ].key='${ dto . key } ' ${ dryRun ? ' \\\n ' : '' } ` ) ;
73- helmDeploymentCommand = helmDeploymentCommand . concat ( `--set ${ helmSecretVariableName } [${ idx } ].value='${ dryRun ? '<REDACTED>' : dto . value } ' ${ dryRun ? ' \\\n ' : '' } ` ) ;
80+ helmDeploymentCommand = helmDeploymentCommand . concat ( `--set ${ helmSecretVariableName } [${ idx } ].key='${ dto . key } ' \\\n ` ) ;
81+ helmDeploymentCommand = helmDeploymentCommand . concat ( `--set ${ helmSecretVariableName } [${ idx } ].value='${ dryRun ? '<REDACTED>' : escapeGoSpecialChars ( dto . value ) } ' \\\n ` ) ;
7482} ) ;
7583
7684helmConfigMaps . forEach ( ( dto , idx ) => {
77- helmDeploymentCommand = helmDeploymentCommand . concat ( `--set ${ helmConfigMapVariableName } [${ idx } ].key='${ dto . key } ' ${ dryRun ? ' \\\n ' : '' } ` ) ;
78- helmDeploymentCommand = helmDeploymentCommand . concat ( `--set ${ helmConfigMapVariableName } [${ idx } ].value='${ dryRun ? '<REDACTED>' : dto . value } ' ${ dryRun ? ' \\\n ' : '' } ` ) ;
85+ helmDeploymentCommand = helmDeploymentCommand . concat ( `--set ${ helmConfigMapVariableName } [${ idx } ].key='${ dto . key } ' \\\n ` ) ;
86+ helmDeploymentCommand = helmDeploymentCommand . concat ( `--set ${ helmConfigMapVariableName } [${ idx } ].value='${ dryRun ? '<REDACTED>' : escapeGoSpecialChars ( dto . value ) } ' \\\n ` ) ;
7987} ) ;
8088
8189helmEnvVars . forEach ( ( dto , idx ) => {
82- helmDeploymentCommand = helmDeploymentCommand . concat ( `--set ${ helmEnvVarVariableName } [${ idx } ].name='${ dto . name } ' ${ dryRun ? ' \\\n ' : '' } ` ) ;
83- helmDeploymentCommand = helmDeploymentCommand . concat ( `--set ${ helmEnvVarVariableName } [${ idx } ].value='${ dto . value } ' ${ dryRun ? ' \\\n ' : '' } ` ) ;
90+ helmDeploymentCommand = helmDeploymentCommand . concat ( `--set ${ helmEnvVarVariableName } [${ idx } ].name='${ dto . name } ' \\\n ` ) ;
91+ helmDeploymentCommand = helmDeploymentCommand . concat ( `--set ${ helmEnvVarVariableName } [${ idx } ].value='${ dryRun ? '<REDACTED>' : escapeGoSpecialChars ( dto . value ) } ' \\\n ` ) ;
8492} ) ;
8593
8694if ( helmChartVersion ) {
87- helmDeploymentCommand = helmDeploymentCommand . concat ( `--version ${ helmChartVersion } ${ dryRun ? ' \\\n ' : '' } ` ) ;
95+ helmDeploymentCommand = helmDeploymentCommand . concat ( `--version ${ helmChartVersion } \\\n ` ) ;
8896}
8997
9098helmDeploymentCommand = helmDeploymentCommand . concat ( helmChartUrl ) ;
9199
92100if ( dryRun ) {
93- console . log ( `This is a Dry Run. Install command to be run: ${ helmDeploymentCommand } ` ) ;
101+ console . log ( `This is a Dry Run. Install command to be run: \n ${ helmDeploymentCommand } ` ) ;
94102} else {
95- execSync ( helmDeploymentCommand ) ;
103+ console . log ( execSync ( helmDeploymentCommand ) . toString ( 'utf-8' ) ) ;
104+ }
105+
106+ function escapeGoSpecialChars ( value : string ) : string {
107+ return value . split ( ',' ) . join ( '\\,' ) . split ( '.' ) . join ( '\\.' ) . split ( '{' ) . join ( '\\{' ) . split ( '[' ) . join ( '\\[' ) . split ( ']' ) . join ( '\\]' ) . split ( '}' ) . join ( '\\}' ) ;
96108}
0 commit comments