Skip to content

Instantly share code, notes, and snippets.

@langheran
Created April 30, 2025 19:07
Show Gist options
  • Save langheran/d0e9febadebbe7984876f5f5d11b62e2 to your computer and use it in GitHub Desktop.
Save langheran/d0e9febadebbe7984876f5f5d11b62e2 to your computer and use it in GitHub Desktop.
C:\Users\NisimHurst\NDS\scripts\cmds\ke.cmd
@echo off
chcp 437 > nul
pushd %~dp0
powershell -command ".\kubernetes_edit.ps1 -name ""%*"""
popd
# read parameters from the command line
param(
[string]$namespace = "default",
[string]$type = "",
[string]$name = "",
[bool]$previous = $false
)
function Show-Menu {
Clear-Host
Write-Host "================== Manifest Type =================="
Write-Host "1. Ingress"
Write-Host "2. Deployment"
Write-Host "3. Service"
Write-Host "Q. Quit"
}
# do {
# Show-Menu
# $selection = Read-Host "Please enter your choice"
# switch ($selection) {
# '1' {
# Write-Host "You selected Option One."
# # Add your code for Option One here
# }
# '2' {
# Write-Host "You selected Option Two."
# # Add your code for Option Two here
# }
# '3' {
# Write-Host "You selected Option Three."
# # Add your code for Option Three here
# }
# 'Q' {
# Write-Host "Exiting the menu."
# break
# }
# default {
# Write-Host "Invalid selection. Please try again."
# }
# }
# if ($selection -ne 'Q') {
# Write-Host "`nPress Enter to continue..."
# [void][System.Console]::ReadLine()
# }
# } while ($selection -ne 'Q')
if ($type -eq "" -and $name -ne "") {
if ($namespace -ne "default") {
$params = "-n $namespace"
} else {
$params = ""
}
$manifests_ = Invoke-Expression $("kubectl get all " + $params + " -o name")
$manifests_ = @($manifests_)
$ingress_ = Invoke-Expression $("kubectl get ingress" + $params + " -o name")
$ingress_ = @($ingress_)
$manifests_ = $ingress_ + $manifests_
# Write-Host "Fetching manifests:`n$manifests_"
$manifests = $manifests_ | ForEach-Object {
$manifest = $_.Split(" ")[0]
# Write-Host "Manifest: $manifest"
# Write-Host "Name: $name"
if ($manifest -match ".*" + $name + ".*") {
# Write-Host "Found manifest: $_"
$type = $_.Split("/")[0]
$object_name = $_.Split("/")[1]
# Write-Host "Object Name: $object_name"
# Write-Host "Type: $type"
return $type
}
}
if ($manifests -is [array]) {
$type = $manifests[0]
} else {
$type = $manifests
}
}
# Write-Host "Fetching manifest: $type"
if ($type -eq "") {
Show-Menu
$selection = Read-Host "Please enter your choice"
switch ($selection) {
'1' {
$type = "ingress"
}
'2' {
$type = "deployment"
}
'3' {
$type = "service"
}
'Q' {
Write-Host "Exiting the menu."
Exit
}
default {
Write-Host "Invalid selection. Please try again."
}
}
}
$params = "edit $type $name"
# kubectl get ingress yomp-ingress -n yompqa -o yaml > latest-ingress.yaml
# set environment variable KUBE_EDITOR="code -w"
$Env:KUBE_EDITOR = "code -w"
start-process -NoNewWindow -Wait -FilePath kubectl -ArgumentList $params
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment