Class: Seira::Cluster
- Inherits:
-
Object
- Object
- Seira::Cluster
- Defined in:
- lib/seira/cluster.rb
Constant Summary collapse
- VALID_ACTIONS =
%w[help bootstrap upgrade].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
Constructor Details
#initialize(action:, args:, context:, settings:) ⇒ Cluster
Returns a new instance of Cluster.
13 14 15 16 17 18 |
# File 'lib/seira/cluster.rb', line 13 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.
11 12 13 |
# File 'lib/seira/cluster.rb', line 11 def action @action end |
#args ⇒ Object (readonly)
Returns the value of attribute args.
11 12 13 |
# File 'lib/seira/cluster.rb', line 11 def args @args end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
11 12 13 |
# File 'lib/seira/cluster.rb', line 11 def context @context end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
11 12 13 |
# File 'lib/seira/cluster.rb', line 11 def settings @settings end |
Class Method Details
.current_cluster ⇒ Object
51 52 53 |
# File 'lib/seira/cluster.rb', line 51 def self.current_cluster `kubectl config current-context`.chomp.strip end |
Instance Method Details
#current ⇒ Object
55 56 57 58 |
# File 'lib/seira/cluster.rb', line 55 def current puts `gcloud config get-value project` puts `kubectl config current-context` end |
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/seira/cluster.rb', line 20 def run case action when 'help' run_help when 'bootstrap' run_bootstrap when 'upgrade' run_upgrade else fail "Unknown command encountered" end end |
#switch(target_cluster:, verbose: false) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/seira/cluster.rb', line 33 def switch(target_cluster:, verbose: false) unless target_cluster && target_cluster != "" && settings.valid_cluster_names.include?(target_cluster) puts "Please specify environment as first param to any seira command" puts "Environment 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 |