Sha256: ad8776f849ecb39dcb275dd6d5f824e2ca094fe82009ae889146f8d3903e77f1

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true
require 'kubernetes-deploy/kubernetes_resource/pod_set_base'
module KubernetesDeploy
  class DaemonSet < PodSetBase
    TIMEOUT = 5.minutes
    attr_reader :pods

    SYNC_DEPENDENCIES = %w(Pod)
    def sync(mediator)
      super
      @pods = exists? ? find_pods(mediator) : []
    end

    def status
      return super unless exists?
      rollout_data.map { |state_replicas, num| "#{num} #{state_replicas}" }.join(", ")
    end

    def deploy_succeeded?
      return false unless exists?
      rollout_data["desiredNumberScheduled"].to_i == rollout_data["currentNumberScheduled"].to_i &&
      rollout_data["desiredNumberScheduled"].to_i == rollout_data["numberReady"].to_i &&
      current_generation == observed_generation
    end

    def deploy_failed?
      pods.present? && pods.any?(&:deploy_failed?)
    end

    def fetch_logs(kubectl)
      return {} unless pods.present?
      most_useful_pod = pods.find(&:deploy_failed?) || pods.find(&:deploy_timed_out?) || pods.first
      most_useful_pod.fetch_logs(kubectl)
    end

    private

    def current_generation
      return -1 unless exists? # must be different default than observed_generation
      @instance_data["metadata"]["generation"]
    end

    def observed_generation
      return -2 unless exists?
      @instance_data["status"]["observedGeneration"]
    end

    def rollout_data
      return { "currentNumberScheduled" => 0 } unless exists?
      @instance_data["status"]
        .slice("currentNumberScheduled", "desiredNumberScheduled", "numberReady")
    end

    def parent_of_pod?(pod_data)
      return false unless pod_data.dig("metadata", "ownerReferences")
      pod_data["metadata"]["ownerReferences"].any? { |ref| ref["uid"] == @instance_data["metadata"]["uid"] } &&
      pod_data["metadata"]["labels"]["pod-template-generation"].to_i ==
        @instance_data["spec"]["templateGeneration"].to_i
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kubernetes-deploy-0.20.0 lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb
kubernetes-deploy-0.19.0 lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb
kubernetes-deploy-0.18.1 lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb