vagrant-rke2 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44cbff5c2550189bfb8d345b2c511d4ee2e15541db773ba88433c36f883d5f85
4
- data.tar.gz: 8204fe3eb22eedebd4edc1b719db57220fb183eaae5c4eae6891df5cb099b4f2
3
+ metadata.gz: 3cf49d824ed2271d901c4f58c230a6f071146545615ab847f099a01725e81286
4
+ data.tar.gz: 2bbfe012a5180f083cc8b09c91f7e11d200744de497120d9de65a57759cd8875
5
5
  SHA512:
6
- metadata.gz: b8a7d3db19e1ab2effc97216b9469251232f3bbd1b66bc19955e72c17939a3d9974e93cc8f916e9695f835d33231c09671802664b8bd517f18b1c97dc89ee704
7
- data.tar.gz: cf0da81adf5067d9b7358531fee5208c2d62834c014223f3c1efc7760025038bd629cf720c7c3343a9457768abc49a7c4f443735c29790a5766b86b0a5972dbb
6
+ metadata.gz: 972ff4e827f656951d83b61abef0c670fa25e49083031f1a760bf756d08770c74c32c0e3e387d1d01ecea29d5897f89e456e54086d105a15557de9b44c923202
7
+ data.tar.gz: '04043292575ed63d8655e0a9433484774cbf96bd14ef40f08293dac8c90758ceb1e7401ac47866c20bb0167d48146d1767f24d2dc432bd07a45f46561fdc3819'
data/.gitignore CHANGED
@@ -6,4 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
- .vagrant/
9
+ .vagrant/
10
+ /*.gem
data/Gemfile CHANGED
@@ -7,4 +7,5 @@ end
7
7
  # Specify your gem's dependencies in vagrant-rke2.gemspec
8
8
  group :plugins do
9
9
  gem "vagrant-rke2", path: "."
10
+ # gem "vagrant-reload", path "."
10
11
  end
data/Gemfile.lock CHANGED
@@ -28,7 +28,7 @@ GIT
28
28
  PATH
29
29
  remote: .
30
30
  specs:
31
- vagrant-rke2 (0.1.0)
31
+ vagrant-rke2 (0.1.1)
32
32
 
33
33
  GEM
34
34
  remote: https://rubygems.org/
@@ -39,8 +39,8 @@ GEM
39
39
  concurrent-ruby (1.1.9)
40
40
  ed25519 (1.2.4)
41
41
  erubi (1.10.0)
42
- excon (0.89.0)
43
- ffi (1.15.4)
42
+ excon (0.90.0)
43
+ ffi (1.15.5)
44
44
  gssapi (1.3.1)
45
45
  ffi (>= 1.0.1)
46
46
  gyoku (1.3.1)
@@ -49,7 +49,7 @@ GEM
49
49
  httpclient (2.8.3)
50
50
  i18n (1.8.11)
51
51
  concurrent-ruby (~> 1.0)
52
- listen (3.7.0)
52
+ listen (3.7.1)
53
53
  rb-fsevent (~> 0.10, >= 0.10.3)
54
54
  rb-inotify (~> 0.9, >= 0.9.10)
55
55
  little-plugger (1.1.4)
data/README.md CHANGED
@@ -10,19 +10,89 @@ vagrant up --provider=<your favorite provider>
10
10
 
11
11
  ## Usage
12
12
 
13
+ ### Linux VMs
13
14
  ```ruby
14
15
  Vagrant.configure("2") do |config|
15
- config.vm.box = ""
16
+ config.vm.box = 'generic/ubuntu2004'
17
+
16
18
  config.vm.provision :rke2, run: "once" do |rke2|
17
-
19
+ # installer_url: can be anything that curl can access from the guest
20
+ # default =>`https://get.rke2.io`
21
+ # type => String
22
+ rke2.installer_url = 'https://get.rke2.io'
23
+
24
+ # env: environment variables to be set before invoking the installer script
25
+ # type => Array<String> || String
26
+ rke2.env = %w[INSTALL_RKE2_CHANNEL=latest INSTALL_RKE2_TYPE=server]
27
+ # or
28
+ rke2.env = <<~ENV
29
+ INSTALL_RKE2_CHANNEL=latest
30
+ INSTALL_RKE2_TYPE=server
31
+ ENV
32
+
33
+ # env_path: where to write the envvars to be sourced prior to invoking the installer script
34
+ # default => `/etc/rancher/rke2/install.env`
35
+ rke2.env_path = '/etc/rancher/rke2/install.env'
36
+ rke2.env_mode = '0600' # default
37
+ rke2.env_owner = 'root:root' #default
38
+
39
+ # config: config file content in yaml
40
+ # type => String
41
+ rke2.config = <<~YAML
42
+ disable:
43
+ - local-storage
44
+ - servicelb
45
+ YAML
46
+ # config_mode: config file permissions
47
+ # type => String
48
+ # default => `0600`
49
+ rke2.config_mode = '0644' # side-step https://github.com/k3s-io/k3s/issues/4321
50
+ rke2.config_owner = 'root:root' #default
51
+
52
+ # install_kubectl: QOL feature, installs latest version of kubectl
53
+ # type => Boolean
54
+ # default => true
55
+ rke2.install_kubectl = false
18
56
  end
19
57
  end
58
+ ```
59
+
60
+ ### Windows VMs
61
+ Windows setup is much more restricted. See https://docs.rke2.io/install/install_options/windows_agent_config/ for more info
62
+ ```ruby
63
+ Vagrant.configure("2") do |config|
64
+ config.vm.box = "StefanScherer/windows_2019"
65
+ config.vm.communicator = "winrm"
66
+
67
+ config.vm.provision :rke2, run: "once" do |rke2|
68
+ # installer_url: can be anything that Invoke-WebRequest can access from the guest
69
+ # default =>`https://raw.githubusercontent.com/rancher/rke2/master/install.ps1`
70
+ # type => String
71
+ rke2.installer_url = 'https://raw.githubusercontent.com/rancher/rke2/master/install.ps1'
72
+
73
+ # env: environment variables passed to the install.ps1 script
74
+ # type => Array<String> || String
75
+ rke2.env = %w[Channel=latest Method=Tar]
76
+ # or
77
+ rke2.env = "-Channel latest -Method Tar"
20
78
 
79
+ # config: config file content in yaml
80
+ # type => String
81
+ # NOTE: kube-proxy-arg: "feature-gates=IPv6DualStack=false" is currently a required config for windows
82
+ rke2.config = <<~YAML
83
+ kube-proxy-arg: "feature-gates=IPv6DualStack=false"
84
+ server: https://172.168.1.200:9345
85
+ token: vagrant-rke2
86
+ YAML
87
+ end
88
+ end
21
89
  ```
90
+
22
91
  ## Development
23
92
 
24
93
  See https://www.vagrantup.com/docs/plugins/development-basics
25
-
94
+ - `gem build`
95
+ - `VAGRANT_CWD=./test bundle exec vagrant up`
26
96
  ## Contributing
27
97
 
28
98
  Bug reports and pull requests are welcome on GitHub at https://github.com/dereknola/vagrant-rke2. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
@@ -0,0 +1,2 @@
1
+ Write-Host "Install Containers feature"
2
+ Install-WindowsFeature -Name Containers
@@ -0,0 +1,22 @@
1
+ # !!ITEMS!! are placeholders for injecting strings via vagrant plugin
2
+ Write-Host "Downloading RKE2 installer for Windows..."
3
+ Invoke-WebRequest -Uri !!INSTALL_URL!! -Outfile install.ps1
4
+
5
+ Write-Host "Creating RKE2 configuration..."
6
+ New-Item -Type Directory C:/etc/rancher/rke2 -Force
7
+ Set-Content -Path !!CONFIG_PATH!! -Value @"
8
+ !!CONFIG!!
9
+ "@
10
+
11
+ Write-Host "Installing RKE2 as an agent..."
12
+ ./install.ps1 !!ENV!!
13
+
14
+ Write-Host "Creating RKE2 environment variables..."
15
+ $env:PATH+=";C:\var\lib\rancher\rke2\bin;c:\usr\local\bin"
16
+ [Environment]::SetEnvironmentVariable("Path",
17
+ [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine) + ";C:\var\lib\rancher\rke2\bin;c:\usr\local\bin",
18
+ [EnvironmentVariableTarget]::Machine)
19
+
20
+ Write-Host "Open ports for RKE2 and Calico in firewall..."
21
+ netsh advfirewall firewall add rule name= "RKE2-kubelet" dir=in action=allow protocol=TCP localport=10250
22
+ netsh advfirewall firewall add rule name= "RKE2-agent" dir=in action=allow protocol=TCP localport=4789
@@ -2,19 +2,23 @@
2
2
 
3
3
  module VagrantPlugins
4
4
  module Rke2
5
+ DEFAULT_CONFIG_PATH_LINUX = '/etc/rancher/rke2/config.yaml'
6
+ DEFAULT_CONFIG_PATH_WINDOWS = 'C:/etc/rancher/rke2/config.yaml'
7
+ DEFAULT_INSTALLER_URL_LINUX = 'https://get.rke2.io'
8
+ DEFAULT_INSTALLER_URL_WINDOWS = 'https://raw.githubusercontent.com/rancher/rke2/master/install.ps1'
9
+
5
10
  class Config < Vagrant.plugin(2, :config)
6
11
  DEFAULT_FILE_MODE = '0600'
7
12
  DEFAULT_FILE_OWNER = 'root:root'
8
13
  DEFAULT_CONFIG_MODE = DEFAULT_FILE_MODE
9
14
  DEFAULT_CONFIG_OWNER = DEFAULT_FILE_OWNER
10
- DEFAULT_CONFIG_PATH = '/etc/rancher/rke2/config.yaml'
15
+
11
16
  DEFAULT_ENV_MODE = DEFAULT_FILE_MODE
12
17
  DEFAULT_ENV_OWNER = DEFAULT_FILE_OWNER
13
18
  DEFAULT_ENV_PATH = '/etc/rancher/rke2/install.env'
14
- DEFAULT_INSTALLER_URL = 'https://get.rke2.io'
15
19
 
16
- # string (.yaml) or hash
17
- # @return [Hash]
20
+ # string (.yaml)
21
+ # @return [String]
18
22
  attr_accessor :config
19
23
 
20
24
  # Defaults to `0600`
@@ -49,6 +53,10 @@ module VagrantPlugins
49
53
  # @return [String]
50
54
  attr_accessor :installer_url
51
55
 
56
+ # Defaults to true
57
+ # @return [Boolean]
58
+ attr_accessor :install_kubectl
59
+
52
60
  def initialize
53
61
  @config = UNSET_VALUE
54
62
  @config_mode = UNSET_VALUE
@@ -59,30 +67,31 @@ module VagrantPlugins
59
67
  @env_owner = UNSET_VALUE
60
68
  @env_path = UNSET_VALUE
61
69
  @installer_url = UNSET_VALUE
70
+ @install_kubectl = UNSET_VALUE
62
71
  end
63
72
 
64
73
  def finalize!
65
74
  @config = "" if @config == UNSET_VALUE
66
75
  @config_mode = @config_mode == UNSET_VALUE ? DEFAULT_CONFIG_MODE : @config_mode.to_s
67
76
  @config_owner = @config_owner == UNSET_VALUE ? DEFAULT_CONFIG_OWNER : @config_owner.to_s
68
- @config_path = @config_path == UNSET_VALUE ? DEFAULT_CONFIG_PATH : @config_path.to_s
77
+ @config_path = @config_path == UNSET_VALUE ? DEFAULT_CONFIG_PATH_LINUX : @config_path.to_s
69
78
  @env = [] if @env == UNSET_VALUE
70
79
  @env_mode = DEFAULT_ENV_MODE if @env_mode == UNSET_VALUE
71
80
  @env_owner = DEFAULT_ENV_OWNER if @env_owner == UNSET_VALUE
72
81
  @env_path = DEFAULT_ENV_PATH if @env_path == UNSET_VALUE
73
- @installer_url = DEFAULT_INSTALLER_URL if @installer_url == UNSET_VALUE
74
-
82
+ @installer_url = DEFAULT_INSTALLER_URL_LINUX if @installer_url == UNSET_VALUE
83
+ @install_kubectl = true if @install_kubectl == UNSET_VALUE
75
84
  end
76
85
 
77
86
  def validate(machine)
78
87
  errors = _detected_errors
79
88
 
80
89
  unless config_valid?
81
- errors << "Rke2 provisioner `config` must be a hash or string (yaml)."
90
+ errors << "Rke2 provisioner `config` must be a string (yaml)."
82
91
  end
83
92
 
84
93
  unless env_valid?
85
- errors << "Rke2 provisioner `env` must be an array, hash, or string."
94
+ errors << "Rke2 provisioner `env` must be an array or string."
86
95
  end
87
96
 
88
97
  { "rke2 provisioner" => errors }
@@ -90,14 +99,12 @@ module VagrantPlugins
90
99
 
91
100
  def config_valid?
92
101
  return true if config.is_a?(String)
93
- return true if config.is_a?(Hash)
94
102
  false
95
103
  end
96
104
 
97
105
  def env_valid?
98
106
  return true unless env
99
107
  return true if env.is_a?(String)
100
- return true if env.is_a?(Hash)
101
108
  if env.is_a?(Array)
102
109
  env.each do |a|
103
110
  return false unless a.kind_of?(String)
@@ -28,24 +28,29 @@ module VagrantPlugins
28
28
  end
29
29
 
30
30
  guest_capability(:alpine, :curl_install) do
31
- require_relative "cap/alpine/curl_install"
31
+ require_relative "cap/curl_install"
32
32
  Cap::Alpine::CurlInstall
33
33
  end
34
34
 
35
35
  guest_capability(:debian, :curl_install) do
36
- require_relative "cap/debian/curl_install"
36
+ require_relative "cap/curl_install"
37
37
  Cap::Debian::CurlInstall
38
38
  end
39
39
 
40
40
  guest_capability(:redhat, :curl_install) do
41
- require_relative "cap/redhat/curl_install"
41
+ require_relative "cap/curl_install"
42
42
  Cap::Redhat::CurlInstall
43
43
  end
44
44
 
45
45
  guest_capability(:suse, :curl_install) do
46
- require_relative "cap/suse/curl_install"
46
+ require_relative "cap/curl_install"
47
47
  Cap::Suse::CurlInstall
48
48
  end
49
+
50
+ guest_capability(:windows, :rke2_installed) do
51
+ require_relative "cap/windows/rke2_installed"
52
+ Cap::Windows::Rke2Installed
53
+ end
49
54
  end
50
55
  end
51
56
  end
@@ -15,6 +15,16 @@ module VagrantPlugins
15
15
  end
16
16
 
17
17
  def provision
18
+ @machine.ui.info "Guest Identity: %s" % @machine.config.vm.guest
19
+ case @machine.config.vm.guest
20
+ when :windows
21
+ provisionWindows
22
+ else
23
+ provisionLinux
24
+ end
25
+ end
26
+
27
+ def provisionLinux
18
28
  unless @machine.guest.capability(:curl_installed)
19
29
  @machine.ui.info 'Installing Curl ...'
20
30
  @machine.guest.capability(:curl_install)
@@ -34,6 +44,9 @@ module VagrantPlugins
34
44
  end
35
45
  file_upload "rke2-install.env", env_file, env_text
36
46
 
47
+ capture = env_text.match(/INSTALL_RKE2_TYPE=([a-z]+)/)
48
+ service = capture ? capture.captures[0] : ""
49
+
37
50
  prv_file = "/vagrant/rke2-provisioner.sh"
38
51
  prv_text = <<~EOF
39
52
  #/usr/bin/env bash
@@ -49,12 +62,30 @@ module VagrantPlugins
49
62
  EOF
50
63
  file_upload("rke2-install.sh", prv_file, prv_text)
51
64
  @machine.ui.info "Invoking: #{prv_file}"
65
+ @machine.communicate.sudo("chmod +x #{prv_file} && #{prv_file}", :error_key => :ssh_bad_exit_status_muted) do |type, line|
66
+ @machine.ui.detail line, :color => :yellow
67
+ end
68
+ # outputs, handler = build_outputs
69
+ # begin
70
+ # @machine.communicate.sudo("chmod +x #{prv_file} && #{prv_file}", error_key: :ssh_bad_exit_status_muted, &handler)
71
+ # ensure
72
+ # outputs.values.map(&:close)
73
+ # end
52
74
 
53
- outputs, handler = build_outputs
54
- begin
55
- @machine.communicate.sudo("chmod +x #{prv_file} && #{prv_file}", error_key: :ssh_bad_exit_status_muted, &handler)
56
- ensure
57
- outputs.values.map(&:close)
75
+ if config.install_kubectl
76
+ kube_file = "/vagrant/kubectl-install.sh"
77
+ kube_text = <<~EOF
78
+ curl -L "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" -o /usr/local/bin/kubectl
79
+ chmod +x /usr/local/bin/kubectl
80
+ EOF
81
+ file_upload("kubectl-install.sh", kube_file, kube_text)
82
+ @machine.ui.info "Invoking: #{kube_file}"
83
+ outputs, handler = build_outputs
84
+ begin
85
+ @machine.communicate.sudo("chmod +x #{kube_file} && #{kube_file}", &handler)
86
+ ensure
87
+ outputs.values.map(&:close)
88
+ end
58
89
  end
59
90
 
60
91
  begin
@@ -66,15 +97,78 @@ module VagrantPlugins
66
97
  rescue Vagrant::Errors::VagrantError => e
67
98
  @machine.ui.detail "#{e.extra_data[:stderr].chomp}", :color => :red
68
99
  else
69
- outputs, handler = build_outputs
70
- begin
71
- @machine.communicate.sudo("#{exe} --version", :error_key => :ssh_bad_exit_status_muted, &handler)
72
- ensure
73
- outputs.values.map(&:close)
100
+ @machine.communicate.sudo("#{exe} --version", :error_key => :ssh_bad_exit_status_muted) do |type, line|
101
+ @machine.ui.detail line, :color => :yellow
102
+ end
103
+ end
104
+
105
+ @machine.ui.info "Starting RKE2 service..."
106
+ if !service.empty?
107
+ @machine.communicate.sudo("systemctl enable rke2-#{service}.service")
108
+ @machine.communicate.sudo("systemctl start rke2-#{service}.service") do |type, line|
109
+ @machine.ui.detail line, :color => :yellow
110
+ end
111
+ else
112
+ @machine.communicate.sudo("systemctl enable rke2-server.service")
113
+ @machine.communicate.sudo("systemctl start rke2-server.service") do |type, line|
114
+ @machine.ui.detail line, :color => :yellow
74
115
  end
75
116
  end
76
117
  end
77
118
 
119
+ def provisionWindows
120
+
121
+ if config.config_path == DEFAULT_CONFIG_PATH_LINUX
122
+ config.config_path = DEFAULT_CONFIG_PATH_WINDOWS
123
+ end
124
+ if config.installer_url == DEFAULT_INSTALLER_URL_LINUX
125
+ config.installer_url = DEFAULT_INSTALLER_URL_WINDOWS
126
+ end
127
+
128
+ config.installer_url
129
+
130
+ scriptDir = File.expand_path('./cap/windows/scripts', File.dirname(__FILE__)) + "/"
131
+
132
+ env_text = ""
133
+ if config.env.is_a?(String)
134
+ env_text = config.env
135
+ end
136
+ if config.env.is_a?(Array)
137
+ config.env.each {|line| env_text << "-#{line.gsub("=", " ")} "}
138
+ end
139
+
140
+ containerScript = "install-containers-feature.ps1"
141
+ @machine.ui.info "Invoking: #{containerScript}"
142
+
143
+ command = File.read(scriptDir + containerScript)
144
+ @machine.communicate.execute(command, {shell: :powershell, elevated: true})
145
+ @machine.guest.capability(:reboot)
146
+ @machine.guest.capability(:wait_for_reboot)
147
+
148
+ setupRke2 = "setup-rke2.ps1"
149
+ @machine.ui.info "Invoking: #{setupRke2}"
150
+
151
+ command = File.read(scriptDir + setupRke2)
152
+ command["!!INSTALL_URL!!"] = config.installer_url
153
+ command["!!CONFIG_PATH!!"] = config.config_path
154
+ command["!!CONFIG!!"] = config.config
155
+ command["!!ENV!!"] = env_text
156
+ @machine.communicate.execute(command, {shell: :powershell, elevated: true}) do |type, line|
157
+ @machine.ui.detail line.chomp, :color => :yellow
158
+ end
159
+
160
+ @machine.ui.info "Checking RKE2 version:"
161
+ @machine.communicate.test("Get-Command rke2", {shell: :powershell})
162
+ @machine.communicate.execute("rke2 --version", {shell: :powershell}) do |type, line|
163
+ @machine.ui.detail line, :color => :yellow
164
+ end
165
+
166
+ @machine.ui.info "Starting RKE2 agent:"
167
+ @machine.communicate.execute("rke2.exe agent service --add", {shell: :powershell, elevated: true} )
168
+ @machine.communicate.execute("Start-Service -Name 'rke2'", {shell: :powershell, elevated: true} )
169
+
170
+ end
171
+
78
172
  def build_outputs
79
173
  outputs = {
80
174
  stdout: Vagrant::Util::LineBuffer.new { |line| handle_comm(:stdout, line) },
@@ -116,9 +210,12 @@ module VagrantPlugins
116
210
  remote_tmp_dir = @machine.guest.capability :create_tmp_path, {:type => :directory}
117
211
  remote_tmp_path = [remote_tmp_dir, File.basename(remote_path)].join('/')
118
212
  @machine.communicate.upload(local_path, remote_tmp_path)
119
- @machine.communicate.sudo("install -v -DTZ #{remote_tmp_path} #{remote_path}") do |type, line|
120
- @machine.ui.info line.chomp, :color => {:stderr => :red, :stdout => :default}[type]
213
+ if @machine.config.vm.guest != "windows"
214
+ @machine.communicate.sudo("install -v -DTZ #{remote_tmp_path} #{remote_path}") do |type, line|
215
+ @machine.ui.info line.chomp, :color => {:stderr => :red, :stdout => :default}[type]
216
+ end
121
217
  end
218
+
122
219
  end
123
220
  @machine.ui.detail content.chomp, :color => :yellow
124
221
  remote_path
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Rke2
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-rke2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Nola
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-08 00:00:00.000000000 Z
11
+ date: 2022-01-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Manage RKE2 installations on Vagrant guests
14
14
  email:
@@ -30,6 +30,8 @@ files:
30
30
  - lib/vagrant-rke2/cap/curl_install.rb
31
31
  - lib/vagrant-rke2/cap/linux/curl_installed.rb
32
32
  - lib/vagrant-rke2/cap/linux/rke2_installed.rb
33
+ - lib/vagrant-rke2/cap/windows/scripts/install-containers-feature.ps1
34
+ - lib/vagrant-rke2/cap/windows/scripts/setup-rke2.ps1
33
35
  - lib/vagrant-rke2/config.rb
34
36
  - lib/vagrant-rke2/plugin.rb
35
37
  - lib/vagrant-rke2/provisioner.rb