Module: VagrantK8s::Kubeconfig
- Defined in:
- lib/vagrant-k8s/kubeconfig.rb
Class Method Summary collapse
- .kubectl_command(machine, extra_args, namespace: nil, context: nil) ⇒ Object
- .present?(value) ⇒ Boolean
- .resolve_path(machine, path) ⇒ Object
Class Method Details
.kubectl_command(machine, extra_args, namespace: nil, context: nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/vagrant-k8s/kubeconfig.rb', line 7 def kubectl_command(machine, extra_args, namespace: nil, context: nil) config = machine.config.k8s command = [config.kubectl] kubeconfig = resolve_path(machine, config.kubeconfig) command += ['--kubeconfig', kubeconfig] if kubeconfig selected_context = context || config.context selected_namespace = namespace || config.namespace command += ['--context', selected_context] if present?(selected_context) command += ['--namespace', selected_namespace] if present?(selected_namespace) command + extra_args end |
.present?(value) ⇒ Boolean
26 27 28 |
# File 'lib/vagrant-k8s/kubeconfig.rb', line 26 def present?(value) value.is_a?(String) && !value.empty? end |
.resolve_path(machine, path) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/vagrant-k8s/kubeconfig.rb', line 19 def resolve_path(machine, path) return nil unless present?(path) return path if Pathname.new(path).absolute? File.(path, machine.env.root_path.to_s) end |