Repository: istio/istio (go)

Issue:
CNI does not attempt to reinstall deleted CNI plugin binary
CNI daemonset watches the CNI plugin configuration and attempt to reconcile it if there is any changes. However it does not watch the CNI plugin binary directory. If the plugin binary is removed, CNI daemonset won't try to reinstall it. This will be problematic if user migrate CNI daemonset from one namespace to another.

Pull request:
add watching for cni plugin bin dir
**Please provide a description of this PR:**

fix #34524

@bianpengyuan 
PR #34710 just fix watching for cni config dir, not the cni bin dir.
We should add cni bin dir to watcher, to make sure the cni bin file(istio-cni) is always correct.

**To help us figure out who should review this PR, please put an X in all the areas that this PR affects.**

- [ ] Configuration Infrastructure
- [ ] Docs
- [ ] Installation
- [X] Networking
- [ ] Performance and Scalability
- [ ] Policies and Telemetry
- [ ] Security
- [ ] Test and Release
- [ ] User Experience
- [ ] Developer Infrastructure

**Please check any characteristics that apply to this pull request.**

- [X] Does not have any [user-facing](https://github.com/istio/istio/tree/master/releasenotes#when-to-add-release-notes) changes. This may include CLI changes, API changes, behavior changes, performance improvements, etc.


Patch:
diff --git a/cni/pkg/install/install.go b/cni/pkg/install/install.go
index 7cfeee47ff..71ddb31673 100644
--- a/cni/pkg/install/install.go
+++ b/cni/pkg/install/install.go
@@ -163,7 +163,7 @@ func readServiceAccountToken() (string, error) {
 func sleepCheckInstall(ctx context.Context, cfg *config.InstallConfig, cniConfigFilepath string, isReady *atomic.Value) error {
 	// Create file watcher before checking for installation
 	// so that no file modifications are missed while and after checking
-	watcher, fileModified, errChan, err := util.CreateFileWatcher(cfg.MountedCNINetDir)
+	watcher, fileModified, errChan, err := util.CreateFileWatcher(append(cfg.CNIBinTargetDirs, cfg.MountedCNINetDir)...)
 	if err != nil {
 		return err
 	}
diff --git a/cni/pkg/util/util.go b/cni/pkg/util/util.go
index 9856977987..d0cbe85d1a 100644
--- a/cni/pkg/util/util.go
+++ b/cni/pkg/util/util.go
@@ -21,10 +21,12 @@ import (
 
 	"github.com/fsnotify/fsnotify"
 	"github.com/pkg/errors"
+
+	"istio.io/istio/pkg/file"
 )
 
 // Creates a file watcher that watches for any changes to the directory
-func CreateFileWatcher(dir string) (watcher *fsnotify.Watcher, fileModified chan bool, errChan chan error, err error) {
+func CreateFileWatcher(dirs ...string) (watcher *fsnotify.Watcher, fileModified chan bool, errChan chan error, err error) {
 	watcher, err = fsnotify.NewWatcher()
 	if err != nil {
 		return
@@ -33,11 +35,16 @@ func CreateFileWatcher(dir string) (watcher *fsnotify.Watcher, fileModified chan
 	fileModified, errChan = make(chan bool), make(chan error)
 	go watchFiles(watcher, fileModified, errChan)
 
-	if err = watcher.Add(dir); err != nil {
-		if closeErr := watcher.Close(); closeErr != nil {
-			err = errors.Wrap(err, closeErr.Error())
+	for _, dir := range dirs {
+		if file.IsDirWriteable(dir) != nil {
+			continue
+		}
+		if err = watcher.Add(dir); err != nil {
+			if closeErr := watcher.Close(); closeErr != nil {
+				err = errors.Wrap(err, closeErr.Error())
+			}
+			return nil, nil, nil, err
 		}
-		return nil, nil, nil, err
 	}
 
 	return
diff --git a/go.mod b/go.mod
index bfa8e0e3bf..b8f7ddfbac 100644
--- a/go.mod
+++ b/go.mod
@@ -23,7 +23,6 @@ require (
 	github.com/aws/aws-sdk-go v1.40.16
 	github.com/cenkalti/backoff v2.2.1+incompatible
 	github.com/census-instrumentation/opencensus-proto v0.3.0
-	github.com/cespare/xxhash v1.1.0 // indirect
 	github.com/cheggaaa/pb/v3 v3.0.8
 	github.com/cncf/udpa/go v0.0.0-20210322005330-6414d713912e
 	github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158
@@ -87,14 +86,14 @@ require (
 	gomodules.xyz/jsonpatch/v3 v3.0.1
 	google.golang.org/api v0.52.0
 	google.golang.org/genproto v0.0.0-20210728212813-7823e685a01f
-	google.golang.org/grpc v1.39.1
+	google.golang.org/grpc v1.40.0
 	google.golang.org/protobuf v1.27.1
 	gopkg.in/square/go-jose.v2 v2.6.0
 	gopkg.in/yaml.v2 v2.4.0
 	gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
 	helm.sh/helm/v3 v3.6.1
-	istio.io/api v0.0.0-20210817134638-1b724d2c575d
-	istio.io/client-go v0.0.0-20210817135142-d003d8f305b3
+	istio.io/api v0.0.0-20210819145325-4e216752748c
+	istio.io/client-go v0.0.0-20210819145837-406323e5416e
 	istio.io/gogo-genproto v0.0.0-20210802150430-d27771a94902
 	istio.io/pkg v0.0.0-20210802150248-cb1ee48dbbb0
 	k8s.io/api v0.22.0
diff --git a/go.sum b/go.sum
index de5908d762..663435f410 100644
--- a/go.sum
+++ b/go.sum
@@ -1854,8 +1854,8 @@ google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQ
 google.golang.org/grpc v1.37.1/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
 google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
 google.golang.org/grpc v1.39.0/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE=
-google.golang.org/grpc v1.39.1 h1:f37vZbBVTiJ6jKG5mWz8ySOBxNqy6ViPgyhSdVnxF3E=
-google.golang.org/grpc v1.39.1/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE=
+google.golang.org/grpc v1.40.0 h1:AGJ0Ih4mHjSeibYkFGh1dD9KJ/eOtZ93I6hoHhukQ5Q=
+google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
 google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
 google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
 google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
@@ -1931,10 +1931,10 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
 honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
 honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
 honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
-istio.io/api v0.0.0-20210817134638-1b724d2c575d h1:p4lku09sX3isDLztiTFIOXWAORqnbRLOCfTHOBX9zG0=
-istio.io/api v0.0.0-20210817134638-1b724d2c575d/go.mod h1:nsSFw1LIMmGL7r/+6fJI6FxeG/UGlLxRK8bkojIvBVs=
-istio.io/client-go v0.0.0-20210817135142-d003d8f305b3 h1:0dkItwKV1y0YWf7NXVeQgIJet497dtxFqVqqxzIoomk=
-istio.io/client-go v0.0.0-20210817135142-d003d8f305b3/go.mod h1:6Bx12TaK4FbLsIOpn6nrjBkrwV6KjNN+XuC5ATOVog4=
+istio.io/api v0.0.0-20210819145325-4e216752748c h1:4GztK5rRFIHXwKVrmUMJnQUDdKY0NHGl/LhuzrtE2eY=
+istio.io/api v0.0.0-20210819145325-4e216752748c/go.mod h1:nsSFw1LIMmGL7r/+6fJI6FxeG/UGlLxRK8bkojIvBVs=
+istio.io/client-go v0.0.0-20210819145837-406323e5416e h1:gd6yn28flsJqsNsPvCqbaZ/B4ixnQUZbdaZ3cIq1X5Q=
+istio.io/client-go v0.0.0-20210819145837-406323e5416e/go.mod h1:Bx5oHMZw6B6SXQi+dKNN1TVSiRRBPSv3YNRxS2PalEM=
 istio.io/gogo-genproto v0.0.0-20210113155706-4daf5697332f/go.mod h1:6BwTZRNbWS570wHX/uR1Wqk5e0157TofTAUMzT7N4+s=
 istio.io/gogo-genproto v0.0.0-20210802150430-d27771a94902 h1:WJci4nt8dv9cYLgIiehTO7TR5C+nFYzuXEdaaKoLNBM=
 istio.io/gogo-genproto v0.0.0-20210802150430-d27771a94902/go.mod h1:6BwTZRNbWS570wHX/uR1Wqk5e0157TofTAUMzT7N4+s=


Test patch:
diff --git a/pilot/pkg/networking/grpcgen/grpcgen_test.go b/pilot/pkg/networking/grpcgen/grpcgen_test.go
index 55a0c3c698..bd4d58e280 100644
--- a/pilot/pkg/networking/grpcgen/grpcgen_test.go
+++ b/pilot/pkg/networking/grpcgen/grpcgen_test.go
@@ -180,7 +180,7 @@ func TestGRPC(t *testing.T) {
 	})
 
 	t.Run("gRPC-cdslb", func(t *testing.T) {
-		rb := balancer.Get("eds_experimental")
+		rb := balancer.Get("cluster_resolver_experimental")
 		b := rb.Build(&testLBClientConn{}, balancer.BuildOptions{})
 		defer b.Close()
 	})