Class: EksCli::Cli

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

Instance Method Summary collapse

Instance Method Details

#add_iam_user(iam_arn) ⇒ Object



194
195
196
197
# File 'lib/eks_cli/cli.rb', line 194

def add_iam_user(iam_arn)
  Config[cluster_name].add_user(iam_arn, options[:username], options[:groups])
  K8s::Auth.new(cluster_name).update if options[:yes]
end

#createObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/eks_cli/cli.rb', line 44

def create
  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

#create_default_storage_classObject



90
91
92
# File 'lib/eks_cli/cli.rb', line 90

def create_default_storage_class
  K8s::Client.new(cluster_name).create_default_storage_class
end

#create_dns_autoscalerObject



173
174
175
# File 'lib/eks_cli/cli.rb', line 173

def create_dns_autoscaler
  K8s::Client.new(cluster_name).create_dns_autoscaler
end

#create_nodegroupObject



108
109
110
111
112
113
114
115
116
117
# File 'lib/eks_cli/cli.rb', line 108

def create_nodegroup
  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

#delete_clusterObject



137
138
139
# File 'lib/eks_cli/cli.rb', line 137

def delete_cluster
  EKS::Cluster.new(cluster_name).delete
end

#delete_nodegroupObject



144
145
146
# File 'lib/eks_cli/cli.rb', line 144

def delete_nodegroup
  nodegroups.each(&:delete)
end

#enable_gpuObject



80
81
82
# File 'lib/eks_cli/cli.rb', line 80

def enable_gpu
  K8s::Client.new(cluster_name).enable_gpu
end

#export_nodegroupObject



186
187
188
# File 'lib/eks_cli/cli.rb', line 186

def export_nodegroup
  nodegroups.each {|ng| ng.export_to_spotinst(options[:exact_instance_type]) }
end

#scale_nodegroupObject



127
128
129
130
131
132
133
134
# File 'lib/eks_cli/cli.rb', line 127

def scale_nodegroup
  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

#set_docker_registry_credentials(username, password, email) ⇒ Object



85
86
87
# File 'lib/eks_cli/cli.rb', line 85

def set_docker_registry_credentials(username, password, email)
  K8s::Client.new(cluster_name).set_docker_registry_credentials(username, password, email)
end

#set_iam_policiesObject



155
156
157
# File 'lib/eks_cli/cli.rb', line 155

def set_iam_policies
  Config[cluster_name].set_iam_policies(options[:policies])
end

#set_inter_vpc_networking(to_vpc_id, to_sg_id) ⇒ Object



168
169
170
# File 'lib/eks_cli/cli.rb', line 168

def set_inter_vpc_networking(to_vpc_id, to_sg_id)
  VPC::Client.new(cluster_name).set_inter_vpc_networking(to_vpc_id, to_sg_id)
end

#show_configObject



66
67
68
69
70
71
72
# File 'lib/eks_cli/cli.rb', line 66

def show_config
  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

#update_authObject



149
150
151
# File 'lib/eks_cli/cli.rb', line 149

def update_auth
  K8s::Auth.new(cluster_name).update
end

#update_cluster_cniObject



75
76
77
# File 'lib/eks_cli/cli.rb', line 75

def update_cluster_cni
  K8s::Client.new(cluster_name).update_cni
end

#update_dns(hostname, k8s_service_name) ⇒ Object



163
164
165
# File 'lib/eks_cli/cli.rb', line 163

def update_dns(hostname, k8s_service_name)
  Route53::Client.new(cluster_name).update_dns(hostname, k8s_service_name, options[:namespace], options[:route53_hosted_zone_id], options[:elb_hosted_zone_id])
end

#versionObject



201
202
203
# File 'lib/eks_cli/cli.rb', line 201

def version
  puts EksCli::VERSION
end

#wait_for_clusterObject



178
179
180
# File 'lib/eks_cli/cli.rb', line 178

def wait_for_cluster
  K8s::Client.new(cluster_name).wait_for_cluster
end