Skip to content

Add "-o json" option for "minikube addon images" #19364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 59 additions & 22 deletions cmd/minikube/cmd/config/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ limitations under the License.
package config

import (
"encoding/json"
"fmt"
"os"
"strings"

"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
Expand All @@ -27,6 +30,8 @@ import (
"k8s.io/minikube/pkg/minikube/reason"
)

var addonImagesOutput string

var addonsImagesCmd = &cobra.Command{
Use: "images ADDON_NAME",
Short: "List image names the addon w/ADDON_NAME used. For a list of available addons use: minikube addons list",
Expand All @@ -38,33 +43,65 @@ var addonsImagesCmd = &cobra.Command{
}

addon := args[0]
// allows for additional prompting of information when enabling addons
if conf, ok := assets.Addons[addon]; ok {
if conf.Images != nil {
out.Infof("{{.name}} has following images:", out.V{"name": addon})

var tData [][]string
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Image Name", "Default Image", "Default Registry"})
table.SetAutoFormatHeaders(true)
table.SetBorders(tablewriter.Border{Left: true, Top: true, Right: true, Bottom: true})
table.SetCenterSeparator("|")

for imageName, defaultImage := range conf.Images {
tData = append(tData, []string{imageName, defaultImage, conf.Registries[imageName]})
}

table.AppendBulk(tData)
table.Render()
} else {
out.Infof("{{.name}} doesn't have images.", out.V{"name": addon})

switch strings.ToLower(addonImagesOutput) {
case "table":
printAddonImagesTable(addon)
case "json":
printAddonImagesJSON(addon)
default:
exit.Message(reason.Usage, fmt.Sprintf("invalid output format: %s. Valid values: 'table', 'json'", addonImagesOutput))
}
},
}

func printAddonImagesTable(addon string) {
// allows for additional prompting of information when enabling addons
if conf, ok := assets.Addons[addon]; ok {
if conf.Images != nil {
out.Infof("{{.name}} has the following images:", out.V{"name": addon})

var tData [][]string
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Image Name", "Default Image", "Default Registry"})
table.SetAutoFormatHeaders(true)
table.SetBorders(tablewriter.Border{Left: true, Top: true, Right: true, Bottom: true})
table.SetCenterSeparator("|")

for imageName, defaultImage := range conf.Images {
tData = append(tData, []string{imageName, defaultImage, conf.Registries[imageName]})
}

table.AppendBulk(tData)
table.Render()
} else {
out.FailureT("No such addon {{.name}}", out.V{"name": addon})
out.Infof("{{.name}} doesn't have images.", out.V{"name": addon})
}
},
} else {
out.FailureT("No such addon {{.name}}", out.V{"name": addon})
}
}

func printAddonImagesJSON(addon string) {
if conf, ok := assets.Addons[addon]; ok {
if conf.Images != nil {
var data []string

for imageName, defaultImage := range conf.Images {
data = append(data, conf.Registries[imageName] + "/" + defaultImage)
}

jsonString, _ := json.Marshal(data)
out.String(string(jsonString))
} else {
out.String("[]")
}
} else {
out.FailureT("No such addon {{.name}}", out.V{"name": addon})
}
}

func init() {
addonsImagesCmd.Flags().StringVarP(&addonImagesOutput, "output", "o", "table", "minikube addons images ADDON_NAME --output OUTPUT. table, json")
AddonsCmd.AddCommand(addonsImagesCmd)
}
6 changes: 6 additions & 0 deletions site/content/en/docs/commands/addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ minikube addons images ADDON_NAME [flags]
minikube addons images ingress
```

### Options

```
-o, --output string minikube addons images ADDON_NAME --output OUTPUT. table, json (default "table")
```

### Options inherited from parent commands

```
Expand Down
2 changes: 2 additions & 0 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@
"list versions of all components included with minikube. (the cluster must be running)": "Liste alle Versionen der Komponenten die in Minikube enthalten sind.",
"loading profile": "Lade Profil",
"max time to wait per Kubernetes or host to be healthy.": "maximale Zeit die gewartet werden soll, bis Kubernetes oder der Host als funktional angesehen soll.",
"minikube addons images ADDON_NAME --output OUTPUT. table, json": "",
"minikube addons list --output OUTPUT. json, list": "",
"minikube does not support the BTRFS storage driver yet, there is a workaround, add the following flag to your start command `--feature-gates=\"LocalStorageCapacityIsolation=false\"`": "Minikube unterstützt den BTRFS Storage Treiber noch nicht, aber es existiert eine Workaround, fügen Sie folgenden Flag zu Ihrem Start-Befehl hinzu `--feature-gates=\"LocalStorageCapacityIsolation=false\"`",
"minikube does not support the BTRFS storage driver yet, there is a workaround, add the following flag to your start command `--feature-gates=\\\"LocalStorageCapacityIsolation=false\\\"`": "minikube unterstützt den BTRFS Storage Treiber nicht, es gibt einen Workaround, füge den folgenden Paramater zum Start-Befehl hinzu `--feature-gates=\\\"LocalStorageCapacityIsolation=false\\\"`",
Expand Down Expand Up @@ -1159,6 +1160,7 @@
"{{.name}} doesn't have images.": "{{.name}} hat keine Images.",
"{{.name}} has following images:": "{{.name}} hat die folgenden Images:",
"{{.name}} has no available configuration options": "{{.name}} hat keine verfügbaren Konfigurations-Optionen",
"{{.name}} has the following images:": "",
"{{.name}} is already running": "{{.name}} läuft bereits",
"{{.name}} was successfully configured": "{{.name}} wurde erfolgreich konfiguriert",
"{{.name}}\" profile does not exist": "Profil \"{{.name}}\" existiert nicht",
Expand Down
3 changes: 2 additions & 1 deletion translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@
"list versions of all components included with minikube. (the cluster must be running)": "",
"loading profile": "",
"max time to wait per Kubernetes or host to be healthy.": "",
"minikube addons images ADDON_NAME --output OUTPUT. table, json": "",
"minikube addons list --output OUTPUT. json, list": "",
"minikube does not support the BTRFS storage driver yet, there is a workaround, add the following flag to your start command `--feature-gates=\"LocalStorageCapacityIsolation=false\"`": "",
"minikube is missing files relating to your guest environment. This can be fixed by running 'minikube delete'": "",
Expand Down Expand Up @@ -1113,8 +1114,8 @@
"{{.driver_name}} has only {{.container_limit}}MB memory but you specified {{.specified_memory}}MB": "",
"{{.driver}} only has {{.size}}MiB available, less than the required {{.req}}MiB for Kubernetes": "",
"{{.name}} doesn't have images.": "",
"{{.name}} has following images:": "",
"{{.name}} has no available configuration options": "",
"{{.name}} has the following images:": "",
"{{.name}} is already running": "",
"{{.name}} was successfully configured": "",
"{{.n}} is nearly out of disk space, which may cause deployments to fail! ({{.p}}% of capacity). You can pass '--force' to skip this check.": "",
Expand Down
2 changes: 2 additions & 0 deletions translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,7 @@
"list versions of all components included with minikube. (the cluster must be running)": "répertorier les versions de tous les composants inclus avec minikube. (le cluster doit être en cours d'exécution)",
"loading profile": "profil de chargement",
"max time to wait per Kubernetes or host to be healthy.": "temps d'attente maximal par Kubernetes ou hôte pour être en bonne santé.",
"minikube addons images ADDON_NAME --output OUTPUT. table, json": "",
"minikube addons list --output OUTPUT. json, list": "liste des modules minikube --output OUTPUT. json, liste",
"minikube does not support the BTRFS storage driver yet, there is a workaround, add the following flag to your start command `--feature-gates=\"LocalStorageCapacityIsolation=false\"`": "minikube ne prend pas encore en charge le pilote de stockage BTRFS, il existe une solution de contournement, ajoutez l'indicateur suivant à votre commande de démarrage `--feature-gates=\"LocalStorageCapacityIsolation=false\"`",
"minikube is missing files relating to your guest environment. This can be fixed by running 'minikube delete'": "minikube manque des fichiers relatifs à votre environnement invité. Cela peut être corrigé en exécutant 'minikube delete'",
Expand Down Expand Up @@ -1150,6 +1151,7 @@
"{{.name}} doesn't have images.": "{{.name}} n'a pas d'images.",
"{{.name}} has following images:": "{{.name}} a les images suivantes :",
"{{.name}} has no available configuration options": "{{.name}} n'a pas d'options de configuration disponible",
"{{.name}} has the following images:": "",
"{{.name}} is already running": "{{.name}} est déjà en cours d'exécution",
"{{.name}} was successfully configured": "{{.name}} a été configuré avec succès",
"{{.n}} is nearly out of disk space, which may cause deployments to fail! ({{.p}}% of capacity)": "{{.n}} manque presque d'espace disque, ce qui peut entraîner l'échec des déploiements ! ({{.p}} % de la capacité)",
Expand Down
2 changes: 2 additions & 0 deletions translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@
"list versions of all components included with minikube. (the cluster must be running)": "minikube に含まれる全コンポーネントのバージョン一覧を出力します (クラスターが実行中でなければなりません)。",
"loading profile": "プロファイルを読み込み中",
"max time to wait per Kubernetes or host to be healthy.": "Kubernetes またはホストが正常稼働するまでの最大待機時間",
"minikube addons images ADDON_NAME --output OUTPUT. table, json": "",
"minikube addons list --output OUTPUT. json, list": "minikube addons list --output OUTPUT. json, list",
"minikube does not support the BTRFS storage driver yet, there is a workaround, add the following flag to your start command `--feature-gates=\"LocalStorageCapacityIsolation=false\"`": "minikube はまだ BTRFS ストレージドライバーに対応していませんが、回避策があります。次のフラグを start コマンドに追加してください: `--feature-gates=\"LocalStorageCapacityIsolation=false\"` ",
"minikube is missing files relating to your guest environment. This can be fixed by running 'minikube delete'": "minikube はあなたのゲスト環境に関連するファイルを見失いました。これは 'minikube delete' を実行することで修正できます",
Expand Down Expand Up @@ -1096,6 +1097,7 @@
"{{.name}} doesn't have images.": "{{.name}} はイメージがありません。",
"{{.name}} has following images:": "{{.name}} は次のイメージがあります:",
"{{.name}} has no available configuration options": "{{.name}} には利用可能な設定オプションがありません",
"{{.name}} has the following images:": "",
"{{.name}} is already running": "{{.name}} はすでに実行中です",
"{{.name}} was successfully configured": "{{.name}} は正常に設定されました",
"{{.n}} is nearly out of disk space, which may cause deployments to fail! ({{.p}}% of capacity). You can pass '--force' to skip this check.": "{{.n}} はほとんどディスクがいっぱいで、デプロイが失敗する原因になりかねません!(容量の {{.p}}%)。'--force' を指定するとこのチェックをスキップできます。",
Expand Down
2 changes: 2 additions & 0 deletions translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@
"logdir set failed": "logdir 설정이 실패하였습니다",
"machine '{{.name}}' does not exist. Proceeding ahead with recreating VM.": "머신 '{{.name}}' 이 존재하지 않습니다. 진행하기 앞서 가상 머신을 재생성합니다",
"max time to wait per Kubernetes or host to be healthy.": "",
"minikube addons images ADDON_NAME --output OUTPUT. table, json": "",
"minikube addons list --output OUTPUT. json, list": "",
"minikube does not support the BTRFS storage driver yet, there is a workaround, add the following flag to your start command `--feature-gates=\"LocalStorageCapacityIsolation=false\"`": "",
"minikube is missing files relating to your guest environment. This can be fixed by running 'minikube delete'": "",
Expand Down Expand Up @@ -1133,6 +1134,7 @@
"{{.name}} doesn't have images.": "{{.name}} 이미지가 없습니다.",
"{{.name}} has following images:": "{{.name}}에는 다음과 같은 이미지가 있습니다.",
"{{.name}} has no available configuration options": "{{.name}} 이 사용 가능한 환경 정보 옵션이 없습니다",
"{{.name}} has the following images:": "",
"{{.name}} is already running": "{{.name}} 이 이미 실행 중입니다",
"{{.name}} was successfully configured": "{{.name}} 이 성공적으로 설정되었습니다",
"{{.n}} is nearly out of disk space, which may cause deployments to fail! ({{.p}}% of capacity). You can pass '--force' to skip this check.": "",
Expand Down
2 changes: 2 additions & 0 deletions translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@
"list versions of all components included with minikube. (the cluster must be running)": "",
"loading profile": "Ładowanie profilu",
"max time to wait per Kubernetes or host to be healthy.": "",
"minikube addons images ADDON_NAME --output OUTPUT. table, json": "",
"minikube addons list --output OUTPUT. json, list": "",
"minikube does not support the BTRFS storage driver yet, there is a workaround, add the following flag to your start command `--feature-gates=\"LocalStorageCapacityIsolation=false\"`": "",
"minikube is missing files relating to your guest environment. This can be fixed by running 'minikube delete'": "",
Expand Down Expand Up @@ -1128,6 +1129,7 @@
"{{.name}} doesn't have images.": "{{.name}} nie ma obrazów.",
"{{.name}} has following images:": "{{.name}} ma następujące obrazy:",
"{{.name}} has no available configuration options": "{{.name}} nie posiada opcji konfiguracji",
"{{.name}} has the following images:": "",
"{{.name}} is already running": "{{.name}} został już wcześniej uruchomiony",
"{{.name}} was successfully configured": "{{.name}} skonfigurowano pomyślnie",
"{{.n}} is nearly out of disk space, which may cause deployments to fail! ({{.p}}% of capacity)": "{{.n}} prawie nie ma wolnej przestrzeni dyskowej, co może powodować, że wdrożenia nie powiodą się ({{.p}}% zużycia przestrzeni dyskowej)",
Expand Down
3 changes: 2 additions & 1 deletion translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@
"list versions of all components included with minikube. (the cluster must be running)": "",
"loading profile": "",
"max time to wait per Kubernetes or host to be healthy.": "",
"minikube addons images ADDON_NAME --output OUTPUT. table, json": "",
"minikube addons list --output OUTPUT. json, list": "",
"minikube does not support the BTRFS storage driver yet, there is a workaround, add the following flag to your start command `--feature-gates=\"LocalStorageCapacityIsolation=false\"`": "",
"minikube is missing files relating to your guest environment. This can be fixed by running 'minikube delete'": "",
Expand Down Expand Up @@ -1041,8 +1042,8 @@
"{{.driver_name}} has only {{.container_limit}}MB memory but you specified {{.specified_memory}}MB": "",
"{{.driver}} only has {{.size}}MiB available, less than the required {{.req}}MiB for Kubernetes": "",
"{{.name}} doesn't have images.": "",
"{{.name}} has following images:": "",
"{{.name}} has no available configuration options": "",
"{{.name}} has the following images:": "",
"{{.name}} is already running": "",
"{{.name}} was successfully configured": "",
"{{.n}} is nearly out of disk space, which may cause deployments to fail! ({{.p}}% of capacity)": "В {{.n}} заканчивается место на диске, что может привести к проблемам в работе! ({{.p}}% занято)",
Expand Down
3 changes: 2 additions & 1 deletion translations/strings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,7 @@
"list versions of all components included with minikube. (the cluster must be running)": "",
"loading profile": "",
"max time to wait per Kubernetes or host to be healthy.": "",
"minikube addons images ADDON_NAME --output OUTPUT. table, json": "",
"minikube addons list --output OUTPUT. json, list": "",
"minikube does not support the BTRFS storage driver yet, there is a workaround, add the following flag to your start command `--feature-gates=\"LocalStorageCapacityIsolation=false\"`": "",
"minikube is missing files relating to your guest environment. This can be fixed by running 'minikube delete'": "",
Expand Down Expand Up @@ -1039,8 +1040,8 @@
"{{.driver_name}} has only {{.container_limit}}MB memory but you specified {{.specified_memory}}MB": "",
"{{.driver}} only has {{.size}}MiB available, less than the required {{.req}}MiB for Kubernetes": "",
"{{.name}} doesn't have images.": "",
"{{.name}} has following images:": "",
"{{.name}} has no available configuration options": "",
"{{.name}} has the following images:": "",
"{{.name}} is already running": "",
"{{.name}} was successfully configured": "",
"{{.n}} is nearly out of disk space, which may cause deployments to fail! ({{.p}}% of capacity). You can pass '--force' to skip this check.": "",
Expand Down
2 changes: 2 additions & 0 deletions translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,7 @@
"loading profile": "加载配置文件",
"max time to wait per Kubernetes core services to be healthy.": "每个 Kubernetes 核心服务保持健康所需的最长时间。",
"max time to wait per Kubernetes or host to be healthy.": "Kubernetes 或主机正常运行前的最大等待时间。",
"minikube addons images ADDON_NAME --output OUTPUT. table, json": "",
"minikube addons list --output OUTPUT. json, list": "minikube addons list --output OUTPUT. json, list",
"minikube does not support the BTRFS storage driver yet, there is a workaround, add the following flag to your start command `--feature-gates=\"LocalStorageCapacityIsolation=false\"`": "minikube 尚不支持 BTRFS 存储驱动程序,有一个解决方法,将以下标志添加到你的启动命令 `--feature-gates=\"LocalStorageCapacityIsolation=false\"`",
"minikube is exiting due to an error. If the above message is not useful, open an issue:": "由于出错 minikube 正在退出。如果以上信息没有帮助,请提交问题反馈:",
Expand Down Expand Up @@ -1270,6 +1271,7 @@
"{{.name}} doesn't have images.": "{{.name}} 没有镜像",
"{{.name}} has following images:": "{{.name}} 有以下镜像",
"{{.name}} has no available configuration options": "{{.name}} 没有可用的配置选项",
"{{.name}} has the following images:": "",
"{{.name}} is already running": "{{.name}} 已经在运行",
"{{.name}} was successfully configured": "{{.name}} 成功配置",
"{{.n}} is nearly out of disk space, which may cause deployments to fail! ({{.p}}% of capacity). You can pass '--force' to skip this check.": "{{.n}} 的磁盘空间即将耗尽,可能导致部署失败!(已使用容量的{{.p}}%)。您可以传递 '--force' 参数来跳过此检查。",
Expand Down
Loading