Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
fe3131ba
Commit
fe3131ba
authored
Oct 15, 2018
by
WanLinghao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean all unused packages under pkg/util
parent
d20912c8
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
0 additions
and
627 deletions
+0
-627
.golint_failures
hack/.golint_failures
+0
-1
BUILD
pkg/util/BUILD
+0
-3
BUILD
pkg/util/limitwriter/BUILD
+0
-35
doc.go
pkg/util/limitwriter/doc.go
+0
-19
limitwriter.go
pkg/util/limitwriter/limitwriter.go
+0
-53
limitwriter_test.go
pkg/util/limitwriter/limitwriter_test.go
+0
-93
BUILD
pkg/util/template/BUILD
+0
-33
template.go
pkg/util/template/template.go
+0
-49
template_test.go
pkg/util/template/template_test.go
+0
-61
BUILD
pkg/util/threading/BUILD
+0
-33
deadlock-detector.go
pkg/util/threading/deadlock-detector.go
+0
-120
deadlock-detector_test.go
pkg/util/threading/deadlock-detector_test.go
+0
-127
No files found.
hack/.golint_failures
View file @
fe3131ba
...
...
@@ -400,7 +400,6 @@ pkg/util/sysctl
pkg/util/sysctl/testing
pkg/util/system
pkg/util/taints
pkg/util/threading
pkg/util/tolerations
pkg/util/workqueue/prometheus
pkg/version/verflag
...
...
pkg/util/BUILD
View file @
fe3131ba
...
...
@@ -35,7 +35,6 @@ filegroup(
"//pkg/util/ipvs:all-srcs",
"//pkg/util/keymutex:all-srcs",
"//pkg/util/labels:all-srcs",
"//pkg/util/limitwriter:all-srcs",
"//pkg/util/maps:all-srcs",
"//pkg/util/metrics:all-srcs",
"//pkg/util/mount:all-srcs",
...
...
@@ -60,8 +59,6 @@ filegroup(
"//pkg/util/system:all-srcs",
"//pkg/util/tail:all-srcs",
"//pkg/util/taints:all-srcs",
"//pkg/util/template:all-srcs",
"//pkg/util/threading:all-srcs",
"//pkg/util/tolerations:all-srcs",
"//pkg/util/workqueue/prometheus:all-srcs",
],
...
...
pkg/util/limitwriter/BUILD
deleted
100644 → 0
View file @
d20912c8
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"limitwriter.go",
],
importpath = "k8s.io/kubernetes/pkg/util/limitwriter",
)
go_test(
name = "go_default_test",
srcs = ["limitwriter_test.go"],
embed = [":go_default_library"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)
pkg/util/limitwriter/doc.go
deleted
100644 → 0
View file @
d20912c8
/*
Copyright 2015 The Kubernetes Authors.
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 limitwriter provides a writer that only allows a certain number of bytes to be
// written.
package
limitwriter
// import "k8s.io/kubernetes/pkg/util/limitwriter"
pkg/util/limitwriter/limitwriter.go
deleted
100644 → 0
View file @
d20912c8
/*
Copyright 2015 The Kubernetes Authors.
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
limitwriter
import
(
"errors"
"io"
)
// New creates a writer that is limited to writing at most n bytes to w. This writer is not
// thread safe.
func
New
(
w
io
.
Writer
,
n
int64
)
io
.
Writer
{
return
&
limitWriter
{
w
:
w
,
n
:
n
,
}
}
// ErrMaximumWrite is returned when all bytes have been written.
var
ErrMaximumWrite
=
errors
.
New
(
"maximum write"
)
type
limitWriter
struct
{
w
io
.
Writer
n
int64
}
func
(
w
*
limitWriter
)
Write
(
p
[]
byte
)
(
n
int
,
err
error
)
{
if
int64
(
len
(
p
))
>
w
.
n
{
p
=
p
[
:
w
.
n
]
}
if
w
.
n
>
0
{
n
,
err
=
w
.
w
.
Write
(
p
)
w
.
n
-=
int64
(
n
)
}
if
w
.
n
==
0
{
err
=
ErrMaximumWrite
}
return
}
pkg/util/limitwriter/limitwriter_test.go
deleted
100644 → 0
View file @
d20912c8
/*
Copyright 2016 The Kubernetes Authors.
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
limitwriter
import
(
"reflect"
"testing"
)
type
recordingWriter
struct
{
Wrote
[][]
byte
}
func
(
r
*
recordingWriter
)
Write
(
data
[]
byte
)
(
int
,
error
)
{
r
.
Wrote
=
append
(
r
.
Wrote
,
data
)
return
len
(
data
),
nil
}
func
TestLimitWriter
(
t
*
testing
.
T
)
{
testcases
:=
map
[
string
]
struct
{
Limit
int64
Writes
[][]
byte
ExpectedRecordedWrites
[][]
byte
ExpectedReportedWrites
[]
int
ExpectedReportedErrors
[]
error
}{
"empty"
:
{},
"empty write"
:
{
Limit
:
1000
,
Writes
:
[][]
byte
{{}},
ExpectedRecordedWrites
:
[][]
byte
{{}},
ExpectedReportedWrites
:
[]
int
{
0
},
ExpectedReportedErrors
:
[]
error
{
nil
},
},
"unlimited write"
:
{
Limit
:
1000
,
Writes
:
[][]
byte
{[]
byte
(
`foo`
)},
ExpectedRecordedWrites
:
[][]
byte
{[]
byte
(
`foo`
)},
ExpectedReportedWrites
:
[]
int
{
3
},
ExpectedReportedErrors
:
[]
error
{
nil
},
},
"limited write"
:
{
Limit
:
5
,
Writes
:
[][]
byte
{[]
byte
(
``
),
[]
byte
(
`1`
),
[]
byte
(
`23`
),
[]
byte
(
`456789`
),
[]
byte
(
`10`
),
[]
byte
(
``
)},
ExpectedRecordedWrites
:
[][]
byte
{[]
byte
(
``
),
[]
byte
(
`1`
),
[]
byte
(
`23`
),
[]
byte
(
`45`
)},
ExpectedReportedWrites
:
[]
int
{
0
,
1
,
2
,
2
,
0
,
0
},
ExpectedReportedErrors
:
[]
error
{
nil
,
nil
,
nil
,
ErrMaximumWrite
,
ErrMaximumWrite
,
ErrMaximumWrite
},
},
}
for
k
,
tc
:=
range
testcases
{
var
reportedWrites
[]
int
var
reportedErrors
[]
error
recordingWriter
:=
&
recordingWriter
{}
limitwriter
:=
New
(
recordingWriter
,
tc
.
Limit
)
for
_
,
w
:=
range
tc
.
Writes
{
n
,
err
:=
limitwriter
.
Write
(
w
)
reportedWrites
=
append
(
reportedWrites
,
n
)
reportedErrors
=
append
(
reportedErrors
,
err
)
}
if
!
reflect
.
DeepEqual
(
recordingWriter
.
Wrote
,
tc
.
ExpectedRecordedWrites
)
{
t
.
Errorf
(
"%s: expected recorded writes %v, got %v"
,
k
,
tc
.
ExpectedRecordedWrites
,
recordingWriter
.
Wrote
)
}
if
!
reflect
.
DeepEqual
(
reportedWrites
,
tc
.
ExpectedReportedWrites
)
{
t
.
Errorf
(
"%s: expected reported writes %v, got %v"
,
k
,
tc
.
ExpectedReportedWrites
,
reportedWrites
)
}
if
!
reflect
.
DeepEqual
(
reportedErrors
,
tc
.
ExpectedReportedErrors
)
{
t
.
Errorf
(
"%s: expected reported errors %v, got %v"
,
k
,
tc
.
ExpectedReportedErrors
,
reportedErrors
)
}
}
}
pkg/util/template/BUILD
deleted
100644 → 0
View file @
d20912c8
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_test(
name = "go_default_test",
srcs = ["template_test.go"],
embed = [":go_default_library"],
deps = ["//vendor/github.com/stretchr/testify/assert:go_default_library"],
)
go_library(
name = "go_default_library",
srcs = ["template.go"],
importpath = "k8s.io/kubernetes/pkg/util/template",
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)
pkg/util/template/template.go
deleted
100644 → 0
View file @
d20912c8
/*
Copyright 2017 The Kubernetes Authors.
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
template
import
(
"bytes"
"go/doc"
"io"
"strings"
"text/template"
)
func
wrap
(
indent
string
,
s
string
)
string
{
var
buf
bytes
.
Buffer
doc
.
ToText
(
&
buf
,
s
,
indent
,
indent
+
" "
,
80
-
len
(
indent
))
return
buf
.
String
()
}
// ExecuteTemplate executes templateText with data and output written to w.
func
ExecuteTemplate
(
w
io
.
Writer
,
templateText
string
,
data
interface
{})
error
{
t
:=
template
.
New
(
"top"
)
t
.
Funcs
(
template
.
FuncMap
{
"trim"
:
strings
.
TrimSpace
,
"wrap"
:
wrap
,
})
template
.
Must
(
t
.
Parse
(
templateText
))
return
t
.
Execute
(
w
,
data
)
}
// ExecuteTemplateToString executes templateText with data and output written to string.
func
ExecuteTemplateToString
(
templateText
string
,
data
interface
{})
(
string
,
error
)
{
b
:=
bytes
.
Buffer
{}
err
:=
ExecuteTemplate
(
&
b
,
templateText
,
data
)
return
b
.
String
(),
err
}
pkg/util/template/template_test.go
deleted
100644 → 0
View file @
d20912c8
/*
Copyright 2017 The Kubernetes Authors.
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
template
import
(
"testing"
"github.com/stretchr/testify/assert"
)
func
TestWrap
(
t
*
testing
.
T
)
{
tt
:=
`before ->{{.Long | wrap "**"}}<- after`
data
:=
struct
{
Long
string
}{
`Hodor, hodor; hodor hodor;
hodor hodor... Hodor hodor hodor? Hodor. Hodor hodor hodor hodor...
Hodor hodor hodor; hodor hodor hodor! Hodor, hodor. Hodor. Hodor,
HODOR hodor, hodor hodor; hodor hodor; hodor HODOR hodor, hodor hodor?
Hodor. Hodor hodor - hodor hodor. Hodor hodor HODOR! Hodor hodor - hodor...
Hodor hodor HODOR hodor, hodor hodor hodor! Hodor, hodor... Hodor hodor
hodor hodor hodor hodor! Hodor, hodor; hodor hodor. Hodor.`
,
}
output
,
_
:=
ExecuteTemplateToString
(
tt
,
data
)
t
.
Logf
(
"%q"
,
output
)
assert
.
Equal
(
t
,
`before ->**Hodor, hodor; hodor hodor; hodor hodor... Hodor hodor hodor? Hodor. Hodor
**hodor hodor hodor... Hodor hodor hodor; hodor hodor hodor! Hodor, hodor.
**Hodor. Hodor, HODOR hodor, hodor hodor; hodor hodor; hodor HODOR hodor, hodor
**hodor? Hodor. Hodor hodor - hodor hodor. Hodor hodor HODOR! Hodor hodor -
**hodor... Hodor hodor HODOR hodor, hodor hodor hodor! Hodor, hodor... Hodor
**hodor hodor hodor hodor hodor! Hodor, hodor; hodor hodor. Hodor.
<- after`
,
output
)
}
func
TestTrim
(
t
*
testing
.
T
)
{
tt
:=
`before ->{{.Messy | trim }}<- after`
data
:=
struct
{
Messy
string
}{
"
\t
stuff
\n
\r
"
,
}
output
,
_
:=
ExecuteTemplateToString
(
tt
,
data
)
t
.
Logf
(
"%q"
,
output
)
assert
.
Equal
(
t
,
`before ->stuff<- after`
,
output
)
}
pkg/util/threading/BUILD
deleted
100644 → 0
View file @
d20912c8
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = ["deadlock-detector.go"],
importpath = "k8s.io/kubernetes/pkg/util/threading",
deps = ["//vendor/github.com/golang/glog:go_default_library"],
)
go_test(
name = "go_default_test",
srcs = ["deadlock-detector_test.go"],
embed = [":go_default_library"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)
pkg/util/threading/deadlock-detector.go
deleted
100644 → 0
View file @
d20912c8
/*
Copyright 2015 The Kubernetes Authors.
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
threading
import
(
"os"
"sync"
"time"
"github.com/golang/glog"
)
type
rwMutexToLockableAdapter
struct
{
rw
*
sync
.
RWMutex
}
func
(
r
*
rwMutexToLockableAdapter
)
Lock
()
{
r
.
rw
.
RLock
()
}
func
(
r
*
rwMutexToLockableAdapter
)
Unlock
()
{
r
.
rw
.
RUnlock
()
}
type
deadlockDetector
struct
{
name
string
lock
sync
.
Locker
maxLockPeriod
time
.
Duration
exiter
exiter
exitChannelFn
func
()
<-
chan
time
.
Time
// Really only useful for testing
stopChannel
<-
chan
bool
}
// DeadlockWatchdogReadLock creates a watchdog on read/write mutex. If the mutex can not be acquired
// for read access within 'maxLockPeriod', the program exits via glog.Exitf() or os.Exit() if that fails
// 'name' is a semantic name that is useful for the user and is printed on exit.
func
DeadlockWatchdogReadLock
(
lock
*
sync
.
RWMutex
,
name
string
,
maxLockPeriod
time
.
Duration
)
{
DeadlockWatchdog
(
&
rwMutexToLockableAdapter
{
lock
},
name
,
maxLockPeriod
)
}
func
DeadlockWatchdog
(
lock
sync
.
Locker
,
name
string
,
maxLockPeriod
time
.
Duration
)
{
if
maxLockPeriod
<=
0
{
panic
(
"maxLockPeriod is <= 0, that can't be what you wanted"
)
}
detector
:=
&
deadlockDetector
{
lock
:
lock
,
name
:
name
,
maxLockPeriod
:
maxLockPeriod
,
exitChannelFn
:
func
()
<-
chan
time
.
Time
{
return
time
.
After
(
maxLockPeriod
)
},
stopChannel
:
make
(
chan
bool
),
}
go
detector
.
run
()
}
// Useful for injecting tests
type
exiter
interface
{
Exitf
(
format
string
,
args
...
interface
{})
}
type
realExiter
struct
{}
func
(
realExiter
)
Exitf
(
format
string
,
args
...
interface
{})
{
func
()
{
defer
func
()
{
// Let's just be extra sure we die, even if Exitf panics
if
r
:=
recover
();
r
!=
nil
{
glog
.
Errorf
(
format
,
args
...
)
os
.
Exit
(
2
)
}
}()
glog
.
Exitf
(
format
,
args
...
)
}()
}
func
(
d
*
deadlockDetector
)
run
()
{
for
{
if
!
d
.
runOnce
()
{
return
}
time
.
Sleep
(
d
.
maxLockPeriod
/
2
)
}
}
func
(
d
*
deadlockDetector
)
runOnce
()
bool
{
ch
:=
make
(
chan
bool
,
1
)
go
func
()
{
d
.
lock
.
Lock
()
d
.
lock
.
Unlock
()
ch
<-
true
}()
exitCh
:=
d
.
exitChannelFn
()
select
{
case
<-
exitCh
:
d
.
exiter
.
Exitf
(
"Deadlock on %s, exiting"
,
d
.
name
)
// return is here for when we use a fake exiter in testing
return
false
case
<-
ch
:
glog
.
V
(
6
)
.
Infof
(
"%s is not deadlocked"
,
d
.
name
)
case
<-
d
.
stopChannel
:
glog
.
V
(
4
)
.
Infof
(
"Stopping deadlock detector for %s"
,
d
.
name
)
return
false
}
return
true
}
pkg/util/threading/deadlock-detector_test.go
deleted
100644 → 0
View file @
d20912c8
/*
Copyright 2015 The Kubernetes Authors.
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
threading
import
(
"sync"
"testing"
"time"
)
type
fakeExiter
struct
{
format
string
args
[]
interface
{}
exited
bool
}
func
(
f
*
fakeExiter
)
Exitf
(
format
string
,
args
...
interface
{})
{
f
.
format
=
format
f
.
args
=
args
f
.
exited
=
true
}
func
TestMaxLockPeriod
(
t
*
testing
.
T
)
{
lock
:=
&
sync
.
RWMutex
{}
panicked
:=
false
func
()
{
defer
func
()
{
if
r
:=
recover
();
r
!=
nil
{
panicked
=
true
}
}()
DeadlockWatchdogReadLock
(
lock
,
"test lock"
,
0
)
}()
if
!
panicked
{
t
.
Errorf
(
"expected a panic for a zero max lock period"
)
}
}
func
TestDeadlockWatchdogLocked
(
t
*
testing
.
T
)
{
lock
:=
&
sync
.
RWMutex
{}
lock
.
Lock
()
exitCh
:=
make
(
chan
time
.
Time
,
1
)
fake
:=
fakeExiter
{}
detector
:=
&
deadlockDetector
{
lock
:
&
rwMutexToLockableAdapter
{
lock
},
name
:
"test deadlock"
,
exitChannelFn
:
func
()
<-
chan
time
.
Time
{
return
exitCh
},
exiter
:
&
fake
,
}
exitCh
<-
time
.
Time
{}
detector
.
run
()
if
!
fake
.
exited
{
t
.
Errorf
(
"expected to have exited"
)
}
if
len
(
fake
.
args
)
!=
1
||
fake
.
args
[
0
]
.
(
string
)
!=
detector
.
name
{
t
.
Errorf
(
"unexpected args: %v"
,
fake
.
args
)
}
}
func
TestDeadlockWatchdogUnlocked
(
t
*
testing
.
T
)
{
lock
:=
&
sync
.
RWMutex
{}
fake
:=
fakeExiter
{}
detector
:=
&
deadlockDetector
{
lock
:
&
rwMutexToLockableAdapter
{
lock
},
name
:
"test deadlock"
,
exitChannelFn
:
func
()
<-
chan
time
.
Time
{
return
time
.
After
(
time
.
Second
*
5
)
},
exiter
:
&
fake
,
}
for
i
:=
0
;
i
<
100
;
i
++
{
detector
.
runOnce
()
}
if
fake
.
exited
{
t
.
Errorf
(
"expected to have not exited"
)
}
}
func
TestDeadlockWatchdogLocking
(
t
*
testing
.
T
)
{
lock
:=
&
sync
.
RWMutex
{}
fake
:=
fakeExiter
{}
go
func
()
{
for
{
lock
.
Lock
()
lock
.
Unlock
()
}
}()
detector
:=
&
deadlockDetector
{
lock
:
&
rwMutexToLockableAdapter
{
lock
},
name
:
"test deadlock"
,
exitChannelFn
:
func
()
<-
chan
time
.
Time
{
return
time
.
After
(
time
.
Second
*
5
)
},
exiter
:
&
fake
,
}
for
i
:=
0
;
i
<
100
;
i
++
{
detector
.
runOnce
()
}
if
fake
.
exited
{
t
.
Errorf
(
"expected to have not exited"
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment