"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/config/mesh/networks_watcher.go" between
istio-1.10.0.tar.gz and istio-1.10.1.tar.gz

About: Istio is a platform-independent service mesh that provides a uniform way to connect, secure, control, and observe microservices.

networks_watcher.go  (istio-1.10.0):networks_watcher.go  (istio-1.10.1)
skipping to change at line 43 skipping to change at line 43
Networks() *meshconfig.MeshNetworks Networks() *meshconfig.MeshNetworks
} }
// NetworkWatcher watches changes to the mesh networks config. // NetworkWatcher watches changes to the mesh networks config.
type NetworksWatcher interface { type NetworksWatcher interface {
NetworksHolder NetworksHolder
AddNetworksHandler(func()) AddNetworksHandler(func())
} }
var _ NetworksWatcher = &networksWatcher{} var _ NetworksWatcher = &InternalNetworkWatcher{}
type networksWatcher struct { type InternalNetworkWatcher struct {
mutex sync.Mutex mutex sync.Mutex
handlers []func() handlers []func()
networks *meshconfig.MeshNetworks networks *meshconfig.MeshNetworks
} }
// NewFixedNetworksWatcher creates a new NetworksWatcher that always returns the given config. // NewFixedNetworksWatcher creates a new NetworksWatcher that always returns the given config.
// It will never fire any events, since the config never changes. // It will never fire any events, since the config never changes.
func NewFixedNetworksWatcher(networks *meshconfig.MeshNetworks) NetworksWatcher { func NewFixedNetworksWatcher(networks *meshconfig.MeshNetworks) NetworksWatcher {
return &networksWatcher{ return &InternalNetworkWatcher{
networks: networks, networks: networks,
} }
} }
// NewNetworksWatcher creates a new watcher for changes to the given networks co nfig file. // NewNetworksWatcher creates a new watcher for changes to the given networks co nfig file.
func NewNetworksWatcher(fileWatcher filewatcher.FileWatcher, filename string) (N etworksWatcher, error) { func NewNetworksWatcher(fileWatcher filewatcher.FileWatcher, filename string) (N etworksWatcher, error) {
meshNetworks, err := ReadMeshNetworks(filename) meshNetworks, err := ReadMeshNetworks(filename)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to read mesh networks configuratio n from %q: %v", filename, err) return nil, fmt.Errorf("failed to read mesh networks configuratio n from %q: %v", filename, err)
} }
ResolveHostsInNetworksConfig(meshNetworks) ResolveHostsInNetworksConfig(meshNetworks)
networksdump, _ := gogoprotomarshal.ToJSONWithIndent(meshNetworks, " ") networksdump, _ := gogoprotomarshal.ToJSONWithIndent(meshNetworks, " ")
log.Infof("mesh networks configuration: %s", networksdump) log.Infof("mesh networks configuration: %s", networksdump)
w := &networksWatcher{ w := &InternalNetworkWatcher{
networks: meshNetworks, networks: meshNetworks,
} }
// Watch the networks config file for changes and reload if it got modifi ed // Watch the networks config file for changes and reload if it got modifi ed
addFileWatcher(fileWatcher, filename, func() { addFileWatcher(fileWatcher, filename, func() {
// Reload the config file // Reload the config file
meshNetworks, err := ReadMeshNetworks(filename) meshNetworks, err := ReadMeshNetworks(filename)
if err != nil { if err != nil {
log.Warnf("failed to read mesh networks configuration fro m %q: %v", filename, err) log.Warnf("failed to read mesh networks configuration fro m %q: %v", filename, err)
return return
} }
w.SetNetworks(meshNetworks) w.SetNetworks(meshNetworks)
}) })
return w, nil return w, nil
} }
// Networks returns the latest network configuration for the mesh. // Networks returns the latest network configuration for the mesh.
func (w *networksWatcher) Networks() *meshconfig.MeshNetworks { func (w *InternalNetworkWatcher) Networks() *meshconfig.MeshNetworks {
return (*meshconfig.MeshNetworks)(atomic.LoadPointer((*unsafe.Pointer)(un safe.Pointer(&w.networks)))) return (*meshconfig.MeshNetworks)(atomic.LoadPointer((*unsafe.Pointer)(un safe.Pointer(&w.networks))))
} }
// SetNetworks will use the given value for mesh networks and notify all handler s of the change // SetNetworks will use the given value for mesh networks and notify all handler s of the change
func (w *networksWatcher) SetNetworks(meshNetworks *meshconfig.MeshNetworks) { func (w *InternalNetworkWatcher) SetNetworks(meshNetworks *meshconfig.MeshNetwor ks) {
var handlers []func() var handlers []func()
w.mutex.Lock() w.mutex.Lock()
if !reflect.DeepEqual(meshNetworks, w.networks) { if !reflect.DeepEqual(meshNetworks, w.networks) {
ResolveHostsInNetworksConfig(meshNetworks) ResolveHostsInNetworksConfig(meshNetworks)
networksdump, _ := gogoprotomarshal.ToJSONWithIndent(meshNetworks , " ") networksdump, _ := gogoprotomarshal.ToJSONWithIndent(meshNetworks , " ")
log.Infof("mesh networks configuration updated to: %s", networksd ump) log.Infof("mesh networks configuration updated to: %s", networksd ump)
// Store the new config. // Store the new config.
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&w.networks) ), unsafe.Pointer(meshNetworks)) atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&w.networks) ), unsafe.Pointer(meshNetworks))
skipping to change at line 115 skipping to change at line 115
} }
w.mutex.Unlock() w.mutex.Unlock()
// Notify the handlers of the change. // Notify the handlers of the change.
for _, h := range handlers { for _, h := range handlers {
h() h()
} }
} }
// AddMeshHandler registers a callback handler for changes to the mesh network c onfig. // AddMeshHandler registers a callback handler for changes to the mesh network c onfig.
func (w *networksWatcher) AddNetworksHandler(h func()) { func (w *InternalNetworkWatcher) AddNetworksHandler(h func()) {
w.mutex.Lock() w.mutex.Lock()
defer w.mutex.Unlock() defer w.mutex.Unlock()
// hack: prepend handlers; the last to be added will be run first and blo ck other handlers // hack: prepend handlers; the last to be added will be run first and blo ck other handlers
w.handlers = append([]func(){h}, w.handlers...) w.handlers = append([]func(){h}, w.handlers...)
} }
 End of changes. 7 change blocks. 
7 lines changed or deleted 7 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)