Sha256: 0205dcb2dc551e75082a7ba4a76775135ecbdb54fd4283083c971c9757505a74

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true
module KubernetesDeploy
  class Cloudsql < KubernetesResource
    TIMEOUT = 10.minutes

    SYNC_DEPENDENCIES = %w(Deployment Service)
    def sync(mediator)
      super
      @proxy_deployment = mediator.get_instance(Deployment.kind, "cloudsql-#{cloudsql_resource_uuid}")
      @proxy_service = mediator.get_instance(Service.kind, "cloudsql-#{@name}")
    end

    def status
      deploy_succeeded? ? "Provisioned" : "Unknown"
    end

    def deploy_succeeded?
      proxy_deployment_ready? && proxy_service_ready?
    end

    def deploy_failed?
      false
    end

    private

    def proxy_deployment_ready?
      return false unless status = @proxy_deployment["status"]
      # all cloudsql-proxy pods are running
      status.fetch("availableReplicas", -1) == status.fetch("replicas", 0)
    end

    def proxy_service_ready?
      return false unless @proxy_service.present?
      # the service has an assigned cluster IP and is therefore functioning
      @proxy_service.dig("spec", "clusterIP").present?
    end

    def cloudsql_resource_uuid
      return unless @instance_data
      @instance_data.dig("metadata", "uid")
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kubernetes-deploy-0.22.0 lib/kubernetes-deploy/kubernetes_resource/cloudsql.rb
kubernetes-deploy-0.21.1 lib/kubernetes-deploy/kubernetes_resource/cloudsql.rb
kubernetes-deploy-0.21.0 lib/kubernetes-deploy/kubernetes_resource/cloudsql.rb
kubernetes-deploy-0.20.6 lib/kubernetes-deploy/kubernetes_resource/cloudsql.rb