Class: Seira::Cluster
Constant Summary collapse
- VALID_ACTIONS =
%w[help bootstrap upgrade-master].freeze
- SUMMARY =
"For managing whole clusters.".freeze
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Class Method Summary collapse
Instance Method Summary collapse
- #current ⇒ Object
-
#initialize(action:, args:, context:, settings:) ⇒ Cluster
constructor
A new instance of Cluster.
- #run ⇒ Object
- #switch(target_cluster:, verbose: false) ⇒ Object
Methods included from Commands
#gcloud, gcloud, kubectl, #kubectl
Constructor Details
#initialize(action:, args:, context:, settings:) ⇒ Cluster
Returns a new instance of Cluster.
15 16 17 18 19 20 |
# File 'lib/seira/cluster.rb', line 15 def initialize(action:, args:, context:, settings:) @action = action @args = args @context = context @settings = settings end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
13 14 15 |
# File 'lib/seira/cluster.rb', line 13 def action @action end |
#args ⇒ Object (readonly)
Returns the value of attribute args.
13 14 15 |
# File 'lib/seira/cluster.rb', line 13 def args @args end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
13 14 15 |
# File 'lib/seira/cluster.rb', line 13 def context @context end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
13 14 15 |
# File 'lib/seira/cluster.rb', line 13 def settings @settings end |
Class Method Details
Instance Method Details
#current ⇒ Object
61 62 63 64 |
# File 'lib/seira/cluster.rb', line 61 def current puts current_project puts current_cluster end |
#run ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/seira/cluster.rb', line 22 def run case action when 'help' run_help when 'bootstrap' run_bootstrap when 'upgrade-master' run_upgrade_master else fail "Unknown command encountered" end end |
#switch(target_cluster:, verbose: false) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/seira/cluster.rb', line 35 def switch(target_cluster:, verbose: false) unless target_cluster && target_cluster != "" && settings.valid_cluster_names.include?(target_cluster) puts "Please specify cluster as first param to any seira command" puts "Cluster should be one of #{settings.valid_cluster_names}" exit(1) end # The context in kubectl are a bit more difficult to name. List by name only and search for the right one using a simple string match = settings.clusters[target_cluster] puts("Switching to gcloud config of '#{target_cluster}' and kubernetes cluster of '#{['cluster']}'") if verbose exit(1) unless system("gcloud config configurations activate #{target_cluster}") exit(1) unless system("kubectl config use-context #{['cluster']}") # If we haven't exited by now, it was successful true end |