Skip to content

Commit

Permalink
Added 'always display cluster get-credentials' checkbox option to hel…
Browse files Browse the repository at this point in the history
…per (#628)

* Added check-box to always get cluster creds
Set getCreds default to true to enable this option
Refactored some post_deploy strings and commands to make this work

* Fixed indentation

* Changed label and removed commented lines

* Updated logic to rely on existing post deploy command
  • Loading branch information
pjlewisuk authored Aug 10, 2023
1 parent ae92a36 commit cc9b612
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 31 deletions.
80 changes: 50 additions & 30 deletions helper/src/components/deployTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,26 +249,37 @@ export default function DeployTab({ defaults, updateFn, tabValues, invalidArray,
}).join('')

const post_deployBASHcmd = `\n\n# Deploy charts into cluster\n` +
(deploy.selectedTemplate === "local" ? `bash .${ cluster.apisecurity === "private" ? '' : '/postdeploy/scripts'}/postdeploy.sh ` : `curl -sL ${deployRelease.postBASH_url} | bash -s -- `) +
(deploy.selectedTemplate === 'local' ? (cluster.apisecurity === "private" ? '-r .' : '') : `-r ${deployRelease.base_download_url}`) +
Object.keys(post_params).map(k => {
const val = post_params[k]
const targetVal = Array.isArray(val) ? JSON.stringify(JSON.stringify(val)) : val
return ` \\\n\t-p ${k}=${targetVal}`
}).join('')+
(!deploy.disablePreviews ? preview_post_deployBASHcmd : '')
(deploy.selectedTemplate === "local" ? `bash .${ cluster.apisecurity === "private" ? '' : '/postdeploy/scripts'}/postdeploy.sh ` : `curl -sL ${deployRelease.postBASH_url} | bash -s -- `) +
(deploy.selectedTemplate === 'local' ? (cluster.apisecurity === "private" ? '-r .' : '') : `-r ${deployRelease.base_download_url}`) +
Object.keys(post_params).map(k => {
const val = post_params[k]
const targetVal = Array.isArray(val) ? JSON.stringify(JSON.stringify(val)) : val
return ` \\\n\t-p ${k}=${targetVal}`
}).join('')+
(!deploy.disablePreviews ? preview_post_deployBASHcmd : '')

const post_deployBASHstr = cluster.apisecurity !== "private" ?
const displayPostCmd =
Object.keys(post_params).length >0 || (!deploy.disablePreviews && Object.keys(preview_post_params).length >0)

const getCredentials =
'# Get credentials for your new AKS cluster & login (interactive)\n' +
`az aks get-credentials -g ${deploy.rg} -n ${aks}\n` +
'kubectl get nodes' +
post_deployBASHcmd
:
'kubectl get nodes'

const privateCluster =
'# Private cluster, so use command invoke\n' +
`az aks command invoke -g ${deploy.rg} -n ${aks} --command "` +
post_deployBASHcmd.replaceAll('"', '\\"') +
`\n"${deploy.selectedTemplate === "local" ? ' --file ./postdeploy/scripts/postdeploy.sh --file ./postdeploy/helm/Az-CertManagerIssuer-0.3.0.tgz --file ./postdeploy/k8smanifests/networkpolicy-deny-all.yml --file ./helper/src/dependencies.json' : ''}`

const post_deployBASHstr = cluster.apisecurity !== "private" ?
(deploy.getCreds || displayPostCmd ?
getCredentials + (displayPostCmd ? post_deployBASHcmd : '')
:
'')
:
(displayPostCmd) ? privateCluster : ''

const networkWatcher = net.nsg && net.nsgFlowLogs !== defaults.net.nsgFlowLogs ?
`# Create Network Watcher Resource Group If It Doesn't Exist\n` +
`if [ $(az group exists --name NetworkWatcherRG) = false ]; then az group create -l ${deploy.location} -n NetworkWatcherRG; fi\n\n` : ''
Expand All @@ -284,16 +295,18 @@ export default function DeployTab({ defaults, updateFn, tabValues, invalidArray,
const val = finalParams[k]
const targetVal = Array.isArray(val) ? JSON.stringify(JSON.stringify(val)) : val
return ` \\\n\t${k}=${targetVal}`
}).join('') + '\n\n' + (Object.keys(post_params).length >0 || (!deploy.disablePreviews && Object.keys(preview_post_params).length >0) ? post_deployBASHstr : '')
}).join('') +
'\n\n' +
(displayPostCmd || deploy.getCreds ? post_deployBASHstr : '')

