Skip to content

Commit c3bc9d8

Browse files
author
Steve Salas
committed
Show tool service resource requirements
- Describe ConfigMap resources that define resource requirements for orchestration - Drop actions that depend on programs that may be unavailable (e.g., vim and argo) - Accept action choice as an alternative to Enter, which re-shows available actions
1 parent 140c387 commit c3bc9d8

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

admin/console.ps1

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<#PSScriptInfo
2-
.VERSION 1.0.1
2+
.VERSION 1.0.2
33
.GUID 9b147f81-cb5d-4f13-830c-f0eb653520a7
44
.AUTHOR Code Dx
55
#>
@@ -54,13 +54,27 @@ function Get-Confirmation([string] $confirmation) {
5454
(Read-Host -prompt "Are you sure? Enter '$confirmation' to proceed") -eq $confirmation
5555
}
5656

57+
function Test-AppCommandPath([string] $commandName) {
58+
59+
$command = Get-Command $commandName -Type Application -ErrorAction SilentlyContinue
60+
$null -ne $command
61+
}
62+
63+
function Test-Vim() {
64+
Test-AppCommandPath 'vim'
65+
}
66+
67+
function Test-Argo() {
68+
Test-AppCommandPath 'argo'
69+
}
70+
5771
$choices = @(
5872

5973
@{id="A1"; name='Show All Workflows';
6074
action={
6175
argo -n $toolOrchestrationNamespace list
6276
};
63-
valid = {$toolOrchestrationNamespace -ne ''}
77+
valid = {$toolOrchestrationNamespace -ne '' -and (Test-Argo)}
6478
}
6579

6680
@{id="A2"; name='Show All Workflow Details';
@@ -70,14 +84,14 @@ $choices = @(
7084
argo -n $toolOrchestrationNamespace get $_
7185
}
7286
};
73-
valid = {$toolOrchestrationNamespace -ne ''}
87+
valid = {$toolOrchestrationNamespace -ne '' -and (Test-Argo)}
7488
}
7589

7690
@{id="A3"; name='Show Running Workflows';
7791
action={
7892
argo -n $toolOrchestrationNamespace list --running
7993
};
80-
valid = {$toolOrchestrationNamespace -ne ''}
94+
valid = {$toolOrchestrationNamespace -ne '' -and (Test-Argo)}
8195
}
8296

8397
@{id="A4"; name='Show Running Workflow Details';
@@ -87,15 +101,15 @@ $choices = @(
87101
argo -n $toolOrchestrationNamespace get $_
88102
}
89103
};
90-
valid = {$toolOrchestrationNamespace -ne ''}
104+
valid = {$toolOrchestrationNamespace -ne '' -and (Test-Argo)}
91105
}
92106

93107
@{id="A5"; name='Show Workflow Detail';
94108
action={
95109
$workflowName = read-host -prompt 'Enter workflow ID'
96110
argo -n $toolOrchestrationNamespace get $workflowName
97111
};
98-
valid = {$toolOrchestrationNamespace -ne ''}
112+
valid = {$toolOrchestrationNamespace -ne '' -and (Test-Argo)}
99113
}
100114

101115
@{id="C1"; name='Get Code Dx Namespace Pods';
@@ -179,12 +193,12 @@ $choices = @(
179193
valid = {$codedxNamespace -ne ''}
180194
}
181195

182-
@{id="L2"; name='Open Code Dx Log in vim (requires vim)';
196+
@{id="L2"; name='Open Code Dx Log in vim';
183197
action={
184198
$podName = kubectl -n $codedxNamespace get pod -l app=codedx -o name
185199
kubectl -n $codedxNamespace logs $podName | vim -
186200
};
187-
valid = {$codedxNamespace -ne ''}
201+
valid = {$codedxNamespace -ne '' -and (Test-Vim)}
188202
}
189203

190204
@{id="L3"; name='Show Code Dx Log (ERRORs)';
@@ -213,14 +227,14 @@ $choices = @(
213227
valid = {$toolOrchestrationNamespace -ne ''}
214228
}
215229

216-
@{id="L6"; name='Open Tool Orchestration Log(s) in vim (requires vim)';
230+
@{id="L6"; name='Open Tool Orchestration Log(s) in vim';
217231
action={
218232
kubectl -n $toolOrchestrationNamespace get pod -l component=service -o name | ForEach-Object {
219233
write-host "`n--------$_--------" -fore red
220234
kubectl -n $toolOrchestrationNamespace logs $_ | vim -
221235
}
222236
};
223-
valid = {$toolOrchestrationNamespace -ne ''}
237+
valid = {$toolOrchestrationNamespace -ne '' -and (Test-Vim)}
224238
}
225239

226240
@{id="L7"; name='Show Tool Orchestration Log(s) (Last 10 Minutes)';
@@ -322,6 +336,14 @@ $choices = @(
322336
};
323337
valid = {$toolOrchestrationNamespace -ne ''}
324338
}
339+
340+
341+
@{id="T4"; name='Describe Resource Requirement(s)';
342+
action={
343+
kubectl -n $toolOrchestrationNamespace describe cm cdx-toolsvc
344+
};
345+
valid = {$toolOrchestrationNamespace -ne ''}
346+
}
325347
)
326348

327349
kubectl config use-context $kubeContext
@@ -339,6 +361,7 @@ $missingCmds = $cmdCount -ne $choices.count
339361

340362
$choices = $choices + @{id="QA"; name='Quit'; action={ exit }}
341363

364+
$choice = ''
342365
$awaitingChoice = $false
343366
while ($true) {
344367

@@ -352,12 +375,16 @@ while ($true) {
352375
$missingCmds=$false
353376
}
354377

355-
$choice = read-host -prompt 'Enter code (e.g., A1)'
378+
if ('' -eq $choice) {
379+
$choice = read-host -prompt 'Enter code (e.g., C1)'
380+
}
381+
356382
$action = $choices | Where-Object {
357383
$_.id -eq $choice
358384
}
359385

360386
if ($null -eq $action) {
387+
$choice = ''
361388
Write-Host 'Try again by specifying a choice from the above list (enter QA to quit)'
362389
continue
363390
}
@@ -366,6 +393,11 @@ while ($true) {
366393
& $action.action
367394
Write-Host "`n---"
368395

369-
Read-Host 'Press Enter to continue...'
370-
$awaitingChoice = $false
396+
$choice = Read-Host 'Specify another command or press Enter to continue...'
397+
if ('' -ne $choice -and ($choices | select-object -ExpandProperty id) -notcontains $choice) {
398+
Write-Host 'Invalid choice'
399+
$choice = ''
400+
}
401+
402+
$awaitingChoice = '' -ne $choice
371403
}

0 commit comments

Comments
 (0)