Skip to content

Instantly share code, notes, and snippets.

@ignlg
Forked from lkoba/run-yaml.sh
Created February 22, 2023 08:32
Show Gist options
  • Save ignlg/a579e7e47041f894a8f18a2ce1817f87 to your computer and use it in GitHub Desktop.
Save ignlg/a579e7e47041f894a8f18a2ce1817f87 to your computer and use it in GitHub Desktop.

Revisions

  1. ignlg revised this gist Feb 22, 2023. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions run-yaml.sh
    Original file line number Diff line number Diff line change
    @@ -2,12 +2,12 @@

    set -eo pipefail

    json=`cat $1 | y2j`
    overrides=`echo "$json" | jq "{spec}"`
    name=`echo "$json" | jq -r ".metadata.name"`
    labels=`echo "$json" | jq -r '.metadata.labels | keys[] as $k | "\($k)=\(.[$k])"' | paste -sd "," -`
    image=`echo "$json" | jq -r ".spec.containers[0].image"`
    json=$(y2j <"$1")
    overrides=$(echo "$json" | jq "{spec}")
    name=$(echo "$json" | jq -r ".metadata.name")
    labels=$(echo "$json" | jq -r '.metadata.labels | keys[] as $k | "\($k)=\(.[$k])"' | paste -sd "," -)
    image=$(echo "$json" | jq -r ".spec.containers[0].image")

    shift

    kubectl run "$name" -it --rm --image="$image" --labels="$labels" --restart=Never --overrides="$overrides" "$@"
    kubectl run "$name" -it --rm --image="$image" --labels="$labels" --restart=Never --overrides="$overrides" "$@"
  2. @lkoba lkoba created this gist Dec 20, 2019.
    13 changes: 13 additions & 0 deletions run-yaml.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    #!/bin/bash

    set -eo pipefail

    json=`cat $1 | y2j`
    overrides=`echo "$json" | jq "{spec}"`
    name=`echo "$json" | jq -r ".metadata.name"`
    labels=`echo "$json" | jq -r '.metadata.labels | keys[] as $k | "\($k)=\(.[$k])"' | paste -sd "," -`
    image=`echo "$json" | jq -r ".spec.containers[0].image"`

    shift

    kubectl run "$name" -it --rm --image="$image" --labels="$labels" --restart=Never --overrides="$overrides" "$@"