Skip to content

Conversation

pavansaikrishna78
Copy link

If status is enabled then the whole row green

command: addons list
image

command: addons list -d
image

command: profile list
image

command: profile list -d
image

ADDON.LIST.MINIKUBE.docx

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pavansaikrishna78
Once this PR has been reviewed and has the lgtm label, please assign spowelljr for approval. For more information see the Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 11, 2025
@k8s-ci-robot k8s-ci-robot requested review from nirs and prezha August 11, 2025 13:45
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 11, 2025
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 11, 2025
@minikube-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@@ -163,6 +163,12 @@ const (

// Mirror CN
AliyunMirror = "registry.cn-hangzhou.aliyuncs.com/google_containers"

//TABLE WRITER COLORS
Copy link
Member

@medyagh medyagh Aug 11, 2025

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?

Copy link
Author

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)
Copy link
Member

@medyagh medyagh Aug 11, 2025

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),
Copy link
Member

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" {
Copy link
Member

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.

Copy link
Contributor

@nirs nirs left a 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.

@@ -163,6 +163,12 @@ const (

// Mirror CN
AliyunMirror = "registry.cn-hangzhou.aliyuncs.com/google_containers"

//TABLE WRITER COLORS
Enabled = "\033[32m"
Copy link
Contributor

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


//TABLE WRITER COLORS
Enabled = "\033[32m"
Default = "\033[0m"
Copy link
Contributor

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.

//TABLE WRITER COLORS
Enabled = "\033[32m"
Default = "\033[0m"
Disabled = "\033[0m"
Copy link
Contributor

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.

Enabled = "\033[32m"
Default = "\033[0m"
Disabled = "\033[0m"
Error = "\033[31m"
Copy link
Contributor

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.
Copy link
Contributor

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
}
Copy link
Contributor

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)
}
Copy link
Contributor

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{}{}
Copy link
Contributor

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"}
Copy link
Contributor

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
}
Copy link
Contributor

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)
}

@pavansaikrishna78 pavansaikrishna78 force-pushed the addon-list branch 2 times, most recently from 3f61c2c to 6bc5fee Compare August 18, 2025 15:11
@k8s-ci-robot k8s-ci-robot added do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 18, 2025
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 18, 2025
addons list and profile list and making pass the test
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 18, 2025
Copy link
Member

@medyagh medyagh left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants