diff --git a/pkg/minikube/bootstrapper/bsutil/bsutil.go b/pkg/minikube/bootstrapper/bsutil/bsutil.go index 3454ec8c44..7f0a271508 100644 --- a/pkg/minikube/bootstrapper/bsutil/bsutil.go +++ b/pkg/minikube/bootstrapper/bsutil/bsutil.go @@ -121,7 +121,7 @@ func NewKubeletConfig(k8s config.KubernetesConfig, r cruntime.Manager) ([]byte, return nil, errors.Wrap(err, "parsing kubernetes version") } - extraOpts, err := ExtraConfigForComponent(Kubelet, k8s.ExtraOptions, version) + extraOpts, err := extraConfigForComponent(Kubelet, k8s.ExtraOptions, version) if err != nil { return nil, errors.Wrap(err, "generating extra configuration for kubelet") } diff --git a/pkg/minikube/bootstrapper/bsutil/extraconfig.go b/pkg/minikube/bootstrapper/bsutil/extraconfig.go index d7d27305fe..a18d51832e 100644 --- a/pkg/minikube/bootstrapper/bsutil/extraconfig.go +++ b/pkg/minikube/bootstrapper/bsutil/extraconfig.go @@ -71,9 +71,9 @@ var KubeadmExtraArgsWhitelist = map[int][]string{ }, } -// ExtraConfigForComponent generates a map of flagname-value pairs for a k8s +// extraConfigForComponent generates a map of flagname-value pairs for a k8s // component. -func ExtraConfigForComponent(component string, opts config.ExtraOptionSlice, version semver.Version) (map[string]string, error) { +func extraConfigForComponent(component string, opts config.ExtraOptionSlice, version semver.Version) (map[string]string, error) { versionedOpts, err := defaultOptionsForComponentAndVersion(component, version) if err != nil { return nil, errors.Wrapf(err, "setting version specific options for %s", component) @@ -142,7 +142,7 @@ func newComponentExtraArgs(opts config.ExtraOptionSlice, version semver.Version, if kubeadmComponentKey == "" { continue } - extraConfig, err := ExtraConfigForComponent(component, opts, version) + extraConfig, err := extraConfigForComponent(component, opts, version) if err != nil { return nil, errors.Wrapf(err, "getting kubeadm extra args for %s", component) } diff --git a/pkg/minikube/bootstrapper/bsutil/featuregates.go b/pkg/minikube/bootstrapper/bsutil/featuregates.go index 2524bc33ec..f0df053698 100644 --- a/pkg/minikube/bootstrapper/bsutil/featuregates.go +++ b/pkg/minikube/bootstrapper/bsutil/featuregates.go @@ -23,8 +23,20 @@ import ( "strings" "github.com/pkg/errors" + "k8s.io/kubernetes/cmd/kubeadm/app/features" ) +// supports indicates whether a feature name is supported on the +// feature gates for kubeadm +func supports(featureName string) bool { + for k := range features.InitFeatureGates { + if featureName == k { + return true + } + } + return false +} + // parseFeatureArgs parses feature args into extra args func parseFeatureArgs(featureGates string) (map[string]bool, string, error) { kubeadmFeatureArgs := map[string]bool{} @@ -42,7 +54,7 @@ func parseFeatureArgs(featureGates string) (map[string]bool, string, error) { k := strings.TrimSpace(fg[0]) v := strings.TrimSpace(fg[1]) - if !Supports(k) { + if !supports(k) { componentFeatureArgs = fmt.Sprintf("%s%s,", componentFeatureArgs, s) continue } diff --git a/pkg/minikube/bootstrapper/bsutil/featuregates_test.go b/pkg/minikube/bootstrapper/bsutil/featuregates_test.go new file mode 100644 index 0000000000..a04975923a --- /dev/null +++ b/pkg/minikube/bootstrapper/bsutil/featuregates_test.go @@ -0,0 +1,67 @@ +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// bsutil package will eventually be renamed to kubeadm package after getting rid of older one +package bsutil + +import ( + "reflect" + "testing" +) + +func TestParseFeatureArgs(t *testing.T) { + tests := []struct { + description string + featureGates string + expectedKubeadmFeatureArgs map[string]bool + expectedComponentFeatureArgs string + }{ + { + description: "CoreDNS enabled", + featureGates: "CoreDNS=true", + expectedKubeadmFeatureArgs: map[string]bool{ + "CoreDNS": true, + }, + expectedComponentFeatureArgs: "", + }, + { + description: "CoreDNS disabled", + featureGates: "CoreDNS=false", + expectedKubeadmFeatureArgs: map[string]bool{ + "CoreDNS": false, + }, + expectedComponentFeatureArgs: "", + }, + } + + for _, test := range tests { + t.Run(test.description, func(t *testing.T) { + kubeadm, component, err := parseFeatureArgs(test.featureGates) + + if err != nil { + t.Fatalf("Error parsing feature args: %v", err) + } + + if !reflect.DeepEqual(kubeadm, test.expectedKubeadmFeatureArgs) { + t.Errorf("Kubeadm Actual: %v, Expected: %v", kubeadm, test.expectedKubeadmFeatureArgs) + } + + if !reflect.DeepEqual(component, test.expectedComponentFeatureArgs) { + t.Errorf("Component Actual: %v, Expected: %v", component, test.expectedComponentFeatureArgs) + } + }) + } +} diff --git a/pkg/minikube/bootstrapper/bsutil/versions.go b/pkg/minikube/bootstrapper/bsutil/versions.go index 824833c122..39644abced 100644 --- a/pkg/minikube/bootstrapper/bsutil/versions.go +++ b/pkg/minikube/bootstrapper/bsutil/versions.go @@ -22,7 +22,6 @@ import ( "github.com/blang/semver" "github.com/pkg/errors" - "k8s.io/kubernetes/cmd/kubeadm/app/features" "k8s.io/minikube/pkg/minikube/config" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/vmpath" @@ -40,15 +39,16 @@ func ParseKubernetesVersion(version string) (semver.Version, error) { return v, nil } -// Supports indicates whether a feature name is supported on the -// feature gates for kubeadm -func Supports(featureName string) bool { - for k := range features.InitFeatureGates { - if featureName == k { - return true - } +// versionIsBetween checks if a version is between (or including) two given versions +func versionIsBetween(version, gte, lte semver.Version) bool { + if gte.NE(semver.Version{}) && !version.GTE(gte) { + return false } - return false + if lte.NE(semver.Version{}) && !version.LTE(lte) { + return false + } + + return true } var versionSpecificOpts = []config.VersionedExtraOption{ @@ -124,15 +124,3 @@ var versionSpecificOpts = []config.VersionedExtraOption{ LessThanOrEqual: semver.MustParse("1.11.1000"), }, } - -// versionIsBetween checks if a version is between (or including) two given versions -func versionIsBetween(version, gte, lte semver.Version) bool { - if gte.NE(semver.Version{}) && !version.GTE(gte) { - return false - } - if lte.NE(semver.Version{}) && !version.LTE(lte) { - return false - } - - return true -} diff --git a/pkg/minikube/bootstrapper/bsutil/versions_test.go b/pkg/minikube/bootstrapper/bsutil/versions_test.go index 439cbd93cb..e08e9b92d6 100644 --- a/pkg/minikube/bootstrapper/bsutil/versions_test.go +++ b/pkg/minikube/bootstrapper/bsutil/versions_test.go @@ -17,7 +17,6 @@ limitations under the License. package bsutil import ( - "reflect" "testing" "github.com/blang/semver" @@ -102,47 +101,3 @@ func TestParseKubernetesVersion(t *testing.T) { t.Errorf("Expected: %s, Actual:%s", "1.8.0-alpha.5", version) } } - -func TestParseFeatureArgs(t *testing.T) { - tests := []struct { - description string - featureGates string - expectedKubeadmFeatureArgs map[string]bool - expectedComponentFeatureArgs string - }{ - { - description: "CoreDNS enabled", - featureGates: "CoreDNS=true", - expectedKubeadmFeatureArgs: map[string]bool{ - "CoreDNS": true, - }, - expectedComponentFeatureArgs: "", - }, - { - description: "CoreDNS disabled", - featureGates: "CoreDNS=false", - expectedKubeadmFeatureArgs: map[string]bool{ - "CoreDNS": false, - }, - expectedComponentFeatureArgs: "", - }, - } - - for _, test := range tests { - t.Run(test.description, func(t *testing.T) { - kubeadm, component, err := parseFeatureArgs(test.featureGates) - - if err != nil { - t.Fatalf("Error parsing feature args: %v", err) - } - - if !reflect.DeepEqual(kubeadm, test.expectedKubeadmFeatureArgs) { - t.Errorf("Kubeadm Actual: %v, Expected: %v", kubeadm, test.expectedKubeadmFeatureArgs) - } - - if !reflect.DeepEqual(component, test.expectedComponentFeatureArgs) { - t.Errorf("Component Actual: %v, Expected: %v", component, test.expectedComponentFeatureArgs) - } - }) - } -}