mirror of
				https://github.com/juanfont/headscale.git
				synced 2025-11-04 10:01:05 +01:00 
			
		
		
		
	Merge pull request #628 from kradalby/acl-update-nodes
This commit is contained in:
		
						commit
						f93cf4b980
					
				
							
								
								
									
										26
									
								
								app.go
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								app.go
									
									
									
									
									
								
							@ -657,7 +657,9 @@ func (h *Headscale) Serve() error {
 | 
			
		||||
					}
 | 
			
		||||
					log.Info().
 | 
			
		||||
						Str("path", aclPath).
 | 
			
		||||
						Msg("ACL policy successfully reloaded")
 | 
			
		||||
						Msg("ACL policy successfully reloaded, notifying nodes of change")
 | 
			
		||||
 | 
			
		||||
					h.setLastStateChangeToNow()
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
			default:
 | 
			
		||||
@ -756,13 +758,25 @@ func (h *Headscale) getTLSSettings() (*tls.Config, error) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (h *Headscale) setLastStateChangeToNow(namespace string) {
 | 
			
		||||
func (h *Headscale) setLastStateChangeToNow(namespaces ...string) {
 | 
			
		||||
	var err error
 | 
			
		||||
 | 
			
		||||
	now := time.Now().UTC()
 | 
			
		||||
	lastStateUpdate.WithLabelValues("", "headscale").Set(float64(now.Unix()))
 | 
			
		||||
	if h.lastStateChange == nil {
 | 
			
		||||
		h.lastStateChange = xsync.NewMapOf[time.Time]()
 | 
			
		||||
 | 
			
		||||
	if len(namespaces) == 0 {
 | 
			
		||||
		namespaces, err = h.ListNamespacesStr()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Error().Caller().Err(err).Msg("failed to fetch all namespaces, failing to update last changed state.")
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, namespace := range namespaces {
 | 
			
		||||
		lastStateUpdate.WithLabelValues(namespace, "headscale").Set(float64(now.Unix()))
 | 
			
		||||
		if h.lastStateChange == nil {
 | 
			
		||||
			h.lastStateChange = xsync.NewMapOf[time.Time]()
 | 
			
		||||
		}
 | 
			
		||||
		h.lastStateChange.Store(namespace, now)
 | 
			
		||||
	}
 | 
			
		||||
	h.lastStateChange.Store(namespace, now)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (h *Headscale) getLastStateChange(namespaces ...string) time.Time {
 | 
			
		||||
 | 
			
		||||
@ -148,6 +148,21 @@ func (h *Headscale) ListNamespaces() ([]Namespace, error) {
 | 
			
		||||
	return namespaces, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (h *Headscale) ListNamespacesStr() ([]string, error) {
 | 
			
		||||
	namespaces, err := h.ListNamespaces()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return []string{}, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	namespaceStrs := make([]string, len(namespaces))
 | 
			
		||||
 | 
			
		||||
	for index, namespace := range namespaces {
 | 
			
		||||
		namespaceStrs[index] = namespace.Name
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return namespaceStrs, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ListMachinesInNamespace gets all the nodes in a given namespace.
 | 
			
		||||
func (h *Headscale) ListMachinesInNamespace(name string) ([]Machine, error) {
 | 
			
		||||
	err := CheckForFQDNRules(name)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user