Class: EksCli::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/eks_cli/config.rb

Constant Summary collapse

AZS =
{"us-east-1" => ["us-east-1a", "us-east-1b", "us-east-1c"],
"us-west-2" => ["us-west-2a", "us-west-2b", "us-west-2c"],
"us-east-2" => ["us-east-2a", "us-east-2b", "us-east-2c"],
"us-west-1" => ["us-west-1b", "us-west-1b", "us-west-1c"]}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cluster_name) ⇒ Config

Returns a new instance of Config.



21
22
23
# File 'lib/eks_cli/config.rb', line 21

def initialize(cluster_name)
  @cluster_name = cluster_name
end

Class Method Details

.[](cluster_name) ⇒ Object



15
16
17
# File 'lib/eks_cli/config.rb', line 15

def [](cluster_name)
  new(cluster_name)
end

Instance Method Details

#[](k) ⇒ Object



32
33
34
# File 'lib/eks_cli/config.rb', line 32

def [](k)
  read_from_disk[k]
end

#add_user(arn, username, groups) ⇒ Object



70
71
72
# File 'lib/eks_cli/config.rb', line 70

def add_user(arn, username, groups)
  write({"users" => {arn => {"username" => username, "groups" => groups}}})
end

#bootstrap(attrs) ⇒ Object



53
54
55
56
57
58
# File 'lib/eks_cli/config.rb', line 53

def bootstrap(attrs)
  write_to_file(attrs, config_path)
  write_to_file({}, state_path)
  write_to_file({}, groups_path)
  Log.info "written configuration files to:\n#{config_path}\n#{state_path}\n#{groups_path}"
end

#for_group(group_name) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/eks_cli/config.rb', line 36

def for_group(group_name)
  all = read_from_disk
  group = all["groups"][group_name]
    .merge(all.slice("cluster_name", "control_plane_sg_id", "nodes_sg_id", "vpc_id"))
  group["subnets"] = group["subnets"].map {|s| all["subnets"][s-1]}.join(",")
  group
end

#read_from_diskObject



25
26
27
28
29
30
# File 'lib/eks_cli/config.rb', line 25

def read_from_disk
  base = read(config_path)
  base["cluster_name"] = @cluster_name
  base = base.merge(read(state_path)).merge(read(groups_path))
  base
end

#set_iam_policies(policies) ⇒ Object



60
61
62
# File 'lib/eks_cli/config.rb', line 60

def set_iam_policies(policies)
  write({iam_policies: policies}, :groups)
end

#update_nodegroup(options) ⇒ Object



64
65
66
67
68
# File 'lib/eks_cli/config.rb', line 64

def update_nodegroup(options)
  options = options.slice("ami", "group_name", "instance_type", "subnets", "ssh_key_name", "volume_size", "taints", "min", "max", "enable_docker_bridge", "desired", "spotinst")
  raise "bad nodegroup name #{options["group_name"]}" if options["group_name"] == nil || options["group_name"].empty?
  write({groups: { options["group_name"] => options }}, :groups)
end

#write(attrs, to = :state) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/eks_cli/config.rb', line 44

def write(attrs, to = :state)
  path = resolve_config_file(to)
  current = read(path) rescue {}
  Log.info "updating configuration file #{path}:\n#{attrs}"
  attrs = attrs.inject({}) {|h,(k,v)| h[k.to_s] = v; h}
  updated = current.deep_merge(attrs)
  write_to_file(updated, path)
end