Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
3a5406f7
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,发现更多精彩内容 >>
提交
3a5406f7
编写于
4月 17, 2020
作者:
T
Thomas Stromberg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Unify client creation around kapi.Client
上级
24606b9a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
15 addition
and
104 deletion
+15
-104
cmd/minikube/cmd/service.go
cmd/minikube/cmd/service.go
+2
-1
cmd/minikube/cmd/tunnel.go
cmd/minikube/cmd/tunnel.go
+2
-3
pkg/addons/addons.go
pkg/addons/addons.go
+5
-4
pkg/minikube/service/service.go
pkg/minikube/service/service.go
+2
-31
pkg/minikube/service/service_test.go
pkg/minikube/service/service_test.go
+0
-7
pkg/minikube/storageclass/storageclass.go
pkg/minikube/storageclass/storageclass.go
+3
-18
pkg/minikube/storageclass/storageclass_test.go
pkg/minikube/storageclass/storageclass_test.go
+1
-40
未找到文件。
cmd/minikube/cmd/service.go
浏览文件 @
3a5406f7
...
...
@@ -33,6 +33,7 @@ import (
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/drivers/kic/oci"
"k8s.io/minikube/pkg/kapi"
"k8s.io/minikube/pkg/minikube/browser"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/localpath"
...
...
@@ -112,7 +113,7 @@ func startKicServiceTunnel(svc, configName string) {
ctrlC
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
ctrlC
,
os
.
Interrupt
)
clientset
,
err
:=
service
.
K8s
.
GetClientset
(
1
*
time
.
Second
)
clientset
,
err
:=
kapi
.
Client
(
configName
)
if
err
!=
nil
{
exit
.
WithError
(
"error creating clientset"
,
err
)
}
...
...
cmd/minikube/cmd/tunnel.go
浏览文件 @
3a5406f7
...
...
@@ -23,17 +23,16 @@ import (
"path/filepath"
"runtime"
"strconv"
"time"
"github.com/golang/glog"
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/drivers/kic/oci"
"k8s.io/minikube/pkg/kapi"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/mustload"
"k8s.io/minikube/pkg/minikube/service"
"k8s.io/minikube/pkg/minikube/tunnel"
"k8s.io/minikube/pkg/minikube/tunnel/kic"
)
...
...
@@ -65,7 +64,7 @@ var tunnelCmd = &cobra.Command{
// We define the tunnel and minikube error free if the API server responds within a second.
// This also contributes to better UX, the tunnel status check can happen every second and
// doesn't hang on the API server call during startup and shutdown time or if there is a temporary error.
clientset
,
err
:=
service
.
K8s
.
GetClientset
(
1
*
time
.
Second
)
clientset
,
err
:=
kapi
.
Client
(
cname
)
if
err
!=
nil
{
exit
.
WithError
(
"error creating clientset"
,
err
)
}
...
...
pkg/addons/addons.go
浏览文件 @
3a5406f7
...
...
@@ -259,10 +259,6 @@ func enableOrDisableStorageClasses(cc *config.ClusterConfig, name string, val st
if
name
==
"storage-provisioner-gluster"
{
class
=
"glusterfile"
}
storagev1
,
err
:=
storageclass
.
GetStoragev1
()
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"Error getting storagev1 interface %v "
,
err
)
}
api
,
err
:=
machine
.
NewAPIClient
()
if
err
!=
nil
{
...
...
@@ -279,6 +275,11 @@ func enableOrDisableStorageClasses(cc *config.ClusterConfig, name string, val st
return
enableOrDisableAddon
(
cc
,
name
,
val
)
}
storagev1
,
err
:=
storageclass
.
GetStoragev1
(
cc
.
Name
)
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"Error getting storagev1 interface %v "
,
err
)
}
if
enable
{
// Only StorageClass for 'name' should be marked as default
err
=
storageclass
.
SetDefaultStorageClass
(
storagev1
,
class
)
...
...
pkg/minikube/service/service.go
浏览文件 @
3a5406f7
...
...
@@ -35,14 +35,11 @@ import (
core
"k8s.io/api/core/v1"
meta
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/kubernetes"
typed_core
"k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi
"k8s.io/client-go/tools/clientcmd/api"
"k8s.io/minikube/pkg/kapi"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/proxy"
"k8s.io/minikube/pkg/util/retry"
)
...
...
@@ -57,7 +54,6 @@ const (
// K8sClient represents a kubernetes client
type
K8sClient
interface
{
GetCoreClient
()
(
typed_core
.
CoreV1Interface
,
error
)
GetClientset
(
timeout
time
.
Duration
)
(
*
kubernetes
.
Clientset
,
error
)
}
// K8sClientGetter can get a K8sClient
...
...
@@ -72,38 +68,13 @@ func init() {
// GetCoreClient returns a core client
func
(
k
*
K8sClientGetter
)
GetCoreClient
()
(
typed_core
.
CoreV1Interface
,
error
)
{
client
,
err
:=
k
.
GetClientset
(
defaultK8sClientTimeout
)
client
,
err
:=
k
api
.
Client
(
viper
.
GetString
(
config
.
ProfileName
)
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"getting clientset"
)
}
return
client
.
CoreV1
(),
nil
}
// GetClientset returns a clientset
func
(
*
K8sClientGetter
)
GetClientset
(
timeout
time
.
Duration
)
(
*
kubernetes
.
Clientset
,
error
)
{
loadingRules
:=
clientcmd
.
NewDefaultClientConfigLoadingRules
()
profile
:=
viper
.
GetString
(
config
.
ProfileName
)
configOverrides
:=
&
clientcmd
.
ConfigOverrides
{
Context
:
clientcmdapi
.
Context
{
Cluster
:
profile
,
AuthInfo
:
profile
,
},
}
kubeConfig
:=
clientcmd
.
NewNonInteractiveDeferredLoadingClientConfig
(
loadingRules
,
configOverrides
)
clientConfig
,
err
:=
kubeConfig
.
ClientConfig
()
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"kubeConfig: %v"
,
err
)
}
clientConfig
.
Timeout
=
timeout
clientConfig
=
proxy
.
UpdateTransport
(
clientConfig
)
client
,
err
:=
kubernetes
.
NewForConfig
(
clientConfig
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"client from config"
)
}
return
client
,
nil
}
// SvcURL represents a service URL. Each item in the URLs field combines the service URL with one of the configured
// node ports. The PortNames field contains the configured names of the ports in the URLs field (sorted correspondingly -
// first item in PortNames belongs to the first item in URLs).
...
...
pkg/minikube/service/service_test.go
浏览文件 @
3a5406f7
...
...
@@ -26,8 +26,6 @@ import (
"testing"
"text/template"
"time"
"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/host"
"github.com/pkg/errors"
...
...
@@ -35,7 +33,6 @@ import (
core
"k8s.io/api/core/v1"
meta
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/kubernetes"
typed_core
"k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/kubernetes/typed/core/v1/fake"
testing_fake
"k8s.io/client-go/testing"
...
...
@@ -65,10 +62,6 @@ func (m *MockClientGetter) GetCoreClient() (typed_core.CoreV1Interface, error) {
secretsMap
:
m
.
secretsMap
},
nil
}
func
(
m
*
MockClientGetter
)
GetClientset
(
timeout
time
.
Duration
)
(
*
kubernetes
.
Clientset
,
error
)
{
return
nil
,
nil
}
func
(
m
*
MockCoreClient
)
Secrets
(
ns
string
)
typed_core
.
SecretInterface
{
return
&
fake
.
FakeSecrets
{
Fake
:
&
fake
.
FakeCoreV1
{
Fake
:
&
testing_fake
.
Fake
{}}}
}
...
...
pkg/minikube/storageclass/storageclass.go
浏览文件 @
3a5406f7
...
...
@@ -22,9 +22,8 @@ import (
"github.com/pkg/errors"
v1
"k8s.io/api/storage/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
storagev1
"k8s.io/client-go/kubernetes/typed/storage/v1"
"k8s.io/
client-go/tools/clientcmd
"
"k8s.io/
minikube/pkg/kapi
"
)
func
annotateDefaultStorageClass
(
storage
storagev1
.
StorageV1Interface
,
class
*
v1
.
StorageClass
,
enable
bool
)
error
{
...
...
@@ -71,25 +70,11 @@ func SetDefaultStorageClass(storage storagev1.StorageV1Interface, name string) e
}
// GetStoragev1 return storage v1 interface for client
func
GetStoragev1
()
(
storagev1
.
StorageV1Interface
,
error
)
{
client
,
err
:=
getClient
(
)
func
GetStoragev1
(
context
string
)
(
storagev1
.
StorageV1Interface
,
error
)
{
client
,
err
:=
kapi
.
Client
(
context
)
if
err
!=
nil
{
return
nil
,
err
}
sv1
:=
client
.
StorageV1
()
return
sv1
,
nil
}
func
getClient
()
(
*
kubernetes
.
Clientset
,
error
)
{
loadingRules
:=
clientcmd
.
NewDefaultClientConfigLoadingRules
()
kubeConfig
:=
clientcmd
.
NewNonInteractiveDeferredLoadingClientConfig
(
loadingRules
,
&
clientcmd
.
ConfigOverrides
{})
config
,
err
:=
kubeConfig
.
ClientConfig
()
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"Error creating kubeConfig"
)
}
client
,
err
:=
kubernetes
.
NewForConfig
(
config
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"Error creating new client from kubeConfig.ClientConfig()"
)
}
return
client
,
nil
}
pkg/minikube/storageclass/storageclass_test.go
浏览文件 @
3a5406f7
...
...
@@ -212,45 +212,6 @@ users:
- name: minikube
`
func
TestGetClient
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
description
string
config
string
err
bool
}{
{
description
:
"ok"
,
config
:
mockK8sConfig
,
},
{
description
:
"no valid config"
,
config
:
"this is not valid config"
,
err
:
true
,
},
}
configFile
,
err
:=
ioutil
.
TempFile
(
"/tmp"
,
""
)
if
err
!=
nil
{
t
.
Fatalf
(
err
.
Error
())
}
defer
os
.
Remove
(
configFile
.
Name
())
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
description
,
func
(
t
*
testing
.
T
)
{
if
err
:=
setK8SConfig
(
test
.
config
,
configFile
.
Name
());
err
!=
nil
{
t
.
Fatalf
(
err
.
Error
())
}
_
,
err
=
getClient
()
if
err
!=
nil
&&
!
test
.
err
{
t
.
Fatalf
(
"Unexpected err: %v for test: %v"
,
err
,
test
.
description
)
}
if
err
==
nil
&&
test
.
err
{
t
.
Fatalf
(
"Expected err for test: %v"
,
test
.
description
)
}
})
}
}
func
TestGetStoragev1
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
description
string
...
...
@@ -278,7 +239,7 @@ func TestGetStoragev1(t *testing.T) {
t
.
Fatalf
(
err
.
Error
())
}
_
,
err
=
GetStoragev1
()
_
,
err
=
GetStoragev1
(
configfile
.
Name
()
)
if
err
!=
nil
&&
!
test
.
err
{
t
.
Fatalf
(
"Unexpected err: %v for test: %v"
,
err
,
test
.
description
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录