Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
a3fee8fd
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,发现更多精彩内容 >>
提交
a3fee8fd
编写于
5月 11, 2016
作者:
D
Dan Lorenc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unused portions of GenerateSelfSignedCert
上级
91c98980
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
41 addition
and
30 deletion
+41
-30
cmd/localkube/cmd/start.go
cmd/localkube/cmd/start.go
+1
-6
pkg/localkube/crypto.go
pkg/localkube/crypto.go
+19
-11
pkg/localkube/localkube.go
pkg/localkube/localkube.go
+14
-5
pkg/localkube/localkube_test.go
pkg/localkube/localkube_test.go
+7
-8
未找到文件。
cmd/localkube/cmd/start.go
浏览文件 @
a3fee8fd
...
...
@@ -56,12 +56,7 @@ func init() {
func
SetupServer
(
s
*
localkube
.
LocalkubeServer
)
{
hostIP
,
err
:=
s
.
GetHostIP
()
if
err
!=
nil
{
fmt
.
Println
(
"Error getting host IP!"
)
panic
(
err
)
}
if
err
:=
s
.
GenerateCerts
(
hostIP
);
err
!=
nil
{
if
err
:=
s
.
GenerateCerts
();
err
!=
nil
{
fmt
.
Println
(
"Failed to create certificates!"
)
panic
(
err
)
}
...
...
pkg/localkube/crypto.go
浏览文件 @
a3fee8fd
/*
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
localkube
import
(
...
...
@@ -7,7 +23,6 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"io/ioutil"
"math/big"
"net"
...
...
@@ -16,12 +31,11 @@ import (
"time"
)
// Host may be an IP or a DNS name
// You may also specify additional subject alt names (either ip or dns names) for the certificate
// The certificate will be created with file mode 0644. The key will be created with file mode 0600.
// If the certificate or key files already exist, they will be overwritten.
// Any parent directories of the certPath or keyPath will be created as needed with file mode 0755.
func
GenerateSelfSignedCert
(
host
,
certPath
,
keyPath
string
,
alternateIP
s
[]
net
.
IP
,
alternateDNS
[]
string
)
error
{
func
GenerateSelfSignedCert
(
certPath
,
keyPath
string
,
ip
s
[]
net
.
IP
,
alternateDNS
[]
string
)
error
{
priv
,
err
:=
rsa
.
GenerateKey
(
rand
.
Reader
,
2048
)
if
err
!=
nil
{
return
err
...
...
@@ -30,7 +44,7 @@ func GenerateSelfSignedCert(host, certPath, keyPath string, alternateIPs []net.I
template
:=
x509
.
Certificate
{
SerialNumber
:
big
.
NewInt
(
1
),
Subject
:
pkix
.
Name
{
CommonName
:
fmt
.
Sprintf
(
"%s@%d"
,
host
,
time
.
Now
()
.
Unix
())
,
CommonName
:
"minikube"
,
},
NotBefore
:
time
.
Now
(),
NotAfter
:
time
.
Now
()
.
Add
(
time
.
Hour
*
24
*
365
),
...
...
@@ -41,13 +55,7 @@ func GenerateSelfSignedCert(host, certPath, keyPath string, alternateIPs []net.I
IsCA
:
true
,
}
if
ip
:=
net
.
ParseIP
(
host
);
ip
!=
nil
{
template
.
IPAddresses
=
append
(
template
.
IPAddresses
,
ip
)
}
else
{
template
.
DNSNames
=
append
(
template
.
DNSNames
,
host
)
}
template
.
IPAddresses
=
append
(
template
.
IPAddresses
,
alternateIPs
...
)
template
.
IPAddresses
=
append
(
template
.
IPAddresses
,
ips
...
)
template
.
DNSNames
=
append
(
template
.
DNSNames
,
alternateDNS
...
)
derBytes
,
err
:=
x509
.
CreateCertificate
(
rand
.
Reader
,
&
template
,
&
template
,
&
priv
.
PublicKey
,
priv
)
...
...
pkg/localkube/localkube.go
浏览文件 @
a3fee8fd
...
...
@@ -124,12 +124,11 @@ func (lk LocalkubeServer) shouldGenerateCerts(ips []net.IP) bool {
return
false
}
func
(
lk
LocalkubeServer
)
GenerateCerts
(
hostIP
net
.
IP
)
error
{
ips
:=
[]
net
.
IP
{
lk
.
ServiceClusterIPRange
.
IP
,
hostIP
}
func
(
lk
LocalkubeServer
)
getAllIPs
()
([]
net
.
IP
,
error
)
{
ips
:=
[]
net
.
IP
{
lk
.
ServiceClusterIPRange
.
IP
}
addrs
,
err
:=
net
.
InterfaceAddrs
()
if
err
!=
nil
{
return
err
return
nil
,
err
}
for
_
,
addr
:=
range
addrs
{
ipnet
,
ok
:=
addr
.
(
*
net
.
IPNet
)
...
...
@@ -139,6 +138,16 @@ func (lk LocalkubeServer) GenerateCerts(hostIP net.IP) error {
}
ips
=
append
(
ips
,
ipnet
.
IP
)
}
return
ips
,
nil
}
func
(
lk
LocalkubeServer
)
GenerateCerts
()
error
{
ips
,
err
:=
lk
.
getAllIPs
()
if
err
!=
nil
{
return
err
}
if
!
lk
.
shouldGenerateCerts
(
ips
)
{
fmt
.
Println
(
"Using these existing certs: "
,
lk
.
GetPublicKeyCertPath
(),
lk
.
GetPrivateKeyCertPath
())
return
nil
...
...
@@ -146,7 +155,7 @@ func (lk LocalkubeServer) GenerateCerts(hostIP net.IP) error {
fmt
.
Println
(
"Creating cert with IPs: "
,
ips
)
alternateDNS
:=
[]
string
{
fmt
.
Sprintf
(
"%s.%s"
,
"kubernetes.default.svc"
,
lk
.
DNSDomain
),
"kubernetes.default.svc"
,
"kubernetes.default"
,
"kubernetes"
}
if
err
:=
GenerateSelfSignedCert
(
hostIP
.
String
(),
lk
.
GetPublicKeyCertPath
(),
lk
.
GetPrivateKeyCertPath
(),
ips
,
alternateDNS
);
err
!=
nil
{
if
err
:=
GenerateSelfSignedCert
(
lk
.
GetPublicKeyCertPath
(),
lk
.
GetPrivateKeyCertPath
(),
ips
,
alternateDNS
);
err
!=
nil
{
fmt
.
Println
(
"Failed to create certs: "
,
err
)
return
err
}
...
...
pkg/localkube/localkube_test.go
浏览文件 @
a3fee8fd
...
...
@@ -39,7 +39,7 @@ func TestGenerateCerts(t *testing.T) {
ServiceClusterIPRange
:
*
ipRange
,
}
if
err
:=
lk
.
GenerateCerts
(
testIPs
[
0
]
);
err
!=
nil
{
if
err
:=
lk
.
GenerateCerts
();
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error generating certs: %s"
,
err
)
}
...
...
@@ -50,13 +50,10 @@ func TestGenerateCerts(t *testing.T) {
t
.
Fatalf
(
"Certificate not created: %s"
,
p
)
}
}
cert
,
err
:=
lk
.
loadCert
(
filepath
.
Join
(
tempDir
,
"certs"
,
"apiserver.crt"
))
_
,
err
:=
lk
.
loadCert
(
filepath
.
Join
(
tempDir
,
"certs"
,
"apiserver.crt"
))
if
err
!=
nil
{
t
.
Fatalf
(
"Error parsing cert: %s"
,
err
)
}
if
!
cert
.
IPAddresses
[
0
]
.
Equal
(
testIPs
[
0
])
{
t
.
Fatalf
(
"IP mismatch: %s != %s."
,
cert
.
IPAddresses
[
0
],
testIPs
[
0
])
}
}
func
TestShouldGenerateCertsNoFiles
(
t
*
testing
.
T
)
{
...
...
@@ -100,7 +97,8 @@ func TestShouldGenerateCertsMismatchedIP(t *testing.T) {
LocalkubeDirectory
:
tempDir
,
ServiceClusterIPRange
:
*
ipRange
,
}
lk
.
GenerateCerts
(
testIPs
[
0
])
lk
.
GenerateCerts
()
if
!
lk
.
shouldGenerateCerts
([]
net
.
IP
{
net
.
ParseIP
(
"4.3.2.1"
)})
{
t
.
Fatalf
(
"IPs don't match, we should generate."
)
...
...
@@ -117,8 +115,9 @@ func TestShouldNotGenerateCerts(t *testing.T) {
LocalkubeDirectory
:
tempDir
,
ServiceClusterIPRange
:
*
ipRange
,
}
lk
.
GenerateCerts
(
testIPs
[
0
])
if
lk
.
shouldGenerateCerts
(
testIPs
)
{
lk
.
GenerateCerts
()
ips
,
_
:=
lk
.
getAllIPs
()
if
lk
.
shouldGenerateCerts
(
ips
)
{
t
.
Fatalf
(
"IPs match, we should not generate."
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录