Skip to content

Commit

Permalink
Merge pull request kubernetes#5 from jimmidyson/upstream-merge
Browse files Browse the repository at this point in the history
Merge latest upstream changes
  • Loading branch information
jimmidyson committed Jul 14, 2016
2 parents f238528 + bd7f74c commit be31e3e
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 59 deletions.
20 changes: 17 additions & 3 deletions DRIVERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,23 @@ the host PATH:

#### KVM driver

Download the `docker-machine-driver-kvm` binary from
https://github.com/dhiltgen/docker-machine-kvm/releases and put it somewhere in
your PATH. Minikube is currently tested against `docker-machine-driver-kvm` 0.7.0.
Minikube is currently tested against `docker-machine-driver-kvm` 0.7.0.

From https://github.com/dhiltgen/docker-machine-kvm#quick-start-instructions:

```
$ sudo curl -L https://github.com/dhiltgen/docker-machine-kvm/releases/download/v0.7.0/docker-machine-driver-kvm -o /usr/local/bin/docker-machine-driver-kvm
$ sudo chmod +x /usr/local/bin/docker-machine-driver-kvm
# Install libvirt and qemu-kvm on your system, e.g.
$ sudo apt install libvirt-bin qemu-kvm
# Add yourself to the libvirtd group (may vary by linux distro) so you don't need to sudo
$ sudo usermod -a -G libvirtd $(whoami)
# Update your current session for the group change to take effect
$ newgrp libvirtd
```

#### xhyve driver

Expand Down
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,25 @@ $(GOPATH)/bin/gh-release:
go get github.com/progrium/gh-release

.PHONY: gendocs
gendocs: $(shell find cmd) out/openshift
gendocs: $(shell find cmd) pkg/minikube/cluster/assets.go
$(MKGOPATH)
cd $(GOPATH)/src/$(REPOPATH) && go run -ldflags="-X github.com/jimmidyson/minishift/pkg/version.version=$(shell cat VERSION)" gen_help_text.go

.PHONY: release
release: clean deploy/iso/minishift.iso test $(GOPATH)/bin/gh-release
GOOS=linux GOARCH=amd64 make out/minishift-linux-amd64
GOOS=darwin GOARCH=amd64 make out/minishift-darwin-amd64
release: clean deploy/iso/minishift.iso test $(GOPATH)/bin/gh-release cross
mkdir -p release
cp out/minishift-linux-amd64 out/minishift-darwin-amd64 release
cp out/minishift-*-amd64* release
cp deploy/iso/minishift.iso release/boot2docker.iso
gh-release checksums sha1
gh-release create jimmidyson/minishift $(VERSION)

.PHONY: cross
cross: out/openshift
GOOS=linux GOARCH=amd64 make out/minishift-linux-amd64
GOOS=darwin GOARCH=amd64 make out/minishift-darwin-amd64
GOOS=windows GOARCH=amd64 make out/minishift-windows-amd64
mv out/minishift-windows-amd64 out/minishift-windows-amd64.exe

.PHONY: clean
clean:
rm -rf $(GOPATH)
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,32 @@ Starting local OpenShift cluster...
Running pre-create checks...
Creating machine...
Starting local OpenShift cluster...
OpenShift is available at https://192.168.99.100:443.
OpenShift is available at https://192.168.99.100:8443.

$ oc run hello-minishift --image=gcr.io/google_containers/echoserver:1.4 --port=8080 --expose --service-overrides='{"apiVersion": "v1", "spec": {"type": "NodePort"}}'
service "hello-minishift" created
deploymentconfig "hello-minishift" created

$ oc run hello-minishift --image=gcr.io/google_containers/echoserver:1.4 --hostport=8000 --port=8080
deployment "hello-minishift" created
# We have now launched an echoserver pod but we have to wait until the pod is up before curling/accessing it
# via the exposed service.
# To check whether the pod is up and running we can use the following:
$ oc get pod
NAME READY STATUS RESTARTS AGE
hello-minishift-3383150820-vctvh 1/1 ContainerCreating 0 3s

# We can see that the pod is still being created from the ContainerCreating status
$ oc get pod
NAME READY STATUS RESTARTS AGE
hello-minishift-3383150820-vctvh 1/1 Running 0 13s

