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

    def sync
      _, _err, st = kubectl.run("get", type, @name)
      @found = st.success?
      @deployment_exists = cloudsql_proxy_deployment_exists?
      @service_exists = mysql_service_exists?
      @status = if @deployment_exists && @service_exists
        "Provisioned"
      else
        "Unknown"
      end
    end

    def deploy_succeeded?
      @service_exists && @deployment_exists
    end

    def deploy_failed?
      false
    end

    def tpr?
      true
    end

    def exists?
      @found
    end

    private

    def cloudsql_proxy_deployment_exists?
      deployment, _err, st = kubectl.run("get", "deployments", "cloudsql-#{cloudsql_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 cloudsql-proxy pods are running
          return true
        end
      end

      false
    end

    def mysql_service_exists?
      service, _err, st = kubectl.run("get", "services", "mysql", "-o=json")

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

        if parsed.fetch("spec", {}).fetch("clusterIP", "") != ""
          # the service has an assigned cluster IP and is therefore functioning
          return true
        end
      end

      false
    end

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

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

        @cloudsql_resource_uuid = parsed.fetch("metadata", {}).fetch("uid", nil)
      end
    end
  end
end<commit_msg>Update Cloudsql to check for a Service named cloudsql-{{ name }}<commit_after># frozen_string_literal: true
module KubernetesDeploy
  class Cloudsql < KubernetesResource
    TIMEOUT = 10.minutes

    def sync
      _, _err, st = kubectl.run("get", type, @name)
      @found = st.success?
      @deployment_exists = cloudsql_proxy_deployment_exists?
      @service_exists = mysql_service_exists?
      @status = if @deployment_exists && @service_exists
        "Provisioned"
      else
        "Unknown"
      end
    end

    def deploy_succeeded?
      @service_exists && @deployment_exists
    end

    def deploy_failed?
      false
    end

    def tpr?
      true
    end

    def exists?
      @found
    end

    private

    def cloudsql_proxy_deployment_exists?
      deployment, _err, st = kubectl.run("get", "deployments", "cloudsql-#{cloudsql_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 cloudsql-proxy pods are running
          return true
        end
      end

      false
    end

    def mysql_service_exists?
      service, _err, st = kubectl.run("get", "services", "cloudsql-#{@name}", "-o=json")

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

        if parsed.fetch("spec", {}).fetch("clusterIP", "") != ""
          # the service has an assigned cluster IP and is therefore functioning
          return true
        end
      end

      false
    end

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

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

        @cloudsql_resource_uuid = parsed.fetch("metadata", {}).fetch("uid", nil)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11044229259356189, 'fraction_numerical': 0.002093692750588851, 'mean_word_length': 2.4967978042086, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2009067', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1178, 'n_words': 289}