class EksCli::Cli

Constants

RED

Public Instance Methods

add_iam_user(iam_arn) click to toggle source
# File lib/eks_cli/cli.rb, line 212
def add_iam_user(iam_arn)
  with_context do
    Config[cluster_name].add_user(iam_arn, options[:username], options[:groups])
    K8s::Auth.new(cluster_name).update if options[:yes]
  end
end
all_nodegroups() click to toggle source
# File lib/eks_cli/cli.rb, line 236
def all_nodegroups; config["groups"].keys ;end
bold(s) click to toggle source
# File lib/eks_cli/cli.rb, line 264
def bold(s)
  "\e[1m#{s}\e[0m"
end
cluster_name() click to toggle source
# File lib/eks_cli/cli.rb, line 226
def cluster_name; options_or_env(:cluster_name); end
colorize(s, color_code) click to toggle source
# File lib/eks_cli/cli.rb, line 256
def colorize(s, color_code)
  "\e[#{color_code}m#{s}\e[0m"
end
config() click to toggle source
# File lib/eks_cli/cli.rb, line 234
def config; Config.new(cluster_name); end
create() click to toggle source
# File lib/eks_cli/cli.rb, line 46
def create
  with_context do

    opts = {region: options[:region],
            kubernetes_version: options[:kubernetes_version],
            open_ports: options[:open_ports],
            cidr: options[:cidr],
            warm_ip_target: options[:warm_ip_target] ? options[:warm_ip_target].to_i : nil,
            subnet1_az: (options[:subnet1_az] || Config::AZS[options[:region]][0]),
            subnet2_az: (options[:subnet2_az] || Config::AZS[options[:region]][1]),
            subnet3_az: (options[:subnet3_az] || Config::AZS[options[:region]][2])}

    config.bootstrap(opts)
    cluster = EKS::Cluster.new(cluster_name).create
    cluster.update_kubeconfig
    wait_for_cluster
    enable_gpu if options[:enable_gpu]
    create_default_storage_class if options[:create_default_storage_class]
    create_dns_autoscaler if options[:create_dns_autoscaler]
    update_cluster_cni if options[:warm_ip_target]
    Log.info "cluster creation completed"
  end
end
create_default_storage_class() click to toggle source
# File lib/eks_cli/cli.rb, line 98
def create_default_storage_class
  with_context { K8s::Client.new(cluster_name).create_default_storage_class }
end
create_dns_autoscaler() click to toggle source
# File lib/eks_cli/cli.rb, line 191
def create_dns_autoscaler
  with_context { K8s::Client.new(cluster_name).create_dns_autoscaler }
end
create_nodegroup() click to toggle source
# File lib/eks_cli/cli.rb, line 116
def create_nodegroup
  with_context do
    opts = options.dup 
    opts[:subnets] = opts[:subnets].map(&:to_i)
    Config[cluster_name].update_nodegroup(opts) unless opts[:all]
    if opts[:yes]
      cf_stacks = nodegroups.map {|ng| ng.create(wait_for_completion: false)}
      CloudFormation::Stack.await(cf_stacks)
      K8s::Auth.new(cluster_name).update
    end
  end
end
delete_cluster() click to toggle source
# File lib/eks_cli/cli.rb, line 149
def delete_cluster
  answer = ask("you are about to delete EKS cluster #{bold(underline(colorize(cluster_name, RED)))} including nodegroups/elastigroups, elbs, kubernetes services and cloudformation stacks.\nare you 100% sure you want to proceed? (y/N)")
  if answer == "y"
    Log.info "deleting cluster #{cluster_name}"
    with_context { EKS::Cluster.new(cluster_name).delete }
  else
    Log.info "aborted"
  end
end
delete_nodegroup() click to toggle source
# File lib/eks_cli/cli.rb, line 162
def delete_nodegroup
  with_context { nodegroups.each(&:delete) }
end
enable_gpu() click to toggle source
# File lib/eks_cli/cli.rb, line 88
def enable_gpu
  with_context { K8s::Client.new(cluster_name).enable_gpu }
