Skip to content

Instantly share code, notes, and snippets.

@duboisf
Last active February 19, 2024 22:32
Show Gist options
  • Save duboisf/581f51842d89661cb1eb9c529badcc37 to your computer and use it in GitHub Desktop.
Save duboisf/581f51842d89661cb1eb9c529badcc37 to your computer and use it in GitHub Desktop.
Get karpenter machines from all clusters #cli #oneliner #nushell #kubectl

Getting machines from all clusters in nushell

I'm migrating karpenter to version v0.32.x and I need to verify if there are some machines left that might not have been migrated to nodepools.

Note

I have a none context that I select to "turn off" kubectl. I need to filter it out. To create this context, I used the following command: kubectl config set-context none

let machines = ^kubectl config view
    | from yaml
    | get contexts
    | where $it.name != none # I have a "null" context called "none"
    | par-each { |ctx|
        try {
            print $"Getting machines from ($ctx.context.cluster)"
            ^kubectl --context $ctx.name get machines -o json
                    | from json
                    | get items
                    | select kind metadata.name
                    | insert cluster $ctx.context.cluster
                    | move cluster --before kind
        } catch {
            []
        }
    }
    | flatten
$machines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment