Sha256: da8a042ddec6ba85e20431ad0b5a1145a7c6a13c3edf433c63ab7fab3aa63238

Contents?: true

Size: 1.74 KB

Versions: 3

Compression:

Stored size: 1.74 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 = {}
      pod.spec.tolerations = [{ key:"key", operator:"Equal", value:"value",effect:"NoSchedule"}]
      
      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

3 entries across 3 versions & 1 rubygems

Version Path
kube_auto_analyzer-0.0.9 lib/kube_auto_analyzer/agent_checks/file_checks.rb
kube_auto_analyzer-0.0.8 lib/kube_auto_analyzer/agent_checks/file_checks.rb
kube_auto_analyzer-0.0.7 lib/kube_auto_analyzer/agent_checks/file_checks.rb