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
55e045d9
Commit
55e045d9
authored
Jun 16, 2017
by
xiangpengzhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change pod config to manifest
parent
cce1c9b4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
15 deletions
+15
-15
file.go
pkg/kubelet/config/file.go
+7
-7
file_linux.go
pkg/kubelet/config/file_linux.go
+4
-4
file_linux_test.go
pkg/kubelet/config/file_linux_test.go
+4
-4
No files found.
pkg/kubelet/config/file.go
View file @
55e045d9
...
@@ -73,7 +73,7 @@ func new(path string, nodeName types.NodeName, period time.Duration, updates cha
...
@@ -73,7 +73,7 @@ func new(path string, nodeName types.NodeName, period time.Duration, updates cha
func
(
s
*
sourceFile
)
run
()
{
func
(
s
*
sourceFile
)
run
()
{
if
err
:=
s
.
watch
();
err
!=
nil
{
if
err
:=
s
.
watch
();
err
!=
nil
{
glog
.
Errorf
(
"unable to read
config
path %q: %v"
,
s
.
path
,
err
)
glog
.
Errorf
(
"unable to read
manifest
path %q: %v"
,
s
.
path
,
err
)
}
}
}
}
...
@@ -118,7 +118,7 @@ func (s *sourceFile) resetStoreFromPath() error {
...
@@ -118,7 +118,7 @@ func (s *sourceFile) resetStoreFromPath() error {
}
}
}
}
// Get as many pod
config
s as we can from a directory. Return an error if and only if something
// Get as many pod
manifest
s as we can from a directory. Return an error if and only if something
// prevented us from reading anything at all. Do not return an error if only some files
// prevented us from reading anything at all. Do not return an error if only some files
// were problematic.
// were problematic.
func
(
s
*
sourceFile
)
extractFromDir
(
name
string
)
([]
*
v1
.
Pod
,
error
)
{
func
(
s
*
sourceFile
)
extractFromDir
(
name
string
)
([]
*
v1
.
Pod
,
error
)
{
...
@@ -142,23 +142,23 @@ func (s *sourceFile) extractFromDir(name string) ([]*v1.Pod, error) {
...
@@ -142,23 +142,23 @@ func (s *sourceFile) extractFromDir(name string) ([]*v1.Pod, error) {
switch
{
switch
{
case
statInfo
.
Mode
()
.
IsDir
()
:
case
statInfo
.
Mode
()
.
IsDir
()
:
glog
.
V
(
1
)
.
Infof
(
"Not recursing into
config
path %q"
,
path
)
glog
.
V
(
1
)
.
Infof
(
"Not recursing into
manifest
path %q"
,
path
)
case
statInfo
.
Mode
()
.
IsRegular
()
:
case
statInfo
.
Mode
()
.
IsRegular
()
:
pod
,
err
:=
s
.
extractFromFile
(
path
)
pod
,
err
:=
s
.
extractFromFile
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
V
(
1
)
.
Infof
(
"Can't process
config
file %q: %v"
,
path
,
err
)
glog
.
V
(
1
)
.
Infof
(
"Can't process
manifest
file %q: %v"
,
path
,
err
)
}
else
{
}
else
{
pods
=
append
(
pods
,
pod
)
pods
=
append
(
pods
,
pod
)
}
}
default
:
default
:
glog
.
V
(
1
)
.
Infof
(
"
Config
path %q is not a directory or file: %v"
,
path
,
statInfo
.
Mode
())
glog
.
V
(
1
)
.
Infof
(
"
Manifest
path %q is not a directory or file: %v"
,
path
,
statInfo
.
Mode
())
}
}
}
}
return
pods
,
nil
return
pods
,
nil
}
}
func
(
s
*
sourceFile
)
extractFromFile
(
filename
string
)
(
pod
*
v1
.
Pod
,
err
error
)
{
func
(
s
*
sourceFile
)
extractFromFile
(
filename
string
)
(
pod
*
v1
.
Pod
,
err
error
)
{
glog
.
V
(
3
)
.
Infof
(
"Reading
config
file %q"
,
filename
)
glog
.
V
(
3
)
.
Infof
(
"Reading
manifest
file %q"
,
filename
)
defer
func
()
{
defer
func
()
{
if
err
==
nil
&&
pod
!=
nil
{
if
err
==
nil
&&
pod
!=
nil
{
objKey
,
keyErr
:=
cache
.
MetaNamespaceKeyFunc
(
pod
)
objKey
,
keyErr
:=
cache
.
MetaNamespaceKeyFunc
(
pod
)
...
@@ -193,7 +193,7 @@ func (s *sourceFile) extractFromFile(filename string) (pod *v1.Pod, err error) {
...
@@ -193,7 +193,7 @@ func (s *sourceFile) extractFromFile(filename string) (pod *v1.Pod, err error) {
return
pod
,
nil
return
pod
,
nil
}
}
return
pod
,
fmt
.
Errorf
(
"%v: couldn't parse as pod(%v), please check
config
file.
\n
"
,
filename
,
podErr
)
return
pod
,
fmt
.
Errorf
(
"%v: couldn't parse as pod(%v), please check
manifest
file.
\n
"
,
filename
,
podErr
)
}
}
func
(
s
*
sourceFile
)
replaceStore
(
pods
...*
v1
.
Pod
)
(
err
error
)
{
func
(
s
*
sourceFile
)
replaceStore
(
pods
...*
v1
.
Pod
)
(
err
error
)
{
...
...
pkg/kubelet/config/file_linux.go
View file @
55e045d9
...
@@ -62,9 +62,9 @@ func (s *sourceFile) watch() error {
...
@@ -62,9 +62,9 @@ func (s *sourceFile) watch() error {
return
fmt
.
Errorf
(
"unable to create inotify for path %q: %v"
,
s
.
path
,
err
)
return
fmt
.
Errorf
(
"unable to create inotify for path %q: %v"
,
s
.
path
,
err
)
}
}
// Reset store with
config
files already existing when starting
// Reset store with
manifest
files already existing when starting
if
err
:=
s
.
resetStoreFromPath
();
err
!=
nil
{
if
err
:=
s
.
resetStoreFromPath
();
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to read
config
path %q: %v"
,
s
.
path
,
err
)
return
fmt
.
Errorf
(
"unable to read
manifest
path %q: %v"
,
s
.
path
,
err
)
}
}
for
{
for
{
...
@@ -89,7 +89,7 @@ func (s *sourceFile) processEvent(e *inotify.Event) error {
...
@@ -89,7 +89,7 @@ func (s *sourceFile) processEvent(e *inotify.Event) error {
var
eventType
podEventType
var
eventType
podEventType
switch
{
switch
{
case
(
e
.
Mask
&
inotify
.
IN_ISDIR
)
>
0
:
case
(
e
.
Mask
&
inotify
.
IN_ISDIR
)
>
0
:
glog
.
V
(
1
)
.
Infof
(
"Not recursing into
config
path %q"
,
s
.
path
)
glog
.
V
(
1
)
.
Infof
(
"Not recursing into
manifest
path %q"
,
s
.
path
)
return
nil
return
nil
case
(
e
.
Mask
&
inotify
.
IN_CREATE
)
>
0
:
case
(
e
.
Mask
&
inotify
.
IN_CREATE
)
>
0
:
eventType
=
podAdd
eventType
=
podAdd
...
@@ -111,7 +111,7 @@ func (s *sourceFile) processEvent(e *inotify.Event) error {
...
@@ -111,7 +111,7 @@ func (s *sourceFile) processEvent(e *inotify.Event) error {
switch
eventType
{
switch
eventType
{
case
podAdd
,
podModify
:
case
podAdd
,
podModify
:
if
pod
,
err
:=
s
.
extractFromFile
(
e
.
Name
);
err
!=
nil
{
if
pod
,
err
:=
s
.
extractFromFile
(
e
.
Name
);
err
!=
nil
{
glog
.
Errorf
(
"can't process
config
file %q: %v"
,
e
.
Name
,
err
)
glog
.
Errorf
(
"can't process
manifest
file %q: %v"
,
e
.
Name
,
err
)
}
else
{
}
else
{
return
s
.
store
.
Add
(
pod
)
return
s
.
store
.
Add
(
pod
)
}
}
...
...
pkg/kubelet/config/file_linux_test.go
View file @
55e045d9
...
@@ -80,7 +80,7 @@ func TestReadPodsFromFileExistAlready(t *testing.T) {
...
@@ -80,7 +80,7 @@ func TestReadPodsFromFileExistAlready(t *testing.T) {
t
.
Fatalf
(
"unable to create temp dir: %v"
,
err
)
t
.
Fatalf
(
"unable to create temp dir: %v"
,
err
)
}
}
defer
os
.
RemoveAll
(
dirName
)
defer
os
.
RemoveAll
(
dirName
)
file
:=
testCase
.
writeToFile
(
dirName
,
"test_pod_
config
"
,
t
)
file
:=
testCase
.
writeToFile
(
dirName
,
"test_pod_
manifest
"
,
t
)
ch
:=
make
(
chan
interface
{})
ch
:=
make
(
chan
interface
{})
NewSourceFile
(
file
,
hostname
,
time
.
Millisecond
,
ch
)
NewSourceFile
(
file
,
hostname
,
time
.
Millisecond
,
ch
)
...
@@ -130,7 +130,7 @@ func TestExtractFromBadDataFile(t *testing.T) {
...
@@ -130,7 +130,7 @@ func TestExtractFromBadDataFile(t *testing.T) {
}
}
defer
os
.
RemoveAll
(
dirName
)
defer
os
.
RemoveAll
(
dirName
)
fileName
:=
filepath
.
Join
(
dirName
,
"test_pod_
config
"
)
fileName
:=
filepath
.
Join
(
dirName
,
"test_pod_
manifest
"
)
err
=
ioutil
.
WriteFile
(
fileName
,
[]
byte
{
1
,
2
,
3
},
0555
)
err
=
ioutil
.
WriteFile
(
fileName
,
[]
byte
{
1
,
2
,
3
},
0555
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unable to write test file %#v"
,
err
)
t
.
Fatalf
(
"unable to write test file %#v"
,
err
)
...
@@ -254,7 +254,7 @@ func watchFileAdded(watchDir bool, t *testing.T) {
...
@@ -254,7 +254,7 @@ func watchFileAdded(watchDir bool, t *testing.T) {
hostname
:=
types
.
NodeName
(
"random-test-hostname"
)
hostname
:=
types
.
NodeName
(
"random-test-hostname"
)
var
testCases
=
getTestCases
(
hostname
)
var
testCases
=
getTestCases
(
hostname
)
fileNamePre
:=
"test_pod_
config
"
fileNamePre
:=
"test_pod_
manifest
"
for
index
,
testCase
:=
range
testCases
{
for
index
,
testCase
:=
range
testCases
{
func
()
{
func
()
{
dirName
,
err
:=
utiltesting
.
MkTmpdir
(
"dir-test"
)
dirName
,
err
:=
utiltesting
.
MkTmpdir
(
"dir-test"
)
...
@@ -292,7 +292,7 @@ func watchFileChanged(watchDir bool, t *testing.T) {
...
@@ -292,7 +292,7 @@ func watchFileChanged(watchDir bool, t *testing.T) {
hostname
:=
types
.
NodeName
(
"random-test-hostname"
)
hostname
:=
types
.
NodeName
(
"random-test-hostname"
)
var
testCases
=
getTestCases
(
hostname
)
var
testCases
=
getTestCases
(
hostname
)
fileNamePre
:=
"test_pod_
config
"
fileNamePre
:=
"test_pod_
manifest
"
for
index
,
testCase
:=
range
testCases
{
for
index
,
testCase
:=
range
testCases
{
func
()
{
func
()
{
dirName
,
err
:=
utiltesting
.
MkTmpdir
(
"dir-test"
)
dirName
,
err
:=
utiltesting
.
MkTmpdir
(
"dir-test"
)
...
...
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