Class: SwarmClusterCliOpe::K8s

Inherits:
Thor
  • Object
show all
Includes:
ConfigurationConcern, LoggerConcern, StackSyncConcern, ThorConfigurationConcern, Thor::Actions
Defined in:
lib/swarm_cluster_cli_ope/k8s.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LoggerConcern

#logger

Class Method Details

.cfgsObject



13
14
15
# File 'lib/swarm_cluster_cli_ope/k8s.rb', line 13

def self.cfgs
  SwarmClusterCliOpe::Kubernetes::Configuration.instance
end

.exit_on_failure?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/swarm_cluster_cli_ope/k8s.rb', line 9

def self.exit_on_failure?
  true
end

Instance Method Details

#installObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/swarm_cluster_cli_ope/k8s.rb', line 19

def install
  #contolliamo se presente la configurazione base nella home
  if Configuration.exist_base?
    say "Configurazione già presente"
  else
    #se non presente allora chiediamo le varie configurazioni
    if yes? "Sei nel contesto corretto di kubectl?"
      #scriviamo le varie configurazioni
      cfg = cfgs
      cfg.save_base_cfgs
    else
      say "Cambia prima contesto, sarà quello usato per l'installazione"
    end
  end

end

#rsync(src, dst) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/swarm_cluster_cli_ope/k8s.rb', line 45

def rsync(src, dst)
  reg_exp = /(?<pod_name>.*)\:(?<path>.*)/
  if File.exist?(src)
    # il src é la cartella, quindi la destizione è il pod
    direction = :up
    local_path = src
    podname = dst.match(reg_exp)[:pod_name]
    podpath = dst.match(reg_exp)[:path]
  else
    direction = :down
    podname = src.match(reg_exp)[:pod_name]
    podpath = src.match(reg_exp)[:path]
    local_path = dst
  end

  puts "#{src} #{direction} #{dst}"

  cfgs.env(options[:environment]) do |cfgs|

    cfgs.stack_name = options[:stack_name] || cfgs.stack_name

    sync = Kubernetes::SyncConfigs::Rsync.new(cfgs, {
      service: Kubernetes::Pod.find_by_name(podname),
      how: 'rsync',
      configs: {
        local: local_path,
        remote: podpath
      }
    })

    if direction == :down
      sync.pull
    end
    if direction == :up
      sync.push
    end

  


  end
end