Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
e3fb420e
M
minikube
项目概览
Chu Peng 楚鹏
/
minikube
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
minikube
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
e3fb420e
编写于
5月 02, 2019
作者:
T
Thomas Strömberg
提交者:
GitHub
5月 02, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4193 from afbjorklund/kubectl2
Add new kubectl command
上级
b3f1eb8f
292f4ec4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
104 addition
and
9 deletion
+104
-9
cmd/minikube/cmd/kubectl.go
cmd/minikube/cmd/kubectl.go
+88
-0
pkg/minikube/bootstrapper/kubeadm/kubeadm.go
pkg/minikube/bootstrapper/kubeadm/kubeadm.go
+2
-1
pkg/minikube/constants/constants.go
pkg/minikube/constants/constants.go
+4
-4
pkg/minikube/machine/cache_binaries.go
pkg/minikube/machine/cache_binaries.go
+10
-4
未找到文件。
cmd/minikube/cmd/kubectl.go
0 → 100644
浏览文件 @
e3fb420e
/*
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
)
}
pkg/minikube/bootstrapper/kubeadm/kubeadm.go
浏览文件 @
e3fb420e
...
...
@@ -22,6 +22,7 @@ import (
"fmt"
"net"
"net/http"
"runtime"
"strings"
"time"
...
...
@@ -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
)
}
...
...
pkg/minikube/constants/constants.go
浏览文件 @
e3fb420e
...
...
@@ -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
...
...
pkg/minikube/machine/cache_binaries.go
浏览文件 @
e3fb420e
...
...
@@ -20,6 +20,7 @@ import (
"crypto"
"os"
"path"
"runtime"
"github.com/golang/glog"
"github.com/jimmidyson/go-download"
...
...
@@ -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
...
...
@@ -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
...
...
@@ -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
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录