Sha256: c8d1f8c9a4ecf6c7cfa16beb0dcd4ef30fe1a27d6e778e077c0bf1d469f8e36a

Contents?: true

Size: 1.73 KB

Versions: 5

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true
module KubernetesDeploy
  class Redis < KubernetesResource
    TIMEOUT = 5.minutes
    UUID_ANNOTATION = "redis.stable.shopify.io/owner_uid"

    def sync
      _, _err, st = kubectl.run("get", type, @name)
      @found = st.success?
      @deployment_exists = redis_deployment_exists?
      @service_exists = redis_service_exists?

      @status = if @deployment_exists && @service_exists
        "Provisioned"
      else
        "Unknown"
      end
    end

    def deploy_succeeded?
      @deployment_exists && @service_exists
    end

    def deploy_failed?
      false
    end

    def tpr?
      true
    end

    def exists?
      @found
    end

    private

    def redis_deployment_exists?
      deployment, _err, st = kubectl.run("get", "deployments", "redis-#{redis_resource_uuid}", "-o=json")

      if st.success?
        parsed = JSON.parse(deployment)

        if parsed.fetch("status", {}).fetch("availableReplicas", -1) == parsed.fetch("status", {}).fetch("replicas", 0)
          # all redis pods are running
          return true
        end
      end

      false
    end

    def redis_service_exists?
      service, _err, st = kubectl.run("get", "services", "redis-#{redis_resource_uuid}", "-o=json")

      if st.success?
        parsed = JSON.parse(service)

        if parsed.dig("spec", "clusterIP").present?
          return true
        end
      end

      false
    end

    def redis_resource_uuid
      return @redis_resource_uuid if defined?(@redis_resource_uuid) && @redis_resource_uuid

      redis, _err, st = kubectl.run("get", "redises", @name, "-o=json")
      if st.success?
        parsed = JSON.parse(redis)

        @redis_resource_uuid = parsed.dig("metadata", "uid")
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kubernetes-deploy-0.11.2 lib/kubernetes-deploy/kubernetes_resource/redis.rb
kubernetes-deploy-0.11.1 lib/kubernetes-deploy/kubernetes_resource/redis.rb
kubernetes-deploy-0.11.0 lib/kubernetes-deploy/kubernetes_resource/redis.rb
kubernetes-deploy-0.10.1 lib/kubernetes-deploy/kubernetes_resource/redis.rb
kubernetes-deploy-0.10.0 lib/kubernetes-deploy/kubernetes_resource/redis.rb