Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
c6dbaf1c
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,体验更适合开发者的 AI 搜索 >>
提交
c6dbaf1c
编写于
7月 23, 2019
作者:
M
Medya Gh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
moving KubectlRunner to its own file
上级
aeaa5733
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
101 addition
and
74 deletion
+101
-74
test/integration/util/kubectl_runner.go
test/integration/util/kubectl_runner.go
+101
-0
test/integration/util/util.go
test/integration/util/util.go
+0
-74
未找到文件。
test/integration/util/kubectl_runner.go
0 → 100644
浏览文件 @
c6dbaf1c
/*
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
util
import
(
"bytes"
"encoding/json"
"fmt"
"math/rand"
"os/exec"
"testing"
"time"
commonutil
"k8s.io/minikube/pkg/util"
)
// KubectlRunner runs a command using kubectl
type
KubectlRunner
struct
{
T
*
testing
.
T
BinaryPath
string
}
// NewKubectlRunner creates a new KubectlRunner
func
NewKubectlRunner
(
t
*
testing
.
T
)
*
KubectlRunner
{
p
,
err
:=
exec
.
LookPath
(
kubectlBinary
)
if
err
!=
nil
{
t
.
Fatalf
(
"Couldn't find kubectl on path."
)
}
return
&
KubectlRunner
{
BinaryPath
:
p
,
T
:
t
}
}
// RunCommandParseOutput runs a command and parses the JSON output
func
(
k
*
KubectlRunner
)
RunCommandParseOutput
(
args
[]
string
,
outputObj
interface
{})
error
{
args
=
append
(
args
,
"-o=json"
)
output
,
err
:=
k
.
RunCommand
(
args
)
if
err
!=
nil
{
return
err
}
d
:=
json
.
NewDecoder
(
bytes
.
NewReader
(
output
))
if
err
:=
d
.
Decode
(
outputObj
);
err
!=
nil
{
return
err
}
return
nil
}
// RunCommand runs a command, returning stdout
func
(
k
*
KubectlRunner
)
RunCommand
(
args
[]
string
)
(
stdout
[]
byte
,
err
error
)
{
inner
:=
func
()
error
{
cmd
:=
exec
.
Command
(
k
.
BinaryPath
,
args
...
)
stdout
,
err
=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
retriable
:=
&
commonutil
.
RetriableError
{
Err
:
fmt
.
Errorf
(
"error running command %s: %v. Stdout:
\n
%s"
,
args
,
err
,
stdout
)}
k
.
T
.
Log
(
retriable
)
return
retriable
}
return
nil
}
err
=
commonutil
.
RetryAfter
(
3
,
inner
,
2
*
time
.
Second
)
return
stdout
,
err
}
// CreateRandomNamespace creates a random namespace
func
(
k
*
KubectlRunner
)
CreateRandomNamespace
()
string
{
const
strLen
=
20
name
:=
genRandString
(
strLen
)
if
_
,
err
:=
k
.
RunCommand
([]
string
{
"create"
,
"namespace"
,
name
});
err
!=
nil
{
k
.
T
.
Fatalf
(
"Error creating namespace: %v"
,
err
)
}
return
name
}
func
genRandString
(
strLen
int
)
string
{
const
chars
=
"abcdefghijklmnopqrstuvwxyz0123456789"
rand
.
Seed
(
time
.
Now
()
.
UTC
()
.
UnixNano
())
result
:=
make
([]
byte
,
strLen
)
for
i
:=
0
;
i
<
strLen
;
i
++
{
result
[
i
]
=
chars
[
rand
.
Intn
(
len
(
chars
))]
}
return
string
(
result
)
}
// DeleteNamespace deletes the namespace
func
(
k
*
KubectlRunner
)
DeleteNamespace
(
namespace
string
)
error
{
_
,
err
:=
k
.
RunCommand
([]
string
{
"delete"
,
"namespace"
,
namespace
})
return
err
}
test/integration/util/util.go
浏览文件 @
c6dbaf1c
...
...
@@ -20,9 +20,7 @@ import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
"math/rand"
"os/exec"
"path/filepath"
"regexp"
...
...
@@ -258,78 +256,6 @@ func (m *MinikubeRunner) CheckStatusNoFail(desired string) error {
return
nil
}
// KubectlRunner runs a command using kubectl
type
KubectlRunner
struct
{
T
*
testing
.
T
BinaryPath
string
}
// NewKubectlRunner creates a new KubectlRunner
func
NewKubectlRunner
(
t
*
testing
.
T
)
*
KubectlRunner
{
p
,
err
:=
exec
.
LookPath
(
kubectlBinary
)
if
err
!=
nil
{
t
.
Fatalf
(
"Couldn't find kubectl on path."
)
}
return
&
KubectlRunner
{
BinaryPath
:
p
,
T
:
t
}
}
// RunCommandParseOutput runs a command and parses the JSON output
func
(
k
*
KubectlRunner
)
RunCommandParseOutput
(
args
[]
string
,
outputObj
interface
{})
error
{
args
=
append
(
args
,
"-o=json"
)
output
,
err
:=
k
.
RunCommand
(
args
)
if
err
!=
nil
{
return
err
}
d
:=
json
.
NewDecoder
(
bytes
.
NewReader
(
output
))
if
err
:=
d
.
Decode
(
outputObj
);
err
!=
nil
{
return
err
}
return
nil
}
// RunCommand runs a command, returning stdout
func
(
k
*
KubectlRunner
)
RunCommand
(
args
[]
string
)
(
stdout
[]
byte
,
err
error
)
{
inner
:=
func
()
error
{
cmd
:=
exec
.
Command
(
k
.
BinaryPath
,
args
...
)
stdout
,
err
=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
retriable
:=
&
commonutil
.
RetriableError
{
Err
:
fmt
.
Errorf
(
"error running command %s: %v. Stdout:
\n
%s"
,
args
,
err
,
stdout
)}
k
.
T
.
Log
(
retriable
)
return
retriable
}
return
nil
}
err
=
commonutil
.
RetryAfter
(
3
,
inner
,
2
*
time
.
Second
)
return
stdout
,
err
}
// CreateRandomNamespace creates a random namespace
func
(
k
*
KubectlRunner
)
CreateRandomNamespace
()
string
{
const
strLen
=
20
name
:=
genRandString
(
strLen
)
if
_
,
err
:=
k
.
RunCommand
([]
string
{
"create"
,
"namespace"
,
name
});
err
!=
nil
{
k
.
T
.
Fatalf
(
"Error creating namespace: %v"
,
err
)
}
return
name
}
func
genRandString
(
strLen
int
)
string
{
const
chars
=
"abcdefghijklmnopqrstuvwxyz0123456789"
rand
.
Seed
(
time
.
Now
()
.
UTC
()
.
UnixNano
())
result
:=
make
([]
byte
,
strLen
)
for
i
:=
0
;
i
<
strLen
;
i
++
{
result
[
i
]
=
chars
[
rand
.
Intn
(
len
(
chars
))]
}
return
string
(
result
)
}
// DeleteNamespace deletes the namespace
func
(
k
*
KubectlRunner
)
DeleteNamespace
(
namespace
string
)
error
{
_
,
err
:=
k
.
RunCommand
([]
string
{
"delete"
,
"namespace"
,
namespace
})
return
err
}
// WaitForBusyboxRunning waits until busybox pod to be running
func
WaitForBusyboxRunning
(
t
*
testing
.
T
,
namespace
string
)
error
{
client
,
err
:=
commonutil
.
GetClient
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录