end
env_param_name(k) click to toggle source
# File lib/eks_cli/cli.rb, line 252
def env_param_name(k)
  "EKS_CLI_#{k.to_s.upcase}"
end
export_nodegroup() click to toggle source
# File lib/eks_cli/cli.rb, line 204
def export_nodegroup
  with_context { nodegroups.each {|ng| ng.export_to_spotinst(options[:exact_instance_type]) } }
end
nodegroups() click to toggle source
# File lib/eks_cli/cli.rb, line 238
def nodegroups
  ng = options[:all] ? all_nodegroups : [options[:group_name]]
  ng.map {|n| NodeGroup.new(cluster_name, n)}
end
options_or_env(k) click to toggle source
# File lib/eks_cli/cli.rb, line 243
def options_or_env(k)
  v = options[k] || ENV[env_param_name(k)]
  if v == nil || v == ""
    Log.error "missing #{k} or #{env_param_name(k)}"
    exit 1
  end
  v
end
s3_bucket() click to toggle source
# File lib/eks_cli/cli.rb, line 227
def s3_bucket; options_or_env(:s3_bucket); end
scale_nodegroup() click to toggle source
# File lib/eks_cli/cli.rb, line 137
def scale_nodegroup
  with_context do
    nodegroups.each do |ng| 
      min = (options[:min] || config.for_group(ng.name)["min"]).to_i
      max = (options[:max] || config.for_group(ng.name)["max"]).to_i
      ng.scale(min, max, options[:asg], options[:spotinst])
      Config[cluster_name].update_nodegroup(options.slice("min", "max").merge({"group_name" => ng.name})) if options[:update]
    end
  end
end
set_docker_registry_credentials(username, password, email) click to toggle source
# File lib/eks_cli/cli.rb, line 93
def set_docker_registry_credentials(username, password, email)
  with_context { K8s::Client.new(cluster_name).set_docker_registry_credentials(username, password, email) }
end
set_iam_policies() click to toggle source
# File lib/eks_cli/cli.rb, line 173
def set_iam_policies
  with_context { Config[cluster_name].set_iam_policies(options[:policies]) }
end
set_inter_vpc_networking(to_vpc_id, to_sg_id) click to toggle source
# File lib/eks_cli/cli.rb, line 186
def set_inter_vpc_networking(to_vpc_id, to_sg_id)
  with_context { VPC::Client.new(cluster_name).set_inter_vpc_networking(to_vpc_id, to_sg_id) }
end
show_config() click to toggle source
# File lib/eks_cli/cli.rb, line 72
def show_config
  with_context do
    if options[:group_name]
      puts JSON.pretty_generate(config.for_group(options[:group_name]))
    else
      puts JSON.pretty_generate(config.read_from_disk)
    end
  end
end
underline(s) click to toggle source
# File lib/eks_cli/cli.rb, line 260
def underline(s)
  "\e[4m#{s}\e[0m"
end
update_auth() click to toggle source
# File lib/eks_cli/cli.rb, line 167
def update_auth
  with_context { K8s::Auth.new(cluster_name).update }
end
update_cluster_cni() click to toggle source
# File lib/eks_cli/cli.rb, line 83
def update_cluster_cni
  with_context { K8s::Client.new(cluster_name).update_cni }
end
update_dns(hostname, k8s_service_name) click to toggle source
# File lib/eks_cli/cli.rb, line 181
def update_dns(hostname, k8s_service_name)
  with_context { Route53::Client.new(cluster_name).update_dns(hostname, k8s_service_name, options[:namespace], options[:route53_hosted_zone_id], options[:elb_hosted_zone_id]) }
end
version() click to toggle source
# File lib/eks_cli/cli.rb, line 221
def version
  puts EksCli::VERSION
end
wait_for_cluster() click to toggle source
# File lib/eks_cli/cli.rb, line 196
def wait_for_cluster
  with_context { K8s::Client.new(cluster_name).wait_for_cluster }
end
with_context() { || ... } click to toggle source
# File lib/eks_cli/cli.rb, line 229
def with_context 
  Config.s3_bucket=(s3_bucket)
  yield
end