提交 a4606583 编写于 作者: A Aaron Prindle 提交者: dlorenc

remove all localkube references from code, change /var/lib/localkube to /var/lib/minikube

上级 236a86f0
......@@ -48,14 +48,12 @@ REPOPATH ?= $(ORG)/minikube
PYTHON := $(shell command -v python || echo "docker run --rm -it -v $(shell pwd):/minikube -w /minikube python python")
BUILD_OS := $(shell uname -s)
LOCALKUBE_VERSION := $(shell $(PYTHON) hack/get_k8s_version.py --k8s-version-only 2>&1)
TAG ?= $(LOCALKUBE_VERSION)
STORAGE_PROVISIONER_TAG := v1.8.1
# Set the version information for the Kubernetes servers, and build localkube statically
# Set the version information for the Kubernetes servers
K8S_VERSION_LDFLAGS := $(shell $(PYTHON) hack/get_k8s_version.py 2>&1)
MINIKUBE_LDFLAGS := -X k8s.io/minikube/pkg/version.version=$(VERSION) -X k8s.io/minikube/pkg/version.isoVersion=$(ISO_VERSION) -X k8s.io/minikube/pkg/version.isoPath=$(ISO_BUCKET)
LOCALKUBE_LDFLAGS := "$(K8S_VERSION_LDFLAGS) $(MINIKUBE_LDFLAGS) -s -w"
PROVISIONER_LDFLAGS := "$(K8S_VERSION_LDFLAGS) $(MINIKUBE_LDFLAGS) -s -w"
MAKEDEPEND := GOPATH=$(GOPATH) ./makedepend.sh
......@@ -292,7 +290,7 @@ out/storage-provisioner.d:
-include out/storage-provisioner.d
out/storage-provisioner:
GOOS=linux go build -o $(BUILD_DIR)/storage-provisioner -ldflags=$(LOCALKUBE_LDFLAGS) cmd/storage-provisioner/main.go
GOOS=linux go build -o $(BUILD_DIR)/storage-provisioner -ldflags=$(PROVISIONER_LDFLAGS) cmd/storage-provisioner/main.go
.PHONY: storage-provisioner-image
storage-provisioner-image: out/storage-provisioner
......
/*
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.
*/
package cmd
import (
"os"
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/kubernetes_versions"
)
// getK8sVersionsCmd represents the ip command
var getK8sVersionsCmd = &cobra.Command{
Use: "get-k8s-versions",
Short: "Gets the list of Kubernetes versions available for minikube when using the localkube bootstrapper",
Long: `Gets the list of Kubernetes versions available for minikube when using the localkube bootstrapper.`,
Run: func(cmd *cobra.Command, args []string) {
kubernetes_versions.PrintKubernetesVersionsFromGCS(os.Stdout)
},
}
func init() {
RootCmd.AddCommand(getK8sVersionsCmd)
}
......@@ -393,13 +393,12 @@ func init() {
startCmd.Flags().String(NFSSharesRoot, "/nfsshares", "Where to root the NFS Shares (defaults to /nfsshares, only supported with hyperkit now)")
startCmd.Flags().StringArrayVar(&dockerEnv, "docker-env", nil, "Environment variables to pass to the Docker daemon. (format: key=value)")
startCmd.Flags().StringArrayVar(&dockerOpt, "docker-opt", nil, "Specify arbitrary flags to pass to the Docker daemon. (format: key=value)")
startCmd.Flags().String(apiServerName, constants.APIServerName, "The apiserver name which is used in the generated certificate for localkube/kubernetes. This can be used if you want to make the apiserver available from outside the machine")
startCmd.Flags().StringArrayVar(&apiServerNames, "apiserver-names", nil, "A set of apiserver names which are used in the generated certificate for localkube/kubernetes. This can be used if you want to make the apiserver available from outside the machine")
startCmd.Flags().IPSliceVar(&apiServerIPs, "apiserver-ips", nil, "A set of apiserver IP Addresses which are used in the generated certificate for localkube/kubernetes. This can be used if you want to make the apiserver available from outside the machine")
startCmd.Flags().String(apiServerName, constants.APIServerName, "The apiserver name which is used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine")
startCmd.Flags().StringArrayVar(&apiServerNames, "apiserver-names", nil, "A set of apiserver names which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine")
startCmd.Flags().IPSliceVar(&apiServerIPs, "apiserver-ips", nil, "A set of apiserver IP Addresses which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine")
startCmd.Flags().String(dnsDomain, constants.ClusterDNSDomain, "The cluster dns domain name used in the kubernetes cluster")
startCmd.Flags().StringSliceVar(&insecureRegistry, "insecure-registry", nil, "Insecure Docker registries to pass to the Docker daemon. The default service CIDR range will automatically be added.")
startCmd.Flags().StringSliceVar(&registryMirror, "registry-mirror", nil, "Registry mirrors to pass to the Docker daemon")
startCmd.Flags().String(kubernetesVersion, constants.DefaultKubernetesVersion, "The kubernetes version that the minikube VM will use (ex: v1.2.3) \n OR a URI which contains a localkube binary (ex: https://storage.googleapis.com/minikube/k8sReleases/v1.3.0/localkube-linux-amd64)")
startCmd.Flags().String(containerRuntime, "", "The container runtime to be used")
startCmd.Flags().String(networkPlugin, "", "The name of the network plugin")
startCmd.Flags().String(featureGates, "", "A set of key=value pairs that describe feature gates for alpha/experimental features.")
......
......@@ -28,7 +28,7 @@ spec:
image: k8s.gcr.io/kube-addon-manager:v8.6
env:
- name: KUBECONFIG
value: /var/lib/localkube/kubeconfig
value: /var/lib/minikube/kubeconfig
imagePullPolicy: IfNotPresent
resources:
requests:
......@@ -38,7 +38,7 @@ spec:
- mountPath: /etc/kubernetes/
name: addons
readOnly: true
- mountPath: /var/lib/localkube/
- mountPath: /var/lib/minikube/
name: kubeconfig
readOnly: true
volumes:
......@@ -46,5 +46,5 @@ spec:
path: /etc/kubernetes/
name: addons
- hostPath:
path: /var/lib/localkube/
path: /var/lib/minikube/
name: kubeconfig
......@@ -178,9 +178,9 @@ if [ -n "$BOOT2DOCKER_DATA" ]; then
chown -R docker:docker /home/docker/.ssh
rm -f '/home/docker/boot2docker, please format-me'
mkdir -p /mnt/$PARTNAME/var/lib/localkube
mkdir /var/lib/localkube
mount --bind /mnt/$PARTNAME/var/lib/localkube /var/lib/localkube
mkdir -p /mnt/$PARTNAME/var/lib/minikube
mkdir /var/lib/minikube
mount --bind /mnt/$PARTNAME/var/lib/minikube /var/lib/minikube
mkdir -p /mnt/$PARTNAME/var/lib/minishift
mkdir /var/lib/minishift
......
......@@ -27,7 +27,6 @@ import (
"testing"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/kubernetes_versions"
"k8s.io/minikube/pkg/minikube/notify"
"k8s.io/minikube/pkg/util"
)
......@@ -70,34 +69,3 @@ func TestReleasesJson(t *testing.T) {
}
}
}
func TestK8sReleases(t *testing.T) {
releases, err := kubernetes_versions.GetK8sVersionsFromURL(constants.KubernetesVersionGCSURL)
if err != nil {
t.Fatalf("Error getting k8s_releases.json: %s", err)
}
for _, r := range releases {
fmt.Printf("Checking release: %s\n", r.Version)
url, err := util.GetLocalkubeDownloadURL(r.Version, constants.LocalkubeLinuxFilename)
if err != nil {
t.Errorf("Error getting URL for %s. Error: %s", r.Version, err)
continue
}
shaURL := fmt.Sprintf("%s%s", url, constants.ShaSuffix)
expectedSha, err := util.ParseSHAFromURL(shaURL)
if err != nil {
t.Errorf("Error retrieving SHA for %s. Error: %s", r.Version, err)
continue
}
actualSha, err := getShaFromURL(url)
if err != nil {
t.Errorf("Error calculating SHA for %s. Error: %s", r.Version, err)
continue
}
if expectedSha != actualSha {
t.Errorf("ERROR: SHA does not match for version %s. Expected %s, got %s.", r.Version, expectedSha, actualSha)
continue
}
}
}
#!/bin/bash
# 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.
# This script runs the integration tests on a Linux machine for the Virtualbox Driver
# The script expects the following env variables:
# MINIKUBE_LOCATION: GIT_COMMIT from upstream build.
# COMMIT: Actual commit ID from upstream build
# EXTRA_BUILD_ARGS (optional): Extra args to be passed into the minikube integrations tests
# access_token: The Github API access token. Injected by the Jenkins credential provider.
set -e
result=0
JOB_NAME="Linux-Container"
CID="$(docker run -d -p 127.0.0.1:4321:4321 --privileged gcr.io/k8s-minikube/localkube-dind-image-devshell:$COMMIT /start.sh)"
kubectl config set-cluster minikube --server=http://127.0.0.1:4321
kubectl config set-context minikube --cluster=minikube
kubectl config use-context minikube
# this for loop waits until kubectl can access the api server that minikube has created
KUBECTL_UP="false"
set +e
for i in {1..150} # timeout for 5 minutes
do
kubectl get po
if [ $? -ne 1 ]; then
KUBECTL_UP="true"
echo "INIT SUCCESS: kubectl could reached api-server in allotted time"
break
fi
sleep 2
done
if [ "$KUBECTL_UP" != "true" ]; then
echo "INIT FAILURE: kubectl could not reach api-server in allotted time"
result=1
fi
# kubectl commands are now able to interact with minikube cluster
set -e
docker stop $CID
docker rm $CID
if [[ $result -eq 0 ]]; then
status="success"
else
status="failure"
source print-debug-info.sh
fi
set +x
target_url="https://storage.googleapis.com/minikube-builds/logs/${MINIKUBE_LOCATION}/${JOB_NAME}.txt"
curl "https://api.github.com/repos/kubernetes/minikube/statuses/${COMMIT}?access_token=$access_token" \
-H "Content-Type: application/json" \
-X POST \
-d "{\"state\": \"$status\", \"description\": \"Jenkins\", \"target_url\": \"$target_url\", \"context\": \"${JOB_NAME}\"}"
set -x
exit $result
......@@ -26,10 +26,6 @@ ${SUDO_PREFIX} cat $KUBECONFIG
kubectl get pods --all-namespaces
kubectl cluster-info dump
# For the none driver
journalctl -u localkube -n 500
${SUDO_PREFIX}cat $KUBECONFIG
cat $HOME/.kube/config
echo $PATH
......
......@@ -120,8 +120,6 @@ FILES_TO_UPLOAD=(
"minikube_${DEB_VERSION}.deb"
'docker-machine-driver-kvm2'
'docker-machine-driver-hyperkit'
'localkube'
'localkube.sha256'
)
for UPLOAD in "${FILES_TO_UPLOAD[@]}"
......
......@@ -29,7 +29,6 @@ import (
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/net"
pkgdrivers "k8s.io/minikube/pkg/drivers"
"k8s.io/minikube/pkg/minikube/constants"
)
const driverName = "none"
......@@ -37,7 +36,7 @@ const dockerstopcmd = `docker kill $(docker ps -a --filter="name=k8s_" --format=
var dockerkillcmd = fmt.Sprintf(`docker rm $(%s)`, dockerstopcmd)
// none Driver is a driver designed to run localkube w/o a VM
// none Driver is a driver designed to run kubeadm w/o a VM
type Driver struct {
*drivers.BaseDriver
*pkgdrivers.CommonDriver
......@@ -101,16 +100,8 @@ func (d *Driver) GetURL() (string, error) {
}
func (d *Driver) GetState() (state.State, error) {
var statuscmd = fmt.Sprintf("if [[ `systemctl` =~ -\\.mount ]] &>/dev/null; "+`then
sudo systemctl is-active kubelet localkube &>/dev/null && echo "Running" || echo "Stopped"
else
if ps $(cat %s) &>/dev/null; then
echo "Running"
else
echo "Stopped"
fi
fi
`, constants.LocalkubePIDPath)
var statuscmd = fmt.Sprintf(
`sudo systemctl is-active kubelet &>/dev/null && echo "Running" || echo "Stopped"`)
out, err := runCommand(statuscmd, true)
if err != nil {
......@@ -122,14 +113,14 @@ fi
} else if state.Stopped.String() == s {
return state.Stopped, nil
} else {
return state.None, fmt.Errorf("Error: Unrecognize output from GetLocalkubeStatus: %s", s)
return state.None, fmt.Errorf("Error: Unrecognize output from GetState: %s", s)
}
}
func (d *Driver) Kill() error {
for _, cmdStr := range [][]string{
{"systemctl", "stop", "localkube.service"},
{"rm", "-rf", "/var/lib/localkube"},
{"systemctl", "stop", "kubelet.service"},
{"rm", "-rf", "/var/lib/minikube"},
} {
cmd := exec.Command("sudo", cmdStr...)
if out, err := cmd.CombinedOutput(); err != nil {
......@@ -140,12 +131,10 @@ func (d *Driver) Kill() error {
}
func (d *Driver) Remove() error {
rmCmd := `for svc in "localkube" "kubelet"; do
sudo systemctl stop "$svc".service
done
rmCmd := `sudo systemctl stop kubelet.service
sudo rm -rf /data/minikube
sudo rm -rf /etc/kubernetes/manifests
sudo rm -rf /var/lib/localkube || true`
sudo rm -rf /var/lib/minikube || true`
for _, cmdStr := range []string{rmCmd, dockerkillcmd} {
if out, err := runCommand(cmdStr, true); err != nil {
......@@ -157,11 +146,10 @@ func (d *Driver) Remove() error {
}
func (d *Driver) Restart() error {
restartCmd := `for svc in "localkube" "kubelet"; do
if systemctl is-active $svc.service; then
sudo systemctl restart "$svc".service
fi
done`
restartCmd := `
if systemctl is-active kubelet.service; then
sudo systemctl restart kubelet.service
fi`
cmd := exec.Command(restartCmd)
if err := cmd.Start(); err != nil {
......@@ -184,14 +172,12 @@ func (d *Driver) Start() error {
}
func (d *Driver) Stop() error {
var stopcmd = fmt.Sprintf("if [[ `systemctl` =~ -\\.mount ]] &>/dev/null; "+`then
for svc in "localkube" "kubelet"; do
var stopcmd = fmt.Sprintf("if [[ `systemctl` =~ -\\.mount ]] &>/dev/null; " + `then
for svc in "kubelet"; do
sudo systemctl stop "$svc".service || true
done
else
sudo kill $(cat %s)
fi
`, constants.LocalkubePIDPath)
`)
_, err := runCommand(stopcmd, false)
if err != nil {
return err
......
......@@ -34,14 +34,11 @@ type Bootstrapper interface {
}
const (
BootstrapperTypeLocalkube = "localkube"
BootstrapperTypeKubeadm = "kubeadm"
BootstrapperTypeKubeadm = "kubeadm"
)
func GetCachedImageList(version string, bootstrapper string) []string {
switch bootstrapper {
case BootstrapperTypeLocalkube:
return constants.LocalkubeCachedImages
case BootstrapperTypeKubeadm:
return constants.GetKubeadmCachedImages(version)
default:
......
......@@ -82,7 +82,7 @@ func SetupCerts(cmd CommandRunner, k8s config.KubernetesConfig) error {
}
kubeCfgFile := assets.NewMemoryAsset(data,
util.DefaultLocalkubeDirectory, "kubeconfig", "0644")
util.DefaultMinikubeDirectory, "kubeconfig", "0644")
copyableFiles = append(copyableFiles, kubeCfgFile)
for _, f := range copyableFiles {
......
......@@ -142,7 +142,6 @@ func (k *KubeadmBootstrapper) StartCluster(k8s config.KubernetesConfig) error {
return nil
}
//TODO(r2d4): Split out into shared function between localkube and kubeadm
func addAddons(files *[]assets.CopyableFile) error {
// add addons to file list
// custom addons
......
......@@ -45,7 +45,7 @@ api:
bindPort: 8443
controlPlaneEndpoint: localhost
kubernetesVersion: v1.10.0
certificatesDir: /var/lib/localkube/certs/
certificatesDir: /var/lib/minikube/certs/
networking:
serviceSubnet: 10.96.0.0/12
etcd:
......@@ -87,7 +87,7 @@ api:
bindPort: 8443
controlPlaneEndpoint: localhost
kubernetesVersion: v1.10.0-alpha.0
certificatesDir: /var/lib/localkube/certs/
certificatesDir: /var/lib/minikube/certs/
networking:
serviceSubnet: 10.96.0.0/12
etcd:
......@@ -129,7 +129,7 @@ api:
bindPort: 8443
controlPlaneEndpoint: localhost
kubernetesVersion: v1.10.0-alpha.0
certificatesDir: /var/lib/localkube/certs/
certificatesDir: /var/lib/minikube/certs/
networking:
serviceSubnet: 10.96.0.0/12
etcd:
......@@ -157,7 +157,7 @@ api:
bindPort: 8443
controlPlaneEndpoint: localhost
kubernetesVersion: v1.10.0-alpha.0
certificatesDir: /var/lib/localkube/certs/
certificatesDir: /var/lib/minikube/certs/
networking:
serviceSubnet: 10.96.0.0/12
etcd:
......@@ -195,7 +195,7 @@ api:
bindPort: 8443
controlPlaneEndpoint: localhost
kubernetesVersion: v1.10.0-alpha.0
certificatesDir: /var/lib/localkube/certs/
certificatesDir: /var/lib/minikube/certs/
networking:
serviceSubnet: 10.96.0.0/12
etcd:
......
......@@ -97,12 +97,6 @@ func MakeMiniPath(fileName ...string) string {
var MountProcessFileName = ".mount-process"
// Only pass along these flags to localkube.
var LogFlags = [...]string{
"v",
"vmodule",
}
const (
DefaultKeepContext = false
ShaSuffix = ".sha256"
......@@ -136,9 +130,6 @@ func GetProfileFile(profile string) string {
return filepath.Join(GetMinipath(), "profiles", profile, "config.json")
}
var LocalkubeDownloadURLPrefix = "https://storage.googleapis.com/minikube/k8sReleases/"
var LocalkubeLinuxFilename = "localkube-linux-amd64"
// DockerAPIVersion is the API version implemented by Docker running in the minikube VM.
const DockerAPIVersion = "1.35"
......@@ -147,12 +138,6 @@ const ReportingURL = "https://clouderrorreporting.googleapis.com/v1beta1/project
const AddonsPath = "/etc/kubernetes/addons"
const FilesPath = "/files"
const (
RemoteLocalKubeErrPath = "/var/lib/localkube/localkube.err"
RemoteLocalKubeOutPath = "/var/lib/localkube/localkube.out"
LocalkubePIDPath = "/var/run/localkube.pid"
)
const (
KubeletServiceFile = "/lib/systemd/system/kubelet.service"
KubeletSystemdConfFile = "/etc/systemd/system/kubelet.service.d/10-kubeadm.conf"
......@@ -177,12 +162,6 @@ var Preflights = []string{
"CRI",
}
const (
LocalkubeServicePath = "/etc/systemd/system/localkube.service"
LocalkubeRunning = "active"
LocalkubeStopped = "inactive"
)
const (
DefaultUfsPort = "5640"
DefaultUfsDebugLvl = 0
......@@ -203,25 +182,6 @@ const IsMinikubeChildProcess = "IS_MINIKUBE_CHILD_PROCESS"
const DriverNone = "none"
const FileScheme = "file"
var LocalkubeCachedImages = []string{
// Dashboard
"k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.1",
// DNS
"k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.5",
"k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.5",
"k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.5",
// Addon Manager
"k8s.gcr.io/kube-addon-manager:v6.5",
// Pause
"k8s.gcr.io/pause-amd64:3.0",
//Storage Provisioner
"gcr.io/k8s-minikube/storage-provisioner:v1.8.0",
}
func GetKubeadmCachedImages(kubernetesVersionStr string) []string {
var images = []string{
......
/*
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.
*/
package kubernetes_versions
import (
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"k8s.io/minikube/pkg/minikube/constants"
"github.com/golang/glog"
"github.com/pkg/errors"
)
func PrintKubernetesVersionsFromGCS(output io.Writer) {
PrintKubernetesVersions(output, constants.KubernetesVersionGCSURL)
}
func PrintKubernetesVersions(output io.Writer, url string) {
k8sVersions, err := GetK8sVersionsFromURL(url)
if err != nil {
glog.Errorln(err)
return
}
fmt.Fprint(output, "The following Kubernetes versions are available when using the localkube bootstrapper: \n")
for _, k8sVersion := range k8sVersions {
fmt.Fprintf(output, "\t- %s\n", k8sVersion.Version)
}
}
type K8sRelease struct {
Version string
}
type K8sReleases []K8sRelease
func getJson(url string, target *K8sReleases) error {
r, err := http.Get(url)
if err != nil {
return errors.Wrapf(err, "Error getting json from url: %s via http", url)
}
defer r.Body.Close()
return json.NewDecoder(r.Body).Decode(target)
}
var cachedK8sVersions = make(K8sReleases, 0)
func GetK8sVersionsFromURL(url string) (K8sReleases, error) {
if len(cachedK8sVersions) != 0 {
return cachedK8sVersions, nil
}
var k8sVersions K8sReleases
if err := getJson(url, &k8sVersions); err != nil {
return K8sReleases{}, errors.Wrapf(err, "Error getting json via http with url: %s", url)
}
if len(k8sVersions) == 0 {
return K8sReleases{}, errors.Errorf("There were no json k8s Releases at the url specified: %s", url)
}
cachedK8sVersions = k8sVersions
return k8sVersions, nil
}
func IsValidLocalkubeVersion(v string, url string) (bool, error) {
if strings.HasPrefix(v, "file://") || strings.HasPrefix(v, "http") {
return true, nil
}
k8sReleases, err := GetK8sVersionsFromURL(url)
glog.Infoln(k8sReleases)
if err != nil {
return false, errors.Wrap(err, "Error getting the localkube versions")
}
isValidVersion := false
for _, version := range k8sReleases {
if version.Version == v {
isValidVersion = true
break
}
}
return isValidVersion, nil
}
/*
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.
*/
package kubernetes_versions
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
type URLHandlerCorrect struct {
K8sReleases K8sReleases
}
func (h *URLHandlerCorrect) ServeHTTP(w http.ResponseWriter, r *http.Request) {
b, err := json.Marshal(h.K8sReleases)
if err != nil {
fmt.Println(err)
return
}
w.Header().Set("Content-Type", "application/javascript")
fmt.Fprintf(w, string(b))
}
func TestGetK8sVersionsFromURLCorrect(t *testing.T) {
cachedK8sVersions = nil
// test that the version is correctly parsed if returned if valid JSON is returned the url endpoint
version0 := "0.0.0"
version1 := "1.0.0"
handler := &URLHandlerCorrect{
K8sReleases: []K8sRelease{{Version: version0}, {Version: version1}},
}
server := httptest.NewServer(handler)
defer server.Close()
k8sVersions, err := GetK8sVersionsFromURL(server.URL)
if err != nil {
t.Fatalf(err.Error())
}
if len(k8sVersions) != 2 { // TODO(aprindle) change to len(handler....)
//Check values here as well? Write eq method?
t.Fatalf("Expected %d kubernetes versions from URL. Instead there were: %d", 2, len(k8sVersions))
}
}
func TestIsValidLocalkubeVersion(t *testing.T) {
version0 := "0.0.0"
version1 := "1.0.0"
correctHandler := &URLHandlerCorrect{
K8sReleases: []K8sRelease{{Version: version0}, {Version: version1}},
}
var tests = []struct {
description string
version string
handler http.Handler
shouldErr bool
isValidVersion bool
}{
{
description: "correct version",
version: version0,
handler: correctHandler,
isValidVersion: true,
},
{
description: "bad version",
version: "2.0.0",
handler: correctHandler,
isValidVersion: false,
},
}
for _, test := range tests {
test := test
t.Run(test.description, func(t *testing.T) {
cachedK8sVersions = nil
server := httptest.NewServer(test.handler)
defer server.Close()
isValid, err := IsValidLocalkubeVersion(test.version, server.URL)
if err != nil && !test.shouldErr {
t.Errorf("Got unexpected error: %v", err)
return
}
if err == nil && test.shouldErr {
t.Error("Got no error but expected an error")
return
}
if isValid != test.isValidVersion {
t.Errorf("Expected version to be %t, but was %t", test.isValidVersion, isValid)
}
})
}
}
type URLHandlerNone struct{}
func (h *URLHandlerNone) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
func TestGetK8sVersionsFromURLNone(t *testing.T) {
cachedK8sVersions = nil
// test that an error is returned if nothing is returned at the url endpoint
handler := &URLHandlerNone{}
server := httptest.NewServer(handler)
_, err := GetK8sVersionsFromURL(server.URL)
if err == nil {
t.Fatalf("No kubernetes versions were returned from URL but no error was thrown")
}
}
type URLHandlerMalformed struct{}
func (h *URLHandlerMalformed) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/javascript")
fmt.Fprintf(w, "Malformed JSON")
}
func TestGetK8sVersionsFromURLMalformed(t *testing.T) {
cachedK8sVersions = nil
// test that an error is returned if malformed JSON is at the url endpoint
handler := &URLHandlerMalformed{}
server := httptest.NewServer(handler)
_, err := GetK8sVersionsFromURL(server.URL)
if err == nil {
t.Fatalf("Malformed version value was returned from URL but no error was thrown")
}
}
func TestPrintKubernetesVersions(t *testing.T) {
cachedK8sVersions = nil
// test that no kubernetes version text is printed if there are no versions being served
// TODO(aprindle) or should this be an error?!?!
handlerNone := &URLHandlerNone{}
server := httptest.NewServer(handlerNone)
var outputBuffer bytes.Buffer
PrintKubernetesVersions(&outputBuffer, server.URL)
if len(outputBuffer.String()) != 0 {
t.Fatalf("Expected PrintKubernetesVersions to not output text as there are no versioned served at the current URL but output was [%s]", outputBuffer.String())
}
// test that update text is printed if the latest version is greater than the current version
// k8sVersionsFromURL = "100.0.0-dev"
version0 := "0.0.0"
version1 := "1.0.0"
handlerCorrect := &URLHandlerCorrect{
K8sReleases: []K8sRelease{{Version: version0}, {Version: version1}},
}
server = httptest.NewServer(handlerCorrect)
PrintKubernetesVersions(&outputBuffer, server.URL)
if len(outputBuffer.String()) == 0 {
t.Fatalf("Expected PrintKubernetesVersion to output text as %d versions were served from URL but output was [%s]",
2, outputBuffer.String()) //TODO(aprindle) change the 2
}
}
......@@ -39,10 +39,6 @@ func MakeTempDir() string {
if err != nil {
log.Fatal(err)
}
err = os.MkdirAll(filepath.Join(tempDir, "cache", "localkube"), 0777)
if err != nil {
log.Fatal(err)
}
os.Setenv(constants.MinikubeHome, tempDir)
return constants.GetMinipath()
}
......@@ -22,14 +22,14 @@ import (
"github.com/pkg/errors"
)
// These constants are used by both minikube and localkube
// These constants are used by both minikube
const (
APIServerPort = 8443
DefaultLocalkubeDirectory = "/var/lib/localkube"
DefaultCertPath = DefaultLocalkubeDirectory + "/certs/"
DefaultKubeConfigPath = DefaultLocalkubeDirectory + "/kubeconfig"
DefaultDNSDomain = "cluster.local"
DefaultServiceCIDR = "10.96.0.0/12"
APIServerPort = 8443
DefaultMinikubeDirectory = "/var/lib/minikube"
DefaultCertPath = DefaultMinikubeDirectory + "/certs/"
DefaultKubeConfigPath = DefaultMinikubeDirectory + "/kubeconfig"
DefaultDNSDomain = "cluster.local"
DefaultServiceCIDR = "10.96.0.0/12"
)
var DefaultAdmissionControllers = []string{
......
......@@ -390,7 +390,7 @@ func tempFile(t *testing.T, data []byte) string {
return tmp.Name()
}
// minikubeConfig returns a config that reasonably approximates a localkube cluster
// minikubeConfig returns a k8s cluster config
func minikubeConfig(config *api.Config) {
// cluster
clusterName := "minikube"
......
......@@ -21,7 +21,6 @@ import (
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"os/user"
"path/filepath"
......@@ -29,13 +28,9 @@ import (
"strings"
"time"
"github.com/blang/semver"
units "github.com/docker/go-units"
"github.com/golang/glog"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/kubernetes_versions"
"k8s.io/minikube/pkg/version"
)
const (
......@@ -115,33 +110,6 @@ func RetryAfter(attempts int, callback func() error, d time.Duration) (err error
return m.ToError()
}
func GetLocalkubeDownloadURL(versionOrURL string, filename string) (string, error) {
urlObj, err := url.Parse(versionOrURL)
if err != nil {
return "", errors.Wrap(err, "Error parsing localkube download url")
}
if urlObj.IsAbs() {
// scheme was specified in input, is a valid URI.
// http.Get will catch unsupported schemes
return versionOrURL, nil
}
if !strings.HasPrefix(versionOrURL, "v") {
// no 'v' prefix in input, need to prepend it to version
versionOrURL = "v" + versionOrURL
}
isValidVersion, err := kubernetes_versions.IsValidLocalkubeVersion(versionOrURL, constants.KubernetesVersionGCSURL)
if err != nil {
return "", errors.Wrap(err, "Error getting valid localkube versions")
}
if !isValidVersion {
return "", errors.New("Not a valid localkube version to download")
}
if _, err = semver.Make(strings.TrimPrefix(versionOrURL, version.VersionPrefix)); err != nil {
return "", errors.Wrap(err, "Error creating semver version from localkube version input string")
}
return fmt.Sprintf("%s%s/%s", constants.LocalkubeDownloadURLPrefix, versionOrURL, filename), nil
}
func ParseSHAFromURL(url string) (string, error) {
r, err := http.Get(url)
if err != nil {
......
......@@ -23,7 +23,6 @@ import (
"testing"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/constants"
)
// Returns a function that will return n errors, then return successfully forever.
......@@ -92,29 +91,6 @@ type getTestArgs struct {
expectedError bool
}
func TestGetLocalkubeDownloadURL(t *testing.T) {
argsList := [...]getTestArgs{
{"v1.3.0",
"https://storage.googleapis.com/minikube/k8sReleases/v1.3.0/localkube-linux-amd64", false},
{"v1.3.3",
"https://storage.googleapis.com/minikube/k8sReleases/v1.3.3/localkube-linux-amd64", false},
{"http://www.example.com/my-localkube", "http://www.example.com/my-localkube", false},
{"abc", "", true},
{"1.2.3.4", "", true},
}
for _, args := range argsList {
url, err := GetLocalkubeDownloadURL(args.input, constants.LocalkubeLinuxFilename)
wasError := err != nil
if wasError != args.expectedError {
t.Errorf("GetLocalkubeDownloadURL Expected error was: %t, Actual Error was: %s",
args.expectedError, err)
}
if url != args.expected {
t.Errorf("GetLocalkubeDownloadURL: Expected %s, Actual: %s", args.expected, url)
}
}
}
var testSHAString = "test"
func TestParseSHAFromURL(t *testing.T) {
......
......@@ -22,7 +22,7 @@ import (
"github.com/blang/semver"
)
// The current version of the minikube and localkube
// The current version of the minikube
// This is a private field and should be set when compiling with --ldflags="-X k8s.io/minikube/pkg/version.version=vX.Y.Z"
const VersionPrefix = "v"
......
......@@ -88,7 +88,7 @@ func testPersistence(t *testing.T) {
"/var/lib/docker",
"/var/lib/cni",
"/var/lib/kubelet",
"/var/lib/localkube",
"/var/lib/minikube",
"/var/lib/rkt",
"/var/lib/boot2docker",
} {
......
// +build integration
// +build versioned
/*
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.
*/
package integration
import (
"fmt"
"testing"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/kubernetes_versions"
"k8s.io/minikube/test/integration/util"
)
func TestVersionedFunctional(t *testing.T) {
k8sVersions, err := kubernetes_versions.GetK8sVersionsFromURL(constants.KubernetesVersionGCSURL)
if err != nil {
t.Fatalf(err.Error())
}
var minikubeRunner util.MinikubeRunner
for _, version := range k8sVersions {
vArgs := fmt.Sprintf("%s --kubernetes-version %s", *args, version.Version)
minikubeRunner = NewMinikubeRunner(t)
minikubeRunner.EnsureRunning()
t.Run("Status", testClusterStatus)
t.Run("DNS", testClusterDNS)
t.Run("Addons", testAddons)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册