Skip to content

Commit

Permalink
Merge branch 'master' into shorter-prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tstromberg committed May 6, 2019
2 parents 5978555 + fe3f7a0 commit ae3b25f
Show file tree
Hide file tree
Showing 20 changed files with 727 additions and 48 deletions.
14 changes: 9 additions & 5 deletions .github/ISSUE_TEMPLATE
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<!-- Thank you for sharing your experience! If you are reporting a bug, please include: -->
<!-- * The exact command-lines used so that we can replicate the issue -->
<!-- * The full output of the command that failed -->
<!-- * The output of the "minikube logs" command, if applicable -->
<!-- * Which operating system version was used -->
<!-- Please use this template while reporting an issue, providing as much information as possible. Failure to do so may result in a delayed response. Thank you! -->

**The exact command to reproduce the issue**:

**The full output of the command that failed**:

**The output of the `minikube logs` command**:

**The operating system version**:
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,7 @@
[[constraint]]
name = "golang.org/x/text"
revision = "342b2e1fbaa52c93f31447ad2c6abc048c63e475"

[[constraint]]
name = "github.com/cloudfoundry-attic/jibber_jabber"
branch = "master"
25 changes: 13 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,18 @@ else
ARCHTAG_NONE ?= -$(GOARCH)
endif

.PHONY: makedeploys
makedeploys:
sed "s|\-ARCHTAG_NONE|$(ARCHTAG_NONE)|g" deploy/addons/addon-manager.template > deploy/addons/addon-manager.yaml
sed "s|\-ARCHTAG|$(ARCHTAG)|g" deploy/addons/dashboard/dashboard-dp.template > deploy/addons/dashboard/dashboard-dp.yaml
sed "s|\-ARCHTAG|$(ARCHTAG)|g" deploy/addons/heapster/heapster-rc.template > deploy/addons/heapster/heapster-rc.yaml
sed "s|\-ARCHTAG|$(ARCHTAG)|g" deploy/addons/heapster/influx-grafana-rc.template > deploy/addons/heapster/influx-grafana-rc.yaml
sed "s|\-ARCHTAG_NONE|$(ARCHTAG_NONE)|g" deploy/addons/ingress/ingress-dp.template > deploy/addons/ingress/ingress-dp.yaml
sed "s|\-ARCHTAG|$(ARCHTAG)|g" deploy/addons/metrics-server/metrics-server-deployment.template > deploy/addons/metrics-server/metrics-server-deployment.yaml
sed "s|\-ARCHTAG_NONE|$(ARCHTAG_NONE)|g" deploy/addons/storage-provisioner/storage-provisioner.template > deploy/addons/storage-provisioner/storage-provisioner.yaml

DEPLOYS=\
deploy/addons/addon-manager.yaml \
deploy/addons/dashboard/dashboard-dp.yaml \
deploy/addons/heapster/heapster-rc.yaml \
deploy/addons/heapster/influx-grafana-rc.yaml \
deploy/addons/ingress/ingress-dp.yaml \
deploy/addons/metrics-server/metrics-server-deployment.yaml \
deploy/addons/storage-provisioner/storage-provisioner.yaml

%.yaml: %.template
sed "s|\-ARCHTAG_NONE|$(ARCHTAG_NONE)|g;s|\-ARCHTAG|$(ARCHTAG)|g" $< > $@

out/minikube$(IS_EXE): out/minikube-$(GOOS)-$(GOARCH)$(IS_EXE)
cp $< $@

Expand All @@ -129,8 +131,7 @@ out/minikube.d: pkg/minikube/assets/assets.go

-include out/minikube.d

PHONY: out/minikube-%
out/minikube-%:makedeploys pkg/minikube/assets/assets.go
out/minikube-%: $(DEPLOYS) pkg/minikube/assets/assets.go
ifeq ($(MINIKUBE_BUILD_IN_DOCKER),y)
$(call DOCKER,$(BUILD_IMAGE),/usr/bin/make $@)
else
Expand Down
88 changes: 88 additions & 0 deletions cmd/minikube/cmd/kubectl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
Copyright 2019 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.
*/

package cmd

import (
"fmt"
"os"
"os/exec"
"runtime"
"syscall"

"github.com/golang/glog"
"github.com/spf13/cobra"
pkg_config "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
)

