Skip to content

Commit

Permalink
[patch] 🐛 fix agent sidecar behavior (#598)
Browse files Browse the repository at this point in the history
Signed-off-by: Rintaro Okamura <rintaro.okamura@gmail.com>
  • Loading branch information
rinx authored Jul 28, 2020
1 parent 98074e3 commit 1658914
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
18 changes: 11 additions & 7 deletions pkg/agent/sidecar/service/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ func (o *observer) onWrite(ctx context.Context, name string) error {
}
}()

ok, err := o.isValidMetadata(name)
if name != o.metadataPath {
return nil
}

ok, err := o.isValidMetadata()
if err != nil {
return err
}
Expand All @@ -338,7 +342,11 @@ func (o *observer) onCreate(ctx context.Context, name string) error {
}
}()

ok, err := o.isValidMetadata(name)
if name != o.metadataPath {
return nil
}

ok, err := o.isValidMetadata()
if err != nil {
return err
}
Expand All @@ -350,11 +358,7 @@ func (o *observer) onCreate(ctx context.Context, name string) error {
return o.terminate()
}

func (o *observer) isValidMetadata(name string) (bool, error) {
if name != o.metadataPath {
return false, nil
}

func (o *observer) isValidMetadata() (bool, error) {
metadata, err := metadata.Load(o.metadataPath)
if err != nil {
return false, err
Expand Down
5 changes: 1 addition & 4 deletions pkg/agent/sidecar/service/observer/observer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,6 @@ func Test_observer_onCreate(t *testing.T) {

func Test_observer_isValidMetadata(t *testing.T) {
type args struct {
name string
}
type fields struct {
w watch.Watcher
Expand Down Expand Up @@ -887,7 +886,6 @@ func Test_observer_isValidMetadata(t *testing.T) {
{
name: "test_case_1",
args: args {
name: "",
},
fields: fields {
w: nil,
Expand All @@ -912,7 +910,6 @@ func Test_observer_isValidMetadata(t *testing.T) {
return test {
name: "test_case_2",
args: args {
name: "",
},
fields: fields {
w: nil,
Expand Down Expand Up @@ -958,7 +955,7 @@ func Test_observer_isValidMetadata(t *testing.T) {
ch: test.fields.ch,
}

got, err := o.isValidMetadata(test.args.name)
got, err := o.isValidMetadata()
if err := test.checkFunc(test.want, got, err); err != nil {
tt.Errorf("error = %v", err)
}
Expand Down

0 comments on commit 1658914

Please sign in to comment.