Sha256: 20f44b645c98209b741fe7dbe3b42fc4aa717faf4f97c2d6819a7c6b38af9515

Contents?: true

Size: 1.61 KB

Versions: 10

Compression:

Stored size: 1.61 KB

Contents

module Shipit
  class DeploySpec
    module KubernetesDiscovery
      def discover_deploy_steps
        discover_kubernetes || super
      end

      def discover_rollback_steps
        discover_kubernetes || super
      end

      def discover_task_definitions
        if kube_config.present?
          {
            'restart' => {
              'action' => "Restart application",
              'description' => "Simulates a rollout of Kubernetes deployments by using kubernetes-restart utility",
              'steps' => [kubernetes_restart_cmd],
            },
          }.merge!(super)
        else
          super
        end
      end

      private

      def timeout_duration
        duration = kube_config.fetch('timeout', '900s')
        Duration.parse(duration).to_i if duration.present?
      end

      def discover_kubernetes
        return if kube_config.blank?

        cmd = ["kubernetes-deploy"]
        cmd += ["--max-watch-seconds", timeout_duration] if timeout_duration
        if kube_config['template_dir']
          cmd << '--template-dir'
          cmd << kube_config['template_dir']
        end

        cmd << kube_config.fetch('namespace')
        cmd << kube_config.fetch('context')

        [Shellwords.join(cmd)]
      end

      def kube_config
        @kube_config ||= config('kubernetes') || {}
      end

      def kubernetes_restart_cmd
        cmd = [
          "kubernetes-restart",
          kube_config.fetch('namespace'),
          kube_config.fetch('context'),
        ]
        cmd += ["--max-watch-seconds", timeout_duration] if timeout_duration
        Shellwords.join(cmd)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
shipit-engine-0.31.0 app/models/shipit/deploy_spec/kubernetes_discovery.rb
shipit-engine-0.30.0 app/models/shipit/deploy_spec/kubernetes_discovery.rb
shipit-engine-0.29.0 app/models/shipit/deploy_spec/kubernetes_discovery.rb
shipit-engine-0.28.1 app/models/shipit/deploy_spec/kubernetes_discovery.rb
shipit-engine-0.28.0 app/models/shipit/deploy_spec/kubernetes_discovery.rb
shipit-engine-0.27.1 app/models/shipit/deploy_spec/kubernetes_discovery.rb
shipit-engine-0.27.0 app/models/shipit/deploy_spec/kubernetes_discovery.rb
shipit-engine-0.26.0 app/models/shipit/deploy_spec/kubernetes_discovery.rb
shipit-engine-0.25.1 app/models/shipit/deploy_spec/kubernetes_discovery.rb
shipit-engine-0.25.0 app/models/shipit/deploy_spec/kubernetes_discovery.rb