Skip to content
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

Add --disable-optimizations flag #13340

Merged
merged 6 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const (
extraDisks = "extra-disks"
certExpiration = "cert-expiration"
binaryMirror = "binary-mirror"
disableOptimizations = "disable-optimizations"
spowelljr marked this conversation as resolved.
Show resolved Hide resolved
)

var (
Expand Down Expand Up @@ -191,6 +192,7 @@ func initMinikubeFlags() {
startCmd.Flags().Int(extraDisks, 0, "Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit and kvm2 drivers)")
startCmd.Flags().Duration(certExpiration, constants.DefaultCertExpiration, "Duration until minikube certificate expiration, defaults to three years (26280h).")
startCmd.Flags().String(binaryMirror, "", "Location to fetch kubectl, kubelet, & kubeadm binaries from.")
startCmd.Flags().Bool(disableOptimizations, false, "If set, disables optimizations that improve minikube performance. The optimizations applied are decreasing CoreDNS replicas from 2 to 1 and increasing kubeadm housekeeping-interval from 10s to 5m. Defaults to false.")
spowelljr marked this conversation as resolved.
Show resolved Hide resolved
}

// initKubernetesFlags inits the commandline flags for Kubernetes related options
Expand Down Expand Up @@ -379,6 +381,27 @@ func getDiskSize() int {
return diskSize
}

func getExtraOptions() config.ExtraOptionSlice {
options := []string{}
if detect.IsCloudShell() {
options = append(options, "kubelet.cgroups-per-qos=false", "kubelet.enforce-node-allocatable=\"\"")
}
if !viper.GetBool(disableOptimizations) {
options = append(options, "kubelet.housekeeping-interval=5m")
}
for _, eo := range options {
if config.ExtraOptions.Exists(eo) {
klog.Infof("skipping extra-config %q.", eo)
continue
}
klog.Infof("setting extra-config: %s", eo)
if err := config.ExtraOptions.Set(eo); err != nil {
exit.Error(reason.InternalConfigSet, "failed to set extra option", err)
}
}
return config.ExtraOptions
}

func getRepository(cmd *cobra.Command, k8sVersion string) string {
repository := viper.GetString(imageRepository)
mirrorCountry := strings.ToLower(viper.GetString(imageMirrorCountry))
Expand Down Expand Up @@ -493,6 +516,7 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, drvName s
MountType: viper.GetString(mountTypeFlag),
MountUID: viper.GetString(mountUID),
BinaryMirror: viper.GetString(binaryMirror),
DisableOptimizations: viper.GetBool(disableOptimizations),
KubernetesConfig: config.KubernetesConfig{
KubernetesVersion: k8sVersion,
ClusterName: ClusterFlagValue(),
Expand All @@ -507,7 +531,7 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, drvName s
NetworkPlugin: chosenNetworkPlugin,
ServiceCIDR: viper.GetString(serviceCIDR),
ImageRepository: getRepository(cmd, k8sVersion),
ExtraOptions: config.ExtraOptions,
ExtraOptions: getExtraOptions(),
ShouldLoadCachedImages: viper.GetBool(cacheImages),
CNI: getCNIConfig(cmd),
NodePort: viper.GetInt(apiServerPort),
Expand All @@ -519,17 +543,6 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, drvName s
cc.ContainerVolumeMounts = []string{viper.GetString(mountString)}
}

if detect.IsCloudShell() {
err := cc.KubernetesConfig.ExtraOptions.Set("kubelet.cgroups-per-qos=false")
if err != nil {
exit.Error(reason.InternalConfigSet, "failed to set cloud shell kubelet config options", err)
}
err = cc.KubernetesConfig.ExtraOptions.Set("kubelet.enforce-node-allocatable=\"\"")
if err != nil {
exit.Error(reason.InternalConfigSet, "failed to set cloud shell kubelet config options", err)
}
}

if driver.IsKIC(drvName) {
si, err := oci.CachedDaemonInfo(drvName)
if err != nil {
Expand Down Expand Up @@ -711,13 +724,14 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterC
updateStringFromFlag(cmd, &cc.MountType, mountTypeFlag)
updateStringFromFlag(cmd, &cc.MountUID, mountUID)
updateStringFromFlag(cmd, &cc.BinaryMirror, binaryMirror)
updateBoolFromFlag(cmd, &cc.DisableOptimizations, disableOptimizations)

if cmd.Flags().Changed(kubernetesVersion) {
cc.KubernetesConfig.KubernetesVersion = getKubernetesVersion(existing)
}

if cmd.Flags().Changed("extra-config") {
cc.KubernetesConfig.ExtraOptions = config.ExtraOptions
cc.KubernetesConfig.ExtraOptions = getExtraOptions()
}

if cmd.Flags().Changed(cniFlag) || cmd.Flags().Changed(enableDefaultCNI) {
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type ClusterConfig struct {
MountType string
MountUID string
BinaryMirror string // Mirror location for kube binaries (kubectl, kubelet, & kubeadm)
DisableOptimizations bool
}

// KubernetesConfig contains the parameters used to configure the VM Kubernetes.
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ type FlagHints struct {

// FlagDefaults returns suggested defaults based on a driver
func FlagDefaults(name string) FlagHints {
fh := FlagHints{ExtraOptions: []string{"kubelet.housekeeping-interval=5m"}}
fh := FlagHints{}
if name != None {
fh.CacheImages = true
return fh
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestMachineType(t *testing.T) {
}

func TestFlagDefaults(t *testing.T) {
expected := FlagHints{CacheImages: true, ExtraOptions: []string{"kubelet.housekeeping-interval=5m"}}
expected := FlagHints{CacheImages: true}
if diff := cmp.Diff(FlagDefaults(VirtualBox), expected); diff != "" {
t.Errorf("defaults mismatch (-want +got):\n%s", diff)
}
Expand All @@ -98,7 +98,7 @@ func TestFlagDefaults(t *testing.T) {

expected = FlagHints{
CacheImages: false,
ExtraOptions: []string{"kubelet.housekeeping-interval=5m", fmt.Sprintf("kubelet.resolv-conf=%s", tf.Name())},
ExtraOptions: []string{fmt.Sprintf("kubelet.resolv-conf=%s", tf.Name())},
}
systemdResolvConf = tf.Name()
if diff := cmp.Diff(FlagDefaults(None), expected); diff != "" {
Expand Down
8 changes: 5 additions & 3 deletions pkg/minikube/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,11 @@ func handleAPIServer(starter Starter, cr cruntime.Manager, hostIP net.IP) (*kube
return nil, bs, errors.Wrap(err, "Failed kubeconfig update")
}

// Scale down CoreDNS from default 2 to 1 replica.
if err := kapi.ScaleDeployment(starter.Cfg.Name, meta.NamespaceSystem, kconst.CoreDNSDeploymentName, 1); err != nil {
klog.Errorf("Unable to scale down deployment %q in namespace %q to 1 replica: %v", kconst.CoreDNSDeploymentName, meta.NamespaceSystem, err)
if !starter.Cfg.DisableOptimizations {
// Scale down CoreDNS from default 2 to 1 replica.
if err := kapi.ScaleDeployment(starter.Cfg.Name, meta.NamespaceSystem, kconst.CoreDNSDeploymentName, 1); err != nil {
klog.Errorf("Unable to scale down deployment %q in namespace %q to 1 replica: %v", kconst.CoreDNSDeploymentName, meta.NamespaceSystem, err)
}
}

// Not running this in a Go func can result in DNS answering taking up to 38 seconds, with the Go func it takes 6-10 seconds.
Expand Down
1 change: 1 addition & 0 deletions site/content/en/docs/commands/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ minikube start [flags]
--cri-socket string The cri socket path to be used.
--delete-on-failure If set, delete the current cluster if start fails and try again. Defaults to false.
--disable-driver-mounts Disables the filesystem mounts provided by the hypervisors
--disable-optimizations If set, disables optimizations that improve minikube performance. The optimizations applied are decreasing CoreDNS replicas from 2 to 1 and increasing kubeadm housekeeping-interval from 10s to 5m. Defaults to false.
--disk-size string Disk size allocated to the minikube VM (format: <number>[<unit>], where unit = b, k, m or g). (default "20000mb")
--dns-domain string The cluster dns domain name used in the Kubernetes cluster (default "cluster.local")
--dns-proxy Enable proxy for NAT DNS requests (virtualbox driver only)
Expand Down
4 changes: 4 additions & 0 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,11 @@ func validateExtraConfig(ctx context.Context, t *testing.T, profile string) {

// docs: Make sure the specified `--extra-config` is correctly returned
expectedExtraOptions := "apiserver.enable-admission-plugins=NamespaceAutoProvision"
if !strings.Contains(afterCfg.Config.KubernetesConfig.ExtraOptions.String(), expectedExtraOptions) {
t.Errorf("expected ExtraOptions to contain %s but got %s", expectedExtraOptions, afterCfg.Config.KubernetesConfig.ExtraOptions.String())
}

expectedExtraOptions = "kubelet.housekeeping-interval=5m"
if !strings.Contains(afterCfg.Config.KubernetesConfig.ExtraOptions.String(), expectedExtraOptions) {
t.Errorf("expected ExtraOptions to contain %s but got %s", expectedExtraOptions, afterCfg.Config.KubernetesConfig.ExtraOptions.String())
}
Expand Down
6 changes: 5 additions & 1 deletion test/integration/guest_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ func TestGuestEnvironment(t *testing.T) {
defer CleanupWithLogs(t, profile, cancel)

t.Run("Setup", func(t *testing.T) {
args := append([]string{"start", "-p", profile, "--install-addons=false", "--memory=2048", "--wait=false"}, StartArgs()...)
args := append([]string{"start", "-p", profile, "--install-addons=false", "--memory=2048", "--wait=false", "--disable-optimizations=true"}, StartArgs()...)
rr, err := Run(t, exec.CommandContext(ctx, Target(), args...))
if err != nil {
t.Errorf("failed to start minikube: args %q: %v", rr.Command(), err)
}

if strings.Contains(rr.Stderr.String(), "kubelet.housekeeping-interval=5m") {
t.Error("--disable-optimizations=true is not working, optimizations found")
}
})

// Run as a group so that our defer doesn't happen as tests are runnings
Expand Down
2 changes: 2 additions & 0 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@
"If present, writes to the provided file instead of stdout.": "Falls gesetzt, wird in die angegebene Datei geschrieben anstatt auf stdout.",
"If set, automatically updates drivers to the latest version. Defaults to true.": "Falls gesetzt, werden alle Treiber automatisch auf die aktuellste Version geupdated. Default: true",
"If set, delete the current cluster if start fails and try again. Defaults to false.": "Falls gesetzt, lösche den Cluster wenn der Start fehlschlägt und versuche erneut zu starten. Default: false",
"If set, disables optimizations that improve minikube performance. The optimizations applied are decreasing CoreDNS replicas from 2 to 1 and increasing kubeadm housekeeping-interval from 10s to 5m. Defaults to false.": "",
"If set, download tarball of preloaded images if available to improve start time. Defaults to true.": "Falls gesetzt, lade einen tarball von vorbereiteten Images herunter, falls vorhanden, um die Startzeit zu verbessern. Default: true",
"If set, force the container runtime to use systemd as cgroup manager. Defaults to false.": "Fall gesetzt, zwinge die Container Runtime systemd als cgroup Manager zu verwenden. Default: false",
"If set, install addons. Defaults to true.": "Falls gesetzt, werden Addons installiert. Default: true",
Expand Down Expand Up @@ -894,6 +895,7 @@
"failed to open browser: {{.error}}": "Öffnen des Browsers fehlgeschlagen: {{.error}}",
"failed to save config": "Speichern der Konfiguration fehlgeschlagen",
"failed to set cloud shell kubelet config options": "Setzen der Cloud Shell Kublet Konfigurations Opetionen fehlgeschlagen",
"failed to set extra option": "",
"failed to start node": "Start des Nodes fehlgeschlagen",
"fish completion failed": "fish completion fehlgeschlagen",
"fish completion.": "fish fehlgeschlagen",
Expand Down
3 changes: 2 additions & 1 deletion translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@
"If present, writes to the provided file instead of stdout.": "",
"If set, automatically updates drivers to the latest version. Defaults to true.": "",
"If set, delete the current cluster if start fails and try again. Defaults to false.": "",
"If set, disables optimizations that improve minikube performance. The optimizations applied are decreasing CoreDNS replicas from 2 to 1 and increasing kubeadm housekeeping-interval from 10s to 5m. Defaults to false.": "",
"If set, download tarball of preloaded images if available to improve start time. Defaults to true.": "",
"If set, force the container runtime to use systemd as cgroup manager. Defaults to false.": "",
"If set, install addons. Defaults to true.": "",
Expand Down Expand Up @@ -900,7 +901,7 @@
"failed to add node": "",
"failed to open browser: {{.error}}": "",
"failed to save config": "",
"failed to set cloud shell kubelet config options": "",
"failed to set extra option": "",
"failed to start node": "",
"fish completion failed": "",
"fish completion.": "",
Expand Down
2 changes: 2 additions & 0 deletions translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
"If present, writes to the provided file instead of stdout.": "S'il est présent, écrit dans le fichier fourni au lieu de la sortie standard.",
"If set, automatically updates drivers to the latest version. Defaults to true.": "Si défini, met automatiquement à jour les pilotes vers la dernière version. La valeur par défaut est true.",
"If set, delete the current cluster if start fails and try again. Defaults to false.": "Si défini, supprime le cluster actuel si le démarrage échoue et réessaye. La valeur par défaut est false.",
"If set, disables optimizations that improve minikube performance. The optimizations applied are decreasing CoreDNS replicas from 2 to 1 and increasing kubeadm housekeeping-interval from 10s to 5m. Defaults to false.": "",
"If set, download tarball of preloaded images if available to improve start time. Defaults to true.": "Si défini, télécharge l'archive tar des images préchargées si disponibles pour améliorer le temps de démarrage. La valeur par défaut est true.",
"If set, force the container runtime to use systemd as cgroup manager. Defaults to false.": "S'il est défini, force l'environnement d'exécution du conteneur à utiliser systemd comme gestionnaire de groupe de contrôle. La valeur par défaut est false.",
"If set, install addons. Defaults to true.": "Si défini, installe les modules. La valeur par défaut est true.",
Expand Down Expand Up @@ -857,6 +858,7 @@
"failed to open browser: {{.error}}": "échec de l'ouverture du navigateur : {{.error}}",
"failed to save config": "échec de l'enregistrement de la configuration",
"failed to set cloud shell kubelet config options": "échec de la définition des options de configuration cloud shell kubelet",
"failed to set extra option": "",
"failed to start node": "échec du démarrage du nœud",
"fish completion failed": "la complétion fish a échoué",
"fish completion.": "complétion fish.",
Expand Down
2 changes: 2 additions & 0 deletions translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@
"If present, writes to the provided file instead of stdout.": "",
"If set, automatically updates drivers to the latest version. Defaults to true.": "",
"If set, delete the current cluster if start fails and try again. Defaults to false.": "",
"If set, disables optimizations that improve minikube performance. The optimizations applied are decreasing CoreDNS replicas from 2 to 1 and increasing kubeadm housekeeping-interval from 10s to 5m. Defaults to false.": "",
"If set, download tarball of preloaded images if available to improve start time. Defaults to true.": "",
"If set, force the container runtime to use systemd as cgroup manager. Defaults to false.": "",
"If set, install addons. Defaults to true.": "",
Expand Down Expand Up @@ -909,6 +910,7 @@
"failed to open browser: {{.error}}": "ブラウザー起動に失敗しました: {{.error}}",
"failed to save config": "設定保存に失敗しました",
"failed to set cloud shell kubelet config options": "クラウドシェル kubelet 設定オプションの設定に失敗しました",
"failed to set extra option": "",
"failed to start node": "ノード開始に失敗しました",
"fish completion failed": "fish のコマンド補完に失敗しました",
"fish completion.": "fish のコマンド補完です。",
Expand Down
3 changes: 2 additions & 1 deletion translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@
"If present, writes to the provided file instead of stdout.": "",
"If set, automatically updates drivers to the latest version. Defaults to true.": "",
"If set, delete the current cluster if start fails and try again. Defaults to false.": "",
"If set, disables optimizations that improve minikube performance. The optimizations applied are decreasing CoreDNS replicas from 2 to 1 and increasing kubeadm housekeeping-interval from 10s to 5m. Defaults to false.": "",
"If set, download tarball of preloaded images if available to improve start time. Defaults to true.": "",
"If set, force the container runtime to use systemd as cgroup manager. Defaults to false.": "",
"If set, install addons. Defaults to true.": "",
Expand Down Expand Up @@ -904,7 +905,7 @@
"failed to add node": "",
"failed to open browser: {{.error}}": "",
"failed to save config": "",
"failed to set cloud shell kubelet config options": "",
"failed to set extra option": "",
"failed to start node": "",
"fish completion failed": "",
"fish completion.": "",
Expand Down
3 changes: 2 additions & 1 deletion translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@
"If present, writes to the provided file instead of stdout.": "",
"If set, automatically updates drivers to the latest version. Defaults to true.": "",
"If set, delete the current cluster if start fails and try again. Defaults to false.": "",
"If set, disables optimizations that improve minikube performance. The optimizations applied are decreasing CoreDNS replicas from 2 to 1 and increasing kubeadm housekeeping-interval from 10s to 5m. Defaults to false.": "",
"If set, download tarball of preloaded images if available to improve start time. Defaults to true.": "",
"If set, force the container runtime to use systemd as cgroup manager. Defaults to false.": "",
"If set, install addons. Defaults to true.": "",
Expand Down Expand Up @@ -910,7 +911,7 @@
"failed to add node": "",
"failed to open browser: {{.error}}": "Nie udało się otworzyć przeglądarki: {{.error}}",
"failed to save config": "",
"failed to set cloud shell kubelet config options": "",
"failed to set extra option": "",
"failed to start node": "",
"fish completion failed": "",
"fish completion.": "",
Expand Down
3 changes: 2 additions & 1 deletion translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
"If present, writes to the provided file instead of stdout.": "",
"If set, automatically updates drivers to the latest version. Defaults to true.": "",
"If set, delete the current cluster if start fails and try again. Defaults to false.": "",
"If set, disables optimizations that improve minikube performance. The optimizations applied are decreasing CoreDNS replicas from 2 to 1 and increasing kubeadm housekeeping-interval from 10s to 5m. Defaults to false.": "",
"If set, download tarball of preloaded images if available to improve start time. Defaults to true.": "",
"If set, force the container runtime to use systemd as cgroup manager. Defaults to false.": "",
"If set, install addons. Defaults to true.": "",
Expand Down Expand Up @@ -835,7 +836,7 @@
"failed to add node": "",
"failed to open browser: {{.error}}": "",
"failed to save config": "",
"failed to set cloud shell kubelet config options": "",
"failed to set extra option": "",
"failed to start node": "",
"fish completion failed": "",
"fish completion.": "",
Expand Down
3 changes: 2 additions & 1 deletion translations/strings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
"If present, writes to the provided file instead of stdout.": "",
"If set, automatically updates drivers to the latest version. Defaults to true.": "",
"If set, delete the current cluster if start fails and try again. Defaults to false.": "",
"If set, disables optimizations that improve minikube performance. The optimizations applied are decreasing CoreDNS replicas from 2 to 1 and increasing kubeadm housekeeping-interval from 10s to 5m. Defaults to false.": "",
"If set, download tarball of preloaded images if available to improve start time. Defaults to true.": "",
"If set, force the container runtime to use systemd as cgroup manager. Defaults to false.": "",
"If set, install addons. Defaults to true.": "",
Expand Down Expand Up @@ -835,7 +836,7 @@
"failed to add node": "",
"failed to open browser: {{.error}}": "",
"failed to save config": "",
"failed to set cloud shell kubelet config options": "",
"failed to set extra option": "",
"failed to start node": "",
"fish completion failed": "",
"fish completion.": "",
Expand Down
Loading