// kubectlCmd represents the kubectl command
var kubectlCmd = &cobra.Command{
Use: "kubectl",
Short: "Run kubectl",
Long: `Run the kubernetes client, download it if necessary.`,
Run: func(cmd *cobra.Command, args []string) {
api, err := machine.NewAPIClient()
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(1)
}
defer api.Close()

cc, err := pkg_config.Load()
if err != nil && !os.IsNotExist(err) {
console.ErrLn("Error loading profile config: %v", err)
}

binary := "kubectl"
if runtime.GOOS == "windows" {
binary = "kubectl.exe"
}

version := constants.DefaultKubernetesVersion
if cc != nil {
version = cc.KubernetesConfig.KubernetesVersion
}

path, err := machine.CacheBinary(binary, version, runtime.GOOS, runtime.GOARCH)
if err != nil {
exit.WithError("Failed to download kubectl", err)
}

glog.Infof("Running %s %v", path, args)
c := exec.Command(path, args...)
c.Stdout = os.Stdout
c.Stderr = os.Stderr
if err := c.Run(); err != nil {
var rc int
if exitError, ok := err.(*exec.ExitError); ok {
waitStatus := exitError.Sys().(syscall.WaitStatus)
rc = waitStatus.ExitStatus()
} else {
fmt.Fprintf(os.Stderr, "Error running %s: %v\n", path, err)
rc = 1
}
os.Exit(rc)
}
},
}

func init() {
RootCmd.AddCommand(kubectlCmd)
}
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ itself, leaving all files intact. The cluster can be started again with the "sta
}

if err := cmdUtil.KillMountProcess(); err != nil {
exit.WithError("Unable to kill mount process", err)
console.OutStyle("warning", "Unable to kill mount process: %s", err)
}
},
}
Expand Down
1 change: 1 addition & 0 deletions cmd/minikube/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ func main() {
}
console.SetOutFile(os.Stdout)
console.SetErrFile(os.Stderr)
console.DetermineLocale()
cmd.Execute()
}
46 changes: 40 additions & 6 deletions cmd/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ limitations under the License.
package util

