class EksCli::Config
Constants
- AZS
Public Class Methods
[](cluster_name)
click to toggle source
# File lib/eks_cli/config.rb, line 16 def [](cluster_name) new(cluster_name) end
new(cluster_name)
click to toggle source
# File lib/eks_cli/config.rb, line 29 def initialize(cluster_name) @cluster_name = cluster_name end
s3_bucket()
click to toggle source
# File lib/eks_cli/config.rb, line 24 def s3_bucket @s3_bucket || raise("no s3 bucket set") end
s3_bucket=(bucket)
click to toggle source
# File lib/eks_cli/config.rb, line 20 def s3_bucket=(bucket) @s3_bucket = bucket end
Public Instance Methods
[](k)
click to toggle source
# File lib/eks_cli/config.rb, line 48 def [](k) read_from_disk[k] end
add_user(arn, username, groups)
click to toggle source
# File lib/eks_cli/config.rb, line 86 def add_user(arn, username, groups) write({"users" => {arn => {"username" => username, "groups" => groups}}}) end
bootstrap(attrs)
click to toggle source
# File lib/eks_cli/config.rb, line 69 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
delete()
click to toggle source
# File lib/eks_cli/config.rb, line 33 def delete Log.info "deleting configuration for #{@cluster_name} at #{dir}" s3.delete_object(bucket: s3_bucket, key: config_path) s3.delete_object(bucket: s3_bucket, key: state_path) s3.delete_object(bucket: s3_bucket, key: groups_path) s3.delete_object(bucket: s3_bucket, key: dir) end
for_group(group_name)
click to toggle source
# File lib/eks_cli/config.rb, line 52 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_disk()
click to toggle source
# File lib/eks_cli/config.rb, line 41 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)
click to toggle source
# File lib/eks_cli/config.rb, line 76 def set_iam_policies(policies) write({iam_policies: policies}, :groups) end
update_nodegroup(options)
click to toggle source
# File lib/eks_cli/config.rb, line 80 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)
click to toggle source
# File lib/eks_cli/config.rb, line 60 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
Private Instance Methods
config_path()
click to toggle source
# File lib/eks_cli/config.rb, line 122 def config_path "#{dir}/config.json" end
dir()
click to toggle source
# File lib/eks_cli/config.rb, line 126 def dir "eks-cli/#{@cluster_name}" end
groups_path()
click to toggle source
# File lib/eks_cli/config.rb, line 114 def groups_path "#{dir}/groups.json" end
read(path)
click to toggle source
# File lib/eks_cli/config.rb, line 108 def read(path) resp = s3.get_object(bucket: s3_bucket, key: path) body = resp.body.read JSON.parse(body) end
resolve_config_file(sym)
click to toggle source
# File lib/eks_cli/config.rb, line 92 def resolve_config_file(sym) case sym when :state state_path when :config config_path when :groups groups_path else raise "no such config #{sym}" end end
s3()
click to toggle source
# File lib/eks_cli/config.rb, line 134 def s3 @s3 ||= Aws::S3::Client.new end
s3_bucket()
click to toggle source
# File lib/eks_cli/config.rb, line 130 def s3_bucket self.class.s3_bucket end
state_path()
click to toggle source
# File lib/eks_cli/config.rb, line 118 def state_path "#{dir}/state.json" end
write_to_file(attrs, path)
click to toggle source
# File lib/eks_cli/config.rb, line 104 def write_to_file(attrs, path) s3.put_object(bucket: s3_bucket, key: path, body: attrs.to_json) end