# We can see that the pod is now Running and we will now be able to curl it:
$ curl http://$(minishift ip):8000
$ curl $(minishift service hello-minikube --url)
CLIENT VALUES:
client_address=192.168.99.1
command=GET
real path=/
...

$ minishift stop
Stopping local OpenShift cluster...
Stopping "minishiftVM"...
Expand Down
40 changes: 40 additions & 0 deletions cmd/minikube/cmd/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright (C) 2016 Red Hat, Inc.
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 "github.com/docker/go-units"

// unitValue represents an int64 flag specified with units as a string.
type unitValue int64

func newUnitValue(v int64) *unitValue {
return (*unitValue)(&v)
}

func (u *unitValue) Set(s string) error {
v, err := units.FromHumanSize(s)
*u = unitValue(v)
return err
}

func (u *unitValue) Type() string {
return "unit"
}

func (u *unitValue) String() string {
return units.HumanSize(float64(*u))
}
39 changes: 19 additions & 20 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ package cmd
import (
"fmt"
"os"
"strconv"
"strings"

"github.com/docker/go-units"
"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/host"
"github.com/golang/glog"
Expand All @@ -36,6 +38,7 @@ var (
minikubeISO string
memory int
cpus int
disk = newUnitValue(20 * units.GB)
vmDriver string
)

Expand All @@ -57,9 +60,12 @@ func runStart(cmd *cobra.Command, args []string) {
MinikubeISO: minikubeISO,
Memory: memory,
CPUs: cpus,
DiskSize: int(*disk / units.MB),
VMDriver: vmDriver,
}

fmt.Println(config.DiskSize)

var host *host.Host
start := func() (err error) {
host, err = cluster.StartHost(api, config)
Expand Down Expand Up @@ -91,38 +97,33 @@ func runStart(cmd *cobra.Command, args []string) {
glog.Errorln("Error connecting to cluster: ", err)
}
kubeHost = strings.Replace(kubeHost, "tcp://", "https://", -1)
kubeHost = strings.Replace(kubeHost, ":2376", ":443", -1)
kubeHost = strings.Replace(kubeHost, ":2376", ":"+strconv.Itoa(constants.APIServerPort), -1)
fmt.Printf("OpenShift is available at %s.\n", kubeHost)

// setup kubeconfig
name := constants.MinikubeContext
certAuth := constants.MakeMiniPath("apiserver.crt")
clientCert := constants.MakeMiniPath("apiserver.crt")
clientKey := constants.MakeMiniPath("apiserver.key")
if active, err := setupKubeconfig(name, kubeHost, certAuth, clientCert, clientKey); err != nil {
if err := setupKubeconfig(name, kubeHost, certAuth, clientCert, clientKey); err != nil {
glog.Errorln("Error setting up kubeconfig: ", err)
os.Exit(1)
} else if !active {
fmt.Println("Run these commands to use the cluster: ")
fmt.Printf("oc config use-context %s\n", name)
fmt.Println("oc login --username=admin --password=admin --insecure-skip-tls-verify")
} else {
fmt.Println("oc is now configured to use the cluster.")
fmt.Println("Run this command to login: ")
fmt.Println("oc login --username=admin --password=admin --insecure-skip-tls-verify")
}
fmt.Println("oc is now configured to use the cluster.")
fmt.Println("Run this command to use the cluster: ")
fmt.Println("oc login --username=admin --password=admin --insecure-skip-tls-verify")
}

// setupKubeconfig reads config from disk, adds the minikube settings, and writes it back.
// activeContext is true when minikube is the CurrentContext
// If no CurrentContext is set, the given name will be used.
func setupKubeconfig(name, server, certAuth, cliCert, cliKey string) (activeContext bool, err error) {
func setupKubeconfig(name, server, certAuth, cliCert, cliKey string) error {
configFile := constants.KubeconfigPath

// read existing config or create new if does not exist
config, err := kubeconfig.ReadConfigOrNew(configFile)
if err != nil {
return false, err
return err
}

clusterName := name
Expand All @@ -145,24 +146,22 @@ func setupKubeconfig(name, server, certAuth, cliCert, cliKey string) (activeCont
context.AuthInfo = userName
config.Contexts[contextName] = context

// set current context to minikube if unset
if len(config.CurrentContext) == 0 {
config.CurrentContext = contextName
}
// Always set current context to minikube.
config.CurrentContext = contextName

// write back to disk
if err := kubeconfig.WriteConfig(config, configFile); err != nil {
return false, err
return err
}

// activeContext if current matches name
return name == config.CurrentContext, nil
return nil
}

func init() {
startCmd.Flags().StringVarP(&minikubeISO, "iso-url", "", constants.DefaultIsoUrl, "Location of the minishift iso")
startCmd.Flags().StringVarP(&vmDriver, "vm-driver", "", constants.DefaultVMDriver, fmt.Sprintf("VM driver is one of: %v", constants.SupportedVMDrivers))
startCmd.Flags().IntVarP(&memory, "memory", "", constants.DefaultMemory, "Amount of RAM allocated to the minishift VM")
startCmd.Flags().IntVarP(&cpus, "cpus", "", constants.DefaultCPUS, "Number of CPUs allocated to the minishift VM")
diskFlag := startCmd.Flags().VarPF(disk, "disk-size", "", "Disk size allocated to the minishift VM (format: <number>[<unit>], where unit = b, k, m or g)")
diskFlag.DefValue = constants.DefaultDiskSize
RootCmd.AddCommand(startCmd)
}
1 change: 1 addition & 0 deletions docs/minishift_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ minishift start

```
--cpus=1: Number of CPUs allocated to the minishift VM
--disk-size=20g: Disk size allocated to the minishift VM (format: <number>[<unit>], where unit = b, k, m or g)
--iso-url="https://github.com/jimmidyson/minishift/releases/download/v0.1.1/boot2docker.iso": Location of the minishift iso
--memory=1024: Amount of RAM allocated to the minishift VM
--vm-driver="kvm": VM driver is one of: [virtualbox kvm]
Expand Down
11 changes: 10 additions & 1 deletion pkg/minikube/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ type MachineConfig struct {
MinikubeISO string
Memory int
CPUs int
DiskSize int
VMDriver string
}

Expand Down Expand Up @@ -259,6 +260,7 @@ func createHost(api libmachine.API, config MachineConfig) (*host.Host, error) {
d.Boot2DockerURL = config.MinikubeISO
d.Memory = config.Memory
d.CPU = config.CPUs
d.DiskSize = int(config.DiskSize)
driver = d
case "vmwarefusion":
driver = createVMwareFusionHost(config)
Expand Down Expand Up @@ -420,7 +422,14 @@ func getServicePortFromServiceGetter(services serviceGetter, service string) (in
if err != nil {
return 0, fmt.Errorf("Error getting %s service: %s", service, err)
}
return int(svc.Spec.Ports[0].NodePort), nil
nodePort := 0
if len(svc.Spec.Ports) > 0 {
nodePort = int(svc.Spec.Ports[0].NodePort)
}
if nodePort == 0 {
return 0, fmt.Errorf("Service %s does not have a node port. To have one assigned automatically, the service type must be NodePort or LoadBalancer, but this service is of type %s.", service, svc.Spec.Type)
}
return nodePort, nil
}

func getKubernetesServicesWithNamespace(namespace string) (serviceGetter, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/cluster/cluster_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ func createXhyveHost(config MachineConfig) *xhyveDriver {
CPU: config.CPUs,
Boot2DockerURL: config.MinikubeISO,
BootCmd: "loglevel=3 user=docker console=ttyS0 console=tty0 noembed nomodeset norestore waitusb=10 base host=boot2docker",
DiskSize: 20000,
DiskSize: int64(config.DiskSize),
}
}
2 changes: 1 addition & 1 deletion pkg/minikube/cluster/cluster_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func createKVMHost(config MachineConfig) *kvmDriver {
Network: "default",
PrivateNetwork: "docker-machines",
Boot2DockerURL: config.MinikubeISO,
DiskSize: 20000,
DiskSize: config.DiskSize,
DiskPath: filepath.Join(constants.Minipath, "machines", constants.MachineName, fmt.Sprintf("%s.img", constants.MachineName)),
ISO: filepath.Join(constants.Minipath, "machines", constants.MachineName, "boot2docker.iso"),
CacheMode: "default",
Expand Down
11 changes: 11 additions & 0 deletions pkg/minikube/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,17 @@ func TestGetDashboardURL(t *testing.T) {

}

func TestGetServiceURLWithoutNodePort(t *testing.T) {
mockServiceGetter := NewMockServiceGetter()
mockDashboardService := api.Service{}
mockServiceGetter.services["mock-service"] = mockDashboardService

_, err := getServicePortFromServiceGetter(mockServiceGetter, "mock-service")
if err == nil {
t.Fatalf("Expected error getting service with no node port")
}
}

func TestUpdate(t *testing.T) {
s, _ := tests.NewSSHServer()
port, err := s.Start()
Expand Down
6 changes: 3 additions & 3 deletions pkg/minikube/cluster/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ var stopCommand = "sudo killall openshift | true"
var startCommandFmtStr = `
# Run with nohup so it stays up. Redirect logs to useful places.
cd /var/lib/minishift;
PATH=/usr/local/sbin:$PATH nohup sudo /usr/local/bin/openshift start --listen=https://0.0.0.0:443 > %s 2> %s < /dev/null &
until $(curl --output /dev/null --silent --fail -k https://localhost/healthz/ready); do
sudo sh -c 'PATH=/usr/local/sbin:$PATH nohup sudo /usr/local/bin/openshift start --listen=https://0.0.0.0:%d> %s 2> %s < /dev/null &'
until $(curl --output /dev/null --silent --fail -k https://localhost:%d/healthz/ready); do
printf '.'
sleep 1
done;
Expand All @@ -39,5 +39,5 @@ sudo /usr/local/bin/openshift admin policy add-cluster-role-to-user cluster-admi
var logsCommand = fmt.Sprintf("tail -n +1 %s %s", constants.RemoteOpenShiftErrPath, constants.RemoteOpenShiftOutPath)

func GetStartCommand() string {
return fmt.Sprintf(startCommandFmtStr, constants.RemoteOpenShiftErrPath, constants.RemoteOpenShiftOutPath)
return fmt.Sprintf(startCommandFmtStr, constants.APIServerPort, constants.RemoteOpenShiftErrPath, constants.RemoteOpenShiftOutPath, constants.APIServerPort)
}
12 changes: 8 additions & 4 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import (
// MachineName is the name to use for the VM.
const MachineName = "minishiftVM"

// APIServerPort is the port that the API server should listen on.
const APIServerPort = 8443

// Fix for windows
var Minipath = filepath.Join(homedir.HomeDir(), ".minishift")

Expand All @@ -49,15 +52,16 @@ var LogFlags = [...]string{
}

const (
DefaultMemory = 1024
DefaultCPUS = 1
DefaultMemory = 1024
DefaultCPUS = 1
DefaultDiskSize = "20g"
)

var DefaultIsoUrl = "https://github.com/jimmidyson/minishift/releases/download/v" + version.GetVersion() + "/boot2docker.iso"

const (
RemoteOpenShiftErrPath = "/var/log/openshift.err"
RemoteOpenShiftOutPath = "/var/log/openshift.out"
RemoteOpenShiftErrPath = "/var/lib/minishift/openshift.err"
RemoteOpenShiftOutPath = "/var/lib/minishift/openshift.out"
)

var ConfigFilePath = MakeMiniPath("config")
4 changes: 3 additions & 1 deletion pkg/minikube/kubeconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strconv"
"testing"

"github.com/jimmidyson/minishift/pkg/minikube/constants"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
)

Expand Down Expand Up @@ -101,7 +103,7 @@ func minikubeConfig(config *api.Config) {
// cluster
clusterName := "minikube"
cluster := api.NewCluster()
cluster.Server = "https://192.168.99.100:443"
cluster.Server = "https://192.168.99.100:" + strconv.Itoa(constants.APIServerPort)
cluster.CertificateAuthority = "/home/tux/.minikube/apiserver.crt"
config.Clusters[clusterName] = cluster

Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func getLatestVersionFromGitHub(githubOwner, githubRepo string) (semver.Version,
return semver.Version{}, err
}
defer resp.Body.Close()
latestVersionString := release.Name
latestVersionString := release.TagName
if latestVersionString != nil {
return semver.Make(strings.TrimPrefix(*latestVersionString, "v"))

Expand Down
Loading

0 comments on commit be31e3e

Please sign in to comment.