Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
8d3fed07
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 搜索 >>
未验证
提交
8d3fed07
编写于
12月 11, 2019
作者:
T
Thomas Strömberg
提交者:
GitHub
12月 11, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6059 from tstromberg/clock
lock names: Remove uid suffix & hash entire path
上级
8666e224
d811f6e4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
36 addition
and
52 deletion
+36
-52
pkg/minikube/bootstrapper/certs.go
pkg/minikube/bootstrapper/certs.go
+1
-1
pkg/minikube/kubeconfig/settings.go
pkg/minikube/kubeconfig/settings.go
+1
-1
pkg/util/lock/lock.go
pkg/util/lock/lock.go
+8
-38
pkg/util/lock/lock_test.go
pkg/util/lock/lock_test.go
+26
-12
未找到文件。
pkg/minikube/bootstrapper/certs.go
浏览文件 @
8d3fed07
...
@@ -70,7 +70,7 @@ func SetupCerts(cmd command.Runner, k8s config.KubernetesConfig) error {
...
@@ -70,7 +70,7 @@ func SetupCerts(cmd command.Runner, k8s config.KubernetesConfig) error {
//
//
// If another process updates the shared certificate, it's invalid.
// If another process updates the shared certificate, it's invalid.
// TODO: Instead of racey manipulation of a shared certificate, use per-profile certs
// TODO: Instead of racey manipulation of a shared certificate, use per-profile certs
spec
:=
lock
.
User
MutexSpec
(
filepath
.
Join
(
localPath
,
"certs"
))
spec
:=
lock
.
Path
MutexSpec
(
filepath
.
Join
(
localPath
,
"certs"
))
glog
.
Infof
(
"acquiring lock: %+v"
,
spec
)
glog
.
Infof
(
"acquiring lock: %+v"
,
spec
)
releaser
,
err
:=
mutex
.
Acquire
(
spec
)
releaser
,
err
:=
mutex
.
Acquire
(
spec
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/minikube/kubeconfig/settings.go
浏览文件 @
8d3fed07
...
@@ -119,7 +119,7 @@ func PopulateFromSettings(cfg *Settings, apiCfg *api.Config) error {
...
@@ -119,7 +119,7 @@ func PopulateFromSettings(cfg *Settings, apiCfg *api.Config) error {
// activeContext is true when minikube is the CurrentContext
// activeContext is true when minikube is the CurrentContext
// If no CurrentContext is set, the given name will be used.
// If no CurrentContext is set, the given name will be used.
func
Update
(
kcs
*
Settings
)
error
{
func
Update
(
kcs
*
Settings
)
error
{
spec
:=
lock
.
User
MutexSpec
(
filepath
.
Join
(
kcs
.
filePath
(),
"settings.Update"
))
spec
:=
lock
.
Path
MutexSpec
(
filepath
.
Join
(
kcs
.
filePath
(),
"settings.Update"
))
glog
.
Infof
(
"acquiring lock: %+v"
,
spec
)
glog
.
Infof
(
"acquiring lock: %+v"
,
spec
)
releaser
,
err
:=
mutex
.
Acquire
(
spec
)
releaser
,
err
:=
mutex
.
Acquire
(
spec
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/util/lock/lock.go
浏览文件 @
8d3fed07
...
@@ -17,12 +17,10 @@ limitations under the License.
...
@@ -17,12 +17,10 @@ limitations under the License.
package
lock
package
lock
import
(
import
(
"crypto/sha1"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"os/user"
"regexp"
"strings"
"time"
"time"
"github.com/golang/glog"
"github.com/golang/glog"
...
@@ -31,42 +29,27 @@ import (
...
@@ -31,42 +29,27 @@ import (
"github.com/pkg/errors"
"github.com/pkg/errors"
)
)
var
(
// nonString is characters to strip from lock names
nonString
=
regexp
.
MustCompile
(
`[\W_]+`
)
// forceID is a user id for consistent testing
forceID
=
""
)
// WriteFile decorates ioutil.WriteFile with a file lock and retry
// WriteFile decorates ioutil.WriteFile with a file lock and retry
func
WriteFile
(
filename
string
,
data
[]
byte
,
perm
os
.
FileMode
)
error
{
func
WriteFile
(
filename
string
,
data
[]
byte
,
perm
os
.
FileMode
)
error
{
spec
:=
User
MutexSpec
(
filename
)
spec
:=
Path
MutexSpec
(
filename
)
glog
.
Infof
(
"
acquiring lock for
%s: %+v"
,
filename
,
spec
)
glog
.
Infof
(
"
WriteFile acquiring
%s: %+v"
,
filename
,
spec
)
releaser
,
err
:=
mutex
.
Acquire
(
spec
)
releaser
,
err
:=
mutex
.
Acquire
(
spec
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"
error acquiring lock for %s"
,
filename
)
return
errors
.
Wrapf
(
err
,
"
failed to acquire lock for %s: %+v"
,
filename
,
spec
)
}
}
defer
releaser
.
Release
()
defer
releaser
.
Release
()
if
err
=
ioutil
.
WriteFile
(
filename
,
data
,
perm
);
err
!=
nil
{
if
err
=
ioutil
.
WriteFile
(
filename
,
data
,
perm
);
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"
error writing file
%s"
,
filename
)
return
errors
.
Wrapf
(
err
,
"
writefile failed for
%s"
,
filename
)
}
}
return
err
return
err
}
}
// UserMutexSpec returns a mutex spec that will not collide with other users
// PathMutexSpec returns a mutex spec for a path
func
UserMutexSpec
(
path
string
)
mutex
.
Spec
{
func
PathMutexSpec
(
path
string
)
mutex
.
Spec
{
id
:=
forceID
if
forceID
==
""
{
u
,
err
:=
user
.
Current
()
if
err
==
nil
{
id
=
u
.
Uid
}
}
s
:=
mutex
.
Spec
{
s
:=
mutex
.
Spec
{
Name
:
getMutexNameForPath
(
fmt
.
Sprintf
(
"%s-%s"
,
path
,
id
))
,
Name
:
fmt
.
Sprintf
(
"mk%x"
,
sha1
.
Sum
([]
byte
(
path
)))[
0
:
40
]
,
Clock
:
clock
.
WallClock
,
Clock
:
clock
.
WallClock
,
// Poll the lock twice a second
// Poll the lock twice a second
Delay
:
500
*
time
.
Millisecond
,
Delay
:
500
*
time
.
Millisecond
,
...
@@ -75,16 +58,3 @@ func UserMutexSpec(path string) mutex.Spec {
...
@@ -75,16 +58,3 @@ func UserMutexSpec(path string) mutex.Spec {
}
}
return
s
return
s
}
}
func
getMutexNameForPath
(
path
string
)
string
{
// juju requires that names match ^[a-zA-Z][a-zA-Z0-9-]*$", and be under 40 chars long.
n
:=
strings
.
Trim
(
nonString
.
ReplaceAllString
(
path
,
"-"
),
"-"
)
// we need to always guarantee an alphanumeric prefix
prefix
:=
"m"
// Prefer the last 40 chars, as paths tend get more specific toward the end
if
len
(
n
)
>=
40
{
return
prefix
+
n
[
len
(
n
)
-
39
:
]
}
return
prefix
+
n
}
pkg/util/lock/lock_test.go
浏览文件 @
8d3fed07
...
@@ -16,11 +16,13 @@ limitations under the License.
...
@@ -16,11 +16,13 @@ limitations under the License.
package
lock
package
lock
import
"testing"
import
(
"testing"
func
TestUserMutexSpec
(
t
*
testing
.
T
)
{
"github.com/juju/mutex"
forceID
=
"test"
)
func
TestUserMutexSpec
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
var
tests
=
[]
struct
{
description
string
description
string
path
string
path
string
...
@@ -29,41 +31,53 @@ func TestUserMutexSpec(t *testing.T) {
...
@@ -29,41 +31,53 @@ func TestUserMutexSpec(t *testing.T) {
{
{
description
:
"standard"
,
description
:
"standard"
,
path
:
"/foo/bar"
,
path
:
"/foo/bar"
,
expected
:
"mfoo-bar-test"
,
},
},
{
{
description
:
"deep directory"
,
description
:
"deep directory"
,
path
:
"/foo/bar/baz/bat"
,
path
:
"/foo/bar/baz/bat"
,
expected
:
"mfoo-bar-baz-bat-test"
,
},
},
{
{
description
:
"underscores"
,
description
:
"underscores"
,
path
:
"/foo_bar/baz"
,
path
:
"/foo_bar/baz"
,
expected
:
"mfoo-bar-baz-test"
,
},
},
{
{
description
:
"starts with number"
,
description
:
"starts with number"
,
path
:
"/foo/2bar/baz"
,
path
:
"/foo/2bar/baz"
,
expected
:
"mfoo-2bar-baz-test"
,
},
},
{
{
description
:
"starts with punctuation"
,
description
:
"starts with punctuation"
,
path
:
"/.foo/bar"
,
path
:
"/.foo/bar"
,
expected
:
"mfoo-bar-test"
,
},
},
{
{
description
:
"long filename"
,
description
:
"long filename"
,
path
:
"/very-very-very-very-very-very-very-very-long/bar"
,
path
:
"/very-very-very-very-very-very-very-very-long/bar"
,
expected
:
"m-very-very-very-very-very-long-bar-test"
,
},
{
description
:
"Windows kubeconfig"
,
path
:
`C:\Users\admin/.kube/config`
,
},
{
description
:
"Windows json"
,
path
:
`C:\Users\admin\.minikube\profiles\containerd-20191210T212325.7356633-8584\config.json`
,
},
},
}
}
seen
:=
map
[
string
]
string
{}
for
_
,
tc
:=
range
tests
{
for
_
,
tc
:=
range
tests
{
t
.
Run
(
tc
.
description
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
tc
.
description
,
func
(
t
*
testing
.
T
)
{
got
:=
UserMutexSpec
(
tc
.
path
)
got
:=
PathMutexSpec
(
tc
.
path
)
if
got
.
Name
!=
tc
.
expected
{
if
len
(
got
.
Name
)
!=
40
{
t
.
Errorf
(
"%s mutex name = %q, expected %q"
,
tc
.
path
,
got
.
Name
,
tc
.
expected
)
t
.
Errorf
(
"%s is not 40 chars long"
,
got
.
Name
)
}
if
seen
[
got
.
Name
]
!=
""
{
t
.
Fatalf
(
"lock name collision between %s and %s"
,
tc
.
path
,
seen
[
got
.
Name
])
}
m
,
err
:=
mutex
.
Acquire
(
got
)
if
err
!=
nil
{
t
.
Errorf
(
"acquire for spec %+v failed: %v"
,
got
,
err
)
}
}
m
.
Release
()
})
})
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录