Repository: hashicorp/nomad
File: client/client.go (Go)

Code before:
	}
	node.Status = structs.NodeStatusInit

	// Setup default static meta
	if _, ok := node.Meta[envoy.SidecarMetaParam]; !ok {
		node.Meta[envoy.SidecarMetaParam] = envoy.ImageFormat
	}
	if _, ok := node.Meta[envoy.GatewayMetaParam]; !ok {
		node.Meta[envoy.GatewayMetaParam] = envoy.ImageFormat
	}
	if _, ok := node.Meta[envoy.DefaultConnectLogLevelParam]; !ok {
		node.Meta[envoy.DefaultConnectLogLevelParam] = envoy.DefaultConnectLogLevel
	}
	if _, ok := node.Meta[envoy.DefaultConnectProxyConcurrencyParam]; !ok {
		node.Meta[envoy.DefaultConnectProxyConcurrencyParam] = envoy.DefaultConnectProxyConcurrency
	}
	if _, ok := node.Meta[envoy.DefaultTransparentProxyUIDParam]; !ok {
		node.Meta[envoy.DefaultTransparentProxyUIDParam] = envoy.DefaultTransparentProxyUID
	}
	if _, ok := node.Meta[envoy.DefaultTransparentProxyOutboundPortParam]; !ok {
		node.Meta[envoy.DefaultTransparentProxyOutboundPortParam] = envoy.DefaultTransparentProxyOutboundPort
	}
	// Set NodeMaxAllocs before dynamic configuration is set
	if newConfig.NodeMaxAllocs != 0 {
		node.NodeMaxAllocs = newConfig.NodeMaxAllocs
	}
	// Since node.Meta will get dynamic metadata merged in, save static metadata
	// here.
	c.metaStatic = maps.Clone(node.Meta)

	// Merge dynamic node metadata
	c.metaDynamic, err = c.stateDB.GetNodeMeta()
	if err != nil {
		return fmt.Errorf("error reading dynamic node metadata: %w", err)
	}

	if c.metaDynamic == nil {
		c.metaDynamic = map[string]*string{}
	}

	for dk, dv := range c.metaDynamic {
		if dv == nil {
			_, ok := node.Meta[dk]
			if ok {
				// Unset static node metadata
				delete(node.Meta, dk)
			} else {
				// Forget dynamic node metadata tombstone as there's no
				// static value to erase.
				delete(c.metaDynamic, dk)
			}

Review comment (suggestion):
I think we can safely skip the conditional here. The default value will be 0 anyways.

```suggestion
	node.NodeMaxAllocs = newConfig.NodeMaxAllocs
```

Code after:
	}
	node.Status = structs.NodeStatusInit

	// Setup default static meta
	if _, ok := node.Meta[envoy.SidecarMetaParam]; !ok {
		node.Meta[envoy.SidecarMetaParam] = envoy.ImageFormat
	}
	if _, ok := node.Meta[envoy.GatewayMetaParam]; !ok {
		node.Meta[envoy.GatewayMetaParam] = envoy.ImageFormat
	}
	if _, ok := node.Meta[envoy.DefaultConnectLogLevelParam]; !ok {
		node.Meta[envoy.DefaultConnectLogLevelParam] = envoy.DefaultConnectLogLevel
	}
	if _, ok := node.Meta[envoy.DefaultConnectProxyConcurrencyParam]; !ok {
		node.Meta[envoy.DefaultConnectProxyConcurrencyParam] = envoy.DefaultConnectProxyConcurrency
	}
	if _, ok := node.Meta[envoy.DefaultTransparentProxyUIDParam]; !ok {
		node.Meta[envoy.DefaultTransparentProxyUIDParam] = envoy.DefaultTransparentProxyUID
	}
	if _, ok := node.Meta[envoy.DefaultTransparentProxyOutboundPortParam]; !ok {
		node.Meta[envoy.DefaultTransparentProxyOutboundPortParam] = envoy.DefaultTransparentProxyOutboundPort
	}
	// Set NodeMaxAllocs before dynamic configuration is set
	node.NodeMaxAllocs = newConfig.NodeMaxAllocs

	// Since node.Meta will get dynamic metadata merged in, save static metadata
	// here.
	c.metaStatic = maps.Clone(node.Meta)

	// Merge dynamic node metadata
	c.metaDynamic, err = c.stateDB.GetNodeMeta()
	if err != nil {
		return fmt.Errorf("error reading dynamic node metadata: %w", err)
	}

	if c.metaDynamic == nil {
		c.metaDynamic = map[string]*string{}
	}

	for dk, dv := range c.metaDynamic {
		if dv == nil {
			_, ok := node.Meta[dk]
			if ok {
				// Unset static node metadata
				delete(node.Meta, dk)
			} else {
				// Forget dynamic node metadata tombstone as there's no
				// static value to erase.
				delete(c.metaDynamic, dk)
			}
			continue