//Powershell (Remember to align any changes with Bash)
const preview_post_deployPScmd = Object.keys(preview_post_params).map(k => {
const val = preview_post_params[k]
const targetVal = Array.isArray(val) ? JSON.stringify(JSON.stringify(val)) : val
return ` \`\n\t-${k} ${targetVal}`
}).join('')
//Powershell (Remember to align any changes with Bash)
const preview_post_deployPScmd = Object.keys(preview_post_params).map(k => {
const val = preview_post_params[k]
const targetVal = Array.isArray(val) ? JSON.stringify(JSON.stringify(val)) : val
return ` \`\n\t-${k} ${targetVal}`
}).join('')

const post_deployPScmd = `\n\n# Deploy charts into cluster\n` +
const post_deployPScmd = `\n\n# Deploy charts into cluster\n` +
(deploy.selectedTemplate === "local" ? ` .${ cluster.apisecurity === "private" ? '' : '/postdeploy/scripts'}/postdeploy.ps1 ` : `& $([scriptblock]::Create((New-Object Net.WebClient).DownloadString("${deployRelease.postPS_url}")))`) +
(deploy.selectedTemplate === 'local' ? (cluster.apisecurity === "private" ? '-r .' : '') : ` -releace_version="${deployRelease.base_download_url}"`) +
Object.keys(post_params).map(k => {
Expand All @@ -303,15 +316,15 @@ export default function DeployTab({ defaults, updateFn, tabValues, invalidArray,
}).join('')+
(!deploy.disablePreviews ? preview_post_deployPScmd : '')

const post_deployPSstr = cluster.apisecurity !== "private" ?
(deploy.getCreds || displayPostCmd ?
getCredentials + (displayPostCmd ? post_deployPScmd : '')
:
'')
:
(displayPostCmd) ? privateCluster : ''

//Below used when not a private cluster (used further below the BASH postdeploy script if a private cluster)
const post_deployPSstr =
'# Get credentials for your new AKS cluster & login (interactive)\n' +
`az aks get-credentials -g ${deploy.rg} -n ${aks}\n` +
'kubectl get nodes' +
post_deployPScmd

const deployPScmd =
const deployPScmd =
`# Create Resource Group\n` +
`az group create -l ${deploy.location} -n ${deploy.rg}\n\n` + networkWatcher +
`# Deploy template with in-line parameters\n` +
Expand All @@ -320,8 +333,9 @@ export default function DeployTab({ defaults, updateFn, tabValues, invalidArray,
const val = finalParams[k]
const targetVal = Array.isArray(val) ? JSON.stringify(JSON.stringify(val)).replaceAll('"[\\', '\'[').replaceAll('\\"]"', '"]\'').replaceAll('\\",\\"','","') : val
return ` \`\n\t${k}=${targetVal}`
}).join('') + '\n\n' + (Object.keys(post_params).length >0 || (!deploy.disablePreviews && Object.keys(preview_post_params).length >0) ? cluster.apisecurity !== "private" ? post_deployPSstr: post_deployBASHstr : '')

}).join('') +
'\n\n' +
(displayPostCmd || deploy.getCreds ? post_deployPSstr : '')

//Terraform
const deployTfcmd = `#download the *.tf files and run these commands to deploy using terraform\n#for more AKS Construction samples of deploying with terraform, see https://aka.ms/aksc/terraform\n\nterraform fmt\nterraform init\nterraform validate\nterraform plan -out main.tfplan\nterraform apply main.tfplan\nterraform output`
Expand Down Expand Up @@ -451,6 +465,12 @@ az role assignment create --role "Managed Identity Operator" --assignee-principa
</Stack.Item>
{ deploy.keyVaultIPAllowlist && net.vnetprivateend && <MessageBar messageBarType={MessageBarType.info}> <Text >"Add current IP to KeyVault firewall" will enable KeyVaults PublicNetworkAccess property</Text></MessageBar> }

<Label>Always retrieve cluster credentials & login (interactive)</Label>
<Stack.Item>
<Checkbox disabled={cluster.apisecurity === "private" || displayPostCmd} checked={deploy.getCreds || displayPostCmd} onChange={(ev, v) => updateFn("getCreds", v)} label="Always show the 'az aks get-credentials' command to quickly connect to your new cluster" />
</Stack.Item>

<Label>Telemetry</Label>
<Stack.Item>
<Checkbox inputProps={{ "data-testid": "akscTelemetryOpt-Checkbox"}} checked={deploy.enableTelemetry} onChange={(ev, v) => updateFn("enableTelemetry", v)} label="Enable telemetry feedback to Microsoft" />
</Stack.Item>
Expand Down
3 changes: 2 additions & 1 deletion helper/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"githubrepo": "",
"githubrepobranch": "main",
"deployItemKey": "deployArmCli",
"workloadDeployCommands" : []
"workloadDeployCommands" : [],
"getCreds" : true
},
"cluster": {
"keyVaultKmsByoRG": "",
Expand Down

0 comments on commit cc9b612

Please sign in to comment.