Sha256: 3ee05b8c54d3209e12b9d624a1d7d2f9584d29c721c8cc95dbcae2d960436c37

Contents?: true

Size: 1.83 KB

Versions: 8

Compression:

Stored size: 1.83 KB

Contents

module KubeAutoAnalyzer

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


    nodes = Array.new
    @client.get_nodes.each do |node|
      nodes << node
    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"}]

      #Try the Toleration for Master
      pod.spec.tolerations = {}
      #Old version doesn't work with 1.8
      #pod.spec.tolerations = [{ key:"key", operator:"Equal", value:"value",effect:"NoSchedule"}]
      pod.spec.tolerations = [{ operator:"Exists" }]
      
      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 = {}
      begin
        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"))
      
        @results[target]['node_files'][node_hostname] = files
      ensure
        @client.delete_pod(container_name,"default")
      end

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

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
kube_auto_analyzer-0.0.17 lib/kube_auto_analyzer/agent_checks/file_checks.rb
kube_auto_analyzer-0.0.16 lib/kube_auto_analyzer/agent_checks/file_checks.rb
kube_auto_analyzer-0.0.15 lib/kube_auto_analyzer/agent_checks/file_checks.rb
kube_auto_analyzer-0.0.14 lib/kube_auto_analyzer/agent_checks/file_checks.rb
kube_auto_analyzer-0.0.13 lib/kube_auto_analyzer/agent_checks/file_checks.rb
kube_auto_analyzer-0.0.12 lib/kube_auto_analyzer/agent_checks/file_checks.rb
kube_auto_analyzer-0.0.11 lib/kube_auto_analyzer/agent_checks/file_checks.rb
kube_auto_analyzer-0.0.10 lib/kube_auto_analyzer/agent_checks/file_checks.rb