-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Improve addons list table design #21288
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
base: master
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: pavansaikrishna78 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hi @pavansaikrishna78. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Can one of the admins verify this patch? |
pkg/minikube/constants/constants.go
Outdated
@@ -163,6 +163,12 @@ const ( | |||
|
|||
// Mirror CN | |||
AliyunMirror = "registry.cn-hangzhou.aliyuncs.com/google_containers" | |||
|
|||
//TABLE WRITER COLORS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a way to show how it looks like maybe a link or copy to the comment ?
is a library to use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if cc == nil { | ||
temp = []string{addonName, maintainer} | ||
} else { | ||
enabled := addonBundle.IsEnabled(cc) | ||
temp = []string{addonName, cc.Name, fmt.Sprintf("%s %s", stringFromStatus(enabled), iconFromStatus(enabled)), maintainer} | ||
if enabled{ | ||
status := fmt.Sprintf("%s%s%s", constants.Enabled, iconFromStatus(enabled), constants.Default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a helper func to Format the text
we have a style package
style.Enable(.....)
cpIP, strconv.Itoa(cpPort), k8sVersion, p.Status, strconv.Itoa(len(p.Config.Nodes)), c, k}) | ||
if p.Status == "OK" { | ||
data = append(data, []string{ | ||
fmt.Sprintf("%s%s%s", constants.Enabled, p.Name, constants.Default), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should have a style func that does
style.Normal( white color)
style.Enabled(
Style.Trouble(
@@ -179,11 +168,77 @@ func profilesToTableData(profiles []*config.Profile) [][]string { | |||
k = "*" | |||
} | |||
if isDetailed { | |||
data = append(data, []string{p.Name, p.Config.Driver, p.Config.KubernetesConfig.ContainerRuntime, | |||
cpIP, strconv.Itoa(cpPort), k8sVersion, p.Status, strconv.Itoa(len(p.Config.Nodes)), c, k}) | |||
if p.Status == "OK" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be an iteration loop that calls the and based on the status it will call the Style Function in the package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please split the logical changes to separate commits instead of posing a new commit on every change.
If tests fail fix the failing commit. Don't post another commit fixing the first commit. This makes reviewing the changes much harder. Adding fix commit locally is fine, but before you post a new version you should squash the fix commit into the commit that introduced the problem.
Please remove all the unrelated and unnecessary changes. Focus on only on the design change to keep the change small, easy to review and be able to complete it quickly.
pkg/minikube/constants/constants.go
Outdated
@@ -163,6 +163,12 @@ const ( | |||
|
|||
// Mirror CN | |||
AliyunMirror = "registry.cn-hangzhou.aliyuncs.com/google_containers" | |||
|
|||
//TABLE WRITER COLORS | |||
Enabled = "\033[32m" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is green forground color. I will help to add a comment like:
Enabled = "\033[32m" // green forground
pkg/minikube/constants/constants.go
Outdated
|
||
//TABLE WRITER COLORS | ||
Enabled = "\033[32m" | ||
Default = "\033[0m" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a color but a reset command, removing all attributes (foreground color, background color, effects). We don't need a constant for default since it does not change the text.
pkg/minikube/constants/constants.go
Outdated
//TABLE WRITER COLORS | ||
Enabled = "\033[32m" | ||
Default = "\033[0m" | ||
Disabled = "\033[0m" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, since this is using the same value as default.
pkg/minikube/constants/constants.go
Outdated
Enabled = "\033[32m" | ||
Default = "\033[0m" | ||
Disabled = "\033[0m" | ||
Error = "\033[31m" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is red foreground, a comment will help.
But I don't think this is the way to go. What we need is a new package for color that can be reused by code writing output for tables or other output.
This package can use constants to the define the color of enabled, disabled, or errors, and provide functions using this signature:
Enabled(s string) string
Code rendering UI should use the functions to decorate fragments of text.
To implement this we can use a library like this:
https://github.com/fatih/color?tab=readme-ov-file#insert-into-noncolor-strings-sprintfunc
The advantage of using a library is using a well tested code that works on all platforms.
@@ -1,5 +1,5 @@ | |||
/* | |||
Copyright 2019 The Kubernetes Authors All rights reserved. | |||
Copyright 2025 The Kubernetes Authors All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to update the dates, that's pointless effort. The best way is to remove the date form the copyright headers, but this is not in the scope of this PR, so just remove this change.
applyColor = true | ||
default: | ||
applyColor = false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too complicated for no reason.
row[i] = fmt.Sprintf("%s%d%s", colorCode, v, constants.Default) | ||
default: | ||
row[i] = fmt.Sprintf("%s%v%s", colorCode, v, constants.Default) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converting the values to string like we did before was better. If we colorize all value in a raw, we can keep the old code as is and apply the right color function to the entire slice.
@@ -208,8 +290,7 @@ func warnInvalidProfiles(invalidProfiles []*config.Profile) { | |||
func printProfilesJSON() { | |||
validProfiles, invalidProfiles, err := listProfiles() | |||
updateProfilesStatus(validProfiles) | |||
|
|||
var body = map[string]interface{}{} | |||
body := map[string]interface{}{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change this?
@@ -107,7 +108,7 @@ var printAddonsList = func(cc *config.ClusterConfig, printDocs bool) { | |||
if cc == nil { | |||
tHeader = []string{"Addon Name", "Maintainer"} | |||
} else { | |||
tHeader = []string{"Addon Name", "Profile", "Status", "Maintainer"} | |||
tHeader = []string{"Addon Name", "Enabled", "Maintainer"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have 3 logic changes:
- Removing the profile column
- Replacing Status with Enabled
- Coloring the output
Each change should be done in a separate commit. This will make it easier to write the code without errors, test it, and review.
temp[i] = fmt.Sprintf("%s%s%s", valueColorCode, valueStr, constants.Default) | ||
} else { | ||
temp[i] = valueStr | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too complicated.
We need 2 steps:
- Create list of strings for the table writer
- Color the strings
For creating list of strings we can modify the previous code a little bit:
enabled := addonBundle.IsEnabled(cc)
row = []string{addonName, cc.Name, iconFromStatus(enabled), maintainer}
iconForStatus() should return empty string if enabled is false. If it does not do this create a function that does this.
Since the list is so simple, we don't really need a loop to color it:
if enabled {
row[0] = color.Enabled(row[0])
row[2] = color.Enabled(row[2])
}
But since wan to color longer lists (like profile list), we can add a function to color rows:
type colorFunc func(string) string
func ColorRow(row []string, colored colorFunc) {
for i := range row {
text := row[i]
if text == "" || isEmoji(text) {
continue
}
row[i] = colored(text)
}
}
With this we can do:
switch status {
case Broken:
color.ColorRow(row, color.Broken)
case Error:
color.ColorRow(row, color.Error)
case Enabled:
color.ColorRow(row, color.Enabled)
}
3f61c2c
to
6bc5fee
Compare
565498b
to
cd36cf8
Compare
addons list and profile list and making pass the test
cd36cf8
to
789116d
Compare
6aab811
to
789116d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets plz not do changes not related to this PR
and also check nir's suggetsions how to make the code more simple
If status is enabled then the whole row green
command: addons list

command: addons list -d

command: profile list

command: profile list -d

ADDON.LIST.MINIKUBE.docx