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
4000ef00
Commit
4000ef00
authored
Feb 04, 2019
by
Ryan Phillips
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubelet: upgrade sourceFile to use fsnotify
Mitigate some flakes for deleted watch directories and use the maintained fsnotify package.
parent
ace0bde0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
22 deletions
+14
-22
BUILD
pkg/kubelet/config/BUILD
+1
-1
file_linux.go
pkg/kubelet/config/file_linux.go
+12
-19
file_linux_test.go
pkg/kubelet/config/file_linux_test.go
+1
-2
No files found.
pkg/kubelet/config/BUILD
View file @
4000ef00
...
@@ -48,7 +48,7 @@ go_library(
...
@@ -48,7 +48,7 @@ go_library(
] + select({
] + select({
"@io_bazel_rules_go//go/platform:linux": [
"@io_bazel_rules_go//go/platform:linux": [
"//staging/src/k8s.io/client-go/util/flowcontrol:go_default_library",
"//staging/src/k8s.io/client-go/util/flowcontrol:go_default_library",
"//vendor/github.com/
sigma/go-i
notify:go_default_library",
"//vendor/github.com/
fsnotify/fs
notify:go_default_library",
],
],
"//conditions:default": [],
"//conditions:default": [],
}),
}),
...
...
pkg/kubelet/config/file_linux.go
View file @
4000ef00
...
@@ -26,7 +26,7 @@ import (
...
@@ -26,7 +26,7 @@ import (
"strings"
"strings"
"time"
"time"
"github.com/
sigma/go-i
notify"
"github.com/
fsnotify/fs
notify"
"k8s.io/klog"
"k8s.io/klog"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
...
@@ -77,30 +77,30 @@ func (s *sourceFile) doWatch() error {
...
@@ -77,30 +77,30 @@ func (s *sourceFile) doWatch() error {
return
&
retryableError
{
"path does not exist, ignoring"
}
return
&
retryableError
{
"path does not exist, ignoring"
}
}
}
w
,
err
:=
i
notify
.
NewWatcher
()
w
,
err
:=
fs
notify
.
NewWatcher
()
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to create inotify: %v"
,
err
)
return
fmt
.
Errorf
(
"unable to create inotify: %v"
,
err
)
}
}
defer
w
.
Close
()
defer
w
.
Close
()
err
=
w
.
Add
Watch
(
s
.
path
,
inotify
.
IN_DELETE_SELF
|
inotify
.
IN_CREATE
|
inotify
.
IN_MOVED_TO
|
inotify
.
IN_MODIFY
|
inotify
.
IN_MOVED_FROM
|
inotify
.
IN_DELETE
|
inotify
.
IN_ATTRIB
)
err
=
w
.
Add
(
s
.
path
)
if
err
!=
nil
{
if
err
!=
nil
{
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
)
}
}
for
{
for
{
select
{
select
{
case
event
:=
<-
w
.
Event
:
case
event
:=
<-
w
.
Event
s
:
if
err
=
s
.
produceWatchEvent
(
event
);
err
!=
nil
{
if
err
=
s
.
produceWatchEvent
(
&
event
);
err
!=
nil
{
return
fmt
.
Errorf
(
"error while processing inotify event (%+v): %v"
,
event
,
err
)
return
fmt
.
Errorf
(
"error while processing inotify event (%+v): %v"
,
event
,
err
)
}
}
case
err
=
<-
w
.
Error
:
case
err
=
<-
w
.
Error
s
:
return
fmt
.
Errorf
(
"error while watching %q: %v"
,
s
.
path
,
err
)
return
fmt
.
Errorf
(
"error while watching %q: %v"
,
s
.
path
,
err
)
}
}
}
}
}
}
func
(
s
*
sourceFile
)
produceWatchEvent
(
e
*
i
notify
.
Event
)
error
{
func
(
s
*
sourceFile
)
produceWatchEvent
(
e
*
fs
notify
.
Event
)
error
{
// Ignore file start with dots
// Ignore file start with dots
if
strings
.
HasPrefix
(
filepath
.
Base
(
e
.
Name
),
"."
)
{
if
strings
.
HasPrefix
(
filepath
.
Base
(
e
.
Name
),
"."
)
{
klog
.
V
(
4
)
.
Infof
(
"Ignored pod manifest: %s, because it starts with dots"
,
e
.
Name
)
klog
.
V
(
4
)
.
Infof
(
"Ignored pod manifest: %s, because it starts with dots"
,
e
.
Name
)
...
@@ -108,23 +108,16 @@ func (s *sourceFile) produceWatchEvent(e *inotify.Event) error {
...
@@ -108,23 +108,16 @@ func (s *sourceFile) produceWatchEvent(e *inotify.Event) error {
}
}
var
eventType
podEventType
var
eventType
podEventType
switch
{
switch
{
case
(
e
.
Mask
&
inotify
.
IN_ISDIR
)
>
0
:
case
(
e
.
Op
&
fsnotify
.
Create
)
>
0
:
klog
.
Errorf
(
"Not recursing into manifest path %q"
,
s
.
path
)
return
nil
case
(
e
.
Mask
&
inotify
.
IN_CREATE
)
>
0
:
eventType
=
podAdd
case
(
e
.
Mask
&
inotify
.
IN_MOVED_TO
)
>
0
:
eventType
=
podAdd
eventType
=
podAdd
case
(
e
.
Mask
&
inotify
.
IN_MODIFY
)
>
0
:
case
(
e
.
Op
&
fsnotify
.
Write
)
>
0
:
eventType
=
podModify
eventType
=
podModify
case
(
e
.
Mask
&
inotify
.
IN_ATTRIB
)
>
0
:
case
(
e
.
Op
&
fsnotify
.
Chmod
)
>
0
:
eventType
=
podModify
eventType
=
podModify
case
(
e
.
Mask
&
inotify
.
IN_DELETE
)
>
0
:
case
(
e
.
Op
&
fsnotify
.
Remove
)
>
0
:
eventType
=
podDelete
eventType
=
podDelete
case
(
e
.
Mask
&
inotify
.
IN_MOVED_FROM
)
>
0
:
case
(
e
.
Op
&
fsnotify
.
Rename
)
>
0
:
eventType
=
podDelete
eventType
=
podDelete
case
(
e
.
Mask
&
inotify
.
IN_DELETE_SELF
)
>
0
:
return
fmt
.
Errorf
(
"the watched path is deleted"
)
default
:
default
:
// Ignore rest events
// Ignore rest events
return
nil
return
nil
...
...
pkg/kubelet/config/file_linux_test.go
View file @
4000ef00
...
@@ -22,7 +22,6 @@ import (
...
@@ -22,7 +22,6 @@ import (
"fmt"
"fmt"
"io"
"io"
"os"
"os"
"os/exec"
"path/filepath"
"path/filepath"
"sync"
"sync"
"testing"
"testing"
...
@@ -428,7 +427,7 @@ func writeFile(filename string, data []byte) error {
...
@@ -428,7 +427,7 @@ func writeFile(filename string, data []byte) error {
func
changeFileName
(
dir
,
from
,
to
string
,
t
*
testing
.
T
)
{
func
changeFileName
(
dir
,
from
,
to
string
,
t
*
testing
.
T
)
{
fromPath
:=
filepath
.
Join
(
dir
,
from
)
fromPath
:=
filepath
.
Join
(
dir
,
from
)
toPath
:=
filepath
.
Join
(
dir
,
to
)
toPath
:=
filepath
.
Join
(
dir
,
to
)
if
err
:=
exec
.
Command
(
"mv"
,
fromPath
,
toPath
)
.
Run
(
);
err
!=
nil
{
if
err
:=
os
.
Rename
(
fromPath
,
toPath
);
err
!=
nil
{
t
.
Errorf
(
"Fail to change file name: %s"
,
err
)
t
.
Errorf
(
"Fail to change file name: %s"
,
err
)
}
}
}
}
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