Class: GClouder::Config::Cluster

Inherits:
DeepMergeHash show all
Defined in:
lib/gclouder/config/cluster.rb

Instance Method Summary collapse

Methods inherited from Hash

#to_snake_keys

Instance Method Details

#context(context) ⇒ Object



6
7
8
9
10
11
12
13
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
40
41
42
43
44
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
# File 'lib/gclouder/config/cluster.rb', line 6

def context(context)
  dup = self.dup

  permitted_keys = case context
  when :create_cluster
    [
      "additional_zones",
      "async",
      "cluster_ipv4_cidr",
      "cluster_version",
      "disable_addons",
      "disk_size",
      "no_enable_cloud_endpoints",
      "no_enable_cloud_logging",
      "no_enable_cloud_monitoring",
      "image_type",
      "machine_type",
      "max_nodes_per_pool",
      "network",
      "node_labels",
      "num_nodes",
      "password",
      "preemptible",
      "scopes",
      "subnetwork",
      "username",
      "wait",
      "zone",
    ]
  when :create_nodepool
    # flip value due to differing key name..
    if self.key?("no_enable_cloud_endpoints")
      dup[:enable_cloud_endpoints] = self[:no_enable_cloud_endpoints] ? false : true
    end

    [
      "disk_size",
      "enable_autoscaling",
      "enable_cloud_endpoints",
      "image_type",
      "machine_type",
      "max_nodes",
      "min_nodes",
      "node_labels",
      "num_nodes",
      "preemptible",
      "scopes",
      "zone",
      "cluster",
    ]
  when :resize_cluster
    dup["size"] = self["num_nodes"] if self.key?("num_nodes")

    [
      "async",
      "size",
      "wait",
      "zone",
      "node_pool",
    ]
  when :autoscale_cluster
    [
      "enable_autoscaling",
      "max_nodes",
      "min_nodes",
    ]
  else
    raise StandardError, "invalid context supplied when querying config object: #{context}"
  end

  dup.delete_if { |k, _| !permitted_keys.include?(k) }
end