› kube_cluster › Source › Kube › Helm › Repo

class Repo

Models a Helm chart repository, traditional or OCI.

Example.

repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami")
chart = repo.fetch("nginx", version: "18.1.0")
manifest = chart.apply_values({ "replicaCount" => 3 })

Example: One-liner

manifest = Kube::Helm::Repo
  .new("bitnami", url: "https://charts.bitnami.com/bitnami")
  .fetch("nginx", version: "18.1.0")
  .apply_values({ "replicaCount" => 3 })

Signature

Definitions

def initialize(name, url:, cluster: nil)

Signature

parameter name String

a local alias for this repo, e.g. "bitnami".

parameter url String

the repo URL, http(s):// or oci://.

parameter cluster Kube::Cluster::Instance, nil

an optional cluster connection.

Implementation

def initialize(name, url:, cluster: nil)
  unless name.is_a?(String) && !name.strip.empty?
    raise ArgumentError, "name must be a non-empty String"
  end

  @name     = name
  @endpoint = Endpoint.new(url)
  @cluster  = cluster
end

def add

Register this repo with the local Helm client.

Signature

returns self

self, unchanged; a no-op for OCI repos.

Implementation

def add
  tap do
    if endpoint.requires_add?
      name = @name
      url  = endpoint.url
      helm.run(
        helm.call { repo.add.(name).(url) }.to_s,
      )
    end
  end
end

def update

Update the local chart index for this repo.

Signature

returns self

self, unchanged; a no-op for OCI repos.

Implementation

def update
  tap do
    if endpoint.requires_add?
      name = @name
      helm.run(
        helm.call { repo.update.(name) }.to_s,
      )
    end
  end
end

def remove

Remove this repo from the local Helm client.

Signature

returns self

self, unchanged; a no-op for OCI repos.

Implementation

def remove
  tap do
    if endpoint.requires_add?
      name = @name
      helm.run(
        helm.call { repo.remove.(name) }.to_s,
      )
    end
  end
end

def fetch(chart_name, version: nil)

Fetch a chart from this repo, via helm show chart.

Signature

parameter chart_name String

the chart name, e.g. "nginx".

parameter version String, nil

a version constraint, e.g. "18.1.0".

returns Chart

the chart, with ref set for later helm commands.

Implementation

def fetch(chart_name, version: nil)
  add
  update

  ref = endpoint.chart_ref(chart_name, repo_name: @name)

  helm.run(
    helm.call {
      if version
        show.chart.(ref).version(version)
      else
        show.chart.(ref)
      end
    }.to_s,
  ).then do |yaml_output|
    (YAML.safe_load(yaml_output, permitted_classes: [Symbol]) || {}).then do |data|
      Chart.new(data, ref: ref, cluster: @cluster)
    end
  end
end

def oci?

Is this an OCI-backed repo?

Signature

returns Boolean

true if the repo's URL uses oci://.

Implementation

def oci?
  endpoint.oci?
end