Class: EksCli::K8s::Client

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

Constant Summary collapse

TIMEOUTS =
{open: 10, read: 20}

Instance Method Summary collapse

Constructor Details

#initialize(cluster_name) ⇒ Client

Returns a new instance of Client.



12
13
14
# File 'lib/eks_cli/k8s/client.rb', line 12

def initialize(cluster_name)
  @cluster_name = cluster_name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/eks_cli/k8s/client.rb', line 85

def method_missing(method, *args, &block)
  if v1_client.respond_to?(method)
    v1_client.send(method, *args, &block)
  elsif apps_client.respond_to?(method)
    apps_client.send(method, *args, &block)
  elsif storage_client.respond_to?(method)
    storage_client.send(method, *args, &block)
  else
    raise "unknown method #{method}"
  end
end

Instance Method Details

#create_default_storage_classObject



35
36
37
38
# File 'lib/eks_cli/k8s/client.rb', line 35

def create_default_storage_class
  Log.info "creating default storage class"
  Log.info self.create_storage_class(resource_from_yaml("k8s/default_storage_class.yaml"))
end

#create_dns_autoscalerObject



40
41
42
43
# File 'lib/eks_cli/k8s/client.rb', line 40

def create_dns_autoscaler
  Log.info "creating kube-dns autoscaler"
  Log.info self.create_deployment(resource_from_yaml("k8s/dns_autoscaler.dep.yaml"))
end

#enable_gpuObject



20
21
22
23
# File 'lib/eks_cli/k8s/client.rb', line 20

def enable_gpu
  Log.info "installing nvidia device plugin daemon set (GPU support)"
  self.create_daemon_set(resource_from_yaml("k8s/nvidia_device_plugin.yaml"))
end

#get_elb(service_name, ns = "default") ⇒ Object



16
17
18
# File 'lib/eks_cli/k8s/client.rb', line 16

def get_elb(service_name, ns = "default")
  self.get_service(service_name, ns).status.loadBalancer.ingress.first.hostname
end

#set_docker_registry_credentials(user, password, email) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/eks_cli/k8s/client.rb', line 25

def set_docker_registry_credentials(user, password, email)
  Log.info "setting docker registry credentials"
  Log.info `kubectl config use-context #{config["cluster_arn"]} &&
   kubectl create secret docker-registry registrykey --docker-server=https://index.docker.io/v1/ --docker-username=#{user} --docker-password=#{password} --docker-email=#{email} &&
   kubectl --namespace=kube-system create secret docker-registry registrykey --docker-server=https://index.docker.io/v1/ --docker-username=#{user} --docker-password=#{password} --docker-email=#{email}`

  Log.info client.("default", {imagePullSecrets: [{name: "registrykey"}]}, "default")
  Log.info client.("default", {imagePullSecrets: [{name: "registrykey"}]}, "kube-system")
end

#update_cniObject



45
46
47
48
49
# File 'lib/eks_cli/k8s/client.rb', line 45

def update_cni
  Log.info "updating cni"
  Log.info self.update_daemon_set(resource_from_erb("k8s/cni/ds.yaml.erb", {custom_warm_ip_target: config["warm_ip_target"]}))
  Log.info `kubectl config use-context #{config["cluster_arn"]} && kubectl apply -f #{file_path("/k8s/cni/rest.yaml")}`
end

#wait_for_clusterObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/eks_cli/k8s/client.rb', line 51

def wait_for_cluster
  Log.info "waiting for cluster #{@cluster_name} to respond"
  successful_calls = 0
  while successful_calls < 3
    begin
      res = self.get_services
      if res.count > 0
        successful_calls += 1
      end
    rescue Kubeclient::HttpError
      Log.info "couldn't connect to server, retrying..."
    end
  end
  Log.info "#{@cluster_name} is up and running!"
end