Skip to content

Commit 23ca443

Browse files
committed
Add -l/--light option for profile list command.
If option is true, Doens't try to get profiles from container and read current status.
1 parent 3f4ff5b commit 23ca443

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

cmd/minikube/cmd/config/profile_list.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
)
4242

4343
var output string
44+
var isLight bool
4445

4546
var profileListCmd = &cobra.Command{
4647
Use: "list",
@@ -58,8 +59,18 @@ var profileListCmd = &cobra.Command{
5859
},
5960
}
6061

62+
func listProfiles() (validProfiles, invalidProfiles []*config.Profile, err error) {
63+
if isLight {
64+
validProfiles, err = config.ListValidProfiles()
65+
} else {
66+
validProfiles, invalidProfiles, err = config.ListProfiles()
67+
}
68+
69+
return validProfiles, invalidProfiles, err
70+
}
71+
6172
func printProfilesTable() {
62-
validProfiles, invalidProfiles, err := config.ListProfiles()
73+
validProfiles, invalidProfiles, err := listProfiles()
6374

6475
if err != nil {
6576
klog.Warningf("error loading profiles: %v", err)
@@ -75,6 +86,13 @@ func printProfilesTable() {
7586
}
7687

7788
func updateProfilesStatus(profiles []*config.Profile) {
89+
if isLight {
90+
for _, p := range profiles {
91+
p.Status = "Skipped"
92+
}
93+
return
94+
}
95+
7896
api, err := machine.NewAPIClient()
7997
if err != nil {
8098
klog.Errorf("failed to get machine api client %v", err)
@@ -168,7 +186,7 @@ func warnInvalidProfiles(invalidProfiles []*config.Profile) {
168186
}
169187

170188
func printProfilesJSON() {
171-
validProfiles, invalidProfiles, err := config.ListProfiles()
189+
validProfiles, invalidProfiles, err := listProfiles()
172190

173191
updateProfilesStatus(validProfiles)
174192

@@ -195,5 +213,6 @@ func profilesOrDefault(profiles []*config.Profile) []*config.Profile {
195213

196214
func init() {
197215
profileListCmd.Flags().StringVarP(&output, "output", "o", "table", "The output format. One of 'json', 'table'")
216+
profileListCmd.Flags().BoolVarP(&isLight, "light", "l", false, "If true, only display vaild profiles and do not check status.")
198217
ProfileCmd.AddCommand(profileListCmd)
199218
}

site/content/en/docs/commands/profile.md

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ minikube profile list [flags]
8989
### Options
9090

9191
```
92+
-l, --light If true, only display vaild profiles and do not check status.
9293
-o, --output string The output format. One of 'json', 'table' (default "table")
9394
```
9495

test/integration/functional_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,58 @@ func validateProfileCmd(ctx context.Context, t *testing.T, profile string) {
813813
}
814814

815815
})
816+
817+
t.Run("profile_list_light", func(t *testing.T) {
818+
// List profiles
819+
rr, err := Run(t, exec.CommandContext(ctx, Target(), "profile", "list", "-l"))
820+
if err != nil {
821+
t.Errorf("failed to list profiles: args %q : %v", rr.Command(), err)
822+
}
823+
824+
// Table output
825+
listLines := strings.Split(strings.TrimSpace(rr.Stdout.String()), "\n")
826+
profileExists := false
827+
for i := 3; i < (len(listLines) - 1); i++ {
828+
profileLine := listLines[i]
829+
if strings.Contains(profileLine, profile) && strings.Contains(profileLine, "Skipped") {
830+
profileExists = true
831+
break
832+
}
833+
}
834+
if !profileExists {
835+
t.Errorf("expected 'profile list' output to include %q with 'Skipped' status but got *%q*. args: %q", profile, rr.Stdout.String(), rr.Command())
836+
}
837+
})
838+
839+
t.Run("profile_list_light_json", func(t *testing.T) {
840+
// Json output
841+
rr, err := Run(t, exec.CommandContext(ctx, Target(), "profile", "list", "--light", "--output", "json"))
842+
if err != nil {
843+
t.Errorf("failed to list profiles with json format. args %q: %v", rr.Command(), err)
844+
}
845+
var jsonObject map[string][]config.Profile
846+
err = json.Unmarshal(rr.Stdout.Bytes(), &jsonObject)
847+
if err != nil {
848+
t.Errorf("failed to decode json from profile list: args %q: %v", rr.Command(), err)
849+
}
850+
validProfiles := jsonObject["valid"]
851+
profileExists := false
852+
for _, profileObject := range validProfiles {
853+
if profileObject.Name != profile {
854+
continue
855+
}
856+
857+
profileExists = true
858+
if profileObject.Status != "Skipped" {
859+
t.Errorf("expected the json of 'profile list --light' to include 'Skipped' status for %q but got *%q*. args: %q", profile, rr.Stdout.String(), rr.Command())
860+
}
861+
break
862+
}
863+
if !profileExists {
864+
t.Errorf("expected the json of 'profile list --light' to include %q but got *%q*. args: %q", profile, rr.Stdout.String(), rr.Command())
865+
}
866+
867+
})
816868
}
817869

818870
// validateServiceCmd asserts basic "service" command functionality

0 commit comments

Comments
 (0)