Sha256: 057197c9da709ce373d180c7f36dc56345f7014661295d0508545096aefafdc2

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 KB

Contents

module KubeAutoAnalyzer

  def self.check_files
    require 'json'
    @log.debug ("entering File check")
    target = @options.target_server
    @results[target]['worker_files'] = Hash.new

    #Run on any nodes that aren't NoSchedule
    #Doesn't necessarily mean worker nodes, but a reasonable facsimile for now.
    nodes = Array.new
    @client.get_nodes.each do |node|
      unless node.spec.taints.to_s =~ /NoSchedule/
        nodes << node
      end
    end
    nodes.each do |nod|
      node_hostname = nod.metadata.labels['kubernetes.io/hostname']
      container_name = "kaa" + node_hostname
      pod = Kubeclient::Resource.new
      pod.metadata = {}
      pod.metadata.name = container_name
      pod.metadata.namespace = "default"
      pod.spec = {}
      pod.spec.restartPolicy = "Never"
      pod.spec.containers = {}
      pod.spec.containers = [{name: "kubeautoanalyzerfiletest", image: "raesene/kaa-agent:latest"}]
      pod.spec.volumes = [{name: 'etck8s', hostPath: {path: '/etc'}}]
      pod.spec.containers[0].volumeMounts = [{mountPath: '/etc', name: 'etck8s'}]
      pod.spec.containers[0].args = ["/file-checker.rb","/etc/kubernetes"]
      pod.spec.nodeselector = {}
      pod.spec.nodeselector['kubernetes.io/hostname'] = node_hostname
      @client.create_pod(pod)
      begin
        sleep(5) until @client.get_pod(container_name,"default")['status']['containerStatuses'][0]['state']['terminated']['reason'] == "Completed"
      rescue
        retry
      end
      files = JSON.parse(@client.get_pod_log(container_name,"default"))
      #files.each do |file|
        #Need to replace the mounted path with the real host path
      #  file[0].sub! "/hostetck8s", "/etc/kubernetes"
      #end
      @results[target]['worker_files'][node_hostname] = files
      @client.delete_pod(container_name,"default")

    end
    @log.debug("Finished Worker File Check")
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kube_auto_analyzer-0.0.1 lib/kube_auto_analyzer/agent_checks/file_checks.rb