Skip to content

Commit 8700f8a

Browse files
authored
Merge pull request #6700 from medyagh/resource_limit
fix inverted logic for resource logic
2 parents 5169325 + 7ada4f5 commit 8700f8a

File tree

3 files changed

+68
-57
lines changed

3 files changed

+68
-57
lines changed

Diff for: cmd/minikube/cmd/start.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ func validateFlags(cmd *cobra.Command, drvName string) {
668668
validateDiskSize()
669669
validateMemorySize()
670670

671-
if !driver.HasResourceLimits(drvName) { // both podman and none need root and they both cant specify resources
671+
if !driver.HasResourceLimits(drvName) {
672672
if cmd.Flags().Changed(cpus) {
673673
out.WarningT("The '{{.name}}' driver does not respect the --cpus flag", out.V{"name": drvName})
674674
}

Diff for: pkg/minikube/driver/driver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func NeedsRoot(name string) bool {
115115

116116
// HasResourceLimits returns true if driver can set resource limits such as memory size or CPU count.
117117
func HasResourceLimits(name string) bool {
118-
return name == None || name == Podman
118+
return !(name == None || name == Podman)
119119
}
120120

121121
// FlagHints are hints for what default options should be used for this driver

Diff for: test/integration/functional_test.go

+66-55
Original file line numberDiff line numberDiff line change
@@ -494,68 +494,79 @@ func validateLogsCmd(ctx context.Context, t *testing.T, profile string) {
494494

495495
// validateProfileCmd asserts "profile" command functionality
496496
func validateProfileCmd(ctx context.Context, t *testing.T, profile string) {
497-
// Profile command should not create a nonexistent profile
498-
nonexistentProfile := "lis"
499-
rr, err := Run(t, exec.CommandContext(ctx, Target(), "profile", nonexistentProfile))
500-
rr, err = Run(t, exec.CommandContext(ctx, Target(), "profile", "list", "--output", "json"))
501-
if err != nil {
502-
t.Errorf("%s failed: %v", rr.Args, err)
503-
}
504-
var profileJson map[string][]map[string]interface{}
505-
err = json.Unmarshal(rr.Stdout.Bytes(), &profileJson)
506-
if err != nil {
507-
t.Errorf("%s failed: %v", rr.Args, err)
508-
}
509-
for profileK := range profileJson {
510-
for _, p := range profileJson[profileK] {
511-
var name = p["Name"]
512-
if (name == nonexistentProfile) {
513-
t.Errorf("minikube profile %s should not exist", nonexistentProfile)
497+
t.Run("profile_not_create", func(t *testing.T) {
498+
// Profile command should not create a nonexistent profile
499+
nonexistentProfile := "lis"
500+
rr, err := Run(t, exec.CommandContext(ctx, Target(), "profile", nonexistentProfile))
501+
if err != nil {
502+
t.Errorf("%s failed: %v", rr.Args, err)
503+
}
504+
rr, err = Run(t, exec.CommandContext(ctx, Target(), "profile", "list", "--output", "json"))
505+
if err != nil {
506+
t.Errorf("%s failed: %v", rr.Args, err)
507+
}
508+
var profileJSON map[string][]map[string]interface{}
509+
err = json.Unmarshal(rr.Stdout.Bytes(), &profileJSON)
510+
if err != nil {
511+
t.Errorf("%s failed: %v", rr.Args, err)
512+
}
513+
for profileK := range profileJSON {
514+
for _, p := range profileJSON[profileK] {
515+
var name = p["Name"]
516+
if name == nonexistentProfile {
517+
t.Errorf("minikube profile %s should not exist", nonexistentProfile)
518+
}
514519
}
515520
}
516-
}
521+
})
517522

518-
// List profiles
519-
rr, err = Run(t, exec.CommandContext(ctx, Target(), "profile", "list"))
520-
if err != nil {
521-
t.Errorf("%s failed: %v", rr.Args, err)
522-
}
523+
t.Run("profile_list", func(t *testing.T) {
524+
// List profiles
525+
rr, err := Run(t, exec.CommandContext(ctx, Target(), "profile", "list"))
526+
if err != nil {
527+
t.Errorf("%s failed: %v", rr.Args, err)
528+
}
523529

524-
// Table output
525-
listLines := strings.Split(strings.TrimSpace(rr.Stdout.String()), "\n")
526-
profileExists := false
527-
for i := 3; i < (len(listLines) - 1); i++ {
528-
profileLine := listLines[i]
529-
if strings.Contains(profileLine, profile) {
530-
profileExists = true
531-
break
530+
// Table output
531+
listLines := strings.Split(strings.TrimSpace(rr.Stdout.String()), "\n")
532+
profileExists := false
533+
for i := 3; i < (len(listLines) - 1); i++ {
534+
profileLine := listLines[i]
535+
if strings.Contains(profileLine, profile) {
536+
profileExists = true
537+
break
538+
}
539+
}
540+
if !profileExists {
541+
t.Errorf("%s failed: Missing profile '%s'. Got '\n%s\n'", rr.Args, profile, rr.Stdout.String())
532542
}
533-
}
534-
if !profileExists {
535-
t.Errorf("%s failed: Missing profile '%s'. Got '\n%s\n'", rr.Args, profile, rr.Stdout.String())
536-
}
537543

538-
// Json output
539-
rr, err = Run(t, exec.CommandContext(ctx, Target(), "profile", "list", "--output", "json"))
540-
if err != nil {
541-
t.Errorf("%s failed: %v", rr.Args, err)
542-
}
543-
var jsonObject map[string][]map[string]interface{}
544-
err = json.Unmarshal(rr.Stdout.Bytes(), &jsonObject)
545-
if err != nil {
546-
t.Errorf("%s failed: %v", rr.Args, err)
547-
}
548-
validProfiles := jsonObject["valid"]
549-
profileExists = false
550-
for _, profileObject := range validProfiles {
551-
if profileObject["Name"] == profile {
552-
profileExists = true
553-
break
544+
})
545+
546+
t.Run("profile_json_output", func(t *testing.T) {
547+
// Json output
548+
rr, err := Run(t, exec.CommandContext(ctx, Target(), "profile", "list", "--output", "json"))
549+
if err != nil {
550+
t.Errorf("%s failed: %v", rr.Args, err)
554551
}
555-
}
556-
if !profileExists {
557-
t.Errorf("%s failed: Missing profile '%s'. Got '\n%s\n'", rr.Args, profile, rr.Stdout.String())
558-
}
552+
var jsonObject map[string][]map[string]interface{}
553+
err = json.Unmarshal(rr.Stdout.Bytes(), &jsonObject)
554+
if err != nil {
555+
t.Errorf("%s failed: %v", rr.Args, err)
556+
}
557+
validProfiles := jsonObject["valid"]
558+
profileExists := false
559+
for _, profileObject := range validProfiles {
560+
if profileObject["Name"] == profile {
561+
profileExists = true
562+
break
563+
}
564+
}
565+
if !profileExists {
566+
t.Errorf("%s failed: Missing profile '%s'. Got '\n%s\n'", rr.Args, profile, rr.Stdout.String())
567+
}
568+
569+
})
559570
}
560571

561572
// validateServiceCmd asserts basic "service" command functionality

0 commit comments

Comments
 (0)