func getSysctlContent()

in aks-node-controller/parser/helper.go [263:411]


func getSysctlContent(s *aksnodeconfigv1.SysctlConfig) string {
	// This is a partial workaround to this upstream Kubernetes issue:
	// https://github.com/kubernetes/kubernetes/issues/41916#issuecomment-312428731

	if s == nil {
		// If the sysctl config is nil, setting it to non-nil so that it can go through the defaulting logic below to get the default values.
		s = &aksnodeconfigv1.SysctlConfig{}
	}

	m := make(map[string]interface{})
	m["net.ipv4.tcp_retries2"] = defaultNetIpv4TcpRetries2
	m["net.core.message_burst"] = defaultNetCoreMessageBurst
	m["net.core.message_cost"] = defaultNetCoreMessageCost

	// Access the variable directly, instead of using the getter, so that it knows whether it's nil or not.
	// This is based on protobuf3 explicit presence feature.
	// Other directly access variables in this function implies the same idea.
	if s.NetCoreSomaxconn == nil {
		m["net.core.somaxconn"] = defaultNetCoreSomaxconn
	} else {
		// either using getter for NetCoreSomaxconn or direct access is fine because we ensure it's not nil.
		m["net.core.somaxconn"] = s.GetNetCoreSomaxconn()
	}

	if s.NetIpv4TcpMaxSynBacklog == nil {
		m["net.ipv4.tcp_max_syn_backlog"] = defaultNetIpv4TcpMaxSynBacklog
	} else {
		m["net.ipv4.tcp_max_syn_backlog"] = s.GetNetIpv4TcpMaxSynBacklog()
	}

	if s.NetIpv4NeighDefaultGcThresh1 == nil {
		m["net.ipv4.neigh.default.gc_thresh1"] = defaultNetIpv4NeighDefaultGcThresh1
	} else {
		m["net.ipv4.neigh.default.gc_thresh1"] = s.GetNetIpv4NeighDefaultGcThresh1()
	}

	if s.NetIpv4NeighDefaultGcThresh2 == nil {
		m["net.ipv4.neigh.default.gc_thresh2"] = defaultNetIpv4NeighDefaultGcThresh2
	} else {
		m["net.ipv4.neigh.default.gc_thresh2"] = s.GetNetIpv4NeighDefaultGcThresh2()
	}

	if s.NetIpv4NeighDefaultGcThresh3 == nil {
		m["net.ipv4.neigh.default.gc_thresh3"] = defaultNetIpv4NeighDefaultGcThresh3
	} else {
		m["net.ipv4.neigh.default.gc_thresh3"] = s.GetNetIpv4NeighDefaultGcThresh3()
	}

	if s.NetCoreNetdevMaxBacklog != nil {
		m["net.core.netdev_max_backlog"] = s.GetNetCoreNetdevMaxBacklog()
	}

	if s.NetCoreRmemDefault != nil {
		m["net.core.rmem_default"] = s.GetNetCoreRmemDefault()
	}

	if s.NetCoreRmemMax != nil {
		m["net.core.rmem_max"] = s.GetNetCoreRmemMax()
	}

	if s.NetCoreWmemDefault != nil {
		m["net.core.wmem_default"] = s.GetNetCoreWmemDefault()
	}

	if s.NetCoreWmemMax != nil {
		m["net.core.wmem_max"] = s.GetNetCoreWmemMax()
	}

	if s.NetCoreOptmemMax != nil {
		m["net.core.optmem_max"] = s.GetNetCoreOptmemMax()
	}

	if s.NetIpv4TcpMaxTwBuckets != nil {
		m["net.ipv4.tcp_max_tw_buckets"] = s.GetNetIpv4TcpMaxTwBuckets()
	}

	if s.NetIpv4TcpFinTimeout != nil {
		m["net.ipv4.tcp_fin_timeout"] = s.GetNetIpv4TcpFinTimeout()
	}

	if s.NetIpv4TcpKeepaliveTime != nil {
		m["net.ipv4.tcp_keepalive_time"] = s.GetNetIpv4TcpKeepaliveTime()
	}

	if s.NetIpv4TcpKeepaliveProbes != nil {
		m["net.ipv4.tcp_keepalive_probes"] = s.GetNetIpv4TcpKeepaliveProbes()
	}

	if s.NetIpv4TcpkeepaliveIntvl != nil {
		m["net.ipv4.tcp_keepalive_intvl"] = s.GetNetIpv4TcpkeepaliveIntvl()
	}

	if s.NetIpv4TcpTwReuse != nil {
		if s.GetNetIpv4TcpTwReuse() {
			m["net.ipv4.tcp_tw_reuse"] = 1
		} else {
			m["net.ipv4.tcp_tw_reuse"] = 0
		}
	}

	if s.GetNetIpv4IpLocalPortRange() != "" {
		m["net.ipv4.ip_local_port_range"] = s.GetNetIpv4IpLocalPortRange()
		if getPortRangeEndValue(s.GetNetIpv4IpLocalPortRange()) > ipLocalReservedPorts {
			m["net.ipv4.ip_local_reserved_ports"] = ipLocalReservedPorts
		}
	}

	if s.NetNetfilterNfConntrackMax != nil {
		m["net.netfilter.nf_conntrack_max"] = s.GetNetNetfilterNfConntrackMax()
	}

	if s.NetNetfilterNfConntrackBuckets != nil {
		m["net.netfilter.nf_conntrack_buckets"] = s.GetNetNetfilterNfConntrackBuckets()
	}

	if s.FsInotifyMaxUserWatches != nil {
		m["fs.inotify.max_user_watches"] = s.GetFsInotifyMaxUserWatches()
	}

	if s.FsFileMax != nil {
		m["fs.file-max"] = s.GetFsFileMax()
	}

	if s.FsAioMaxNr != nil {
		m["fs.aio-max-nr"] = s.GetFsAioMaxNr()
	}

	if s.FsNrOpen != nil {
		m["fs.nr_open"] = s.GetFsNrOpen()
	}

	if s.KernelThreadsMax != nil {
		m["kernel.threads-max"] = s.GetKernelThreadsMax()
	}

	if s.VmMaxMapCount != nil {
		m["vm.max_map_count"] = s.GetVmMaxMapCount()
	}

	if s.VmSwappiness != nil {
		m["vm.swappiness"] = s.GetVmSwappiness()
	}

	if s.VmVfsCachePressure != nil {
		m["vm.vfs_cache_pressure"] = s.GetVmVfsCachePressure()
	}

	return base64.StdEncoding.EncodeToString([]byte(createSortedKeyValuePairs(m, "\n")))
}