mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	AWS: Create a helper to set salt grain from env var
This is better from a DRY standpoint. This helps reduce the script size, so we have a little bit of breathing room vs the 16KB limit.
This commit is contained in:
		@@ -26,35 +26,24 @@ grains:
 | 
				
			|||||||
  cbr-cidr: "${MASTER_IP_RANGE}"
 | 
					  cbr-cidr: "${MASTER_IP_RANGE}"
 | 
				
			||||||
EOF
 | 
					EOF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [[ -n "${DOCKER_OPTS}" ]]; then
 | 
					# Helper that sets a salt grain in grains.conf, if the upper-cased key is a non-empty env
 | 
				
			||||||
  cat <<EOF >>/etc/salt/minion.d/grains.conf
 | 
					function env_to_salt {
 | 
				
			||||||
  docker_opts: '$(echo "$DOCKER_OPTS" | sed -e "s/'/''/g")'
 | 
					  local key=$1
 | 
				
			||||||
 | 
					  local env_key=`echo $key | tr '[:lower:]' '[:upper:]'`
 | 
				
			||||||
 | 
					  local value=${!env_key}
 | 
				
			||||||
 | 
					  if [[ -n "${value}" ]]; then
 | 
				
			||||||
 | 
					    # Note this is yaml, so indentation matters
 | 
				
			||||||
 | 
					    cat <<EOF # >>/etc/salt/minion.d/grains.conf
 | 
				
			||||||
 | 
					  ${key}: '$(echo "${value}" | sed -e "s/'/''/g")'
 | 
				
			||||||
EOF
 | 
					EOF
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [[ -n "${DOCKER_ROOT}" ]]; then
 | 
					env_to_salt docker_opts
 | 
				
			||||||
  cat <<EOF >>/etc/salt/minion.d/grains.conf
 | 
					env_to_salt docker_root
 | 
				
			||||||
  docker_root: '$(echo "$DOCKER_ROOT" | sed -e "s/'/''/g")'
 | 
					env_to_salt kubelet_root
 | 
				
			||||||
EOF
 | 
					env_to_salt master_extra_sans
 | 
				
			||||||
fi
 | 
					env_to_salt runtime_config
 | 
				
			||||||
 | 
					 | 
				
			||||||
if [[ -n "${KUBELET_ROOT}" ]]; then
 | 
					 | 
				
			||||||
  cat <<EOF >>/etc/salt/minion.d/grains.conf
 | 
					 | 
				
			||||||
  kubelet_root: '$(echo "$KUBELET_ROOT" | sed -e "s/'/''/g")'
 | 
					 | 
				
			||||||
EOF
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if [[ -n "${MASTER_EXTRA_SANS}" ]]; then
 | 
					 | 
				
			||||||
  cat <<EOF >>/etc/salt/minion.d/grains.conf
 | 
					 | 
				
			||||||
  master_extra_sans: '$(echo "$MASTER_EXTRA_SANS" | sed -e "s/'/''/g")'
 | 
					 | 
				
			||||||
EOF
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if [[ ! -z "${RUNTIME_CONFIG:-}" ]]; then
 | 
					 | 
				
			||||||
  cat <<EOF >>/etc/salt/minion.d/grains.conf
 | 
					 | 
				
			||||||
  runtime_config: '$(echo "$RUNTIME_CONFIG" | sed -e "s/'/''/g")'
 | 
					 | 
				
			||||||
EOF
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Auto accept all keys from minions that try to join
 | 
					# Auto accept all keys from minions that try to join
 | 
				
			||||||
mkdir -p /etc/salt/master.d
 | 
					mkdir -p /etc/salt/master.d
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user