Class: VagrantPlugins::K3s::Config
- Inherits:
-
Object
- Object
- VagrantPlugins::K3s::Config
- Defined in:
- lib/vagrant-k3s/config.rb
Constant Summary collapse
- DEFAULT_FILE_MODE =
'0600'- DEFAULT_FILE_OWNER =
'root:root'- DEFAULT_CONFIG_MODE =
DEFAULT_FILE_MODE- DEFAULT_CONFIG_OWNER =
DEFAULT_FILE_OWNER- DEFAULT_CONFIG_PATH =
'/etc/rancher/k3s/config.yaml'- DEFAULT_ENV_MODE =
DEFAULT_FILE_MODE- DEFAULT_ENV_OWNER =
DEFAULT_FILE_OWNER- DEFAULT_ENV_PATH =
'/etc/rancher/k3s/install.env'- DEFAULT_INSTALLER_URL =
'https://get.k3s.io'
Instance Attribute Summary collapse
-
#args ⇒ Array<String>
string or array.
-
#config ⇒ Hash
string (.yaml) or hash.
-
#config_mode ⇒ String
Defaults to ‘0600`.
-
#config_owner ⇒ String
Defaults to ‘root:root`.
-
#config_path ⇒ String
Defaults to ‘/etc/rancher/k3s/config.yaml`.
-
#env ⇒ Array<String>
string (.env), array, or hash.
-
#env_mode ⇒ String
Defaults to ‘0600`.
-
#env_owner ⇒ String
Defaults to ‘root:root`.
-
#env_path ⇒ String
Defaults to ‘/etc/rancher/k3s/install.env`.
-
#installer_url ⇒ String
Defaults to ‘get.k3s.io`.
-
#skip_complete ⇒ Boolean
Defaults to false.
-
#skip_start ⇒ Boolean
Defaults to false.
Instance Method Summary collapse
- #args_valid? ⇒ Boolean
- #config_valid? ⇒ Boolean
- #env_valid? ⇒ Boolean
- #finalize! ⇒ Object
-
#initialize ⇒ Config
constructor
# INSTALL_K3S_BIN_DIR # @return [String] attr_accessor :install_bin_dir.
- #validate(machine) ⇒ Object
Constructor Details
#initialize ⇒ Config
# INSTALL_K3S_BIN_DIR # @return [String] attr_accessor :install_bin_dir
# INSTALL_K3S_BIN_DIR_READ_ONLY # @return [Boolean] attr_accessor :install_bin_dir_ro
# INSTALL_K3S_CHANNEL # @return [String] attr_accessor :install_channel
# INSTALL_K3S_CHANNEL_URL # @return [String] attr_accessor :install_channel_url
# INSTALL_K3S_COMMIT # @return [String] attr_accessor :install_commit
# INSTALL_K3S_EXEC # @return [String] attr_accessor :install_exec
# INSTALL_K3S_NAME # @return [String] attr_accessor :install_name
# INSTALL_K3S_SYSTEMD_DIR # @return [String] attr_accessor :install_systemd_dir
# INSTALL_K3S_TYPE # @return [String] attr_accessor :install_systemd_type
# INSTALL_K3S_VERSION # @return [String] attr_accessor :install_version
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/vagrant-k3s/config.rb', line 104 def initialize @args = UNSET_VALUE @config = UNSET_VALUE @config_mode = UNSET_VALUE @config_owner = UNSET_VALUE @config_path = UNSET_VALUE @env = UNSET_VALUE @env_mode = UNSET_VALUE @env_owner = UNSET_VALUE @env_path = UNSET_VALUE @installer_url = UNSET_VALUE @skip_start = UNSET_VALUE @skip_complete = UNSET_VALUE end |
Instance Attribute Details
#args ⇒ Array<String>
string or array
18 19 20 |
# File 'lib/vagrant-k3s/config.rb', line 18 def args @args end |
#config ⇒ Hash
string (.yaml) or hash
22 23 24 |
# File 'lib/vagrant-k3s/config.rb', line 22 def config @config end |
#config_mode ⇒ String
Defaults to ‘0600`
26 27 28 |
# File 'lib/vagrant-k3s/config.rb', line 26 def config_mode @config_mode end |
#config_owner ⇒ String
Defaults to ‘root:root`
30 31 32 |
# File 'lib/vagrant-k3s/config.rb', line 30 def config_owner @config_owner end |
#config_path ⇒ String
Defaults to ‘/etc/rancher/k3s/config.yaml`
34 35 36 |
# File 'lib/vagrant-k3s/config.rb', line 34 def config_path @config_path end |
#env ⇒ Array<String>
string (.env), array, or hash
38 39 40 |
# File 'lib/vagrant-k3s/config.rb', line 38 def env @env end |
#env_mode ⇒ String
Defaults to ‘0600`
42 43 44 |
# File 'lib/vagrant-k3s/config.rb', line 42 def env_mode @env_mode end |
#env_owner ⇒ String
Defaults to ‘root:root`
46 47 48 |
# File 'lib/vagrant-k3s/config.rb', line 46 def env_owner @env_owner end |
#env_path ⇒ String
Defaults to ‘/etc/rancher/k3s/install.env`
50 51 52 |
# File 'lib/vagrant-k3s/config.rb', line 50 def env_path @env_path end |
#installer_url ⇒ String
Defaults to ‘get.k3s.io`
54 55 56 |
# File 'lib/vagrant-k3s/config.rb', line 54 def installer_url @installer_url end |
#skip_complete ⇒ Boolean
Defaults to false
62 63 64 |
# File 'lib/vagrant-k3s/config.rb', line 62 def skip_complete @skip_complete end |
#skip_start ⇒ Boolean
Defaults to false
58 59 60 |
# File 'lib/vagrant-k3s/config.rb', line 58 def skip_start @skip_start end |
Instance Method Details
#args_valid? ⇒ Boolean
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/vagrant-k3s/config.rb', line 156 def args_valid? return true unless args return true if args.is_a?(String) return true if args.is_a?(Integer) if args.is_a?(Array) args.each do |a| return false if !a.kind_of?(String) && !a.kind_of?(Integer) end return true end false end |
#config_valid? ⇒ Boolean
169 170 171 172 173 174 |
# File 'lib/vagrant-k3s/config.rb', line 169 def config_valid? return true unless args return true if config.is_a?(String) return true if config.is_a?(Hash) false end |
#env_valid? ⇒ Boolean
176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/vagrant-k3s/config.rb', line 176 def env_valid? return true unless env return true if env.is_a?(String) return true if env.is_a?(Hash) if env.is_a?(Array) env.each do |a| return false unless a.kind_of?(String) end return true end false end |
#finalize! ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/vagrant-k3s/config.rb', line 119 def finalize! @args = [] if @args == UNSET_VALUE @config = "" if @config == UNSET_VALUE @config_mode = @config_mode == UNSET_VALUE ? DEFAULT_CONFIG_MODE : @config_mode.to_s @config_owner = @config_owner == UNSET_VALUE ? DEFAULT_CONFIG_OWNER : @config_owner.to_s @config_path = @config_path == UNSET_VALUE ? DEFAULT_CONFIG_PATH : @config_path.to_s @env = [] if @env == UNSET_VALUE @env_mode = DEFAULT_ENV_MODE if @env_mode == UNSET_VALUE @env_owner = DEFAULT_ENV_OWNER if @env_owner == UNSET_VALUE @env_path = DEFAULT_ENV_PATH if @env_path == UNSET_VALUE @installer_url = DEFAULT_INSTALLER_URL if @installer_url == UNSET_VALUE @skip_start = false if @skip_start == UNSET_VALUE @skip_complete = false if @skip_complete == UNSET_VALUE if @args && args_valid? @args = @args.is_a?(Array) ? @args.map { |a| a.to_s } : @args.to_s end end |
#validate(machine) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/vagrant-k3s/config.rb', line 138 def validate(machine) errors = _detected_errors unless args_valid? errors << "K3s provisioner `args` must be an array or string." end unless config_valid? errors << "K3s provisioner `config` must be a hash or string (yaml)." end unless env_valid? errors << "K3s provisioner `env` must be an array, hash, or string." end { "k3s provisioner" => errors } end |