Class: VagrantK8s::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-k8s/config.rb

Overview

Vagrant configuration for connecting to a Kubernetes cluster.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



17
18
19
20
21
22
# File 'lib/vagrant-k8s/config.rb', line 17

def initialize
  @kubeconfig = UNSET_VALUE
  @context = UNSET_VALUE
  @namespace = UNSET_VALUE
  @kubectl = UNSET_VALUE
end

Instance Attribute Details

#contextString?

Returns Kubeconfig context used for kubectl and Helm commands.

Returns:

  • (String, nil)

    Kubeconfig context used for kubectl and Helm commands.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-k8s/config.rb', line 14

class Config < Vagrant.plugin('2', :config)
  attr_accessor :kubeconfig, :context, :namespace, :kubectl

  def initialize
    @kubeconfig = UNSET_VALUE
    @context = UNSET_VALUE
    @namespace = UNSET_VALUE
    @kubectl = UNSET_VALUE
  end

  def finalize!
    @kubeconfig = nil if @kubeconfig == UNSET_VALUE
    @context = nil if @context == UNSET_VALUE
    @namespace = nil if @namespace == UNSET_VALUE
    @kubectl = 'kubectl' if @kubectl == UNSET_VALUE
  end

  def validate(_machine)
    errors = []
    errors << 'k8s.kubeconfig must be a path string or nil' unless @kubeconfig.nil? || @kubeconfig.is_a?(String)
    errors << 'k8s.context must be a string or nil' unless @context.nil? || @context.is_a?(String)
    errors << 'k8s.namespace must be a string or nil' unless @namespace.nil? || @namespace.is_a?(String)
    errors << 'k8s.kubectl must be a command string' unless @kubectl.is_a?(String) && !@kubectl.empty?
    { 'vagrant-k8s' => errors }
  end
end

#kubeconfigString?

Returns Path to the kubeconfig file, relative to the Vagrantfile.

Returns:

  • (String, nil)

    Path to the kubeconfig file, relative to the Vagrantfile.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-k8s/config.rb', line 14

class Config < Vagrant.plugin('2', :config)
  attr_accessor :kubeconfig, :context, :namespace, :kubectl

  def initialize
    @kubeconfig = UNSET_VALUE
    @context = UNSET_VALUE
    @namespace = UNSET_VALUE
    @kubectl = UNSET_VALUE
  end

  def finalize!
    @kubeconfig = nil if @kubeconfig == UNSET_VALUE
    @context = nil if @context == UNSET_VALUE
    @namespace = nil if @namespace == UNSET_VALUE
    @kubectl = 'kubectl' if @kubectl == UNSET_VALUE
  end

  def validate(_machine)
    errors = []
    errors << 'k8s.kubeconfig must be a path string or nil' unless @kubeconfig.nil? || @kubeconfig.is_a?(String)
    errors << 'k8s.context must be a string or nil' unless @context.nil? || @context.is_a?(String)
    errors << 'k8s.namespace must be a string or nil' unless @namespace.nil? || @namespace.is_a?(String)
    errors << 'k8s.kubectl must be a command string' unless @kubectl.is_a?(String) && !@kubectl.empty?
    { 'vagrant-k8s' => errors }
  end
end

#kubectlString

Returns Path to the kubectl executable.

Returns:

  • (String)

    Path to the kubectl executable.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-k8s/config.rb', line 14

class Config < Vagrant.plugin('2', :config)
  attr_accessor :kubeconfig, :context, :namespace, :kubectl

  def initialize
    @kubeconfig = UNSET_VALUE
    @context = UNSET_VALUE
    @namespace = UNSET_VALUE
    @kubectl = UNSET_VALUE
  end

  def finalize!
    @kubeconfig = nil if @kubeconfig == UNSET_VALUE
    @context = nil if @context == UNSET_VALUE
    @namespace = nil if @namespace == UNSET_VALUE
    @kubectl = 'kubectl' if @kubectl == UNSET_VALUE
  end

  def validate(_machine)
    errors = []
    errors << 'k8s.kubeconfig must be a path string or nil' unless @kubeconfig.nil? || @kubeconfig.is_a?(String)
    errors << 'k8s.context must be a string or nil' unless @context.nil? || @context.is_a?(String)
    errors << 'k8s.namespace must be a string or nil' unless @namespace.nil? || @namespace.is_a?(String)
    errors << 'k8s.kubectl must be a command string' unless @kubectl.is_a?(String) && !@kubectl.empty?
    { 'vagrant-k8s' => errors }
  end
end

#namespaceString?

Returns Default namespace for kubectl and Helm commands.

Returns:

  • (String, nil)

    Default namespace for kubectl and Helm commands.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-k8s/config.rb', line 14

class Config < Vagrant.plugin('2', :config)
  attr_accessor :kubeconfig, :context, :namespace, :kubectl

  def initialize
    @kubeconfig = UNSET_VALUE
    @context = UNSET_VALUE
    @namespace = UNSET_VALUE
    @kubectl = UNSET_VALUE
  end

  def finalize!
    @kubeconfig = nil if @kubeconfig == UNSET_VALUE
    @context = nil if @context == UNSET_VALUE
    @namespace = nil if @namespace == UNSET_VALUE
    @kubectl = 'kubectl' if @kubectl == UNSET_VALUE
  end

  def validate(_machine)
    errors = []
    errors << 'k8s.kubeconfig must be a path string or nil' unless @kubeconfig.nil? || @kubeconfig.is_a?(String)
    errors << 'k8s.context must be a string or nil' unless @context.nil? || @context.is_a?(String)
    errors << 'k8s.namespace must be a string or nil' unless @namespace.nil? || @namespace.is_a?(String)
    errors << 'k8s.kubectl must be a command string' unless @kubectl.is_a?(String) && !@kubectl.empty?
    { 'vagrant-k8s' => errors }
  end
end

Instance Method Details

#finalize!Object



24
25
26
27
28
29
# File 'lib/vagrant-k8s/config.rb', line 24

def finalize!
  @kubeconfig = nil if @kubeconfig == UNSET_VALUE
  @context = nil if @context == UNSET_VALUE
  @namespace = nil if @namespace == UNSET_VALUE
  @kubectl = 'kubectl' if @kubectl == UNSET_VALUE
end

#validate(_machine) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/vagrant-k8s/config.rb', line 31

def validate(_machine)
  errors = []
  errors << 'k8s.kubeconfig must be a path string or nil' unless @kubeconfig.nil? || @kubeconfig.is_a?(String)
  errors << 'k8s.context must be a string or nil' unless @context.nil? || @context.is_a?(String)
  errors << 'k8s.namespace must be a string or nil' unless @namespace.nil? || @namespace.is_a?(String)
  errors << 'k8s.kubectl must be a command string' unless @kubectl.is_a?(String) && !@kubectl.empty?
  { 'vagrant-k8s' => errors }
end