Module: GClouder::Resources::Container::NodePools

Includes:
GCloud, Helpers, Logging, Shell
Defined in:
lib/gclouder/resources/container/node_pools.rb

Defined Under Namespace

Modules: Local, NodePool, Remote

Class Method Summary collapse

Methods included from Helpers

#hash_to_args, included, #module_exists?, #to_arg, #to_deep_merge_hash, #valid_json?

Methods included from GCloud

#gcloud, included, #verify

Methods included from Config::CLIArgs

check, #cli_args, cli_args, included, load, valid_resources

Methods included from Config::Project

load, #project, project

Methods included from Logging

#add, #bad, #change, #debug, #error, #fatal, #good, included, #info, log, loggers, #remove, report, #resource_state, setup, #warn, #warning

Methods included from Shell

included, #shell

Class Method Details

.cleanObject

FIXME: create a collection then iterate through it to avoid printing messages when no clusters are undefined



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/gclouder/resources/container/node_pools.rb', line 56

def self.clean
  return if GClouder::Resources::Container::Clusters::Local.list.empty?
  header :clean

  GClouder::Resources::Container::Clusters::Local.list.each do |region, clusters|
    info region, heading: true, indent: 2
    clusters.each do |cluster|
      next if undefined(cluster).empty?

      info cluster["name"], heading: true, indent: 3
      undefined(cluster).each do |namespace, resources|
        resources.each do |resource|
          message = resource['name']
          message += " (not defined locally)"
          info
          warning message, indent: 4
          #resource_purge(namespace, user)
        end
      end
    end
  end
end

.delete_default_nodepoolObject



14
15
16
# File 'lib/gclouder/resources/container/node_pools.rb', line 14

def self.delete_default_nodepool
  Resource.purge :"container node-pools", "default-pool"
end

.ensureObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gclouder/resources/container/node_pools.rb', line 32

def self.ensure
  return if GClouder::Resources::Container::Clusters::Local.list.empty?
  header

  GClouder::Resources::Container::Clusters::Local.list.each do |region, clusters|
    info region, heading: true, indent: 2
    clusters.each do |cluster|
      next if cluster["node_pools"].empty?
      info cluster["name"], heading: true, indent: 3
      cluster["node_pools"].each do |pool|
        NodePool.create(cluster, pool)
        NodePool.resize(cluster, pool)
        NodePool.autoscale(cluster, pool)
      end
    end
  end
end

.header(stage = :ensure) ⇒ Object



50
51
52
# File 'lib/gclouder/resources/container/node_pools.rb', line 50

def self.header(stage = :ensure)
  info "[#{stage}] container / node-pools", title: true, indent: 1
end

.undefined(cluster) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/gclouder/resources/container/node_pools.rb', line 79

def self.undefined(cluster)
  return {} unless Resource.resource?("container clusters", cluster["name"], silent: true)
  self::Remote.list(cluster).each_with_object({}) do |(namespace, resources), collection|
    resources.each do |resource|
      namespace_resources = self::Local.list(cluster)[namespace]

      next if namespace_resources && namespace_resources.select {|r| resource["name"] == r["name"] }.length > 0

      collection[namespace] ||= []
      collection[namespace] << resource
    end
  end
end

.validateObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gclouder/resources/container/node_pools.rb', line 18

def self.validate
  return if GClouder::Resources::Container::Clusters::Local.list.empty?
  header :validate

  GClouder::Resources::Container::Clusters::Local.list.each do |region, clusters|
    info region, heading: true, indent: 2
    clusters.each do |cluster|
      next if cluster["node_pools"].empty?
      info cluster["name"], heading: true, indent: 3
      Local.validate(cluster)
    end
  end
end