import (
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
"strconv"

"github.com/golang/glog"
ps "github.com/mitchellh/go-ps"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/constants"
)
Expand All @@ -45,19 +48,50 @@ func GetPort() (int, error) {

// KillMountProcess kills the mount process, if it is running
func KillMountProcess() error {
out, err := ioutil.ReadFile(filepath.Join(constants.GetMinipath(), constants.MountProcessFileName))
pidPath := filepath.Join(constants.GetMinipath(), constants.MountProcessFileName)
if _, err := os.Stat(pidPath); os.IsNotExist(err) {
return nil
}

glog.Infof("Found %s ...", pidPath)
out, err := ioutil.ReadFile(pidPath)
if err != nil {
return nil // no mount process to kill
return errors.Wrap(err, "ReadFile")
}
glog.Infof("pidfile contents: %s", out)
pid, err := strconv.Atoi(string(out))
if err != nil {
return errors.Wrap(err, "error converting mount string to pid")
return errors.Wrap(err, "error parsing pid")
}
// os.FindProcess does not check if pid is running :(
entry, err := ps.FindProcess(pid)
if err != nil {
return errors.Wrap(err, "ps.FindProcess")
}
mountProc, err := os.FindProcess(pid)
if entry == nil {
glog.Infof("Stale pid: %d", pid)
if err := os.Remove(pidPath); err != nil {
return errors.Wrap(err, "Removing stale pid")
}
return nil
}

// We found a process, but it still may not be ours.
glog.Infof("Found process %d: %s", pid, entry.Executable())
proc, err := os.FindProcess(pid)
if err != nil {
return errors.Wrap(err, "error converting mount string to pid")
return errors.Wrap(err, "os.FindProcess")
}

glog.Infof("Killing pid %d ...", pid)
if err := proc.Kill(); err != nil {
glog.Infof("Kill failed with %v - removing probably stale pid...", err)
if err := os.Remove(pidPath); err != nil {
return errors.Wrap(err, "Removing likely stale unkillable pid")
}
return errors.Wrap(err, fmt.Sprintf("Kill(%d/%s)", pid, entry.Executable()))
}
return mountProc.Kill()
return nil
}

// GetKubeConfigPath gets the path to the first kubeconfig
Expand Down
3 changes: 2 additions & 1 deletion pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"net"
"net/http"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -572,7 +573,7 @@ func downloadBinaries(cfg config.KubernetesConfig, c bootstrapper.CommandRunner)
for _, bin := range constants.GetKubeadmCachedBinaries() {
bin := bin
g.Go(func() error {
path, err := machine.CacheBinary(bin, cfg.KubernetesVersion)
path, err := machine.CacheBinary(bin, cfg.KubernetesVersion, "linux", runtime.GOARCH)
if err != nil {
return errors.Wrapf(err, "downloading %s", bin)
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/minikube/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strconv"
"strings"

"github.com/cloudfoundry-attic/jibber_jabber"
"github.com/golang/glog"
isatty "github.com/mattn/go-isatty"
"golang.org/x/text/language"
Expand Down Expand Up @@ -198,6 +199,15 @@ func SetErrFile(w fdWriter) {
useColor = wantsColor(w.Fd())
}

func DetermineLocale() {
locale, err := jibber_jabber.DetectIETF()
if err != nil {
glog.Warningf("Getting system locale failed: %s", err)
locale = ""
}
SetPreferredLanguage(locale)
}

// wantsColor determines if the user might want colorized output.
func wantsColor(fd uintptr) bool {
// First process the environment: we allow users to force colors on or off.
Expand Down
8 changes: 4 additions & 4 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ const (
)

// GetKubernetesReleaseURL gets the location of a kubernetes client
func GetKubernetesReleaseURL(binaryName, version string) string {
return fmt.Sprintf("https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/%s/%s", version, runtime.GOARCH, binaryName)
func GetKubernetesReleaseURL(binaryName, version, osName, archName string) string {
return fmt.Sprintf("https://storage.googleapis.com/kubernetes-release/release/%s/bin/%s/%s/%s", version, osName, archName, binaryName)
}

// GetKubernetesReleaseURLSHA1 gets the location of a kubernetes client checksum
func GetKubernetesReleaseURLSHA1(binaryName, version string) string {
return fmt.Sprintf("%s.sha1", GetKubernetesReleaseURL(binaryName, version))
func GetKubernetesReleaseURLSHA1(binaryName, version, osName, archName string) string {
return fmt.Sprintf("%s.sha1", GetKubernetesReleaseURL(binaryName, version, osName, archName))
}

// IsMinikubeChildProcess is the name of "is minikube child process" variable
Expand Down
3 changes: 2 additions & 1 deletion pkg/minikube/exit/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package exit
import (
"fmt"
"os"
"runtime"

"github.com/golang/glog"
"k8s.io/minikube/pkg/minikube/console"
Expand Down Expand Up @@ -59,7 +60,7 @@ func WithCode(code int, format string, a ...interface{}) {

// WithError outputs an error and exits.
func WithError(msg string, err error) {
p := problem.FromError(err)
p := problem.FromError(err, runtime.GOOS)
if p != nil {
WithProblem(msg, p)
}
Expand Down
14 changes: 10 additions & 4 deletions pkg/minikube/machine/cache_binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"crypto"
"os"
"path"
"runtime"

"github.com/golang/glog"
"github.com/jimmidyson/go-download"
Expand All @@ -39,7 +40,7 @@ func CacheBinariesForBootstrapper(version string, clusterBootstrapper string) er
for _, bin := range binaries {
bin := bin
g.Go(func() error {
if _, err := CacheBinary(bin, version); err != nil {
if _, err := CacheBinary(bin, version, "linux", runtime.GOARCH); err != nil {
return errors.Wrapf(err, "caching image %s", bin)
}
return nil
Expand All @@ -49,11 +50,11 @@ func CacheBinariesForBootstrapper(version string, clusterBootstrapper string) er
}

// CacheBinary will cache a binary on the host
func CacheBinary(binary, version string) (string, error) {
func CacheBinary(binary, version, osName, archName string) (string, error) {
targetDir := constants.MakeMiniPath("cache", version)
targetFilepath := path.Join(targetDir, binary)

url := constants.GetKubernetesReleaseURL(binary, version)
url := constants.GetKubernetesReleaseURL(binary, version, osName, archName)

_, err := os.Stat(targetFilepath)
// If it exists, do no verification and continue
Expand All @@ -73,13 +74,18 @@ func CacheBinary(binary, version string) (string, error) {
Mkdirs: download.MkdirAll,
}

options.Checksum = constants.GetKubernetesReleaseURLSHA1(binary, version)
options.Checksum = constants.GetKubernetesReleaseURLSHA1(binary, version, osName, archName)
options.ChecksumHash = crypto.SHA1

console.OutStyle("file-download", "Downloading %s %s", binary, version)
if err := download.ToFile(url, targetFilepath, options); err != nil {
return "", errors.Wrapf(err, "Error downloading %s %s", binary, version)
}
if osName == runtime.GOOS && archName == runtime.GOARCH {
if err = os.Chmod(targetFilepath, 0755); err != nil {
return "", errors.Wrapf(err, "chmod +x %s", targetFilepath)
}
}
return targetFilepath, nil
}

Expand Down
Loading

0 comments on commit ae3b25f

Please sign in to comment.