You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

304 lines
13 KiB

Use supported version of fedora in CI (#10108) * tests: replace fedora35 with fedora37 Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@proton.ch> * tests: replace fedora36 with fedora38 Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@proton.ch> * docs: update fedora version in docs Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@proton.ch> * molecule: upgrade fedora version Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@proton.ch> * tests: upgrade fedora images for vagrant and kubevirt Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@proton.ch> * vagrant: workaround to fix private network ip address in fedora Fedora stop supporting syconfig network script so we added a workaround here https://github.com/hashicorp/vagrant/issues/12762#issuecomment-1535957837 to fix it. * netowrkmanager: do not configure dns if using systemd-resolved We should not configure dns if we point to systemd-resolved. Systemd-resolved is using NetworkManager to infer the upstream DNS server so if we set NetworkManager to 127.0.0.53 it will prevent systemd-resolved to get the correct network DNS server. Thus if we are in this case we just don't set this setting. Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@proton.ch> * image-builder: update centos7 image Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@proton.ch> * gitlab-ci: mark fedora packet jobs as allow failure Fedora networking is still broken on Packet, let's mark it as allow failure for now. Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@proton.ch> --------- Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@proton.ch>
1 year ago
Added file and container image caching (#4828) * File and container image downloads are now cached localy, so that repeated vagrant up/down runs do not trigger downloading of those files. This is especially useful on laptops with kubernetes runnig locally on vm's. The total size of the cache, after an ansible run, is currently around 800MB, so bandwidth (=time) savings can be quite significant. * When download_run_once is false, the default is still not to cache, but setting download_force_cache will still enable caching. * The local cache location can be set with download_cache_dir and defaults to /tmp/kubernetes_cache * A local docker instance is no longer required to cache docker images; Images are cached to file. A local docker instance is still required, though, if you wish to download images on localhost. * Fixed a FIXME, wher the argument was that delegate_to doesn't play nice with omit. That is a correct observation and the fix is to use default(inventory_host) instead of default(omit). See ansible/ansible#26009 * Removed "Register docker images info" task from download_container and set_docker_image_facts because it was faulty and unused. * Removed redundant when:download.{container,enabled,run_once} conditions from {sync,download}_container.yml * All features of commit d6fd0d2acaec9f53e75d82db30411f96a5bf2cc9 by Timoses <timosesu@gmail.com>, merged May 1st 2019, are included in this patch. Not all code was included verbatim, but each feature of that commit was checked to be working in this patch. One notable change: The actual downloading of the kubeadm images was moved to {download,sync)_container, to enable caching. Note 1: I considered splitting this patch, but most changes that are not directly related to caching, are a pleasant by-product of implementing the caching code, so splitting would be impractical. Note 2: I have my doubts about the usefulness of the upload, download and upgrade tags in the download role. Must they remain or can they be removed? If anybody knows, then please speak up.
5 years ago
Added file and container image caching (#4828) * File and container image downloads are now cached localy, so that repeated vagrant up/down runs do not trigger downloading of those files. This is especially useful on laptops with kubernetes runnig locally on vm's. The total size of the cache, after an ansible run, is currently around 800MB, so bandwidth (=time) savings can be quite significant. * When download_run_once is false, the default is still not to cache, but setting download_force_cache will still enable caching. * The local cache location can be set with download_cache_dir and defaults to /tmp/kubernetes_cache * A local docker instance is no longer required to cache docker images; Images are cached to file. A local docker instance is still required, though, if you wish to download images on localhost. * Fixed a FIXME, wher the argument was that delegate_to doesn't play nice with omit. That is a correct observation and the fix is to use default(inventory_host) instead of default(omit). See ansible/ansible#26009 * Removed "Register docker images info" task from download_container and set_docker_image_facts because it was faulty and unused. * Removed redundant when:download.{container,enabled,run_once} conditions from {sync,download}_container.yml * All features of commit d6fd0d2acaec9f53e75d82db30411f96a5bf2cc9 by Timoses <timosesu@gmail.com>, merged May 1st 2019, are included in this patch. Not all code was included verbatim, but each feature of that commit was checked to be working in this patch. One notable change: The actual downloading of the kubeadm images was moved to {download,sync)_container, to enable caching. Note 1: I considered splitting this patch, but most changes that are not directly related to caching, are a pleasant by-product of implementing the caching code, so splitting would be impractical. Note 2: I have my doubts about the usefulness of the upload, download and upgrade tags in the download role. Must they remain or can they be removed? If anybody knows, then please speak up.
5 years ago
Added file and container image caching (#4828) * File and container image downloads are now cached localy, so that repeated vagrant up/down runs do not trigger downloading of those files. This is especially useful on laptops with kubernetes runnig locally on vm's. The total size of the cache, after an ansible run, is currently around 800MB, so bandwidth (=time) savings can be quite significant. * When download_run_once is false, the default is still not to cache, but setting download_force_cache will still enable caching. * The local cache location can be set with download_cache_dir and defaults to /tmp/kubernetes_cache * A local docker instance is no longer required to cache docker images; Images are cached to file. A local docker instance is still required, though, if you wish to download images on localhost. * Fixed a FIXME, wher the argument was that delegate_to doesn't play nice with omit. That is a correct observation and the fix is to use default(inventory_host) instead of default(omit). See ansible/ansible#26009 * Removed "Register docker images info" task from download_container and set_docker_image_facts because it was faulty and unused. * Removed redundant when:download.{container,enabled,run_once} conditions from {sync,download}_container.yml * All features of commit d6fd0d2acaec9f53e75d82db30411f96a5bf2cc9 by Timoses <timosesu@gmail.com>, merged May 1st 2019, are included in this patch. Not all code was included verbatim, but each feature of that commit was checked to be working in this patch. One notable change: The actual downloading of the kubeadm images was moved to {download,sync)_container, to enable caching. Note 1: I considered splitting this patch, but most changes that are not directly related to caching, are a pleasant by-product of implementing the caching code, so splitting would be impractical. Note 2: I have my doubts about the usefulness of the upload, download and upgrade tags in the download role. Must they remain or can they be removed? If anybody knows, then please speak up.
5 years ago
  1. # -*- mode: ruby -*-
  2. # # vi: set ft=ruby :
  3. # For help on using kubespray with vagrant, check out docs/developers/vagrant.md
  4. require 'fileutils'
  5. Vagrant.require_version ">= 2.0.0"
  6. CONFIG = File.join(File.dirname(__FILE__), ENV['KUBESPRAY_VAGRANT_CONFIG'] || 'vagrant/config.rb')
  7. FLATCAR_URL_TEMPLATE = "https://%s.release.flatcar-linux.net/amd64-usr/current/flatcar_production_vagrant.json"
  8. # Uniq disk UUID for libvirt
  9. DISK_UUID = Time.now.utc.to_i
  10. SUPPORTED_OS = {
  11. "flatcar-stable" => {box: "flatcar-stable", user: "core", box_url: FLATCAR_URL_TEMPLATE % ["stable"]},
  12. "flatcar-beta" => {box: "flatcar-beta", user: "core", box_url: FLATCAR_URL_TEMPLATE % ["beta"]},
  13. "flatcar-alpha" => {box: "flatcar-alpha", user: "core", box_url: FLATCAR_URL_TEMPLATE % ["alpha"]},
  14. "flatcar-edge" => {box: "flatcar-edge", user: "core", box_url: FLATCAR_URL_TEMPLATE % ["edge"]},
  15. "ubuntu2004" => {box: "generic/ubuntu2004", user: "vagrant"},
  16. "ubuntu2204" => {box: "generic/ubuntu2204", user: "vagrant"},
  17. "ubuntu2404" => {box: "bento/ubuntu-24.04", user: "vagrant"},
  18. "centos8" => {box: "centos/8", user: "vagrant"},
  19. "centos8-bento" => {box: "bento/centos-8", user: "vagrant"},
  20. "almalinux8" => {box: "almalinux/8", user: "vagrant"},
  21. "almalinux8-bento" => {box: "bento/almalinux-8", user: "vagrant"},
  22. "rockylinux8" => {box: "rockylinux/8", user: "vagrant"},
  23. "rockylinux9" => {box: "rockylinux/9", user: "vagrant"},
  24. "fedora39" => {box: "fedora/39-cloud-base", user: "vagrant"},
  25. "fedora40" => {box: "fedora/40-cloud-base", user: "vagrant"},
  26. "fedora39-arm64" => {box: "bento/fedora-39-arm64", user: "vagrant"},
  27. "fedora40-arm64" => {box: "bento/fedora-40", user: "vagrant"},
  28. "opensuse" => {box: "opensuse/Leap-15.4.x86_64", user: "vagrant"},
  29. "opensuse-tumbleweed" => {box: "opensuse/Tumbleweed.x86_64", user: "vagrant"},
  30. "oraclelinux" => {box: "generic/oracle7", user: "vagrant"},
  31. "oraclelinux8" => {box: "generic/oracle8", user: "vagrant"},
  32. "rhel8" => {box: "generic/rhel8", user: "vagrant"},
  33. "debian11" => {box: "debian/bullseye64", user: "vagrant"},
  34. "debian12" => {box: "debian/bookworm64", user: "vagrant"},
  35. }
  36. if File.exist?(CONFIG)
  37. require CONFIG
  38. end
  39. # Defaults for config options defined in CONFIG
  40. $num_instances ||= 3
  41. $instance_name_prefix ||= "k8s"
  42. $vm_gui ||= false
  43. $vm_memory ||= 2048
  44. $vm_cpus ||= 2
  45. $shared_folders ||= {}
  46. $forwarded_ports ||= {}
  47. $subnet ||= "172.18.8"
  48. $subnet_ipv6 ||= "fd3c:b398:0698:0756"
  49. $os ||= "ubuntu2004"
  50. $network_plugin ||= "flannel"
  51. $inventory ||= "inventory/sample"
  52. $inventories ||= [$inventory]
  53. # Setting multi_networking to true will install Multus: https://github.com/k8snetworkplumbingwg/multus-cni
  54. $multi_networking ||= "False"
  55. $download_run_once ||= "True"
  56. $download_force_cache ||= "False"
  57. # The first three nodes are etcd servers
  58. $etcd_instances ||= [$num_instances, 3].min
  59. # The first two nodes are kube masters
  60. $kube_master_instances ||= [$num_instances, 2].min
  61. # All nodes are kube nodes
  62. $kube_node_instances ||= $num_instances
  63. # The following only works when using the libvirt provider
  64. $kube_node_instances_with_disks ||= false
  65. $kube_node_instances_with_disks_size ||= "20G"
  66. $kube_node_instances_with_disks_number ||= 2
  67. $override_disk_size ||= false
  68. $disk_size ||= "20GB"
  69. $local_path_provisioner_enabled ||= "False"
  70. $local_path_provisioner_claim_root ||= "/opt/local-path-provisioner/"
  71. $libvirt_nested ||= false
  72. # boolean or string (e.g. "-vvv")
  73. $ansible_verbosity ||= false
  74. $ansible_tags ||= ENV['VAGRANT_ANSIBLE_TAGS'] || ""
  75. $vagrant_dir ||= File.join(File.dirname(__FILE__), ".vagrant")
  76. $playbook ||= "cluster.yml"
  77. $extra_vars ||= {}
  78. host_vars = {}
  79. # throw error if os is not supported
  80. if ! SUPPORTED_OS.key?($os)
  81. puts "Unsupported OS: #{$os}"
  82. puts "Supported OS are: #{SUPPORTED_OS.keys.join(', ')}"
  83. exit 1
  84. end
  85. $box = SUPPORTED_OS[$os][:box]
  86. if Vagrant.has_plugin?("vagrant-proxyconf")
  87. $no_proxy = ENV['NO_PROXY'] || ENV['no_proxy'] || "127.0.0.1,localhost"
  88. (1..$num_instances).each do |i|
  89. $no_proxy += ",#{$subnet}.#{i+100}"
  90. end
  91. end
  92. Vagrant.configure("2") do |config|
  93. config.vm.box = $box
  94. if SUPPORTED_OS[$os].has_key? :box_url
  95. config.vm.box_url = SUPPORTED_OS[$os][:box_url]
  96. end
  97. config.ssh.username = SUPPORTED_OS[$os][:user]
  98. # plugin conflict
  99. if Vagrant.has_plugin?("vagrant-vbguest") then
  100. config.vbguest.auto_update = false
  101. end
  102. # always use Vagrants insecure key
  103. config.ssh.insert_key = false
  104. if ($override_disk_size)
  105. unless Vagrant.has_plugin?("vagrant-disksize")
  106. system "vagrant plugin install vagrant-disksize"
  107. end
  108. config.disksize.size = $disk_size
  109. end
  110. (1..$num_instances).each do |i|
  111. config.vm.define vm_name = "%s-%01d" % [$instance_name_prefix, i] do |node|
  112. node.vm.hostname = vm_name
  113. if Vagrant.has_plugin?("vagrant-proxyconf")
  114. node.proxy.http = ENV['HTTP_PROXY'] || ENV['http_proxy'] || ""
  115. node.proxy.https = ENV['HTTPS_PROXY'] || ENV['https_proxy'] || ""
  116. node.proxy.no_proxy = $no_proxy
  117. end
  118. ["vmware_fusion", "vmware_workstation"].each do |vmware|
  119. node.vm.provider vmware do |v|
  120. v.vmx['memsize'] = $vm_memory
  121. v.vmx['numvcpus'] = $vm_cpus
  122. end
  123. end
  124. node.vm.provider :virtualbox do |vb|
  125. vb.memory = $vm_memory
  126. vb.cpus = $vm_cpus
  127. vb.gui = $vm_gui
  128. vb.linked_clone = true
  129. vb.customize ["modifyvm", :id, "--vram", "8"] # ubuntu defaults to 256 MB which is a waste of precious RAM
  130. vb.customize ["modifyvm", :id, "--audio", "none"]
  131. end
  132. node.vm.provider :libvirt do |lv|
  133. lv.nested = $libvirt_nested
  134. lv.cpu_mode = "host-model"
  135. lv.memory = $vm_memory
  136. lv.cpus = $vm_cpus
  137. lv.default_prefix = 'kubespray'
  138. # Fix kernel panic on fedora 28
  139. if $os == "fedora"
  140. lv.cpu_mode = "host-passthrough"
  141. end
  142. end
  143. if $kube_node_instances_with_disks
  144. # Libvirt
  145. driverletters = ('a'..'z').to_a
  146. node.vm.provider :libvirt do |lv|
  147. # always make /dev/sd{a/b/c} so that CI can ensure that
  148. # virtualbox and libvirt will have the same devices to use for OSDs
  149. (1..$kube_node_instances_with_disks_number).each do |d|
  150. lv.storage :file, :device => "hd#{driverletters[d]}", :path => "disk-#{i}-#{d}-#{DISK_UUID}.disk", :size => $kube_node_instances_with_disks_size, :bus => "scsi"
  151. end
  152. end
  153. node.vm.provider :virtualbox do |vb|
  154. # always make /dev/sd{a/b/c} so that CI can ensure that
  155. # virtualbox and libvirt will have the same devices to use for OSDs
  156. (1..$kube_node_instances_with_disks_number).each do |d|
  157. vb.customize ['createhd', '--filename', "disk-#{i}-#{driverletters[d]}-#{DISK_UUID}.disk", '--size', $kube_node_instances_with_disks_size] # 10GB disk
  158. vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', d, '--device', 0, '--type', 'hdd', '--medium', "disk-#{i}-#{driverletters[d]}-#{DISK_UUID}.disk", '--nonrotational', 'on', '--mtype', 'normal']
  159. end
  160. end
  161. end
  162. if $expose_docker_tcp
  163. node.vm.network "forwarded_port", guest: 2375, host: ($expose_docker_tcp + i - 1), auto_correct: true
  164. end
  165. $forwarded_ports.each do |guest, host|
  166. node.vm.network "forwarded_port", guest: guest, host: host, auto_correct: true
  167. end
  168. if ["rhel8"].include? $os
  169. # Vagrant synced_folder rsync options cannot be used for RHEL boxes as Rsync package cannot
  170. # be installed until the host is registered with a valid Red Hat support subscription
  171. node.vm.synced_folder ".", "/vagrant", disabled: false
  172. $shared_folders.each do |src, dst|
  173. node.vm.synced_folder src, dst
  174. end
  175. else
  176. node.vm.synced_folder ".", "/vagrant", disabled: false, type: "rsync", rsync__args: ['--verbose', '--archive', '--delete', '-z'] , rsync__exclude: ['.git','venv']
  177. $shared_folders.each do |src, dst|
  178. node.vm.synced_folder src, dst, type: "rsync", rsync__args: ['--verbose', '--archive', '--delete', '-z']
  179. end
  180. end
  181. ip = "#{$subnet}.#{i+100}"
  182. node.vm.network :private_network,
  183. :ip => ip,
  184. :libvirt__guest_ipv6 => 'yes',
  185. :libvirt__ipv6_address => "#{$subnet_ipv6}::#{i+100}",
  186. :libvirt__ipv6_prefix => "64",
  187. :libvirt__forward_mode => "none",
  188. :libvirt__dhcp_enabled => false
  189. # Disable swap for each vm
  190. node.vm.provision "shell", inline: "swapoff -a"
  191. # ubuntu2004 and ubuntu2204 have IPv6 explicitly disabled. This undoes that.
  192. if ["ubuntu2004", "ubuntu2204"].include? $os
  193. node.vm.provision "shell", inline: "rm -f /etc/modprobe.d/local.conf"
  194. node.vm.provision "shell", inline: "sed -i '/net.ipv6.conf.all.disable_ipv6/d' /etc/sysctl.d/99-sysctl.conf /etc/sysctl.conf"
  195. end
  196. # Hack for fedora39/40 to get the IP address of the second interface
  197. if ["fedora39", "fedora40", "fedora39-arm64", "fedora40-arm64"].include? $os
  198. config.vm.provision "shell", inline: <<-SHELL
  199. nmcli conn modify 'Wired connection 2' ipv4.addresses $(cat /etc/sysconfig/network-scripts/ifcfg-eth1 | grep IPADDR | cut -d "=" -f2)/24
  200. nmcli conn modify 'Wired connection 2' ipv4.method manual
  201. service NetworkManager restart
  202. SHELL
  203. end
  204. # Rockylinux boxes needs UEFI
  205. if ["rockylinux8", "rockylinux9"].include? $os
  206. config.vm.provider "libvirt" do |domain|
  207. domain.loader = "/usr/share/OVMF/x64/OVMF_CODE.fd"
  208. end
  209. end
  210. # Disable firewalld on oraclelinux/redhat vms
  211. if ["oraclelinux","oraclelinux8", "rhel8","rockylinux8"].include? $os
  212. node.vm.provision "shell", inline: "systemctl stop firewalld; systemctl disable firewalld"
  213. end
  214. host_vars[vm_name] = {
  215. "ip": ip,
  216. "flannel_interface": "eth1",
  217. "kube_network_plugin": $network_plugin,
  218. "kube_network_plugin_multus": $multi_networking,
  219. "download_run_once": $download_run_once,
  220. "download_localhost": "False",
  221. "download_cache_dir": ENV['HOME'] + "/kubespray_cache",
  222. # Make kubespray cache even when download_run_once is false
  223. "download_force_cache": $download_force_cache,
  224. # Keeping the cache on the nodes can improve provisioning speed while debugging kubespray
  225. "download_keep_remote_cache": "False",
  226. "docker_rpm_keepcache": "1",
  227. # These two settings will put kubectl and admin.config in $inventory/artifacts
  228. "kubeconfig_localhost": "True",
  229. "kubectl_localhost": "True",
  230. "local_path_provisioner_enabled": "#{$local_path_provisioner_enabled}",
  231. "local_path_provisioner_claim_root": "#{$local_path_provisioner_claim_root}",
  232. "ansible_ssh_user": SUPPORTED_OS[$os][:user],
  233. "ansible_ssh_private_key_file": File.join(Dir.home, ".vagrant.d", "insecure_private_key"),
  234. "unsafe_show_logs": "True"
  235. }
  236. # Only execute the Ansible provisioner once, when all the machines are up and ready.
  237. # And limit the action to gathering facts, the full playbook is going to be ran by testcases_run.sh
  238. if i == $num_instances
  239. node.vm.provision "ansible" do |ansible|
  240. ansible.playbook = $playbook
  241. ansible.compatibility_mode = "2.0"
  242. ansible.verbose = $ansible_verbosity
  243. ansible.become = true
  244. ansible.limit = "all,localhost"
  245. ansible.host_key_checking = false
  246. ansible.raw_arguments = ["--forks=#{$num_instances}",
  247. "--flush-cache",
  248. "-e ansible_become_pass=vagrant"] +
  249. $inventories.map {|inv| ["-i", inv]}.flatten
  250. ansible.host_vars = host_vars
  251. ansible.extra_vars = $extra_vars
  252. if $ansible_tags != ""
  253. ansible.tags = [$ansible_tags]
  254. end
  255. ansible.groups = {
  256. "etcd" => ["#{$instance_name_prefix}-[1:#{$etcd_instances}]"],
  257. "kube_control_plane" => ["#{$instance_name_prefix}-[1:#{$kube_master_instances}]"],
  258. "kube_node" => ["#{$instance_name_prefix}-[1:#{$kube_node_instances}]"],
  259. "k8s_cluster:children" => ["kube_control_plane", "kube_node"],
  260. }
  261. end
  262. end
  263. end
  264. end
  265. end